| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Mail/Salsa/Sendmail.pm | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # Last Modification: Wed Jun 23 17:11:01 WEST 2004 | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Copyright (c) 2004 Henrique Dias <hdias@aesbuc.pt>. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # This module is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||
| 9 | package Mail::Salsa::Sendmail; | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use 5.008000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 11 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use AutoLoader qw(AUTOLOAD); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # This allows declaration use Mail::Salsa::Sendmail ':all'; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # will save memory. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 11 | our %EXPORT_TAGS = ( 'all' => [ qw() ] ); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 11 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | 11 | our @EXPORT = qw(); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 11 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 37 | 'smtp_server' => ["localhost"], | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 'smtp_port' => 25, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 'timeout' => 120, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 'mail_from' => "", | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 'rcpt_to' => [], | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 'list_file' => "", | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 'data' => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 'filehandle' => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | @_ | ||||||||||||||||||||||||||||||||||||||||||
| 46 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | bless ($self, $class); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return($self->init() ? $self : undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub send_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_data: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $handle = shift; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | unless($data =~ /\n+$/) { $data = join("", $data, "\n"); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | print $handle "$data"; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | return(&get_answer($handle)); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub helo { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
helo: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | defined($self->{'filehandle'}) or return("Error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $hostname = $self->{'smtp_server'}->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return(&send_data($self->{'filehandle'}, "HELO $hostname\n")); | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub mail_from { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mail_from: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | my $mailfrom = shift || return("Error"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || (return 'Error')
MC/DC0%0/1
shift() || (return 'Error')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | defined($self->{'filehandle'}) or return("Error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return(&send_data($self->{'filehandle'}, "MAIL FROM: $mailfrom\n")); | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub rcpt_to { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rcpt_to: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $param = { | |||||||||||||||||||||||||||||||||||||||||
| 79 | list_file => "", | ||||||||||||||||||||||||||||||||||||||||||
| 80 | addresses => [], | ||||||||||||||||||||||||||||||||||||||||||
| 81 | @_, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | defined($self->{'filehandle'}) or return("Error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if($param->{'list_file'} && -e $param->{'list_file'} && -s $param->{'list_file'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$param->{"list_file"} and -e $param->{"list_file"} and -s $param->{"list_file"}
$param->{"list_file"} and -e $param->{"list_file"}
MC/DC0%0/3
$param->{"list_file"} and -e $param->{"list_file"} and -s $param->{"list_file"}
$param->{"list_file"}
-e $param->{"list_file"}
-s $param->{"list_file"}
Truth table0%0/4
A and B and C
A= $param->{"list_file"}B= -e $param->{"list_file"}C= -s $param->{"list_file"}
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | open(LIST, "<", $param->{'list_file'}) or die("$!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | while(<LIST>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | next if(/^\#/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my ($email) = (/\<?([^\@\<\>]+\@[^\@\<\>]+)\>?/); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | &send_data($self->{'filehandle'}, "RCPT TO: $email\n"); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | close(LIST); | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if(scalar(@{$param->{'addresses'}})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | for my $email (@{$param->{'addresses'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | &send_data($self->{'filehandle'}, "RCPT TO: $email\n"); | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $code = shift || return("Error"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || (return 'Error')
MC/DC0%0/1
shift() || (return 'Error')
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | defined($self->{'filehandle'}) or return("Error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | &send_data($self->{'filehandle'}, "DATA\n"); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | (ref($code) eq "CODE") or return("Error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $code->($self->{'filehandle'}); | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return(&send_data($self->{'filehandle'}, ".\n")); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub quit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quit: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | defined($self->{'filehandle'}) or return("Error"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | &send_data($self->{'filehandle'}, "QUIT\n"); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $self->{'filehandle'}->close(); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub everything { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
everything: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 124 | my $param = { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 'mail_from' => $self->{'mail_from'}, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 'rcpt_to' => $self->{'rcpt_to'}, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 'list_file' => $self->{'list_file'}, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | 'data' => $self->{'data'}, | |||||||||||||||||||||||||||||||||||||||||
| 129 | @_ | ||||||||||||||||||||||||||||||||||||||||||
| 130 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $self->helo(); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->mail_from($param->{'mail_from'}); | |||||||||||||||||||||||||||||||||||||||||
| 133 | $self->rcpt_to( | ||||||||||||||||||||||||||||||||||||||||||
| 134 | list_file => $param->{'list_file'}, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | addresses => $param->{'rcpt_to'} | |||||||||||||||||||||||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $self->data($param->{'data'}); | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->quit(); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $handle; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | for my $host (@{$self->{'smtp_server'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 147 | $handle = IO::Socket::INET->new( | ||||||||||||||||||||||||||||||||||||||||||
| 148 | Timeout => $self->{'timeout'}, | ||||||||||||||||||||||||||||||||||||||||||
| 149 | Proto => "tcp", | ||||||||||||||||||||||||||||||||||||||||||
| 150 | PeerAddr => $host, | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | PeerPort => $self->{'smtp_port'} | |||||||||||||||||||||||||||||||||||||||||
| 152 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $self->{'smtp_server'}->[0] = $host; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | last if(defined($handle)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | defined($handle) or return(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $handle->autoflush(1); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | &get_answer($handle); | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $self->{'filehandle'} = $handle; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | return(1); | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub get_answer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_answer: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $handle = shift; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $answer = <$handle>; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my ($code) = ($answer =~ /^(\d\d\d) /); | |||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | ## &logs("SMTP ANSWER: $answer"); | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | ($code < 500) or return($answer); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | ## print "SMTP ANSWER: $answer\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub logs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logs: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | open(LOGS, ">>", "/tmp/____logs.log") or die("$!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | print LOGS "$string\n"; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | close(LOGS); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | # Preloaded methods go here. | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 189 | __END__ | ||||||||||||||||||||||||||||||||||||||||||