blib/lib/Mail/Sendmail/Enhanced.pm

filter: Statementstmt 71.4% 100 / 140 Branchbran 51.8% 28 / 54 Conditioncond 44.2% 50 / 113 MC/DCmcdc 6.6% 4 / 60 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 3 totaltotal 50.4% 191 / 379 SCAR 62.7
CC
78
Cov
58%
send
349.3
encode_qp
36.4
new
28.2
CRAP 529.4
↑ Summary
1 package Mail::Sendmail::Enhanced;
2  
3 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Encode qw(decode encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Mail::Sendmail '0.79_16';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our $VERSION = '0.02';
14  
15 ################################################################################
16  
17 sub new
18 {
19 1 ▶ my ( $this ) = ( shift );
Subroutine new: called CC=18 SCAR=33.4
Pod undocumented
20  
21 1 my $mail = {};
22 1 bless ( $mail, $this );
23  
24 1 ▶ while ( my $key = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = shift()) 8 1 9
25 8 ▶ if ( ref ( $key ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $key eq 'HASH') { } 0 8 8
26 0 foreach my $k (sort keys %{$key} ) {
27 0 $mail->{$k} = $$key{$k};
28 }
29 } else {
30 8 my $value = shift;
31 8 $mail->{$key} = $value;
32 }
33 }
34  
35 1 ▶ $mail->{smtp} ||= '';
Condition50%1/2
$mail->{"smtp"} ||= ""
l!l
10
MC/DC0%0/1
$mail->{"smtp"} ||= ""
$mail->{"smtp"}
Truth table50%1/2
A
A= $mail->{"smtp"}
Aresult
11
00
36 1 ▶ $mail->{from} ||= '';
Condition50%1/2
$mail->{"from"} ||= ""
l!l
10
MC/DC0%0/1
$mail->{"from"} ||= ""
$mail->{"from"}
Truth table50%1/2
A
A= $mail->{"from"}
Aresult
11
00
37 1 ▶ $mail->{charset} ||= 'utf-8';
Condition50%1/2
$mail->{"charset"} ||= "utf-8"
l!l
10
MC/DC0%0/1
$mail->{"charset"} ||= "utf-8"
$mail->{"charset"}
Truth table50%1/2
A
A= $mail->{"charset"}
Aresult
11
00
38 1 ▶ $mail->{type} ||= 'text/plain';
Condition50%1/2
$mail->{"type"} ||= "text/plain"
l!l
01
MC/DC0%0/1
$mail->{"type"} ||= "text/plain"
$mail->{"type"}
Truth table50%1/2
A
A= $mail->{"type"}
Aresult
11
00
39  
40 1 ▶ $mail->{user} ||= '';
Condition50%1/2
$mail->{"user"} ||= ""
l!l
10
MC/DC0%0/1
$mail->{"user"} ||= ""
$mail->{"user"}
Truth table50%1/2
A
A= $mail->{"user"}
Aresult
11
00
41 1 ▶ $mail->{pass} ||= '';
Condition50%1/2
$mail->{"pass"} ||= ""
l!l
10
MC/DC0%0/1
$mail->{"pass"} ||= ""
$mail->{"pass"}
Truth table50%1/2
A
A= $mail->{"pass"}
Aresult
11
00
42 1 ▶ $mail->{method} ||= 'LOGIN';
Condition50%1/2
$mail->{"method"} ||= "LOGIN"
l!l
10
MC/DC0%0/1
$mail->{"method"} ||= "LOGIN"
$mail->{"method"}
Truth table50%1/2
A
A= $mail->{"method"}
Aresult
11
00
43 1 ▶ $mail->{required} ||= 1;
Condition50%1/2
$mail->{"required"} ||= 1
l!l
10
MC/DC0%0/1
$mail->{"required"} ||= 1
$mail->{"required"}
Truth table50%1/2
A
A= $mail->{"required"}
Aresult
11
00
44  
45 1 ▶ $mail->{to} ||= '';
Condition50%1/2
$mail->{"to"} ||= ""
l!l
01
MC/DC0%0/1
$mail->{"to"} ||= ""
$mail->{"to"}
Truth table50%1/2
A
A= $mail->{"to"}
Aresult
11
00
46 1 ▶ $mail->{cc} ||= '';
Condition50%1/2
$mail->{"cc"} ||= ""
l!l
01
MC/DC0%0/1
$mail->{"cc"} ||= ""
$mail->{"cc"}
Truth table50%1/2
A
A= $mail->{"cc"}
Aresult
11
00
47 1 ▶ $mail->{subject} ||= 'No subject defined';
Condition50%1/2
$mail->{"subject"} ||= "No subject defined"
l!l
01
MC/DC0%0/1
$mail->{"subject"} ||= "No subject defined"
$mail->{"subject"}
Truth table50%1/2
A
A= $mail->{"subject"}
Aresult
11
00
48 1 ▶ $mail->{message} ||= 'No message defined!';
Condition50%1/2
$mail->{"message"} ||= "No message defined!"
l!l
01
MC/DC0%0/1
$mail->{"message"} ||= "No message defined!"
$mail->{"message"}
Truth table50%1/2
A
A= $mail->{"message"}
Aresult
11
00
49  
50 1 ▶ $mail->{attachments} ||= {};
Condition50%1/2
$mail->{"attachments"} ||= {}
l!l
01
MC/DC0%0/1
$mail->{"attachments"} ||= {}
$mail->{"attachments"}
Truth table50%1/2
A
A= $mail->{"attachments"}
Aresult
11
00
51 1 ▶ $mail->{attachments_size_max} ||= 0; #no limit "-1" means no attachment allowed
Condition50%1/2
$mail->{"attachments_size_max"} ||= 0
l!l
01
MC/DC0%0/1
$mail->{"attachments_size_max"} ||= 0
$mail->{"attachments_size_max"}
Truth table50%1/2
A
A= $mail->{"attachments_size_max"}
Aresult
11
00
52  
53 1 return $mail;
54 }
55  
56 ################################################################################
57  
58 sub send
59 {
60 3 ▶ my ( $self, $ARG ) = ( shift, shift );
Subroutine send: called CC=40 SCAR=58.6
Pod undocumented
61  
62 3 ▶ $ARG->{to} || $ARG->{cc} || die 'No to: or cc: email address given!';
Branch: 1 branch
BranchTrueFalseTotal
$ARG->{"to"} or $ARG->{"cc"} or die "No to: or cc: email address given!" 0 3 3
Condition33%1/3
$ARG->{"to"} or $ARG->{"cc"}
l!l&&r!l&&!r
300
MC/DC0%0/2
$ARG->{"to"} or $ARG->{"cc"}
$ARG->{"to"} $ARG->{"cc"}
Truth table33%1/3
A or B
A= $ARG->{"to"}B= $ARG->{"cc"}
ABresult
1X1
011
000
63  
64 3 ▶ my $charset = $ARG->{charset} || $self->{charset} || 'utf-8';
Condition40%2/5
$ARG->{'charset'} || $self->{'charset'} || 'utf-8'
l!l
30
$ARG->{"charset"} or $self->{"charset"}
l!l&&r!l&&!r
030
MC/DC0%0/2
$ARG->{'charset'} || $self->{'charset'} || 'utf-8'
$ARG->{"charset"} $self->{"charset"}
Truth table33%1/3
A or B
A= $ARG->{"charset"}B= $self->{"charset"}
ABresult
1X1
011
000
65 3 ▶ my $type = $ARG->{type} || $self->{type} || 'text/plain';
Condition40%2/5
$ARG->{'type'} || $self->{'type'} || 'text/plain'
l!l
30
$ARG->{"type"} or $self->{"type"}
l!l&&r!l&&!r
030
MC/DC0%0/2
$ARG->{'type'} || $self->{'type'} || 'text/plain'
$ARG->{"type"} $self->{"type"}
Truth table33%1/3
A or B
A= $ARG->{"type"}B= $self->{"type"}
ABresult
1X1
011
000
66  
67 3 my $boundary = "====" . time() . "====";
68  
69 # Email subject is encoded using proper character encoding.
70 # original "encode_qp" function contains up to 2 arguments,
71 # but in a case of character set it is needed to start every
72 # new line with a statemant of the encoding, so - as a the
73 # third parameter - the charset is sent to the function.
74  
75 3 ▶ my $subject = $ARG->{subject} || $self->{subject} || '';
Condition40%2/5
$ARG->{'subject'} || $self->{'subject'} || ''
l!l
30
$ARG->{"subject"} or $self->{"subject"}
l!l&&r!l&&!r
030
MC/DC0%0/2
$ARG->{'subject'} || $self->{'subject'} || ''
$ARG->{"subject"} $self->{"subject"}
Truth table33%1/3
A or B
A= $ARG->{"subject"}B= $self->{"subject"}
ABresult
1X1
011
000
76  
77 3 my $flnoc = 67;
78 3 my $nlnoc = 78;
79 3 my $bol = " =?$charset?Q?";
80 3 my $eol = "?=\n";
81  
82 {
83 # this part consider multibytes characters and keep that folding
84 # does not divide the multibyte characters into two lines.
85 # The reason is that some email clients are not able to put
86 # together these separated bytes into one character.
87 3 require bytes;
88  
89  
90 3 ▶ my $t_subject = decode( $charset, $subject ) if $charset;
Branch: 1 branch
BranchTrueFalseTotal
if $charset 3 0 3
91  
92 3 ▶ if ( bytes::length($t_subject) > length($t_subject) || $t_subject =~ /[^\0-\xFF]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&bytes::length($t_subject) > length $t_subject or $t_subject =~ /[^\0-\xFF]/) { } 0 3 3
Condition33%1/3
&bytes::length($t_subject) > length $t_subject or $t_subject =~ /[^\0-\xFF]/
l!l&&r!l&&!r
003
MC/DC0%0/2
&bytes::length($t_subject) > length $t_subject or $t_subject =~ /[^\0-\xFF]/
&bytes::length($t_subject) > length $t_subject $t_subject =~ /[^\0-\xFF]/
Truth table33%1/3
A or B
A= &bytes::length($t_subject) > length $t_subjectB= $t_subject =~ /[^\0-\xFF]/
ABresult
1X1
011
000
93  
94 0 $subject = '';
95 0 my $t_string = ''; # substring of $t_subject which is testing if can be added to $subject
96 0 my $t_length = 0; # the length of $t_subject
97  
98 0 my $t_return = ''; # $t_string which match to the condition
99 0 my $t_result = ''; # encoded string of $t_string
100 0 my $t_number = 0; # number of row of the folded "Subject" field
101 0 ▶ while ( $t_subject ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t_subject) 0 0 0
102 0 foreach(0..$flnoc) {
103 0 $t_string = substr($t_subject,0,$_);
104 0 $t_result = encode_qp(encode($charset,$t_string),{bol=>$bol,eol=>$eol,flnoc=>0,nlnoc=>0,charset=>$charset,});
105  
106 #checking if encoded string $t_result of the tested substring $t_string satisfies length condition:
107 # and if yes we go out with the last good value $t_return and $t_subject get shorter by $t_length
108 0 ▶ last if length( $t_result ) > ($t_number ? $nlnoc : $flnoc);
Branch: 2 branches
BranchTrueFalseTotal
if length $t_result > ($t_number ? $nlnoc : $flnoc) 0 0 0
$t_number ? : 0 0 0
109 0 $t_return = $t_result;
110 0 $t_length = length($t_string);
111 }
112 0 $subject = $subject.$t_return;
113 0 $t_subject = substr( $t_subject, $t_length );
114 0 $t_number++;
115 }
116  
117 } else {
118 3 $subject = encode_qp( $subject , { bol=>$bol, eol=>$eol, flnoc=>$flnoc, nlnoc=>$nlnoc, charset=>$charset, } );
119 }
120 }
121  
122 3 $subject = substr($subject,1);
123  
124 my %mail = (
125 'X-Mailer' => "This is Perl Mail::Sendmail::Enhanced version $Mail::Sendmail::Enhanced::VERSION",
126 'Content-Type' => "multipart/mixed; charset=$charset; boundary=\"$boundary\"",
127 'Smtp' => ($ARG->{smpt}|| $self->{smtp} ),
128 'From' => ($ARG->{from}|| $self->{from} ),
129 'To' => ($ARG->{to} || $self->{to} || '' ),
130 'Cc' => ($ARG->{cc} || $self->{cc} || '' ),
131 'Subject' => $subject,
132 auth => {
133 user => ($ARG->{user} || $self->{user} ),
134 pass => ($ARG->{pass} || $self->{pass} ),
135 method => ($ARG->{method} || $self->{method} ),
136 3 ▶ required => ($ARG->{required}|| $self->{required} ),
Condition35%10/28
$ARG->{'smpt'} || $self->{'smtp'}
l!l&&r!l&&!r
030
$ARG->{'from'} || $self->{'from'}
l!l&&r!l&&!r
030
$ARG->{'to'} || $self->{'to'} || ''
l!l
30
$ARG->{"to"} or $self->{"to"}
l!l&&r!l&&!r
300
$ARG->{'cc'} || $self->{'cc'} || ''
l!l
03
$ARG->{"cc"} or $self->{"cc"}
l!l&&r!l&&!r
003
$ARG->{'user'} || $self->{'user'}
l!l&&r!l&&!r
030
$ARG->{'pass'} || $self->{'pass'}
l!l&&r!l&&!r
030
$ARG->{'method'} || $self->{'method'}
l!l&&r!l&&!r
030
$ARG->{'required'} || $self->{'required'}
l!l&&r!l&&!r
030
MC/DC0%0/2
$ARG->{'smpt'} || $self->{'smtp'}
$ARG->{'smpt'} $self->{'smtp'}
MC/DC0%0/2
$ARG->{'from'} || $self->{'from'}
$ARG->{'from'} $self->{'from'}
MC/DC0%0/2
$ARG->{'to'} || $self->{'to'} || ''
$ARG->{"to"} $self->{"to"}
MC/DC0%0/2
$ARG->{'cc'} || $self->{'cc'} || ''
$ARG->{"cc"} $self->{"cc"}
MC/DC0%0/2
$ARG->{'user'} || $self->{'user'}
$ARG->{'user'} $self->{'user'}
MC/DC0%0/2
$ARG->{'pass'} || $self->{'pass'}
$ARG->{'pass'} $self->{'pass'}
MC/DC0%0/2
$ARG->{'method'} || $self->{'method'}
$ARG->{'method'} $self->{'method'}
MC/DC0%0/2
$ARG->{'required'} || $self->{'required'}
$ARG->{'required'} $self->{'required'}
Truth table33%1/3
A || B
A= $ARG->{'smpt'}B= $self->{'smtp'}
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $ARG->{'from'}B= $self->{'from'}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $ARG->{"to"}B= $self->{"to"}
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $ARG->{"cc"}B= $self->{"cc"}
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $ARG->{'user'}B= $self->{'user'}
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $ARG->{'pass'}B= $self->{'pass'}
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $ARG->{'method'}B= $self->{'method'}
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $ARG->{'required'}B= $self->{'required'}
ABresult
1X1
011
000
137 },
138 );
139  
140 3 $boundary = '--'.$boundary;
141 $mail{'Message'} = "$boundary\n"
142 ."Content-Type: $type; charset=$charset; format=flowed\n"
143 ."Content-Transfer-Encoding: 8bit\n\n"
144 3 .$ARG->{'message'}."\n";
145  
146 # ."Content-Transfer-Encoding: quoted-printable\n\n"
147 # .encode_qp( $ARG->{'message'}, {} )."\n";
148  
149 3 ▶ $ARG->{attachments} ||= $self->{attachments} || {};
Condition20%1/5
$ARG->{"attachments"} ||= $self->{"attachments"} || {}
l!l&&r!l&&!r
300
$self->{'attachments'} || {}
l!l
00
MC/DC0%0/2
$ARG->{"attachments"} ||= $self->{"attachments"} || {}
$ARG->{"attachments"} $self->{'attachments'}
Truth table33%1/3
A ||= B
A= $ARG->{"attachments"}B= $self->{'attachments'}
ABresult
1X1
011
000
150 3 ▶ $ARG->{attachments_size_max} ||= $self->{attachments_size_max} || 0; #no limit "-1" means no attachment allowed
Condition60%3/5
$ARG->{"attachments_size_max"} ||= $self->{"attachments_size_max"} || 0
l!l&&r!l&&!r
201
$self->{'attachments_size_max'} || 0
l!l
01
MC/DC50%1/2
$ARG->{"attachments_size_max"} ||= $self->{"attachments_size_max"} || 0
$ARG->{"attachments_size_max"} $self->{'attachments_size_max'}
Truth table66%2/3
A ||= B
A= $ARG->{"attachments_size_max"}B= $self->{'attachments_size_max'}
ABresult
1X1
011
000
151  
152 3 ▶ return "Attachments are not allowed whereas some are preperad to send!" if $ARG->{attachments} && $ARG->{attachments_size_max} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ARG->{"attachments"} and $ARG->{"attachments_size_max"} < 0 1 2 3
Condition66%2/3
$ARG->{"attachments"} and $ARG->{"attachments_size_max"} < 0
!ll&&!rl&&r
021
MC/DC50%1/2
$ARG->{"attachments"} and $ARG->{"attachments_size_max"} < 0
$ARG->{"attachments"} $ARG->{"attachments_size_max"} < 0
Truth table66%2/3
A and B
A= $ARG->{"attachments"}B= $ARG->{"attachments_size_max"} < 0
ABresult
0X0
100
111
153 # attachment files are packed one by one into the message part each divided by boundary
154  
155 # checking attachments:
156 2 foreach my $fileName ( sort keys %{$ARG->{'attachments'}} ) {
157  
158 2 my $fileLocation = $ARG->{'attachments'}->{$fileName};
159  
160 # if does not exists:
161 2 ▶ return "Attachment does not exists! [$fileLocation]" unless -f $fileLocation;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $fileLocation 1 1 2
162  
163 # if it is too big:
164 1 ▶ my $size = -s $fileLocation || 0;
Condition50%1/2
-s $fileLocation || 0
l!l
10
MC/DC0%0/1
-s $fileLocation || 0
-s $fileLocation
Truth table50%1/2
A
A= -s $fileLocation
Aresult
11
00
165 return "Attachment too big! [$fileLocation: $size > ".$ARG->{attachments_size_max}."B max.]"
166 1 ▶ if $ARG->{attachments_size_max} > 0 && $size > $ARG->{attachments_size_max};
Branch: 1 branch
BranchTrueFalseTotal
if $ARG->{"attachments_size_max"} > 0 and $size > $ARG->{"attachments_size_max"} 1 0 1
Condition33%1/3
$ARG->{"attachments_size_max"} > 0 and $size > $ARG->{"attachments_size_max"}
!ll&&!rl&&r
001
MC/DC0%0/2
$ARG->{"attachments_size_max"} > 0 and $size > $ARG->{"attachments_size_max"}
$ARG->{"attachments_size_max"} > 0 $size > $ARG->{"attachments_size_max"}
Truth table33%1/3
A and B
A= $ARG->{"attachments_size_max"} > 0B= $size > $ARG->{"attachments_size_max"}
ABresult
0X0
100
111
167 }
168  
169  
170 0 foreach my $fileName ( sort keys %{$ARG->{'attachments'}} ) {
171 0 my $fileLocation = $ARG->{'attachments'}->{$fileName};
172 0 ▶ if (open (my $F, $fileLocation )) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $F, $fileLocation) 0 0 0
173 0 my $input_record_separator = $/;
174 0 binmode $F; undef $/;
175 0 my $attachment = encode_base64(<$F>);
176 0 close $F;
177 0 $/ = $input_record_separator;
178  
179 0 $mail{'Message'} .= "$boundary\n"
180 ."Content-Type: application/octet-stream; name=\"$fileName\"\n"
181 ."Content-ID: <$fileName>\n"
182 ."Content-Transfer-Encoding: base64\n"
183 ."Content-Disposition: attachment; filename=\"$fileName\"\n\n"
184 ."$attachment\n";
185 }
186 }
187  
188 0 $mail{'Message'} .= "$boundary--\n";
189  
190  
191 0 ▶ return $Mail::Sendmail::error unless sendmail( %mail );
Branch: 1 branch
BranchTrueFalseTotal
unless sendmail(%mail) 0 0 0
192  
193 0 return;
194 }
195  
196 ################################################################################
197  
198 sub encode_qp
199 {
200 ############################################################################
201 # This function is an exact copy of the that of the same name from the
202 # module: "MIME::QuotedPrint::Perl" '1.00' with the following changes:
203 # 1. The second argument can be scalar - as previously -
204 # or hash which would contain more information
205 # 2. There are changes in counting character in each line in accordance
206 # with hash sent to the function: it can be different in first line
207 # and the next ones. It is so, because usually in the firs line there
208 # is some word (Subject for instance).
209 # The behaviour of the function is identical with the original one in case
210 # we send two scalar arguments only.
211 ############################################################################
212  
213 # $res = text to be encoded
214 4 ▶ my ( $res ) = ( shift );
Subroutine encode_qp: called CC=22 SCAR=35.9
Pod undocumented
215 4 ▶ return '' unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 4 4
216  
217 # The arguments can be sent in old way, when the second argument was the
218 # end of character rows, or in a new way - as a hash:
219 4 my %par = (
220 bol => " ", # characters at the begining of each lines
221 eol => "\n", # characters at the end of each line
222 flnoc => 68, # first line number of characters, 0 = unlimit
223 nlnoc => 78, # next lines number of characters, 0 = unlimit
224 );
225  
226 4 ▶ while ( my $key = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = shift()) 3 4 7
227 3 ▶ if ( ref ( $key ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $key eq 'HASH') { } 3 0 3
228 3 foreach my $k (sort keys %{$key} ) {
229 15 ▶ next unless $k =~ /^(bol|charset|eol|flnoc|nlnoc)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^(bol|charset|eol|flnoc|nlnoc)$/ 0 15 15
230 15 ▶ next if $k eq 'flnoc' && $par{$k} !~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "flnoc" and not $par{$k} =~ /^\d+$/ 0 15 15
Condition66%2/3
$k eq "flnoc" and not $par{$k} =~ /^\d+$/
!ll&&!rl&&r
1230
MC/DC0%0/2
$k eq "flnoc" and not $par{$k} =~ /^\d+$/
$k eq "flnoc" not $par{$k} =~ /^\d+$/
Truth table66%2/3
A and not(B)
A= $k eq "flnoc"B= not $par{$k} =~ /^\d+$/
ABresult
0X0
100
111
231 15 ▶ next if $k eq 'nlnoc' && $par{$k} !~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "nlnoc" and not $par{$k} =~ /^\d+$/ 0 15 15
Condition66%2/3
$k eq "nlnoc" and not $par{$k} =~ /^\d+$/
!ll&&!rl&&r
1230
MC/DC0%0/2
$k eq "nlnoc" and not $par{$k} =~ /^\d+$/
$k eq "nlnoc" not $par{$k} =~ /^\d+$/
Truth table66%2/3
A and not(B)
A= $k eq "nlnoc"B= not $par{$k} =~ /^\d+$/
ABresult
0X0
100
111
232  
233 15 $par{$k} = $$key{$k};
234 }
235 } else { # you can only send - as a second scalar argument the "EOL"
236 # characters in accordance with the original function
237 0 $par{eol} = $key;
238 }
239 }
240  
241 4 ▶ if ($] >= 5.006) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.006") 4 0 4
242 4 require bytes;
243 4 ▶ if (bytes::length($res) > length($res) || ($] >= 5.008 && $res =~ /[^\0-\xFF]/))
Branch: 1 branch
BranchTrueFalseTotal
if (&bytes::length($res) > length $res or $] >= "5.008" and $res =~ /[^\0-\xFF]/) 0 4 4
Condition33%2/6
&bytes::length($res) > length $res or $] >= "5.008" and $res =~ /[^\0-\xFF]/
l!l&&r!l&&!r
004
$] >= "5.008" and $res =~ /[^\0-\xFF]/
!ll&&!rl&&r
040
MC/DC0%0/3
&bytes::length($res) > length $res or $] >= "5.008" and $res =~ /[^\0-\xFF]/
&bytes::length($res) > length $res $] >= "5.008" $res =~ /[^\0-\xFF]/
Truth table25%1/4
A or B and C
A= &bytes::length($res) > length $resB= $] >= "5.008"C= $res =~ /[^\0-\xFF]/
ABCresult
1XX1
0111
00X0
0100
244 {
245 0 require Carp;
246 0 Carp::croak("The Quoted-Printable encoding is only defined for bytes");
247 }
248 }
249  
250 # usefull shorthands
251 4 my $bol = $par{bol};
252 4 my $eol = $par{eol};
253 4 my $flnoc = $par{flnoc} - 0 - length($eol) - length($bol);
254 4 my $nlnoc = $par{nlnoc} - 1 - length($eol) - length($bol);
255 4 my $mid = '';
256 4 ▶ unless ( defined $bol ) { $mid = '='; $bol = '' }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bol) 0 4 4
257  
258 # Do not mention ranges such as $res =~ s/([^ \t\n!-<>-~])/sprintf("=%02X", ord($1))/eg;
259 # since that will not even compile on an EBCDIC machine (where ord('!') > ord('<')).
260 4 if (ord('A') == 193) { # EBCDIC style machine
261 if (ord('[') == 173) {
262 $res =~ s/([^ \t\n!"#\$%&'()*+,\-.\/0-9:;<>?\@A-Z[\\\]^_`a-z{|}~])/sprintf("=%02X", ord(Encode::encode('iso-8859-1',Encode::decode('cp1047',$1))))/eg; # rule #2,#3
263 $res =~ s/([ \t]+)$/
264 join('', map { sprintf("=%02X", ord(Encode::encode('iso-8859-1',Encode::decode('cp1047',$_)))) }
265 split('', $1)
266 )/egm; # rule #3 (encode whitespace at eol)
267 }
268 elsif (ord('[') == 187) {
269 $res =~ s/([^ \t\n!"#\$%&'()*+,\-.\/0-9:;<>?\@A-Z[\\\]^_`a-z{|}~])/sprintf("=%02X", ord(Encode::encode('iso-8859-1',Encode::decode('posix-bc',$1))))/eg; # rule #2,#3
270 $res =~ s/([ \t]+)$/
271 join('', map { sprintf("=%02X", ord(Encode::encode('iso-8859-1',Encode::decode('posix-bc',$_)))) }
272 split('', $1)
273 )/egm; # rule #3 (encode whitespace at eol)
274 }
275 elsif (ord('[') == 186) {
276 $res =~ s/([^ \t\n!"#\$%&'()*+,\-.\/0-9:;<>?\@A-Z[\\\]^_`a-z{|}~])/sprintf("=%02X", ord(Encode::encode('iso-8859-1',Encode::decode('cp37',$1))))/eg; # rule #2,#3
277 $res =~ s/([ \t]+)$/
278 join('', map { sprintf("=%02X", ord(Encode::encode('iso-8859-1',Encode::decode('cp37',$_)))) }
279 split('', $1)
280 )/egm; # rule #3 (encode whitespace at eol)
281 }
282 }
283 else { # ASCII style machine
284 4 $res =~ s/([^ \t\n!"#\$%&'()*+,\-.\/0-9:;<>?\@A-Z[\\\]^_`a-z{|}~])/sprintf("=%02X", ord($1))/eg; # rule #2,#3
285 4 ▶ $res =~ s/\n/=0A/g unless length($eol);
Branch: 1 branch
BranchTrueFalseTotal
unless length $eol 0 4 4
286 4 $res =~ s/([ \t]+)$/
287 0 join('', map { sprintf("=%02X", ord($_)) }
288 split('', $1)
289 )/egm; # rule #3 (encode whitespace at eol)
290 }
291  
292 4 ▶ return $res unless length($eol);
Branch: 1 branch
BranchTrueFalseTotal
unless length $eol 0 4 4
293  
294 # rule #5 (lines must be shorter than 76 chars, but we are not allowed
295 # to break =XX escapes. This makes things complicated :-( )
296 4 my $brokenlines = "";
297  
298 4 ▶ $brokenlines .= "$bol$1$mid$eol" if $flnoc && $res =~ s/(.*?^[^\n]{$flnoc} (?:
Branch: 1 branch
BranchTrueFalseTotal
if $flnoc and $res =~ s/(.*?^[^\n]{$flnoc} (?: [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n |[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n | (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n ))//msx 1 3 4
Condition66%2/3
$flnoc and $res =~ s/(.*?^[^\n]{$flnoc} (?: [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n |[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n | (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n ))//msx
!ll&&!rl&&r
031
MC/DC50%1/2
$flnoc and $res =~ s/(.*?^[^\n]{$flnoc} (?: [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n |[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n | (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n ))//msx
$flnoc $res =~ s/(.*?^[^\n]{$flnoc} (?: [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n |[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n | (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n ))//msx
Truth table66%2/3
A and B
A= $flnocB= $res =~ s/(.*?^[^\n]{$flnoc} (?: [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n |[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n | (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n ))//msx
ABresult
0X0
100
111
299 [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n
300 |[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n
301 | (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n
302 ))//xsm;
303  
304 4 ▶ $brokenlines .= "$bol$1$mid$eol" while $nlnoc && $res =~ s/(.*?^[^\n]{$nlnoc} (?:
Branch: 1 branch
BranchTrueFalseTotal
$nlnoc and $res =~ s/(.*?^[^\n]{$nlnoc} (?: [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n |[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n | (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n ))//msx and do { $brokenlines .= "$bol$1$mid$eol" } 4 4 8
Condition66%2/3
$nlnoc and $res =~ s/(.*?^[^\n]{$nlnoc} (?: [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n |[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n | (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n ))//msx
!ll&&!rl&&r
044
MC/DC50%1/2
$nlnoc and $res =~ s/(.*?^[^\n]{$nlnoc} (?: [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n |[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n | (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n ))//msx
$nlnoc $res =~ s/(.*?^[^\n]{$nlnoc} (?: [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n |[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n | (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n ))//msx
Truth table66%2/3
A and B
A= $nlnocB= $res =~ s/(.*?^[^\n]{$nlnoc} (?: [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n |[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n | (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n ))//msx
ABresult
0X0
100
111
305 [^=\n]{2} (?! [^=\n]{0,1} $) # 75 not followed by .?\n
306 |[^=\n] (?! [^=\n]{0,2} $) # 74 not followed by .?.?\n
307 | (?! [^=\n]{0,3} $) # 73 not followed by .?.?.?\n
308 ))//xsm;
309  
310 4 ▶ $brokenlines .= "$bol$res$eol" if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 4 0 4
311  
312 #print "$brokenlines\n";
313 4 $brokenlines;
314 }
315  
316 ################################################################################
317  
318 2 1;
319  
320 ################################################################################
321  
322 =pod
323  
324 =head1 NAME
325  
326 Mail::Sendmail::Enhanced v.0.02 = L<Mail::Sendmail> + encoding + attachments (pure Perl)
327  
328 =head1 SYNOPSIS
329  
330 #!/usr/bin/perl -w
331  
332 use strict;
333 use warnings;
334  
335 use Mail::Sendmail::Enhanced;
336  
337 my $MAIL = Mail::Sendmail::Enhanced-> new(
338 charset => 'UTF-8',
339 smtp => 'Your SMTP server',
340 from => 'Your mail',
341 user => 'user',
342 pass => 'password',
343 method => 'LOGIN',
344 required => 1,
345 attachments => {
346 'name for email of the file1' => 'OS file1 location',
347 'name for email of the file2' => 'OS file2 location',
348 },
349 attachments_size_max => 0,
350 );
351  
352 for (1..2) {
353 print $MAIL-> send( {
354 to => 'author of the module: <wb@webswing.co.uk>',
355 subject => "Subject longer than 80 characters with Polish letters: lowercase: ąćęłńóśźż and uppercase: ĄĆĘŁŃÓŚŹŻ.",
356 message => "This is the message nr $_. in the character encoding UTF-8.
357  
358 This is an example of using UTF-8 Polish letters in an email subject field: encoded and longer than 80 characters.",
359  
360 __END__
361  
362 =head1 DESCRIPTION
363  
364 Enhanced version of the module Mail::Sendmail with multibytes encoding
365 and attachments. It is pure Perl solution.
366  
367 From L<Mail::Sendmail>:
368  
369 "Simple platform independent e-mail from your perl script. Only
370 requires Perl 5 and a network connection. Mail::Sendmail takes a hash
371 with the message to send and sends it to your mail server. It is
372 intended to be very easy to setup and use."
373  
374  
375 In L<Mail::Sendmail::Enhanced> two things were added:
376  
377 1. Encoding - which uses the refurbish function B<encode_qp> from the
378 module L<MIME::QuotedPrint::Perl> which is put into the current one.
379 This is pure Perl solution.
380  
381 Simple encoding multibytes character long header field "Subject:"
382 caused that some characters were divided between two folded rows.
383 Some email clients are not able to put together these separated bytes
384 into one character and words were displeyed inproperly. Since the
385 version 0.02 this problem is solved by keeping bytes of one character
386 in one folded row.
387  
388 2. Attachments - which allows to add attachments easily. It makes it
389 by using the technique connected with "multipart/mixed" and "boundary"
390 'Content-Type' attribute.
391  
392 List of files to send (attachments) is given as a simple hash:
393  
394 attachments => {
395 'name for email of the file1' => 'OS file1 location',
396 'name for email of the file2' => 'OS file2 location',
397 },
398  
399 where the keys of the hash are "public" (in email) names of files and
400 values of the hash are these files OS locations, respectively.
401  
402 It possible to do additional specificification of sending attachments
403 throug the parameter B<attachments_size_max>. The possible values are:
404  
405 attachments_size_max => 0, # No limit for sizes of attachments
406  
407 attachments_size_max => -1, # Negative value means that sending attachments is forbidden.
408 # Every try of sending them with this value negative is fatal one.
409  
410 attachments_size_max => 100000, # Positive value is maximum size limit of attachment.
411 # When attachment is bigger then fatal error is return;
412  
413  
414 =head1 BUGS
415  
416 Please report any bugs or feature requests to
417 C<bug-mail-sendmail-enhanced at rt.cpan.org>, or through the web interface at
418 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mail-Sendmail-Enhanced>.
419 I will be notified, and then you'll automatically be notified of progress on your
420 bug as I make changes.
421  
422 =head1 LICENSE AND COPYRIGHT
423  
424 Copyright (C) 2015 Waldemar Biernacki, C<< <wb at webswing.co.uk> >>
425  
426 This program is free software; you can redistribute it and/or modify it
427 under the terms of the the Artistic License (2.0). You may obtain a
428 copy of the full license at:
429  
430 L<http://www.perlfoundation.org/artistic_license_2_0>
431  
432 Any use, modification, and distribution of the Standard or Modified
433 Versions is governed by this Artistic License. By using, modifying or
434 distributing the Package, you accept this license. Do not use, modify,
435 or distribute the Package, if you do not accept this license.
436  
437 If your Modified Version has been derived from a Modified Version made
438 by someone other than you, you are nevertheless required to ensure that
439 your Modified Version complies with the requirements of this license.
440  
441 This license does not grant you the right to use any trademark, service
442 mark, tradename, or logo of the Copyright Holder.
443  
444 This license includes the non-exclusive, worldwide, free-of-charge
445 patent license to make, have made, use, offer to sell, sell, import and
446 otherwise transfer the Package with respect to any patent claims
447 licensable by the Copyright Holder that are necessarily infringed by the
448 Package. If you institute patent litigation (including a cross-claim or
449 counterclaim) against any party alleging that the Package constitutes
450 direct or contributory patent infringement, then this Artistic License
451 to you shall terminate on the date that such litigation is filed.
452  
453 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
454 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
455 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
456 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
457 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
458 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
459 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
460 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
461  
462 =head1 SEE ALSO
463  
464 L<Mail::Sendmail>, L<MIME::QuotedPrint::Perl>
465  
466 =cut
467  
↑ Summary