| 1 | # The "Artistic License" | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Preamble | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # The intent of this document is to state the conditions under which a | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Package may be copied, such that the Copyright Holder maintains some | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # semblance of artistic control over the development of the package, | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # while giving the users of the package the right to use and distribute | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # the Package in a more-or-less customary fashion, plus the right to make | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # reasonable modifications. | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # Definitions: | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # "Package" refers to the collection of files distributed by the | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # Copyright Holder, and derivatives of that collection of files | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # created through textual modification. | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # "Standard Version" refers to such a Package if it has not been | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # modified, or has been modified in accordance with the wishes | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # of the Copyright Holder as specified below. | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # "Copyright Holder" is whoever is named in the copyright or | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # copyrights for the package. | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # "You" is you, if you're thinking about copying or distributing | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # this Package. | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # "Reasonable copying fee" is whatever you can justify on the | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # basis of media cost, duplication charges, time of people involved, | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # and so on. (You will not be required to justify it to the | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Copyright Holder, but only to the computing community at large | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # as a market that must bear the fee.) | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # "Freely Available" means that no fee is charged for the item | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # itself, though there may be fees involved in handling the item. | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # It also means that recipients of the item may redistribute it | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # under the same conditions they received it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # 1. You may make and give away verbatim copies of the source form of the | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # Standard Version of this Package without restriction, provided that you | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # duplicate all of the original copyright notices and associated disclaimers. | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # 2. You may apply bug fixes, portability fixes and other modifications | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # derived from the Public Domain or from the Copyright Holder. A Package | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # modified in such a way shall still be considered the Standard Version. | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # 3. You may otherwise modify your copy of this Package in any way, provided | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # that you insert a prominent notice in each changed file stating how and | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # when you changed that file, and provided that you do at least ONE of the | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # following: | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # a) place your modifications in the Public Domain or otherwise make them | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # Freely Available, such as by posting said modifications to Usenet or | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # an equivalent medium, or placing the modifications on a major archive | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # site such as uunet.uu.net, or by allowing the Copyright Holder to include | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # your modifications in the Standard Version of the Package. | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # b) use the modified Package only within your corporation or organization. | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # c) rename any non-standard executables so the names do not conflict | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # with standard executables, which must also be provided, and provide | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # a separate manual page for each non-standard executable that clearly | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # documents how it differs from the Standard Version. | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # d) make other distribution arrangements with the Copyright Holder. | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # 4. You may distribute the programs of this Package in object code or | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # executable form, provided that you do at least ONE of the following: | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # a) distribute a Standard Version of the executables and library files, | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # together with instructions (in the manual page or equivalent) on where | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # to get the Standard Version. | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # b) accompany the distribution with the machine-readable source of | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # the Package with your modifications. | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # c) give non-standard executables non-standard names, and clearly | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # document the differences in manual pages (or equivalent), together | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # with instructions on where to get the Standard Version. | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # d) make other distribution arrangements with the Copyright Holder. | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # 5. You may charge a reasonable copying fee for any distribution of this | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # Package. You may charge any fee you choose for support of this | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Package. You may not charge a fee for this Package itself. However, | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # you may distribute this Package in aggregate with other (possibly | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # commercial) programs as part of a larger (possibly commercial) software | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # distribution provided that you do not advertise this Package as a | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # product of your own. You may embed this Package's interpreter within | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # an executable of yours (by linking); this shall be construed as a mere | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # form of aggregation, provided that the complete Standard Version of the | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # interpreter is so embedded. | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # 6. The scripts and library files supplied as input to or produced as | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # output from the programs of this Package do not automatically fall | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # under the copyright of this Package, but belong to whoever generated | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # them, and may be sold commercially, and may be aggregated with this | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # Package. If such scripts or library files are aggregated with this | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Package via the so-called "undump" or "unexec" methods of producing a | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # binary executable image, then distribution of such an image shall | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # neither be construed as a distribution of this Package nor shall it | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # fall under the restrictions of Paragraphs 3 and 4, provided that you do | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # not represent such an executable image as a Standard Version of this | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Package. | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # 7. C subroutines (or comparably compiled subroutines in other | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # languages) supplied by you and linked into this Package in order to | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # emulate subroutines and variables of the language defined by this | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # Package shall not be considered part of this Package, but are the | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # equivalent of input as in Paragraph 6, provided these subroutines do | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # not change the language in any way that would cause it to fail the | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # regression tests for the language. | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # 8. Aggregation of this Package with a commercial distribution is always | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # permitted provided that the use of this Package is embedded; that is, | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # when no overt attempt is made to make this Package's interfaces visible | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # to the end user of the commercial distribution. Such use shall not be | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # construed as a distribution of this Package. | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # 9. The name of the Copyright Holder may not be used to endorse or promote | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # products derived from this software without specific prior written permission. | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | package Net::validMX; | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 7 | ▶ | use Net::DNS; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 7 | ▶ | use vars qw( | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | $VERSION | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | @ISA | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | @EXPORT_OK | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | $DEBUG | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | $ALLOW_IP_ADDRESS_AS_MX | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | $FLAG_INTRANETS | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | $RESOLUTION_PROBLEM_RETURN | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 7 | $QUERY_TIMEOUT); | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 7 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 7 | require DynaLoader; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 7 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 7 | @ISA = qw(Exporter DynaLoader); | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | 7 | $VERSION = '2.5.2'; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | 7 | $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | 7 | $ALLOW_IP_ADDRESS_AS_MX = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 7 | $FLAG_INTRANETS = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | 7 | $RESOLUTION_PROBLEM_RETURN = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 7 | $QUERY_TIMEOUT = 4; | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub version { $VERSION; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 7 | @EXPORT_OK = qw(check_valid_mx get_output_result check_email_and_mx check_email_validity get_domain_from_email); | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=31.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | my $self = bless {}, shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | $DEBUG = $self->{'debug'} if (defined $self->{'debug'} and $self->{'debug'} ne ''); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"debug"} and $self->{"debug"} ne ""
MC/DC0%0/2
defined $self->{"debug"} and $self->{"debug"} ne ""
defined $self->{"debug"}
$self->{"debug"} ne ""
Truth table33%1/3
A and B
A= defined $self->{"debug"}B= $self->{"debug"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | ▶ | $ALLOW_IP_ADDRESS_AS_MX = $self->{'allow_ip_address_as_mx'} if (defined $self->{'allow_ip_address_as_mx'} and $self->{'allow_ip_address_as_mx'} ne ''); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"allow_ip_address_as_mx"} and $self->{"allow_ip_address_as_mx"} ne ""
MC/DC0%0/2
defined $self->{"allow_ip_address_as_mx"} and $self->{"allow_ip_address_as_mx"} ne ""
defined $self->{"allow_ip_address_as_mx"}
$self->{"allow_ip_address_as_mx"} ne ""
Truth table33%1/3
A and B
A= defined $self->{"allow_ip_address_as_mx"}B= $self->{"allow_ip_address_as_mx"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | ▶ | $FLAG_INTRANETS = $self->{'flag_intranets'} if (defined $self->{'flag_intranets'} and $self->{'flag_intranets'} ne ''); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"flag_intranets"} and $self->{"flag_intranets"} ne ""
MC/DC0%0/2
defined $self->{"flag_intranets"} and $self->{"flag_intranets"} ne ""
defined $self->{"flag_intranets"}
$self->{"flag_intranets"} ne ""
Truth table33%1/3
A and B
A= defined $self->{"flag_intranets"}B= $self->{"flag_intranets"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | $RESOLUTION_PROBLEM_RETURN = $self->{'resolution_problem_return'} if (defined $self->{'resolution_problem_return'} and $self->{'resolution_problem_return'} ne ''); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"resolution_problem_return"} and $self->{"resolution_problem_return"} ne ""
MC/DC0%0/2
defined $self->{"resolution_problem_return"} and $self->{"resolution_problem_return"} ne ""
defined $self->{"resolution_problem_return"}
$self->{"resolution_problem_return"} ne ""
Truth table33%1/3
A and B
A= defined $self->{"resolution_problem_return"}B= $self->{"resolution_problem_return"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | $QUERY_TIMEOUT = $self->{'query_timeout'} if (defined $self->{'query_timeout'} and $self->{'query_timeout'} ne ''); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"query_timeout"} and $self->{"query_timeout"} ne ""
MC/DC0%0/2
defined $self->{"query_timeout"} and $self->{"query_timeout"} ne ""
defined $self->{"query_timeout"}
$self->{"query_timeout"} ne ""
Truth table33%1/3
A and B
A= defined $self->{"query_timeout"}B= $self->{"query_timeout"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub get_debug { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_debug: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | return $DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub set_debug { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_debug: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my $debug = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $DEBUG = $debug; | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 37 | ▶ | sub get_output_result { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_output_result: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 37 | my ($email, $rv, $reason) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 37 | my ($output); | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 37 | $output = "$email\n\tValid MX? ".Net::validMX::int_to_truefalse($rv); | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 37 | ▶ | if ($reason ne '') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 13 | $output .= " - $reason"; | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 37 | $output .= "\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 37 | return $output; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 36 | ▶ | sub check_valid_mx { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_valid_mx: called CC=93 SCAR=61.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | #Based on Idea from Les Miksell and much input from Jan Pieter Cornet | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | #KAM 9-12-05 updated 10-24-05 & 11-3-05. | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | #takes the email address, extracts the domain name and performs multiple MX tests to see if the domain has valid | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | #MX exchange records | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 36 | my ($res, $packet, @answer, $domain, @answer2, @answer3, $rv, $reason, $i, @unsorted_answer); | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 36 | my ($check_implicit_mx, %params, $self, $ref, $resolution_problem_status); | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | #print "DEBUG: ref for \$_[0] ".ref($_[0]). "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | #IN OO INSTEAD OF PROCEDURAL MODE? | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 36 | ▶ | if (uc(ref($_[0])) eq 'NET::VALIDMX') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | $self = shift(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | #foreach $ref (keys %$self) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # print "DEBUG: OO MODE - $ref: $self->{$ref} \n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | #} | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | #DID WE RECEIVE A HASH INSTEAD OF A SINGLE EMAIL? | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 36 | ▶ | if ($#_ % 2 == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 34 | ($params{'email'}) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | %params = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 36 | ▶ | $params{'email'} || $params{'sender'} || return (0, 'A blank email address will not be tested.'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$params{"email"} or $params{"sender"}
MC/DC0%0/2
$params{"email"} or $params{"sender"}
$params{"email"}
$params{"sender"}
Truth table33%1/3
A or B
A= $params{"email"}B= $params{"sender"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | #CONSTANTS / SETTABLE OPTIONS | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 36 | ▶ | $params{'debug'} = $DEBUG unless (defined $params{'debug'}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 36 | ▶ | $params{'allow_ip_address_as_mx'} = $ALLOW_IP_ADDRESS_AS_MX unless (defined $params{'allow_ip_address_as_mx'}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 36 | ▶ | $params{'resolution_problem_return'} = $RESOLUTION_PROBLEM_RETURN unless (defined $params{'resolution_problem_return'}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 36 | ▶ | $params{'query_timeout'} = $QUERY_TIMEOUT unless (defined $params{'query_timeout'}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 36 | ▶ | if ($params{'resolution_problem_return'} > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 36 | $resolution_problem_status = 'Passed'; | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $resolution_problem_status = 'Failed'; | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 36 | ▶ | print "DEBUG: function debug setting is $params{'debug'}\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 36 | ▶ | print "DEBUG: function allow_ip_address_as_mx setting is $params{'allow_ip_address_as_mx'}\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 36 | ▶ | print "DEBUG: function resolution_problem_return setting is $params{'resolution_problem_return'}\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 36 | ▶ | print "DEBUG: function query_timeout setting is $params{'query_timeout'}\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | #FLAGS - I THINK THIS HAS A LOGIC ISSUE - I LIKELY MEANT ALLOW_IMPLICIT_MX as an option FIX | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 36 | $check_implicit_mx = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | #Setup a DNS Resolver Resource | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 36 | $res = Net::DNS::Resolver->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 36 | ▶ | if (defined ($res)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 36 | $check_implicit_mx = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 247 | 36 | $res->defnames(0); #Turn off appending the default domain for names that have no dots just in case | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | 36 | $res->searchlist(); #Set the search list to undefined just in case | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | #We have also set the default timeout to only 4 seconds which means we might get network | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | #delays which we do not want to handle as an error. | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 36 | $res->tcp_timeout($params{'query_timeout'}); #Number of Seconds before query will fail | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 36 | $res->udp_timeout($params{'query_timeout'}); #Number of Seconds before query will fail | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | #Strip domain name from an email address | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 36 | $domain = get_domain_from_email($params{'email'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | #Deny Explicit IP Address Domains | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 36 | ▶ | if ($domain =~ /^\[.*\]$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | $reason = "Use of IP Address $domain instead of a hostname is not allowed"; | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | ▶ | print "DEBUG: Test Failed - $reason\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | #Perform the DNS Query - Changed to Send instead of Query method to utilize the ancount method | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 35 | $packet = $res->send($domain,'MX'); | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | #Net::DNS::Resolver had an error | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 35 | ▶ | if (!defined $packet) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | print "DEBUG: There was an error retrieving the MX Records for $domain\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | print "DEBUG: Test Passed by Default\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | return($params{'resolution_problem_return'}, "Test $resolution_problem_status due to a Resolution Problem retrieving the MX Records"); | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 35 | ▶ | print "DEBUG: Number of Answers in the MX resolution packet is: ".$packet->header->ancount."\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | #Parse the Query | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 35 | ▶ | if ($packet->header->ancount > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 33 | ▶ | if (defined ($packet->answer)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 33 | @answer = $packet->answer; | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 33 | ▶ | for ($i = 0; $i < scalar(@answer); $i++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 43 | ▶ | if ($answer[$i]->type ne 'MX') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | #DISCARD ANSWER IF THE RECORD IS NOT AN MX RECORD SUCH AS THE CNAME FOR londo.cysticercus.com | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 4 | ▶ | print "DEBUG: Discarding one non-MX answer of type: ".$answer[$i]->type."\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 39 | push @unsorted_answer, $answer[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 33 | undef @answer; | |||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 33 | ▶ | print "DEBUG: Number of Answers Left to Check after discarding all but MX: ".scalar(@unsorted_answer)."\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 33 | ▶ | if (scalar(@unsorted_answer) < 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 2 | $check_implicit_mx++; | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | #Sort to put answers into ascending order by mail exchange preference | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 31 | @answer = sort {$a->preference <=> $b->preference} @unsorted_answer; | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | #LOOP THROUGH THE ANSWERS WE HAVE | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 33 | ▶ | for ($i = 0; $i < scalar(@answer); $i++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 38 | undef $packet; | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | 38 | ▶ | print "DEBUG: $i - MX Answer - Type: ".$answer[$i]->type." - Exchange: ".$answer[$i]->exchange." - Length: ".length($answer[$i]->exchange)."\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | #localhost isn't a valid MX so return false | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 38 | ▶ | if ($answer[$i]->exchange eq 'localhost') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | $reason = 'Invalid use of Localhost as an MX record'; | |||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | print "DEBUG: Test Failed - $reason\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | #IF the exchange is blank and the priority is 0 and it's the last answer, let's fail | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 38 | ▶ | if ($answer[$i]->exchange eq '' && int($answer[$i]->preference) == 0 && $i == $#answer) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$answer[$i]->exchange eq "" and int $answer[$i]->preference == 0 and $i == $#answer
$answer[$i]->exchange eq "" and int $answer[$i]->preference == 0
MC/DC0%0/3
$answer[$i]->exchange eq "" and int $answer[$i]->preference == 0 and $i == $#answer
$answer[$i]->exchange eq ""
int $answer[$i]->preference == 0
$i == $#answer
Truth table25%1/4
A and B and C
A= $answer[$i]->exchange eq ""B= int $answer[$i]->preference == 0C= $i == $#answer
| |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | #Test if there is a Blank MX record in the first slot Per Jan-Pieter Cornet recommendation | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | #and based on http://ietfreport.isoc.org/all-ids/draft-delany-nullmx-00.txt | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $reason = 'Domain is publishing a blank MX record at Priority 0'; | |||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | print "DEBUG: Test Failed - $reason\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | #resolve the exchange record | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 38 | ▶ | if ($answer[$i]->exchange ne '' and $answer[$i]->exchange !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$answer[$i]->exchange ne "" and not $answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
MC/DC50%1/2
$answer[$i]->exchange ne "" and not $answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
$answer[$i]->exchange ne ""
not $answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
Truth table66%2/3
A and not(B)
A= $answer[$i]->exchange ne ""B= not $answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 36 | $packet = $res->send($answer[$i]->exchange, 'A'); | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 36 | ▶ | if (!defined ($packet)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | #THERE WAS AN ERROR TRYING TO RESOLVE THE MAIL EXCHANGE | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | print "DEBUG: Test Passed by Default\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | return ($params{'resolution_problem_return'}, 'Test '.$resolution_problem_status.' due to a Resolution Problem'); | |||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 36 | ▶ | print "DEBUG: $i - Number of Answers in the MX->A resolution packet is: ".$packet->header->ancount."\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | #TEST TO SEE IF IT'S AN AAAA IPv6 RECORD - Thanks to Subramanian MOONESAMY sm@megawatt.resistor.net for pointing this out! | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 36 | ▶ | if (defined $packet && $packet->header->ancount < 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $packet and $packet->header->ancount < 1
MC/DC50%1/2
defined $packet and $packet->header->ancount < 1
defined $packet
$packet->header->ancount < 1
Truth table66%2/3
A and B
A= defined $packetB= $packet->header->ancount < 1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 7 | $packet = $res->send($answer[$i]->exchange, 'AAAA'); | |||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 7 | ▶ | if (!defined ($packet)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | #THERE WAS AN ERROR TRYING TO RESOLVE THE MAIL EXCHANGE | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | print "DEBUG: Test Passed by Default\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | return ($params{'resolution_problem_return'}, 'Test '.$resolution_problem_status.' due to a Resolution Problem'); | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 7 | ▶ | print "DEBUG: $i - Number of Answers in the MX->AAAA resolution packet is: ".$packet->header->ancount."\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 38 | ▶ | if (defined $packet && $packet->header->ancount > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $packet and $packet->header->ancount > 0
MC/DC100%2/2
defined $packet and $packet->header->ancount > 0
defined $packet
$packet->header->ancount > 0
Truth table100%3/3
A and B
A= defined $packetB= $packet->header->ancount > 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 31 | @answer2 = $packet->answer; | |||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 31 | ▶ | print "DEBUG: $i - Resolution type of ".$answer[$i]->exchange.": ".$answer2[0]->type."\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 31 | ▶ | if ($answer2[0]->type =~ /^A{1,4}/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 29 | ▶ | print "DEBUG: $i - A Name Address for ".$answer[$i]->exchange.": ".$answer2[0]->address."\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 29 | ($rv, $reason) = invalid_mx($answer2[0]->address); | |||||||||||||||||||||||||||||||||||||||||||||
| 352 | 29 | ▶ | if ($rv == 1 or ($rv == 2 && $i == $#answer)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
$rv == 1 or $rv == 2 and $i == $#answer
$rv == 2 and $i == $#answer
MC/DC100%3/3
$rv == 1 or $rv == 2 and $i == $#answer
$rv == 1
$rv == 2
$i == $#answer
Truth table100%4/4
A or B and C
A= $rv == 1B= $rv == 2C= $i == $#answer
| |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 2 | ▶ | if ($rv == 2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | $reason .= ' - All MX Records Failed'; | |||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 2 | ▶ | print "DEBUG: Test Failed - $reason\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 2 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 358 | } elsif ($rv < 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 22 | ▶ | print "DEBUG: Test Passed ".$answer2[0]->address." looks good\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 22 | return (1, ''); | |||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } elsif ($answer2[0]->type eq "CNAME") { | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 2 | $packet = $res->send($answer2[0]->cname,'A'); | |||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 2 | ▶ | if (!defined ($packet)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | #THERE WAS AN ERROR TRYING TO RESOLVE THE CNAME FOR THE MAIL EXCHANGE | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | print "DEBUG: Test Passed by Default\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | return ($params{'resolution_problem_return'}, 'Test '.$resolution_problem_status.' due to a Resolution Problem'); | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | ▶ | if ($packet->header->ancount > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 2 | ▶ | if (defined ($packet->answer)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 2 | @answer3 = $packet->answer; | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | 2 | ▶ | print "DEBUG: $i - CNAME Resolution of Type: ".$answer3[0]->type." - Address: ".$answer3[0]->address."\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 2 | ▶ | if ($answer3[0]->type eq "A") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | ($rv, $reason) = invalid_mx($answer3[0]->address); | |||||||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | ▶ | if ($rv == 1 or ($rv == 2 && $i == $#answer)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
$rv == 1 or $rv == 2 and $i == $#answer
$rv == 2 and $i == $#answer
MC/DC0%0/3
$rv == 1 or $rv == 2 and $i == $#answer
$rv == 1
$rv == 2
$i == $#answer
Truth table25%1/4
A or B and C
A= $rv == 1B= $rv == 2C= $i == $#answer
| |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | if ($rv == 2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $reason .= ' - All MX Records Failed'; | |||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | print "DEBUG: Test Failed - $reason\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 383 | } elsif ($rv < 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | ▶ | print "DEBUG: Test Passed ".$answer3[0]->address." looks good\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | return (1,''); | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | #CNAMEs aren't RFC valid for MX's so if they chained two together, I'm not recursively resolving anymore levels, I'm just failing it | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | $reason = 'Invalid use of CNAME for MX record'; | |||||||||||||||||||||||||||||||||||||||||||||
| 390 | 1 | ▶ | print "DEBUG: Test Failed - $reason\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | if ($params{'allow_ip_address_as_mx'} > 0 && $answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$params{"allow_ip_address_as_mx"} > 0 and $answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
MC/DC0%0/2
$params{"allow_ip_address_as_mx"} > 0 and $answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
$params{"allow_ip_address_as_mx"} > 0
$answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
Truth table0%0/3
A and B
A= $params{"allow_ip_address_as_mx"} > 0B= $answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ($rv, $reason) = invalid_mx($answer[$i]->exchange); | |||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 399 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | print "DEBUG: Test Passed - Allowing IP Address as Hostname\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | return (1, ''); | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | #MX RECORD IS A CNAME WHICH DOES NOT RESOLVE | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $reason = "MX Record: ".$answer2[0]->cname." does not resolve"; | |||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | print "DEBUG: Test Failed - $reason\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } else { # ! $packet->header->ancount > 0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | #IF THIS IS THE LAST MX RECORD AND THE EXCHANGE IS BLANK, WE FAIL IT | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 7 | ▶ | if ($answer[$i]->exchange eq '') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | if ($i == $#answer) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $reason = 'Domain is publishing only invalid and/or blank MX records'; | |||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | print "DEBUG: Test Failed - $reason\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | #PERHAPS WE'LL ALLOW AN IP ADDRESS AS AN MX FOR CLOWNS WHO CONFIGURE DNS INCORRECTLY | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 7 | ▶ | if ($params{'allow_ip_address_as_mx'} > 0 && $answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$params{"allow_ip_address_as_mx"} > 0 and $answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
MC/DC50%1/2
$params{"allow_ip_address_as_mx"} > 0 and $answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
$params{"allow_ip_address_as_mx"} > 0
$answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
Truth table66%2/3
A and B
A= $params{"allow_ip_address_as_mx"} > 0B= $answer[$i]->exchange =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2 | ($rv, $reason) = invalid_mx($answer[$i]->exchange); | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | 2 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 1 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 426 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 1 | ▶ | print "DEBUG: Test Passed - Allowing IP Address as Hostname\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 1 | return (1, ''); | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # Keep looping, unless this was the last answer in the MX | ||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # resolution packet. | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # XXX $packet->header->ancount, in the case of corrupt packets, | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # may differ from the actual number of records and may return unwanted failures | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 5 | ▶ | if ($i == $#answer) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | #MX RECORD RETURNED DOES NOT RESOLVE | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 3 | $reason = "MX Record: ".$answer[$i]->exchange." does not resolve"; | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | 3 | ▶ | print "DEBUG: Test Failed - $reason\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 3 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } # for | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 2 | ($rv, $reason) = $check_implicit_mx++; | |||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 4 | ▶ | print "DEBUG: Checking Implicit MX is set to $check_implicit_mx\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 4 | ▶ | if ($check_implicit_mx > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 4 | ($rv, $reason) = check_implicit_mx($domain, $res, $params{'debug'}, $params{'resolution_problem_return'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 456 | 4 | ▶ | if (defined $rv) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 4 | return ($rv, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | print "DEBUG: There was an error setting up a Net::DNS::Resolver resource\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | print "DEBUG: Test Passed by Default\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | return ($params{'resolution_problem_return'}, 'Test '.$resolution_problem_status.' due to a Resolution Problem'); | |||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | print "DEBUG: Test Passed\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | return (1,''); | |||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 4 | ▶ | sub check_implicit_mx { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_implicit_mx: called CC=26 SCAR=41.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 4 | my ($SenderDomain, $res, $debug, $resolution_problem_return) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 4 | my ($rv, $reason, $packet, @answer, @answer2, $resolution_problem_status); | |||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | #CONSTANTS/SETTABLE OPTIONS | ||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 4 | ▶ | $resolution_problem_return ||= $RESOLUTION_PROBLEM_RETURN; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$resolution_problem_return ||= $Net::validMX::RESOLUTION_PROBLEM_RETURN
MC/DC0%0/2
$resolution_problem_return ||= $Net::validMX::RESOLUTION_PROBLEM_RETURN
$resolution_problem_return
$Net::validMX::RESOLUTION_PROBLEM_RETURN
Truth table33%1/3
A ||= B
A= $resolution_problem_returnB= $Net::validMX::RESOLUTION_PROBLEM_RETURN
| |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 4 | ▶ | if ($resolution_problem_return > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 4 | $resolution_problem_status = 'Passed'; | |||||||||||||||||||||||||||||||||||||||||||||
| 480 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | $resolution_problem_status = 'Failed'; | |||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 4 | ▶ | print "DEBUG: Checking for Implicit MX Records\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | #NO MX RECORDS RETURNED - CHECK FOR IMPLICIT MX RECORD BY A RECORD per Jan-Pieter Cornet recommendation | ||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 4 | $packet = $res->send($SenderDomain,'A'); | |||||||||||||||||||||||||||||||||||||||||||||
| 487 | 4 | ▶ | if (!defined ($packet)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | #THERE WAS AN ERROR - NO IMPLICIT A RECORD COULD BE RESOLVED | ||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | print "DEBUG: Test Passed by Default\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | return ($resolution_problem_return, 'Test '.$resolution_problem_status.' due to a Resolution Problem'); | |||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 4 | ▶ | print "DEBUG: Number of Answers in the Implicit A record resolution packet is: ".$packet->header->ancount."\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 4 | ▶ | if ($packet->header->ancount > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 3 | @answer = $packet->answer; | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | 3 | ▶ | if ($answer[0]->type eq "A") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 1 | ▶ | print "DEBUG: $SenderDomain has no MX Records - Using Implicit A Record: ".$answer[0]->address."\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | ($rv, $reason) = invalid_mx($answer[0]->address); | |||||||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | ▶ | if ($rv) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | print "DEBUG: Test Failed - $reason\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 502 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 1 | ▶ | print "DEBUG: Test Passed ".$answer[0]->address." looks good\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 1 | return (1, ''); | |||||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } elsif ($answer[0]->type eq "CNAME") { | ||||||||||||||||||||||||||||||||||||||||||||||
| 507 | #IS THIS REALLY A NECESSARY TEST? SHOULD WE BE TESTING FOR IMPLICIT CNAME RECORDS? | ||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 2 | ▶ | print "DEBUG: $SenderDomain has no MX Records - Using CNAME to Check for Implicit A Record: ".$answer[0]->cname."\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 2 | $packet = $res->send($answer[0]->cname,'A'); | |||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 2 | ▶ | if (!defined ($packet)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 512 | #THERE WAS AN ERROR TRYING TO RESOLVE THE CNAME FOR THE MAIL EXCHANGE | ||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | print "DEBUG: Test Passed by Default\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | return (1, ''); | |||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 2 | ▶ | if ($packet->header->ancount > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 2 | ▶ | if (defined ($packet->answer)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 2 | @answer2 = $packet->answer; | |||||||||||||||||||||||||||||||||||||||||||||
| 520 | 2 | ▶ | if ($answer2[0]->type eq "A") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | ▶ | print "DEBUG: CNAME Resolution of Type: ".$answer2[0]->type." - Address: ".$answer2[0]->address."\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 1 | ($rv, $reason) = invalid_mx($answer2[0]->address); | |||||||||||||||||||||||||||||||||||||||||||||
| 523 | 1 | ▶ | if ($rv > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | ▶ | print "DEBUG: Test Failed - $reason\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 526 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | ▶ | print "DEBUG: Test Passed ".$answer2[0]->address." looks good\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 1 | return (1, ''); | |||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 531 | #CNAMEs aren't RFC valid for MX's so if they chained two together, I'm not recursively resolving anymore levels, I'm just failing it | ||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 1 | $reason = 'Invalid use of CNAME for Implicit MX record'; | |||||||||||||||||||||||||||||||||||||||||||||
| 533 | 1 | ▶ | print "DEBUG: Test Failed - $reason\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 1 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 539 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 1 | $reason = "No MX or A Records Exist for $SenderDomain"; | |||||||||||||||||||||||||||||||||||||||||||||
| 541 | 1 | ▶ | print "DEBUG: Test Failed - $reason\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 1 | return (0, $reason); | |||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 34 | ▶ | sub invalid_mx { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
invalid_mx: called CC=18 SCAR=36.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 34 | my ($ip) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 549 | 34 | my ($flag_intranets); | |||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||
| 551 | #UPDATED MORE ON 11-18-2011 based on RFC 5735 | ||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||
| 553 | #0/8, 255/8, 127/8 aren't a valid MX so return false - added per Matthew van Eerde recomendation | ||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 34 | ▶ | if ($ip =~ /^(255|127|0)\./) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | return (1, "Invalid use of 0/8, 255/8 or 127/8 ($ip) as an MX record"); | |||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 34 | $flag_intranets = $FLAG_INTRANETS; | |||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||
| 560 | #10/8 | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 34 | ▶ | if ($flag_intranets && $ip =~ /^10\./) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$flag_intranets and $ip =~ /^10\./
MC/DC50%1/2
$flag_intranets and $ip =~ /^10\./
$flag_intranets
$ip =~ /^10\./
Truth table66%2/3
A and B
A= $flag_intranetsB= $ip =~ /^10\./
| |||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 3 | return (2, "Invalid use of private IP (e.g. $ip) range for MX"); | |||||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 564 | #172.16/12 - Fixed per Matthen van Eerde | ||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 31 | ▶ | if ($flag_intranets && $ip =~ /^172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\./) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$flag_intranets and $ip =~ /^172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\./
MC/DC0%0/2
$flag_intranets and $ip =~ /^172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\./
$flag_intranets
$ip =~ /^172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\./
Truth table33%1/3
A and B
A= $flag_intranetsB= $ip =~ /^172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\./
| |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | return (2, "Invalid use of private IP (e.g. $ip) range for MX"); | |||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 568 | #192.168/16 | ||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 31 | ▶ | if ($flag_intranets && $ip =~ /^192\.168\./) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$flag_intranets and $ip =~ /^192\.168\./
MC/DC50%1/2
$flag_intranets and $ip =~ /^192\.168\./
$flag_intranets
$ip =~ /^192\.168\./
Truth table66%2/3
A and B
A= $flag_intranetsB= $ip =~ /^192\.168\./
| |||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 4 | return (2, "Invalid use of private IP (e.g. $ip) range for MX"); | |||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||
| 573 | #fc00::/7 | ||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 27 | ▶ | if ($flag_intranets && $ip =~ /^fc00\:0\:/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$flag_intranets and $ip =~ /^fc00\:0\:/i
MC/DC0%0/2
$flag_intranets and $ip =~ /^fc00\:0\:/i
$flag_intranets
$ip =~ /^fc00\:0\:/i
Truth table33%1/3
A and B
A= $flag_intranetsB= $ip =~ /^fc00\:0\:/i
| |||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | return (2, "Invalid use of unique local address (e.g. $ip) range for MX"); | |||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||
| 578 | #fd00::/8 | ||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 27 | ▶ | if ($flag_intranets && $ip =~ /^fd00\:0\:/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$flag_intranets and $ip =~ /^fd00\:0\:/i
MC/DC0%0/2
$flag_intranets and $ip =~ /^fd00\:0\:/i
$flag_intranets
$ip =~ /^fd00\:0\:/i
Truth table33%1/3
A and B
A= $flag_intranetsB= $ip =~ /^fd00\:0\:/i
| |||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | return (2, "Invalid use of private IP (e.g. $ip) range for MX"); | |||||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||
| 583 | #DHCP auto-discover added per Matthew van Eerde recomendation 169.254/16 | ||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 27 | ▶ | if ($ip =~ /^169\.254\./) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | return (1, "Invalid use of a DHCP auto-discover IP range ($ip) as an MX record"); | |||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||
| 588 | #IPv6 link-local addresses fe80::/10 | ||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 27 | ▶ | if ($ip =~ /^fe80\:0\:/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 1 | return (1, "Invalid use of a link-local IP range ($ip) as an MX record"); | |||||||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||
| 593 | #Multicast 224/8 through 239/8 added per Matthew van Eerde recomendation | ||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 26 | ▶ | if ($ip =~ /^(224|225|226|227|228|229|230|231|232|233|234|235|236|237|238|239)\./) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | return (1, "Invalid use of a Multicast IP range ($ip) as an MX record"); | |||||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||
| 598 | #Experimental block - Former Class E - 240.0.0.0/4 courtesy of Mark Damrose | ||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 26 | ▶ | if ($ip =~ /^2[45]\d\./) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | return (1, "Invalid use of an experimental IP ($ip) as an MX record"); | |||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||
| 603 | #Reserved for benchmark tests of interconnect devices 192.18.0.0/15 courtesy of Mark Damrose | ||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 26 | ▶ | if ($ip =~ /^192\.1[89]\./) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | return (1, "Invalid use of a reserved IP ($ip) as an MX record"); | |||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||
| 608 | #Reserved for documentation or published examples 192.0.2.0/24 courtesy of Mark Damrose | ||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 26 | ▶ | if ($ip =~ /^192\.0\.2\./) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | return (1, "Invalid use of a reserved IP ($ip) as an MX record"); | |||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 26 | return (0,''); | |||||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 37 | ▶ | sub int_to_truefalse { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
int_to_truefalse: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 37 | my ($int) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 37 | ▶ | if ($int) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 25 | return "True"; | |||||||||||||||||||||||||||||||||||||||||||||
| 622 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 12 | return "False"; | |||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 3 | ▶ | sub check_email_and_mx { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_email_and_mx: called CC=6 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 3 | my ($email) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 629 | 3 | my ($rv, $fail_reason, $status, $debug); | |||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 3 | $debug = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 3 | ▶ | $email || return 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 3 | ▶ | print "DEBUG: e-mail address is: $email<br>\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||
| 637 | # SANITIZE THE E-MAIL ADDRESS OF SPACES | ||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 3 | $email =~ s/ //g; | |||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||
| 640 | # CHECK FOR INCOMPLETE ADDRESSES AT LARGE ISPS | ||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 3 | $email =~ s/\@aol\.?$/\@aol.com/i; | |||||||||||||||||||||||||||||||||||||||||||||
| 642 | 3 | $email =~ s/\@hotmail\.?$/\@hotmail.com/i; | |||||||||||||||||||||||||||||||||||||||||||||
| 643 | 3 | $email =~ s/\@gmail\.?$/\@gmail.com/i; | |||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 3 | ▶ | print "DEBUG: e-mail address is now: $email<br>\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||
| 647 | # CHECK FOR A VALIDLY CONSTRUCTED E-MAIL ADDRESS | ||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 3 | ($rv) = Net::validMX::check_email_validity($email); | |||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 3 | ▶ | if ($rv < 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | return($rv, "Failed check_email_validity", $email); | |||||||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||
| 654 | # CHECK FOR VALID MX RECORD | ||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 3 | ($rv, $fail_reason) = Net::validMX::check_valid_mx($email); | |||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 3 | ▶ | if ($rv < 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | return($rv, $fail_reason, $email); | |||||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 3 | return($rv, "Passed", $email); | |||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 11 | ▶ | sub check_email_validity { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_email_validity: called CC=12 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 11 | my ($email) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 666 | 11 | my ($local); | |||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||
| 668 | #allows an email address that contains -()/!#$%&*+~. A through Z a through Z and 0 through 9 in a format of [valid]@([valid].[valid]...).[valid]. = will also be | ||||||||||||||||||||||||||||||||||||||||||||||
| 669 | #allowed in the username. Thanks to Paul Whittney for reporting the issue. | ||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||
| 671 | #PER WIKIPEDIA | ||||||||||||||||||||||||||||||||||||||||||||||
| 672 | #Per Wikipedia: | ||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||
| 674 | #The format of email addresses is local-part@domain where the local-part may be up to 64 characters long and the domain name may have a maximum of 253 characters - but the maximum 256 characters length of a forward or reverse path restricts the entire email address to be no more than 254 characters.[1] - formally defined in RFC 5322 (sections 3.2.3 and 3.4.1) and by RFC 5321. | ||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||
| 676 | #Can't have two dots | ||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 11 | ▶ | if ($email =~ /\.\./) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||
| 681 | #Can't be longer than 254 chars | ||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 11 | ▶ | if (length($email) > 254) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||
| 686 | #Can't end in a period | ||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 11 | ▶ | if ($email =~ /\.$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 11 | ▶ | if ($email =~ /^(.*)@[-()\/!#$%&*+~_A-Za-z0-9\.]+\.[-()\/!#$%&*+~_A-Za-z0-9\.]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 8 | $local = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||
| 695 | #check local length | ||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 8 | ▶ | if (length($local) > 64) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 699 | #no need to check if domain is over 253 chars, as it would not pass both overall length and regex if it was | ||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||
| 701 | # per RFC 3696 section 3 the local part of an address cannot begin or end with a period | ||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 6 | ▶ | if ($local =~ /^\./ or $local =~ /\.$/g) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$local =~ /^\./ or $local =~ /\.$/g
MC/DC0%0/2
$local =~ /^\./ or $local =~ /\.$/g
$local =~ /^\./
$local =~ /\.$/g
Truth table33%1/3
A or B
A= $local =~ /^\./B= $local =~ /\.$/g
| |||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||||||
| 706 | # PURGE BACKSLASHES | ||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 6 | $local =~ s/\\//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||
| 709 | # per RFC 3696 section 3 the local part of the email can be quoted, which allows any character to appear if inside quotes | ||||||||||||||||||||||||||||||||||||||||||||||
| 710 | # PURGE BEGINNING AND END QUOTE IF IT CONTAINS QUOTES | ||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 6 | ▶ | if ($local =~ /"/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 1 | ▶ | if($local =~ /^".*"$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | $local =~ s/^"//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | $local =~ s/"$//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||
| 717 | # IF IT STILL CONTAINS A QUOTE, IT IS INVALID, OTHERWISE THE LOCAL PART IS VALID | ||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 1 | ▶ | if ($local =~ /"/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 720 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||||||
| 725 | # check for allowed characters, per RFC 3696 section 3 | ||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 5 | ▶ | if ($local =~ /^[\@'-`\/!\?=#\$\%&*+~_A-Za-z0-9\.{}|]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 728 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||
| 737 | #get domain name from an email address | ||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 38 | ▶ | sub get_domain_from_email { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_domain_from_email: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 38 | my ($email, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 38 | my ($domain, $local); | |||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 38 | $domain = $email; | |||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||
| 745 | #REMOVE ANY LEADING/TRAILING <>'s | ||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 38 | $domain =~ s/(^<|>$)//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 747 | #REMOVE ANY LEADING/TRAILING SPACE'S | ||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 38 | $domain =~ s/^ *//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 749 | 38 | $domain =~ s/ *$//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 750 | #REMOVE EVERYTHING UP TO THE @ SYMBOL | ||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 38 | $domain =~ s/(.*)\@//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 38 | $local = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 38 | ▶ | print "\nDEBUG: Extracted Sender Domain: $domain / Local: $local from $params{'email'}\n" if $params{'debug'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 38 | ▶ | return wantarray ? ($local,$domain) : $domain; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | ▶ | sub dns_lookup { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dns_lookup: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | my ($domain, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | my ($dns, $query); | |||||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | $dns = Net::DNS::Resolver->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | $query = $dns->search($domain, $type); | |||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | ▶ | if ($query) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | return $query->answer; | |||||||||||||||||||||||||||||||||||||||||||||
| 768 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | warn "Error performing $type query for $domain! ". $dns->errorstring; | |||||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | ▶ | sub check_spf_for_domain { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_spf_for_domain: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | my ($domain, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | my ($dns, $query, $spf_line, @clauses, $found_spf); | |||||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | $dns = Net::DNS::Resolver->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | $query = $dns->search($domain, 'TXT'); | |||||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | ▶ | if (not $query) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | warn "Error performing TXT query for $domain! ". $dns->errorstring; | |||||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | return ("suspect", "no TXT record found"); | |||||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | foreach my $result ($query->answer) { | |||||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | ▶ | next unless $result->type eq 'TXT'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | $spf_line = $result->txtdata; | |||||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | ▶ | if ($spf_line =~ /^v=spf[12]/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | $found_spf++; | |||||||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||||||
| 791 | # split into clauses | ||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | @clauses = split / /, $spf_line; | |||||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | foreach my $clause (@clauses) { | |||||||||||||||||||||||||||||||||||||||||||||
| 795 | # ignore clauses that reject email - only false accepts are good spam indicators | ||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | ▶ | next if $clause =~ /^[-~]/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | ▶ | if ($clause =~ /^.?all/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 798 | # if accepting email from all, rule is clearly useless | ||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | return ("bad", "use of universal pass rule $clause"); | |||||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 802 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | ▶ | if ($found_spf == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | return ("suspect", "no TXT record matching SPF format found"); | |||||||||||||||||||||||||||||||||||||||||||||
| 807 | } elsif ($found_spf > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | return ("suspect", "multiple TXT records matching SPF format found"); | |||||||||||||||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | return ("valid", undef); | |||||||||||||||||||||||||||||||||||||||||||||
| 812 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||||||
| 816 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||