]>
git.ipfire.org Git - thirdparty/git.git/blob - git-send-email-script
2 # horrible hack of a script to send off a large number of email messages, one after
3 # each other, all chained together. This is useful for large numbers of patches.
5 # Use at your own risk!!!!
7 # greg kroah-hartman Jan 8, 2002
10 # GPL v2 (See COPYING)
12 # Ported to support git "mbox" format files by Ryan Anderson <ryan@michonline.com>
14 # Sends emails to the email listed on the command line.
16 # updated to give a valid subject and CC the owner of the patch - Jan 2005
17 # first line of the message is who to CC,
18 # and second line is the subject of the message.
29 # Variables we fill in automatically, or via prompting:
30 my (@to,@cc,$initial_reply_to,$initial_subject,@files,$from);
33 # modify these options each time you run the script
34 #$to = 'torvalds@osdl.org,git@vger.kernel.org';
35 #$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';
36 #$initial_subject = "[PATCH] Deb package build fixes";
38 #0001-Make-debian-rules-executable-and-correct-the-spelling-of-rsync-in.txt
39 #0002-Debian-packages-should-include-the-binaries.txt
40 #0003-The-deb-package-building-needs-these-two-new-files-to-work-correctly.txt
43 # change this to your email address.
44 #$from = "Ryan Anderson <ryan\@michonline.com>";
46 my $term = new Term
::ReadLine
'git-send-email';
48 # Begin by accumulating all the variables (defined above), that we will end up
49 # needing, first, from the command line:
51 my $rc = GetOptions
("from=s" => \
$from,
52 "in-reply-to=s" => \
$initial_reply_to,
53 "subject=s" => \
$initial_subject,
57 # Now, let's fill any that aren't set in with defaults:
59 open(GITVAR
,"-|","git-var","-l")
60 or die "Failed to open pipe from git-var: $!";
62 my ($author,$committer);
65 my ($var,$data) = split /=/,$_,2;
66 my @fields = split /\s+/, $data;
68 my $ident = join(" ", @fields[0...(@fields-3)]);
70 if ($var eq 'GIT_AUTHOR_IDENT') {
72 } elsif ($var eq 'GIT_COMMITTER_IDENT') {
80 $from = $author || $committer;
81 1 while (!defined ($_ = $term->readline("Who should the emails appear to be from? ",
84 print "Emails will be sent from: ", $from, "\n";
88 1 while (!defined ($_ = $term->readline("Who should the emails be sent to? ",
91 push @to, split /,/, $to;
94 if (!defined $initial_subject) {
95 1 while (!defined ($_ =
96 $term->readline("What subject should the emails start with? ",
98 $initial_subject = $_;
101 if (!defined $initial_reply_to) {
102 1 while (!defined ($_ =
103 $term->readline("Message-ID to be used as In-Reply-To? ",
104 $initial_reply_to)));
105 $initial_reply_to = $_;
108 # Now that all the defaults are set, process the rest of the command line
109 # arguments and collect up the files that need to be processed.
113 or die "Failed to opendir $f: $!";
115 push @files, map { +$f . "/" . $_ } grep !/^\
.{1,2}$/,
121 print STDERR
"Skipping $f - not found.\n";
126 print $_,"\n" for @files;
129 git-send-email-script [options] <file | directory> [... file | directory ]
131 --from Specify the "From:" line of the email to be sent.
132 --to Specify the primary "To:" line of the email.
133 --subject Specify the initial "Subject:" line.
134 --in-reply-to Specify the first "In-Reply-To:" header line.
136 Error: Please specify a file or a directory on the command line.
141 # Variables we set as part of the loop over files
142 our ($message_id, $cc, %mail, $subject, $reply_to, $message);
145 # Usually don't need to change anything below here.
147 # we make a "fake" message id by taking the current number
148 # of seconds since the beginning of Unix time and tacking on
149 # a random number to the end, in case we are called quicker than
150 # 1 second since the last time we were called.
153 my $date = `date "+\%s"`;
155 my $pseudo_rand = int (rand(4200));
156 $message_id = "<$date$pseudo_rand\@foobar.com>";
157 print "new message id = $message_id\n";
167 $to{lc(Email
::Valid
->address($_))}++ for (@to);
169 my $to = join(",", keys %to);
177 'In-Reply-To' => $reply_to,
178 'Message-ID' => $message_id,
179 'X-Mailer' => "git-send-email-script",
182 $mail{smtp
} = 'localhost';
184 #print Data::Dumper->Dump([\%mail],[qw(*mail)]);
186 sendmail
(%mail) or die $Mail::Sendmail
::error
;
188 print "OK. Log says:\n", $Mail::Sendmail
::log;
193 $reply_to = $initial_reply_to;
195 $subject = $initial_subject;
197 foreach my $t (@files) {
199 open(F
,"<",$t) or die "can't open file $t";
207 $found_mbox = 1, next if (/^From /);
211 if (/^Subject:\s+(.*)$/) {
214 } elsif (/^(Cc|From):\s+(.*)$/) {
215 printf("(mbox) Adding cc: %s from line '%s'\n",
222 # "send lots of email" format,
225 # So let's support that, too.
227 printf("(non-mbox) Adding cc: %s from line '%s'\n",
232 } elsif (!defined $subject) {
237 # A whitespace line will terminate the headers
243 if (/^Signed-off-by: (.*)$/i) {
247 printf("(sob) Adding cc: %s from line '%s'\n",
255 $clean_ccs{lc(Email
::Valid
->address($_))}++ for @cc;
257 $cc = join(",", keys %clean_ccs);
261 # set up for the next message
262 $reply_to = $message_id;
264 # $subject = "Re: ".$initial_subject;