3 # Copyright 2002,2005 Greg Kroah-Hartman <greg@kroah.com>
4 # Copyright 2005 Ryan Anderson <ryan@michonline.com>
8 # Ported to support git "mbox" format files by Ryan Anderson <ryan@michonline.com>
10 # Sends a collection of emails to the given email addresses, disturbingly fast.
12 # Supports two formats:
13 # 1. mbox format files (ignoring most headers and MIME formatting - this is designed for sending patches)
14 # 2. The original format support by Greg's script:
15 # first line of the message is who to CC,
16 # and second line is the subject of the message.
29 my ($class, $reason) = @_;
30 return bless \
$reason, shift;
34 die "Cannot use readline on FakeTerm: $$self";
41 git send-email [options] <file | directory>...
43 --identity <str> * Use the sendemail.<id> options.
44 --from <str> * Email From:
45 --envelope-sender <str> * Email envelope sender.
46 --to <str> * Email To:
47 --cc <str> * Email Cc:
48 --cc-cmd <str> * Email Cc: via `<str> \$patch_path`
49 --bcc <str> * Email Bcc:
50 --subject <str> * Email "Subject:" (only if --compose).
51 --compose * Open an editor for introduction.
52 --in-reply-to <str> * First "In-Reply-To:" (only if --compose).
53 --[no-]chain-reply-to * Chain In-Reply-To: fields. Default on.
54 --[no-]thread * Use In-Reply-To: field. Default on.
55 --[no-]signed-off-by-cc * Actually send to Cc: and Signed-off-by:
56 addresses. Default on.
57 --suppress-cc <str> * author, self, sob, cccmd, all.
58 --[no-]suppress-from * Don't send email to self. Default off.
59 --smtp-server <str:int> * Outgoing SMTP server to use. The port
60 is optional. Default 'localhost'.
61 --smtp-server-port <int> * Outgoing SMTP server port.
62 --smtp-user <str> * The username for SMTP-AUTH.
63 --smtp-pass <str> * The password for SMTP-AUTH; not necessary.
64 --smtp-encryption <str> * tls or ssl; anything else disables.
65 --smtp-ssl * Deprecated. Use '--smtp-encryption ssl'.
66 --quiet * Output one line of info per email.
67 --dry-run * Don't actually send the emails.
68 --[no-]validate * Perform patch sanity checks. Default on.
74 # most mail servers generate the Date: header, but not all...
75 sub format_2822_time
{
77 my @localtm = localtime($time);
78 my @gmttm = gmtime($time);
79 my $localmin = $localtm[1] + $localtm[2] * 60;
80 my $gmtmin = $gmttm[1] + $gmttm[2] * 60;
81 if ($localtm[0] != $gmttm[0]) {
82 die "local zone differs from GMT by a non-minute interval\n";
84 if ((($gmttm[6] + 1) % 7) == $localtm[6]) {
86 } elsif ((($gmttm[6] - 1) % 7) == $localtm[6]) {
88 } elsif ($gmttm[6] != $localtm[6]) {
89 die "local time offset greater than or equal to 24 hours\n";
91 my $offset = $localmin - $gmtmin;
92 my $offhour = $offset / 60;
93 my $offmin = abs($offset % 60);
94 if (abs($offhour) >= 24) {
95 die ("local time offset greater than or equal to 24 hours\n");
98 return sprintf("%s, %2d %s %d %02d:%02d:%02d %s%02d%02d",
99 qw(Sun Mon Tue Wed Thu Fri Sat)[$localtm[6]],
101 qw(Jan Feb Mar Apr May Jun
102 Jul Aug Sep Oct Nov Dec)[$localtm[4]],
107 ($offset >= 0) ?
'+' : '-',
113 my $have_email_valid = eval { require Email
::Valid
; 1 };
117 sub unique_email_list
(@
);
118 sub cleanup_compose_files
();
120 # Constants (essentially)
121 my $compose_filename = ".msg.$$";
123 # Variables we fill in automatically, or via prompting:
124 my (@to,@cc,@initial_cc,@bcclist,@xh,
125 $initial_reply_to,$initial_subject,@files,$author,$sender,$smtp_authpass,$compose,$time);
130 #$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';
132 my $repo = eval { Git
->repository() };
133 my @repo = $repo ?
($repo) : ();
135 $ENV{"GIT_SEND_EMAIL_NOTTY"}
136 ? new Term
::ReadLine
'git-send-email', \
*STDIN
, \
*STDOUT
137 : new Term
::ReadLine
'git-send-email';
140 $term = new FakeTerm
"$@: going non-interactive";
143 # Behavior modification variables
144 my ($quiet, $dry_run) = (0, 0);
146 # Variables with corresponding config settings
147 my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);
148 my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);
149 my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
153 my %config_bool_settings = (
154 "thread" => [\
$thread, 1],
155 "chainreplyto" => [\
$chain_reply_to, 1],
156 "suppressfrom" => [\
$suppress_from, undef],
157 "signedoffcc" => [\
$signed_off_cc, undef],
158 "validate" => [\
$validate, 1],
161 my %config_settings = (
162 "smtpserver" => \
$smtp_server,
163 "smtpserverport" => \
$smtp_server_port,
164 "smtpuser" => \
$smtp_authuser,
165 "smtppass" => \
$smtp_authpass,
167 "cc" => \
@initial_cc,
169 "aliasfiletype" => \
$aliasfiletype,
171 "aliasesfile" => \
@alias_files,
172 "suppresscc" => \
@suppress_cc,
173 "envelopesender" => \
$envelope_sender,
176 # Handle Uncouth Termination
180 print color
("reset"), "\n";
182 # SMTP password masked
185 # tmp files from --compose
186 if (-e
$compose_filename) {
187 print "'$compose_filename' contains an intermediate version of the email you were composing.\n";
189 if (-e
($compose_filename . ".final")) {
190 print "'$compose_filename.final' contains the composed email.\n"
196 $SIG{TERM
} = \
&signal_handler
;
197 $SIG{INT
} = \
&signal_handler
;
199 # Begin by accumulating all the variables (defined above), that we will end up
200 # needing, first, from the command line:
202 my $rc = GetOptions
("sender|from=s" => \
$sender,
203 "in-reply-to=s" => \
$initial_reply_to,
204 "subject=s" => \
$initial_subject,
206 "cc=s" => \
@initial_cc,
207 "bcc=s" => \
@bcclist,
208 "chain-reply-to!" => \
$chain_reply_to,
209 "smtp-server=s" => \
$smtp_server,
210 "smtp-server-port=s" => \
$smtp_server_port,
211 "smtp-user=s" => \
$smtp_authuser,
212 "smtp-pass:s" => \
$smtp_authpass,
213 "smtp-ssl" => sub { $smtp_encryption = 'ssl' },
214 "smtp-encryption=s" => \
$smtp_encryption,
215 "identity=s" => \
$identity,
216 "compose" => \
$compose,
218 "cc-cmd=s" => \
$cc_cmd,
219 "suppress-from!" => \
$suppress_from,
220 "suppress-cc=s" => \
@suppress_cc,
221 "signed-off-cc|signed-off-by-cc!" => \
$signed_off_cc,
222 "dry-run" => \
$dry_run,
223 "envelope-sender=s" => \
$envelope_sender,
224 "thread!" => \
$thread,
225 "validate!" => \
$validate,
232 # Now, let's fill any that aren't set in with defaults:
237 foreach my $setting (keys %config_bool_settings) {
238 my $target = $config_bool_settings{$setting}->[0];
239 $$target = Git
::config_bool
(@repo, "$prefix.$setting") unless (defined $$target);
242 foreach my $setting (keys %config_settings) {
243 my $target = $config_settings{$setting};
244 if (ref($target) eq "ARRAY") {
246 my @values = Git
::config
(@repo, "$prefix.$setting");
247 @
$target = @values if (@values && defined $values[0]);
251 $$target = Git
::config
(@repo, "$prefix.$setting") unless (defined $$target);
255 if (!defined $smtp_encryption) {
256 my $enc = Git
::config
(@repo, "$prefix.smtpencryption");
258 $smtp_encryption = $enc;
259 } elsif (Git
::config_bool
(@repo, "$prefix.smtpssl")) {
260 $smtp_encryption = 'ssl';
265 # read configuration from [sendemail "$identity"], fall back on [sendemail]
266 $identity = Git
::config
(@repo, "sendemail.identity") unless (defined $identity);
267 read_config
("sendemail.$identity") if (defined $identity);
268 read_config
("sendemail");
270 # fall back on builtin bool defaults
271 foreach my $setting (values %config_bool_settings) {
272 ${$setting->[0]} = $setting->[1] unless (defined (${$setting->[0]}));
275 # 'default' encryption is none -- this only prevents a warning
276 $smtp_encryption = '' unless (defined $smtp_encryption);
278 # Set CC suppressions
281 foreach my $entry (@suppress_cc) {
282 die "Unknown --suppress-cc field: '$entry'\n"
283 unless $entry =~ /^(all|cccmd|cc|author|self|sob)$/;
284 $suppress_cc{$entry} = 1;
288 if ($suppress_cc{'all'}) {
289 foreach my $entry (qw
(ccmd cc author self sob
)) {
290 $suppress_cc{$entry} = 1;
292 delete $suppress_cc{'all'};
295 # If explicit old-style ones are specified, they trump --suppress-cc.
296 $suppress_cc{'self'} = $suppress_from if defined $suppress_from;
297 $suppress_cc{'sob'} = !$signed_off_cc if defined $signed_off_cc;
299 # Debugging, print out the suppressions.
301 print "suppressions:\n";
302 foreach my $entry (keys %suppress_cc) {
303 printf " %-5s -> $suppress_cc{$entry}\n", $entry;
307 my ($repoauthor, $repocommitter);
308 ($repoauthor) = Git
::ident_person
(@repo, 'author');
309 ($repocommitter) = Git
::ident_person
(@repo, 'committer');
311 # Verify the user input
313 foreach my $entry (@to) {
314 die "Comma in --to entry: $entry'\n" unless $entry !~ m/,/;
317 foreach my $entry (@initial_cc) {
318 die "Comma in --cc entry: $entry'\n" unless $entry !~ m/,/;
321 foreach my $entry (@bcclist) {
322 die "Comma in --bcclist entry: $entry'\n" unless $entry !~ m/,/;
327 # multiline formats can be supported in the future
328 mutt
=> sub { my $fh = shift; while (<$fh>) {
329 if (/^\s*alias\s+(\S+)\s+(.*)$/) {
330 my ($alias, $addr) = ($1, $2);
331 $addr =~ s/#.*$//; # mutt allows # comments
332 # commas delimit multiple addresses
333 $aliases{$alias} = [ split(/\s*,\s*/, $addr) ];
335 mailrc
=> sub { my $fh = shift; while (<$fh>) {
336 if (/^alias\s+(\S+)\s+(.*)$/) {
337 # spaces delimit multiple addresses
338 $aliases{$1} = [ split(/\s+/, $2) ];
340 pine
=> sub { my $fh = shift; while (<$fh>) {
341 if (/^(\S+)\t.*\t(.*)$/) {
342 $aliases{$1} = [ split(/\s*,\s*/, $2) ];
344 gnus
=> sub { my $fh = shift; while (<$fh>) {
345 if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
346 $aliases{$1} = [ $2 ];
350 if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {
351 foreach my $file (@alias_files) {
352 open my $fh, '<', $file or die "opening $file: $!\n";
353 $parse_alias{$aliasfiletype}->($fh);
358 ($sender) = expand_aliases
($sender) if defined $sender;
360 # Now that all the defaults are set, process the rest of the command line
361 # arguments and collect up the files that need to be processed.
365 or die "Failed to opendir $f: $!";
367 push @files, grep { -f
$_ } map { +$f . "/" . $_ }
370 } elsif (-f
$f or -p
$f) {
374 print STDERR
"Skipping $f - not found.\n";
379 foreach my $f (@files) {
381 my $error = validate_patch
($f);
382 $error and die "fatal: $f: $error\nwarning: no patches were sent\n";
389 print $_,"\n" for (@files);
392 print STDERR
"\nNo patch files specified!\n\n";
397 if (!defined $sender) {
398 $sender = $repoauthor || $repocommitter || '';
401 $_ = $term->readline("Who should the emails appear to be from? [$sender] ");
406 $sender = $_ if ($_);
407 print "Emails will be sent from: ", $sender, "\n";
415 $_ = $term->readline("Who should the emails be sent to? ", "");
421 push @to, split /,\s*/, $to;
430 @cur = map { $aliases{$_} ? @
{$aliases{$_}} : $_ } @last;
431 } while (join(',',@cur) ne join(',',@last));
435 @to = expand_aliases
(@to);
436 @to = (map { sanitize_address
($_) } @to);
437 @initial_cc = expand_aliases
(@initial_cc);
438 @bcclist = expand_aliases
(@bcclist);
440 if (!defined $initial_subject && $compose) {
442 $_ = $term->readline("What subject should the initial email start with? ", $initial_subject);
447 $initial_subject = $_;
451 if ($thread && !defined $initial_reply_to && $prompting) {
453 $_= $term->readline("Message-ID to be used as In-Reply-To for the first email? ", $initial_reply_to);
458 $initial_reply_to = $_;
460 if (defined $initial_reply_to) {
461 $initial_reply_to =~ s/^\s*<?//;
462 $initial_reply_to =~ s/>?\s*$//;
463 $initial_reply_to = "<$initial_reply_to>" if $initial_reply_to ne '';
466 if (!defined $smtp_server) {
467 foreach (qw( /usr/sbin/sendmail /usr/lib/sendmail )) {
473 $smtp_server ||= 'localhost'; # could be 127.0.0.1, too... *shrug*
477 # Note that this does not need to be secure, but we will make a small
478 # effort to have it be unique
479 open(C
,">",$compose_filename)
480 or die "Failed to open for writing $compose_filename: $!";
481 print C
"From $sender # This line is ignored.\n";
482 printf C
"Subject: %s\n\n", $initial_subject;
484 GIT: Please enter your email below.
485 GIT: Lines beginning in "GIT: " will be removed.
486 GIT: Consider including an overall diffstat or table of contents
487 GIT: for the patch you are writing.
492 my $editor = $ENV{GIT_EDITOR
} || Git
::config
(@repo, "core.editor") || $ENV{VISUAL
} || $ENV{EDITOR
} || "vi";
493 system('sh', '-c', $editor.' "$@"', $editor, $compose_filename);
495 open(C2
,">",$compose_filename . ".final")
496 or die "Failed to open $compose_filename.final : " . $!;
498 open(C
,"<",$compose_filename)
499 or die "Failed to open $compose_filename : " . $!;
501 my $need_8bit_cte = file_has_nonascii
($compose_filename);
505 if (!$in_body && /^\n$/) {
507 if ($need_8bit_cte) {
508 print C2
"MIME-Version: 1.0\n",
509 "Content-Type: text/plain; ",
511 "Content-Transfer-Encoding: 8bit\n";
514 if (!$in_body && /^MIME-Version:/i) {
517 if (!$in_body && /^Subject: ?(.*)/i) {
520 ($subject =~ /[^[:ascii:]]/ ?
521 quote_rfc2047
($subject) :
531 $_ = $term->readline("Send this email? (y|n) ");
536 if (uc substr($_,0,1) ne 'Y') {
537 cleanup_compose_files
();
541 @files = ($compose_filename . ".final", @files);
544 # Variables we set as part of the loop over files
545 our ($message_id, %mail, $subject, $reply_to, $references, $message);
547 sub extract_valid_address
{
549 my $local_part_regexp = '[^<>"\s@]+';
550 my $domain_regexp = '[^.<>"\s@]+(?:\.[^.<>"\s@]+)+';
552 # check for a local address:
553 return $address if ($address =~ /^($local_part_regexp)$/);
555 $address =~ s/^\s*<(.*)>\s*$/$1/;
556 if ($have_email_valid) {
557 return scalar Email
::Valid
->address($address);
559 # less robust/correct than the monster regexp in Email::Valid,
560 # but still does a 99% job, and one less dependency
561 $address =~ /($local_part_regexp\@$domain_regexp)/;
566 # Usually don't need to change anything below here.
568 # we make a "fake" message id by taking the current number
569 # of seconds since the beginning of Unix time and tacking on
570 # a random number to the end, in case we are called quicker than
571 # 1 second since the last time we were called.
573 # We'll setup a template for the message id, using the "from" address:
575 my ($message_id_stamp, $message_id_serial);
579 if (!defined $message_id_stamp) {
580 $message_id_stamp = sprintf("%s-%s", time, $$);
581 $message_id_serial = 0;
583 $message_id_serial++;
584 $uniq = "$message_id_stamp-$message_id_serial";
587 for ($sender, $repocommitter, $repoauthor) {
588 $du_part = extract_valid_address
(sanitize_address
($_));
589 last if (defined $du_part and $du_part ne '');
591 if (not defined $du_part or $du_part eq '') {
592 use Sys
::Hostname
qw();
593 $du_part = 'user@' . Sys
::Hostname
::hostname
();
595 my $message_id_template = "<%s-git-send-email-%s>";
596 $message_id = sprintf($message_id_template, $uniq, $du_part);
597 #print "new message id = $message_id\n"; # Was useful for debugging
602 $time = time - scalar $#files;
604 sub unquote_rfc2047
{
607 if (s/=\?([^?]+)\?q\?(.*)\?=/$2/g) {
610 s/=([0-9A-F]{2})/chr(hex($1))/eg;
612 return wantarray ?
($_, $encoding) : $_;
617 my $encoding = shift || 'utf-8';
618 s/([^-a-zA-Z0-9!*+\/])/sprintf
("=%02X", ord($1))/eg
;
619 s/(.*)/=\?$encoding\?q\?$1\?=/;
623 # use the simplest quoting being able to handle the recipient
626 my ($recipient) = @_;
627 my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\s*(<.*)/);
629 if (not $recipient_name) {
633 # if recipient_name is already quoted, do nothing
634 if ($recipient_name =~ /^(".*"|=\?utf-8\?q\?.*\?=)$/) {
638 # rfc2047 is needed if a non-ascii char is included
639 if ($recipient_name =~ /[^[:ascii:]]/) {
640 $recipient_name = quote_rfc2047
($recipient_name);
643 # double quotes are needed if specials or CTLs are included
644 elsif ($recipient_name =~ /[][()<>@,;:\\".\000-\037\177]/) {
645 $recipient_name =~ s/(["\\\r])/\\$1/g;
646 $recipient_name = "\"$recipient_name\"";
649 return "$recipient_name $recipient_addr";
655 my @recipients = unique_email_list
(@to);
656 @cc = (grep { my $cc = extract_valid_address
($_);
657 not grep { $cc eq $_ } @recipients
659 map { sanitize_address
($_) }
661 my $to = join (",\n\t", @recipients);
662 @recipients = unique_email_list
(@recipients,@cc,@bcclist);
663 @recipients = (map { extract_valid_address
($_) } @recipients);
664 my $date = format_2822_time
($time++);
665 my $gitversion = '@@GIT_VERSION@@';
666 if ($gitversion =~ m/..GIT_VERSION../) {
667 $gitversion = Git
::version
();
670 my $cc = join(", ", unique_email_list
(@cc));
673 $ccline = "\nCc: $cc";
675 my $sanitized_sender = sanitize_address
($sender);
676 make_message_id
() unless defined($message_id);
678 my $header = "From: $sanitized_sender
682 Message-Id: $message_id
683 X-Mailer: git-send-email $gitversion
685 if ($thread && $reply_to) {
687 $header .= "In-Reply-To: $reply_to\n";
688 $header .= "References: $references\n";
691 $header .= join("\n", @xh) . "\n";
694 my @sendmail_parameters = ('-i', @recipients);
695 my $raw_from = $sanitized_sender;
696 $raw_from = $envelope_sender if (defined $envelope_sender);
697 $raw_from = extract_valid_address
($raw_from);
698 unshift (@sendmail_parameters,
699 '-f', $raw_from) if(defined $envelope_sender);
702 # We don't want to send the email.
703 } elsif ($smtp_server =~ m
#^/#) {
704 my $pid = open my $sm, '|-';
705 defined $pid or die $!;
707 exec($smtp_server, @sendmail_parameters) or die $!;
709 print $sm "$header\n$message";
713 if (!defined $smtp_server) {
714 die "The required SMTP server is not properly defined."
717 if ($smtp_encryption eq 'ssl') {
718 $smtp_server_port ||= 465; # ssmtp
719 require Net
::SMTP
::SSL
;
720 $smtp ||= Net
::SMTP
::SSL
->new($smtp_server, Port
=> $smtp_server_port);
724 $smtp ||= Net
::SMTP
->new((defined $smtp_server_port)
725 ?
"$smtp_server:$smtp_server_port"
727 if ($smtp_encryption eq 'tls') {
728 require Net
::SMTP
::SSL
;
729 $smtp->command('STARTTLS');
731 if ($smtp->code == 220) {
732 $smtp = Net
::SMTP
::SSL
->start_SSL($smtp)
733 or die "STARTTLS failed! ".$smtp->message;
734 $smtp_encryption = '';
735 # Send EHLO again to receive fresh
739 die "Server does not support STARTTLS! ".$smtp->message;
745 die "Unable to initialize SMTP properly. Is there something wrong with your config?";
748 if (defined $smtp_authuser) {
750 if (!defined $smtp_authpass) {
758 } while (!defined $_);
760 chomp($smtp_authpass = $_);
765 $auth ||= $smtp->auth( $smtp_authuser, $smtp_authpass ) or die $smtp->message;
768 $smtp->mail( $raw_from ) or die $smtp->message;
769 $smtp->to( @recipients ) or die $smtp->message;
770 $smtp->data or die $smtp->message;
771 $smtp->datasend("$header\n$message") or die $smtp->message;
772 $smtp->dataend() or die $smtp->message;
773 $smtp->ok or die "Failed to send $subject\n".$smtp->message;
776 printf (($dry_run ?
"Dry-" : "")."Sent %s\n", $subject);
778 print (($dry_run ?
"Dry-" : "")."OK. Log says:\n");
779 if ($smtp_server !~ m
#^/#) {
780 print "Server: $smtp_server\n";
781 print "MAIL FROM:<$raw_from>\n";
782 print "RCPT TO:".join(',',(map { "<$_>" } @recipients))."\n";
784 print "Sendmail: $smtp_server ".join(' ',@sendmail_parameters)."\n";
788 print "Result: ", $smtp->code, ' ',
789 ($smtp->message =~ /\n([^\n]+\n)$/s), "\n";
791 print "Result: OK\n";
796 $reply_to = $initial_reply_to;
797 $references = $initial_reply_to || '';
798 $subject = $initial_subject;
800 foreach my $t (@files) {
801 open(F
,"<",$t) or die "can't open file $t";
805 my $has_content_type;
809 my $input_format = undef;
815 $input_format = 'mbox';
819 if (!defined $input_format && /^[-A-Za-z]+:\s/) {
820 $input_format = 'mbox';
823 if (defined $input_format && $input_format eq 'mbox') {
824 if (/^Subject:\s+(.*)$/) {
827 } elsif (/^(Cc|From):\s+(.*)$/) {
828 if (unquote_rfc2047
($2) eq $sender) {
829 next if ($suppress_cc{'self'});
831 elsif ($1 eq 'From') {
832 ($author, $author_encoding)
833 = unquote_rfc2047
($2);
834 next if ($suppress_cc{'author'});
836 next if ($suppress_cc{'cc'});
838 printf("(mbox) Adding cc: %s from line '%s'\n",
839 $2, $_) unless $quiet;
842 elsif (/^Content-type:/i) {
843 $has_content_type = 1;
844 if (/charset="?([^ "]+)/) {
849 elsif (/^Message-Id: (.*)/i) {
852 elsif (!/^Date:\s/ && /^[-A-Za-z]+:\s+\S/) {
858 # "send lots of email" format,
861 # So let's support that, too.
862 $input_format = 'lots';
863 if (@cc == 0 && !$suppress_cc{'cc'}) {
864 printf("(non-mbox) Adding cc: %s from line '%s'\n",
865 $_, $_) unless $quiet;
869 } elsif (!defined $subject) {
874 # A whitespace line will terminate the headers
880 if (/^(Signed-off-by|Cc): (.*)$/i) {
881 next if ($suppress_cc{'sob'});
885 next if ($c eq $sender and $suppress_cc{'self'});
887 printf("(sob) Adding cc: %s from line '%s'\n",
888 $c, $_) unless $quiet;
894 if (defined $cc_cmd && !$suppress_cc{'cccmd'}) {
895 open(F
, "$cc_cmd $t |")
896 or die "(cc-cmd) Could not execute '$cc_cmd'";
901 next if ($c eq $sender and $suppress_from);
903 printf("(cc-cmd) Adding cc: %s from: '%s'\n",
904 $c, $cc_cmd) unless $quiet;
907 or die "(cc-cmd) failed to close pipe to '$cc_cmd'";
910 if (defined $author) {
911 $message = "From: $author\n\n$message";
912 if (defined $author_encoding) {
913 if ($has_content_type) {
914 if ($body_encoding eq $author_encoding) {
915 # ok, we already have the right encoding
918 # uh oh, we should re-encode
924 "Content-Type: text/plain; charset=$author_encoding",
925 'Content-Transfer-Encoding: 8bit';
932 # set up for the next message
933 if ($chain_reply_to || !defined $reply_to || length($reply_to) == 0) {
934 $reply_to = $message_id;
935 if (length $references > 0) {
936 $references .= "\n $message_id";
938 $references = "$message_id";
945 cleanup_compose_files
();
948 sub cleanup_compose_files
() {
949 unlink($compose_filename, $compose_filename . ".final");
953 $smtp->quit if $smtp;
955 sub unique_email_list
(@
) {
959 foreach my $entry (@_) {
960 if (my $clean = extract_valid_address
($entry)) {
962 next if $seen{$clean}++;
963 push @emails, $entry;
965 print STDERR
"W: unable to extract a valid address",
974 open(my $fh, '<', $fn)
975 or die "unable to open $fn: $!\n";
976 while (my $line = <$fh>) {
977 if (length($line) > 998) {
978 return "$.: patch contains a line longer than 998 characters";
984 sub file_has_nonascii
{
986 open(my $fh, '<', $fn)
987 or die "unable to open $fn: $!\n";
988 while (my $line = <$fh>) {
989 return 1 if $line =~ /[^[:ascii:]]/;