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