]> git.ipfire.org Git - thirdparty/git.git/blame - git-send-email.perl
Don't ignore a pack-refs write failure
[thirdparty/git.git] / git-send-email.perl
CommitLineData
83b24437 1#!/usr/bin/perl -w
83b24437 2#
f3d9f354
RA
3# Copyright 2002,2005 Greg Kroah-Hartman <greg@kroah.com>
4# Copyright 2005 Ryan Anderson <ryan@michonline.com>
83b24437
RA
5#
6# GPL v2 (See COPYING)
5825e5b2 7#
83b24437
RA
8# Ported to support git "mbox" format files by Ryan Anderson <ryan@michonline.com>
9#
f3d9f354 10# Sends a collection of emails to the given email addresses, disturbingly fast.
5825e5b2 11#
f3d9f354
RA
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:
5825e5b2 15# first line of the message is who to CC,
f3d9f354 16# and second line is the subject of the message.
5825e5b2 17#
83b24437
RA
18
19use strict;
20use warnings;
21use Term::ReadLine;
83b24437
RA
22use Getopt::Long;
23use Data::Dumper;
3cb8caf7 24use Git;
83b24437 25
280242d1
JH
26package FakeTerm;
27sub new {
28 my ($class, $reason) = @_;
29 return bless \$reason, shift;
30}
31sub readline {
32 my $self = shift;
33 die "Cannot use readline on FakeTerm: $$self";
34}
35package main;
36
1b0baf14
MC
37
38sub usage {
39 print <<EOT;
40git-send-email [options] <file | directory>...
41Options:
42 --from Specify the "From:" line of the email to be sent.
43
44 --to Specify the primary "To:" line of the email.
45
46 --cc Specify an initial "Cc:" list for the entire series
47 of emails.
48
49 --bcc Specify a list of email addresses that should be Bcc:
50 on all the emails.
51
52 --compose Use \$EDITOR to edit an introductory message for the
53 patch series.
54
55 --subject Specify the initial "Subject:" line.
56 Only necessary if --compose is also set. If --compose
57 is not set, this will be prompted for.
58
59 --in-reply-to Specify the first "In-Reply-To:" header line.
60 Only used if --compose is also set. If --compose is not
61 set, this will be prompted for.
62
63 --chain-reply-to If set, the replies will all be to the previous
64 email sent, rather than to the first email sent.
65 Defaults to on.
66
67 --no-signed-off-cc Suppress the automatic addition of email addresses
abec100c
BF
68 that appear in Signed-off-by: or Cc: lines to the cc:
69 list. Note: Using this option is not recommended.
1b0baf14
MC
70
71 --smtp-server If set, specifies the outgoing SMTP server to use.
72 Defaults to localhost.
73
74 --suppress-from Suppress sending emails to yourself if your address
75 appears in a From: line.
76
77 --quiet Make git-send-email less verbose. One line per email
78 should be all that is output.
79
238cc635
RJ
80 --dry-run Do everything except actually send the emails.
81
f073a592
RJ
82 --envelope-sender Specify the envelope sender used to send the emails.
83
1b0baf14
MC
84EOT
85 exit(1);
86}
87
4bc87a28 88# most mail servers generate the Date: header, but not all...
6bdca890
JN
89sub format_2822_time {
90 my ($time) = @_;
91 my @localtm = localtime($time);
92 my @gmttm = gmtime($time);
93 my $localmin = $localtm[1] + $localtm[2] * 60;
94 my $gmtmin = $gmttm[1] + $gmttm[2] * 60;
95 if ($localtm[0] != $gmttm[0]) {
96 die "local zone differs from GMT by a non-minute interval\n";
97 }
98 if ((($gmttm[6] + 1) % 7) == $localtm[6]) {
99 $localmin += 1440;
100 } elsif ((($gmttm[6] - 1) % 7) == $localtm[6]) {
101 $localmin -= 1440;
102 } elsif ($gmttm[6] != $localtm[6]) {
103 die "local time offset greater than or equal to 24 hours\n";
104 }
105 my $offset = $localmin - $gmtmin;
106 my $offhour = $offset / 60;
107 my $offmin = abs($offset % 60);
108 if (abs($offhour) >= 24) {
109 die ("local time offset greater than or equal to 24 hours\n");
110 }
111
112 return sprintf("%s, %2d %s %d %02d:%02d:%02d %s%02d%02d",
113 qw(Sun Mon Tue Wed Thu Fri Sat)[$localtm[6]],
114 $localtm[3],
115 qw(Jan Feb Mar Apr May Jun
116 Jul Aug Sep Oct Nov Dec)[$localtm[4]],
117 $localtm[5]+1900,
118 $localtm[2],
119 $localtm[1],
120 $localtm[0],
121 ($offset >= 0) ? '+' : '-',
122 abs($offhour),
123 $offmin,
124 );
125}
4bc87a28 126
567ffeb7 127my $have_email_valid = eval { require Email::Valid; 1 };
4bc87a28
EW
128my $smtp;
129
e205735d 130sub unique_email_list(@);
1f038a0c
RA
131sub cleanup_compose_files();
132
133# Constants (essentially)
134my $compose_filename = ".msg.$$";
e205735d 135
83b24437 136# Variables we fill in automatically, or via prompting:
ce91c2f6 137my (@to,@cc,@initial_cc,@bcclist,@xh,
58063245 138 $initial_reply_to,$initial_subject,@files,$from,$compose,$time);
83b24437 139
78488b2c 140# Behavior modification variables
6130259c
MW
141my ($chain_reply_to, $quiet, $suppress_from, $no_signed_off_cc,
142 $dry_run) = (1, 0, 0, 0, 0);
aca7ad76 143my $smtp_server;
f073a592 144my $envelope_sender;
78488b2c 145
9133261f 146# Example reply to:
83b24437 147#$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';
83b24437 148
3cb8caf7 149my $repo = Git->repository();
280242d1
JH
150my $term = eval {
151 new Term::ReadLine 'git-send-email';
152};
153if ($@) {
154 $term = new FakeTerm "$@: going non-interactive";
155}
83b24437 156
35c49eea
PB
157my $def_chain = $repo->config_bool('sendemail.chainreplyto');
158if (defined $def_chain and not $def_chain) {
4a62d3f5
AK
159 $chain_reply_to = 0;
160}
161
162@bcclist = $repo->config('sendemail.bcc');
163if (!@bcclist or !$bcclist[0]) {
164 @bcclist = ();
165}
166
83b24437
RA
167# Begin by accumulating all the variables (defined above), that we will end up
168# needing, first, from the command line:
169
170my $rc = GetOptions("from=s" => \$from,
171 "in-reply-to=s" => \$initial_reply_to,
172 "subject=s" => \$initial_subject,
173 "to=s" => \@to,
da140f8b 174 "cc=s" => \@initial_cc,
58063245 175 "bcc=s" => \@bcclist,
78488b2c 176 "chain-reply-to!" => \$chain_reply_to,
3342d850 177 "smtp-server=s" => \$smtp_server,
1f038a0c 178 "compose" => \$compose,
30d08b34 179 "quiet" => \$quiet,
a985d595 180 "suppress-from" => \$suppress_from,
8e69b31e 181 "no-signed-off-cc|no-signed-off-by-cc" => \$no_signed_off_cc,
6130259c 182 "dry-run" => \$dry_run,
f073a592 183 "envelope-sender=s" => \$envelope_sender,
83b24437
RA
184 );
185
1b0baf14
MC
186unless ($rc) {
187 usage();
188}
189
79ee555b
EB
190# Verify the user input
191
192foreach my $entry (@to) {
193 die "Comma in --to entry: $entry'\n" unless $entry !~ m/,/;
194}
195
196foreach my $entry (@initial_cc) {
197 die "Comma in --cc entry: $entry'\n" unless $entry !~ m/,/;
198}
199
200foreach my $entry (@bcclist) {
201 die "Comma in --bcclist entry: $entry'\n" unless $entry !~ m/,/;
202}
203
83b24437
RA
204# Now, let's fill any that aren't set in with defaults:
205
c7a30e56
PB
206my ($author) = $repo->ident_person('author');
207my ($committer) = $repo->ident_person('committer');
83b24437 208
994d6c66 209my %aliases;
3cb8caf7
PB
210my @alias_files = $repo->config('sendemail.aliasesfile');
211my $aliasfiletype = $repo->config('sendemail.aliasfiletype');
994d6c66
EW
212my %parse_alias = (
213 # multiline formats can be supported in the future
214 mutt => sub { my $fh = shift; while (<$fh>) {
504ceab6 215 if (/^\s*alias\s+(\S+)\s+(.*)$/) {
994d6c66
EW
216 my ($alias, $addr) = ($1, $2);
217 $addr =~ s/#.*$//; # mutt allows # comments
218 # commas delimit multiple addresses
219 $aliases{$alias} = [ split(/\s*,\s*/, $addr) ];
220 }}},
221 mailrc => sub { my $fh = shift; while (<$fh>) {
222 if (/^alias\s+(\S+)\s+(.*)$/) {
223 # spaces delimit multiple addresses
224 $aliases{$1} = [ split(/\s+/, $2) ];
225 }}},
226 pine => sub { my $fh = shift; while (<$fh>) {
227 if (/^(\S+)\s+(.*)$/) {
228 $aliases{$1} = [ split(/\s*,\s*/, $2) ];
229 }}},
230 gnus => sub { my $fh = shift; while (<$fh>) {
231 if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
232 $aliases{$1} = [ $2 ];
233 }}}
234);
235
3cb8caf7 236if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {
994d6c66
EW
237 foreach my $file (@alias_files) {
238 open my $fh, '<', $file or die "opening $file: $!\n";
239 $parse_alias{$aliasfiletype}->($fh);
240 close $fh;
241 }
242}
243
1f038a0c 244my $prompting = 0;
83b24437
RA
245if (!defined $from) {
246 $from = $author || $committer;
8037d1a3 247 do {
2ef58055 248 $_ = $term->readline("Who should the emails appear to be from? [$from] ");
ca9a7d65 249 } while (!defined $_);
8037d1a3 250
2ef58055 251 $from = $_ if ($_);
83b24437 252 print "Emails will be sent from: ", $from, "\n";
1f038a0c 253 $prompting++;
83b24437
RA
254}
255
256if (!@to) {
8037d1a3 257 do {
5825e5b2 258 $_ = $term->readline("Who should the emails be sent to? ",
8037d1a3
RA
259 "");
260 } while (!defined $_);
83b24437
RA
261 my $to = $_;
262 push @to, split /,/, $to;
1f038a0c 263 $prompting++;
83b24437
RA
264}
265
994d6c66
EW
266sub expand_aliases {
267 my @cur = @_;
268 my @last;
269 do {
270 @last = @cur;
271 @cur = map { $aliases{$_} ? @{$aliases{$_}} : $_ } @last;
272 } while (join(',',@cur) ne join(',',@last));
273 return @cur;
274}
275
276@to = expand_aliases(@to);
bf7af116 277@to = (map { sanitize_address_rfc822($_) } @to);
994d6c66 278@initial_cc = expand_aliases(@initial_cc);
58063245 279@bcclist = expand_aliases(@bcclist);
994d6c66 280
1f038a0c 281if (!defined $initial_subject && $compose) {
8037d1a3 282 do {
5825e5b2 283 $_ = $term->readline("What subject should the emails start with? ",
8037d1a3
RA
284 $initial_subject);
285 } while (!defined $_);
83b24437 286 $initial_subject = $_;
1f038a0c 287 $prompting++;
83b24437
RA
288}
289
1f038a0c 290if (!defined $initial_reply_to && $prompting) {
8037d1a3 291 do {
1f038a0c 292 $_= $term->readline("Message-ID to be used as In-Reply-To for the first email? ",
8037d1a3
RA
293 $initial_reply_to);
294 } while (!defined $_);
295
83b24437 296 $initial_reply_to = $_;
78488b2c 297 $initial_reply_to =~ s/(^\s+|\s+$)//g;
83b24437
RA
298}
299
6dcfa306
SV
300if (!$smtp_server) {
301 $smtp_server = $repo->config('sendemail.smtpserver');
302}
aca7ad76
EW
303if (!$smtp_server) {
304 foreach (qw( /usr/sbin/sendmail /usr/lib/sendmail )) {
305 if (-x $_) {
306 $smtp_server = $_;
307 last;
308 }
309 }
310 $smtp_server ||= 'localhost'; # could be 127.0.0.1, too... *shrug*
3342d850
RA
311}
312
1f038a0c
RA
313if ($compose) {
314 # Note that this does not need to be secure, but we will make a small
315 # effort to have it be unique
316 open(C,">",$compose_filename)
317 or die "Failed to open for writing $compose_filename: $!";
d366c703 318 print C "From $from # This line is ignored.\n";
1f038a0c
RA
319 printf C "Subject: %s\n\n", $initial_subject;
320 printf C <<EOT;
321GIT: Please enter your email below.
322GIT: Lines beginning in "GIT: " will be removed.
323GIT: Consider including an overall diffstat or table of contents
324GIT: for the patch you are writing.
325
326EOT
327 close(C);
328
329 my $editor = $ENV{EDITOR};
330 $editor = 'vi' unless defined $editor;
331 system($editor, $compose_filename);
332
333 open(C2,">",$compose_filename . ".final")
334 or die "Failed to open $compose_filename.final : " . $!;
335
336 open(C,"<",$compose_filename)
337 or die "Failed to open $compose_filename : " . $!;
338
339 while(<C>) {
340 next if m/^GIT: /;
341 print C2 $_;
342 }
343 close(C);
344 close(C2);
345
346 do {
347 $_ = $term->readline("Send this email? (y|n) ");
348 } while (!defined $_);
349
350 if (uc substr($_,0,1) ne 'Y') {
351 cleanup_compose_files();
352 exit(0);
353 }
354
355 @files = ($compose_filename . ".final");
356}
357
358
83b24437
RA
359# Now that all the defaults are set, process the rest of the command line
360# arguments and collect up the files that need to be processed.
361for my $f (@ARGV) {
362 if (-d $f) {
363 opendir(DH,$f)
364 or die "Failed to opendir $f: $!";
365
5825e5b2 366 push @files, grep { -f $_ } map { +$f . "/" . $_ }
8037d1a3
RA
367 sort readdir(DH);
368
83b24437
RA
369 } elsif (-f $f) {
370 push @files, $f;
371
372 } else {
373 print STDERR "Skipping $f - not found.\n";
374 }
375}
376
377if (@files) {
2718435b
RA
378 unless ($quiet) {
379 print $_,"\n" for (@files);
380 }
83b24437 381} else {
1b0baf14
MC
382 print STDERR "\nNo patch files specified!\n\n";
383 usage();
83b24437
RA
384}
385
386# Variables we set as part of the loop over files
af068d27 387our ($message_id, %mail, $subject, $reply_to, $references, $message);
83b24437 388
567ffeb7
EW
389sub extract_valid_address {
390 my $address = shift;
ad9c18f5 391 my $local_part_regexp = '[^<>"\s@]+';
09302e17 392 my $domain_regexp = '[^.<>"\s@]+(?:\.[^.<>"\s@]+)+';
db3106b2
EW
393
394 # check for a local address:
ad9c18f5 395 return $address if ($address =~ /^($local_part_regexp)$/);
db3106b2 396
567ffeb7 397 if ($have_email_valid) {
ad9c18f5 398 return scalar Email::Valid->address($address);
567ffeb7
EW
399 } else {
400 # less robust/correct than the monster regexp in Email::Valid,
401 # but still does a 99% job, and one less dependency
ad9c18f5 402 $address =~ /($local_part_regexp\@$domain_regexp)/;
e96fd305 403 return $1;
567ffeb7
EW
404 }
405}
83b24437
RA
406
407# Usually don't need to change anything below here.
408
409# we make a "fake" message id by taking the current number
410# of seconds since the beginning of Unix time and tacking on
411# a random number to the end, in case we are called quicker than
412# 1 second since the last time we were called.
8037d1a3
RA
413
414# We'll setup a template for the message id, using the "from" address:
8037d1a3 415
83b24437
RA
416sub make_message_id
417{
72095d5c 418 my $date = time;
83b24437 419 my $pseudo_rand = int (rand(4200));
aeb59328
JH
420 my $du_part;
421 for ($from, $committer, $author) {
422 $du_part = extract_valid_address($_);
423 last if ($du_part ne '');
424 }
425 if ($du_part eq '') {
426 use Sys::Hostname qw();
427 $du_part = 'user@' . Sys::Hostname::hostname();
428 }
429 my $message_id_template = "<%s-git-send-email-$du_part>";
8037d1a3
RA
430 $message_id = sprintf $message_id_template, "$date$pseudo_rand";
431 #print "new message id = $message_id\n"; # Was useful for debugging
83b24437
RA
432}
433
434
435
a5370b16 436$time = time - scalar $#files;
83b24437 437
374c5905
JR
438sub unquote_rfc2047 {
439 local ($_) = @_;
440 if (s/=\?utf-8\?q\?(.*)\?=/$1/g) {
441 s/_/ /g;
442 s/=([0-9A-F]{2})/chr(hex($1))/eg;
443 }
3740b04f 444 return "$_";
374c5905
JR
445}
446
732263d4
RJ
447# If an address contains a . in the name portion, the name must be quoted.
448sub sanitize_address_rfc822
449{
450 my ($recipient) = @_;
451 my ($recipient_name) = ($recipient =~ /^(.*?)\s+</);
452 if ($recipient_name && $recipient_name =~ /\./ && $recipient_name !~ /^".*"$/) {
453 my ($name, $addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
454 $recipient = "\"$name\"$addr";
455 }
456 return $recipient;
457}
458
83b24437
RA
459sub send_message
460{
4bc87a28 461 my @recipients = unique_email_list(@to);
732263d4 462 @cc = (map { sanitize_address_rfc822($_) } @cc);
4bc87a28 463 my $to = join (",\n\t", @recipients);
58063245 464 @recipients = unique_email_list(@recipients,@cc,@bcclist);
c38f0247 465 @recipients = (map { extract_valid_address($_) } @recipients);
6bdca890 466 my $date = format_2822_time($time++);
e923effb
ML
467 my $gitversion = '@@GIT_VERSION@@';
468 if ($gitversion =~ m/..GIT_VERSION../) {
3cb8caf7 469 $gitversion = Git::version();
e923effb 470 }
4bc87a28 471
af068d27 472 my $cc = join(", ", unique_email_list(@cc));
f06a6a49
JH
473 my $ccline = "";
474 if ($cc ne '') {
475 $ccline = "\nCc: $cc";
476 }
732263d4 477 $from = sanitize_address_rfc822($from);
aeb59328
JH
478 make_message_id();
479
4bc87a28 480 my $header = "From: $from
f06a6a49 481To: $to${ccline}
4bc87a28 482Subject: $subject
4bc87a28
EW
483Date: $date
484Message-Id: $message_id
e923effb 485X-Mailer: git-send-email $gitversion
4bc87a28 486";
7ccf7927
RA
487 if ($reply_to) {
488
489 $header .= "In-Reply-To: $reply_to\n";
490 $header .= "References: $references\n";
491 }
ce91c2f6
JH
492 if (@xh) {
493 $header .= join("\n", @xh) . "\n";
494 }
4bc87a28 495
c38f0247 496 my @sendmail_parameters = ('-i', @recipients);
f073a592
RJ
497 my $raw_from = $from;
498 $raw_from = $envelope_sender if (defined $envelope_sender);
499 $raw_from = extract_valid_address($raw_from);
500 unshift (@sendmail_parameters,
501 '-f', $raw_from) if(defined $envelope_sender);
8e3d436b 502
6130259c
MW
503 if ($dry_run) {
504 # We don't want to send the email.
505 } elsif ($smtp_server =~ m#^/#) {
aca7ad76
EW
506 my $pid = open my $sm, '|-';
507 defined $pid or die $!;
508 if (!$pid) {
8e3d436b 509 exec($smtp_server, @sendmail_parameters) or die $!;
aca7ad76
EW
510 }
511 print $sm "$header\n$message";
512 close $sm or die $?;
513 } else {
87840620 514 require Net::SMTP;
aca7ad76 515 $smtp ||= Net::SMTP->new( $smtp_server );
2b69bfc2 516 $smtp->mail( $raw_from ) or die $smtp->message;
aca7ad76
EW
517 $smtp->to( @recipients ) or die $smtp->message;
518 $smtp->data or die $smtp->message;
519 $smtp->datasend("$header\n$message") or die $smtp->message;
520 $smtp->dataend() or die $smtp->message;
521 $smtp->ok or die "Failed to send $subject\n".$smtp->message;
522 }
2718435b 523 if ($quiet) {
71c7da94 524 printf (($dry_run ? "Dry-" : "")."Sent %s\n", $subject);
2718435b 525 } else {
71c7da94 526 print (($dry_run ? "Dry-" : "")."OK. Log says:\nDate: $date\n");
2b69bfc2 527 if ($smtp_server !~ m#^/#) {
aca7ad76 528 print "Server: $smtp_server\n";
2b69bfc2
RJ
529 print "MAIL FROM:<$raw_from>\n";
530 print "RCPT TO:".join(',',(map { "<$_>" } @recipients))."\n";
aca7ad76 531 } else {
8e3d436b 532 print "Sendmail: $smtp_server ".join(' ',@sendmail_parameters)."\n";
aca7ad76
EW
533 }
534 print "From: $from\nSubject: $subject\nCc: $cc\nTo: $to\n\n";
535 if ($smtp) {
536 print "Result: ", $smtp->code, ' ',
537 ($smtp->message =~ /\n([^\n]+\n)$/s), "\n";
538 } else {
539 print "Result: OK\n";
540 }
30d08b34 541 }
83b24437
RA
542}
543
83b24437 544$reply_to = $initial_reply_to;
2186d566 545$references = $initial_reply_to || '';
83b24437
RA
546$subject = $initial_subject;
547
548foreach my $t (@files) {
83b24437
RA
549 open(F,"<",$t) or die "can't open file $t";
550
8a8e6235 551 my $author_not_sender = undef;
da140f8b 552 @cc = @initial_cc;
ce91c2f6 553 @xh = ();
e6b0964a 554 my $input_format = undef;
83b24437
RA
555 my $header_done = 0;
556 $message = "";
557 while(<F>) {
558 if (!$header_done) {
e6b0964a
JH
559 if (/^From /) {
560 $input_format = 'mbox';
561 next;
562 }
83b24437 563 chomp;
e6b0964a
JH
564 if (!defined $input_format && /^[-A-Za-z]+:\s/) {
565 $input_format = 'mbox';
566 }
83b24437 567
e6b0964a 568 if (defined $input_format && $input_format eq 'mbox') {
83b24437
RA
569 if (/^Subject:\s+(.*)$/) {
570 $subject = $1;
571
572 } elsif (/^(Cc|From):\s+(.*)$/) {
2cf69cf6
KH
573 if (unquote_rfc2047($2) eq $from) {
574 $from = $2;
8a8e6235
JH
575 next if ($suppress_from);
576 }
68d42c41 577 elsif ($1 eq 'From') {
8a8e6235
JH
578 $author_not_sender = $2;
579 }
83b24437 580 printf("(mbox) Adding cc: %s from line '%s'\n",
2718435b 581 $2, $_) unless $quiet;
83b24437
RA
582 push @cc, $2;
583 }
1d6a003a 584 elsif (!/^Date:\s/ && /^[-A-Za-z]+:\s+\S/) {
ce91c2f6
JH
585 push @xh, $_;
586 }
83b24437
RA
587
588 } else {
589 # In the traditional
590 # "send lots of email" format,
591 # line 1 = cc
592 # line 2 = subject
593 # So let's support that, too.
e6b0964a 594 $input_format = 'lots';
83b24437
RA
595 if (@cc == 0) {
596 printf("(non-mbox) Adding cc: %s from line '%s'\n",
2718435b 597 $_, $_) unless $quiet;
83b24437
RA
598
599 push @cc, $_;
600
601 } elsif (!defined $subject) {
602 $subject = $_;
603 }
604 }
5825e5b2 605
83b24437
RA
606 # A whitespace line will terminate the headers
607 if (m/^\s*$/) {
608 $header_done = 1;
609 }
610 } else {
611 $message .= $_;
abec100c
BF
612 if (/^(Signed-off-by|Cc): (.*)$/i && !$no_signed_off_cc) {
613 my $c = $2;
83b24437
RA
614 chomp $c;
615 push @cc, $c;
616 printf("(sob) Adding cc: %s from line '%s'\n",
2718435b 617 $c, $_) unless $quiet;
83b24437
RA
618 }
619 }
620 }
621 close F;
8a8e6235 622 if (defined $author_not_sender) {
374c5905 623 $author_not_sender = unquote_rfc2047($author_not_sender);
8a8e6235
JH
624 $message = "From: $author_not_sender\n\n$message";
625 }
83b24437 626
83b24437
RA
627
628 send_message();
629
630 # set up for the next message
bc108f63 631 if ($chain_reply_to || !defined $reply_to || length($reply_to) == 0) {
78488b2c 632 $reply_to = $message_id;
7ccf7927 633 if (length $references > 0) {
a925b89c 634 $references .= "\n $message_id";
7ccf7927
RA
635 } else {
636 $references = "$message_id";
637 }
78488b2c 638 }
83b24437 639}
e205735d 640
1f038a0c
RA
641if ($compose) {
642 cleanup_compose_files();
643}
644
645sub cleanup_compose_files() {
646 unlink($compose_filename, $compose_filename . ".final");
647
648}
649
4bc87a28 650$smtp->quit if $smtp;
e205735d
RA
651
652sub unique_email_list(@) {
653 my %seen;
654 my @emails;
655
656 foreach my $entry (@_) {
db3106b2
EW
657 if (my $clean = extract_valid_address($entry)) {
658 $seen{$clean} ||= 0;
659 next if $seen{$clean}++;
660 push @emails, $entry;
661 } else {
662 print STDERR "W: unable to extract a valid address",
663 " from: $entry\n";
664 }
e205735d
RA
665 }
666 return @emails;
667}