@@ -126,6 +126,7 @@ sub format_2822_time {
126
126
}
127
127
128
128
my $have_email_valid = eval { require Email::Valid; 1 };
129
+ my $have_mail_address = eval { require Mail::Address; 1 };
129
130
my $smtp ;
130
131
my $auth ;
131
132
@@ -366,6 +367,14 @@ sub read_config {
366
367
die " Comma in --bcclist entry: $entry '\n " unless $entry !~ m / ,/ ;
367
368
}
368
369
370
+ sub parse_address_line {
371
+ if ($have_mail_address ) {
372
+ return map { $_ -> format } Mail::Address-> parse($_ [0]);
373
+ } else {
374
+ return split_addrs($_ [0]);
375
+ }
376
+ }
377
+
369
378
sub split_addrs {
370
379
return quotewords(' \s*,\s*' , 1, @_ );
371
380
}
602
611
}
603
612
604
613
my $to = $_ ;
605
- push @to , split_addrs ($to );
614
+ push @to , parse_address_line ($to );
606
615
$prompting ++;
607
616
}
608
617
@@ -929,88 +938,98 @@ sub send_message
929
938
@cc = @initial_cc ;
930
939
@xh = ();
931
940
my $input_format = undef ;
932
- my $header_done = 0 ;
941
+ my @header = () ;
933
942
$message = " " ;
943
+ # First unfold multiline header fields
934
944
while (<F>) {
935
- if (!$header_done ) {
936
- if (/ ^From / ) {
937
- $input_format = ' mbox' ;
938
- next ;
945
+ last if / ^\s *$ / ;
946
+ if (/ ^\s +\S / and @header ) {
947
+ chomp ($header [$#header ]);
948
+ s / ^\s +/ / ;
949
+ $header [$#header ] .= $_ ;
950
+ } else {
951
+ push (@header , $_ );
952
+ }
953
+ }
954
+ # Now parse the header
955
+ foreach (@header ) {
956
+ if (/ ^From / ) {
957
+ $input_format = ' mbox' ;
958
+ next ;
959
+ }
960
+ chomp ;
961
+ if (!defined $input_format && / ^[-A-Za-z]+:\s / ) {
962
+ $input_format = ' mbox' ;
963
+ }
964
+
965
+ if (defined $input_format && $input_format eq ' mbox' ) {
966
+ if (/ ^Subject:\s +(.*)$ / ) {
967
+ $subject = $1 ;
939
968
}
940
- chomp ;
941
- if (!defined $input_format && / ^[-A-Za-z]+:\s / ) {
942
- $input_format = ' mbox' ;
969
+ elsif (/ ^From:\s +(.*)$ / ) {
970
+ ($author , $author_encoding ) = unquote_rfc2047($1 );
971
+ next if $suppress_cc {' author' };
972
+ next if $suppress_cc {' self' } and $author eq $sender ;
973
+ printf (" (mbox) Adding cc: %s from line '%s '\n " ,
974
+ $1 , $_ ) unless $quiet ;
975
+ push @cc , $1 ;
943
976
}
944
-
945
- if (defined $input_format && $input_format eq ' mbox' ) {
946
- if (/ ^Subject:\s +(.*)$ / ) {
947
- $subject = $1 ;
948
-
949
- } elsif (/ ^(Cc|From):\s +(.*)$ / ) {
950
- if (unquote_rfc2047($2 ) eq $sender ) {
977
+ elsif (/ ^Cc:\s +(.*)$ / ) {
978
+ foreach my $addr (parse_address_line($1 )) {
979
+ if (unquote_rfc2047($addr ) eq $sender ) {
951
980
next if ($suppress_cc {' self' });
952
- }
953
- elsif ($1 eq ' From' ) {
954
- ($author , $author_encoding )
955
- = unquote_rfc2047($2 );
956
- next if ($suppress_cc {' author' });
957
981
} else {
958
982
next if ($suppress_cc {' cc' });
959
983
}
960
984
printf (" (mbox) Adding cc: %s from line '%s '\n " ,
961
- $2 , $_ ) unless $quiet ;
962
- push @cc , $2 ;
985
+ $addr , $_ ) unless $quiet ;
986
+ push @cc , $addr ;
963
987
}
964
- elsif (/ ^Content-type:/i ) {
965
- $has_content_type = 1;
966
- if (/ charset="?([^ "]+)/ ) {
967
- $body_encoding = $1 ;
968
- }
969
- push @xh , $_ ;
970
- }
971
- elsif (/ ^Message-Id: (.*)/i ) {
972
- $message_id = $1 ;
973
- }
974
- elsif (!/^Date:\s / && / ^[-A-Za-z]+:\s +\S / ) {
975
- push @xh , $_ ;
976
- }
977
-
978
- } else {
979
- # In the traditional
980
- # "send lots of email" format,
981
- # line 1 = cc
982
- # line 2 = subject
983
- # So let's support that, too.
984
- $input_format = ' lots' ;
985
- if (@cc == 0 && !$suppress_cc {' cc' }) {
986
- printf (" (non-mbox) Adding cc: %s from line '%s '\n " ,
987
- $_ , $_ ) unless $quiet ;
988
-
989
- push @cc , $_ ;
990
-
991
- } elsif (!defined $subject ) {
992
- $subject = $_ ;
988
+ }
989
+ elsif (/ ^Content-type:/i ) {
990
+ $has_content_type = 1;
991
+ if (/ charset="?([^ "]+)/ ) {
992
+ $body_encoding = $1 ;
993
993
}
994
+ push @xh , $_ ;
994
995
}
995
-
996
- # A whitespace line will terminate the headers
997
- if (m / ^\s *$ / ) {
998
- $header_done = 1;
996
+ elsif (/ ^Message-Id: (.*)/i ) {
997
+ $message_id = $1 ;
999
998
}
999
+ elsif (!/^Date:\s / && / ^[-A-Za-z]+:\s +\S / ) {
1000
+ push @xh , $_ ;
1001
+ }
1002
+
1000
1003
} else {
1001
- $message .= $_ ;
1002
- if (/ ^(Signed-off-by|Cc): (.*)$ /i ) {
1003
- next if ($suppress_cc {' sob' });
1004
- chomp ;
1005
- my $c = $2 ;
1006
- chomp $c ;
1007
- next if ($c eq $sender and $suppress_cc {' self' });
1008
- push @cc , $c ;
1009
- printf (" (sob) Adding cc: %s from line '%s '\n " ,
1010
- $c , $_ ) unless $quiet ;
1004
+ # In the traditional
1005
+ # "send lots of email" format,
1006
+ # line 1 = cc
1007
+ # line 2 = subject
1008
+ # So let's support that, too.
1009
+ $input_format = ' lots' ;
1010
+ if (@cc == 0 && !$suppress_cc {' cc' }) {
1011
+ printf (" (non-mbox) Adding cc: %s from line '%s '\n " ,
1012
+ $_ , $_ ) unless $quiet ;
1013
+ push @cc , $_ ;
1014
+ } elsif (!defined $subject ) {
1015
+ $subject = $_ ;
1011
1016
}
1012
1017
}
1013
1018
}
1019
+ # Now parse the message body
1020
+ while (<F>) {
1021
+ $message .= $_ ;
1022
+ if (/ ^(Signed-off-by|Cc): (.*)$ /i ) {
1023
+ next if ($suppress_cc {' sob' });
1024
+ chomp ;
1025
+ my $c = $2 ;
1026
+ chomp $c ;
1027
+ next if ($c eq $sender and $suppress_cc {' self' });
1028
+ push @cc , $c ;
1029
+ printf (" (sob) Adding cc: %s from line '%s '\n " ,
1030
+ $c , $_ ) unless $quiet ;
1031
+ }
1032
+ }
1014
1033
close F;
1015
1034
1016
1035
if (defined $cc_cmd && !$suppress_cc {' cccmd' }) {
@@ -1029,7 +1048,7 @@ sub send_message
1029
1048
or die " (cc-cmd) failed to close pipe to '$cc_cmd '" ;
1030
1049
}
1031
1050
1032
- if (defined $author ) {
1051
+ if (defined $author and $author ne $sender ) {
1033
1052
$message = " From: $author \n\n $message " ;
1034
1053
if (defined $author_encoding ) {
1035
1054
if ($has_content_type ) {
0 commit comments