public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* script to send changesets per mail
@ 2005-03-03 10:59 Martin Waitz
  2005-03-03 18:23 ` Jeff Garzik
  2005-03-13 11:31 ` Sam Ravnborg
  0 siblings, 2 replies; 4+ messages in thread
From: Martin Waitz @ 2005-03-03 10:59 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2730 bytes --]

hoi :)

I just tested my little script that can send changesets per mail.
okok, it still had a bug when I first tested it but that should be
fixed now.

If anyone is interested (perhaps for Documentation/BK-usage), here it
is:


#!/usr/bin/perl -w

# after sending an announcement (created by Documentation/BK-usage/bk-make-sum)
# just pipe your mail through this script.
# It will create one new mail per Changeset, properly threaded.

# Copyright © 2005 Martin Waitz <tali@admingilde.org>

use strict;

my $from;
my $to;
my $cc;
my $references;

# all local repositories are in ~/src/.
# you have to adjust this function if you keep them elsewhere.
sub local_repository($) {
	my $repo;
	
	$repo= shift;

	$repo =~ s,.*/,"$ENV{HOME}/src/",e;
	return $repo;
}

# this checks if we are allowed to send mails with this sender
# please modify the regexp to check for your adress!
sub check_from($) {
	my $from = shift;

	exit 1 unless $from =~ /insert-your-email-here/; #FIXME
}

# send one changeset.
# Parameters: the cset number, description prefix and the actual description.
sub send_cset($$$$) {
	my ($cset, $serial, $desc, $longdesc) = @_;

	open (MAIL, "| /usr/sbin/sendmail -t") or die "fork sendmail: $!";
	print MAIL "From: $from\n";
	print MAIL "To: $to\n";
	print MAIL "Cc: $cc\n" if $cc;
	print MAIL "References: $references\n" if $references;
	print MAIL "Subject: [PATCH $serial] $desc\n";
	print MAIL "\n";
	print MAIL "$desc\n";
	print MAIL "$longdesc\n";
	print MAIL "\n";
	print MAIL `bk export -tpatch -du -r $cset`;
	close (MAIL) or die "could not send mail: error code $?";
}



# Parse header
while (<>) {
	chomp;
	last if /^$/;

	if (/^From:\s+(.+)$/i) {
		$from = $1;
	} elsif (/^To:\s+(.+)$/i) {
		$to = $1;
	} elsif (/^Cc:\s+(.+)$/i) {
		$cc = $1;
	} elsif (/^Message-Id:\s+(.+)$/i) {
		$references = $1;
	}
}

my @cset;
my @desc;
my @longdesc;

# Parse body
my $cset;
while (<>) {
	chomp;
	if (/^\s+bk pull (\S+)$/) {
		chdir local_repository($1) ||
			die "could not find local repository for $1\n";
	} elsif (/^<\S+> \(\S+ ([\d.]+)\)$/) {
		# start of new ChangeSet
		$cset = $1;
	} elsif (/^   (.*)$/ && $cset) {
		# first line of a description
		unshift @cset, $cset;
		unshift @desc, $1;
		unshift @longdesc, "";
		$cset = "";
	} elsif (/^   (.*)$/) {
		# next lines of description
		$longdesc[0] .= "$1\n";
	}
}


check_from($from);


my $i;
my $count;
$count = scalar @cset;
foreach $i (1 .. $count) {
	print "$desc[$i-1]\n";
	send_cset($cset[$i-1], "$i/$count", $desc[$i-1], $longdesc[$i-1]);
	# let sendmail process the mail...
	sleep 3;
}
exit(0);



-- 
Martin Waitz

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: script to send changesets per mail
  2005-03-03 10:59 script to send changesets per mail Martin Waitz
@ 2005-03-03 18:23 ` Jeff Garzik
  2005-03-13 11:31 ` Sam Ravnborg
  1 sibling, 0 replies; 4+ messages in thread
From: Jeff Garzik @ 2005-03-03 18:23 UTC (permalink / raw)
  To: Martin Waitz; +Cc: linux-kernel

Martin Waitz wrote:
> hoi :)
> 
> I just tested my little script that can send changesets per mail.
> okok, it still had a bug when I first tested it but that should be
> fixed now.
> 
> If anyone is interested (perhaps for Documentation/BK-usage), here it
> is:

Putting this in Documentation/BK-usage would be fine.


> #!/usr/bin/perl -w
> 
> # after sending an announcement (created by Documentation/BK-usage/bk-make-sum)
> # just pipe your mail through this script.
> # It will create one new mail per Changeset, properly threaded.
> 
> # Copyright © 2005 Martin Waitz <tali@admingilde.org>
> 
> use strict;
> 
> my $from;
> my $to;
> my $cc;
> my $references;
> 
> # all local repositories are in ~/src/.
> # you have to adjust this function if you keep them elsewhere.
> sub local_repository($) {
> 	my $repo;
> 	
> 	$repo= shift;
> 
> 	$repo =~ s,.*/,"$ENV{HOME}/src/",e;
> 	return $repo;
> }
> 
> # this checks if we are allowed to send mails with this sender
> # please modify the regexp to check for your adress!
> sub check_from($) {
> 	my $from = shift;
> 
> 	exit 1 unless $from =~ /insert-your-email-here/; #FIXME
> }

Move 'insert email here' into a default variable, a variable that can be 
overridden by an environment variable.


> # send one changeset.
> # Parameters: the cset number, description prefix and the actual description.
> sub send_cset($$$$) {
> 	my ($cset, $serial, $desc, $longdesc) = @_;
> 
> 	open (MAIL, "| /usr/sbin/sendmail -t") or die "fork sendmail: $!";
> 	print MAIL "From: $from\n";
> 	print MAIL "To: $to\n";
> 	print MAIL "Cc: $cc\n" if $cc;
> 	print MAIL "References: $references\n" if $references;
> 	print MAIL "Subject: [PATCH $serial] $desc\n";
> 	print MAIL "\n";
> 	print MAIL "$desc\n";
> 	print MAIL "$longdesc\n";
> 	print MAIL "\n";
> 	print MAIL `bk export -tpatch -du -r $cset`;
> 	close (MAIL) or die "could not send mail: error code $?";

I would suggest '-hdu' to avoid the patch header, but some may disagree.


> # Parse header
> while (<>) {
> 	chomp;
> 	last if /^$/;
> 
> 	if (/^From:\s+(.+)$/i) {
> 		$from = $1;
> 	} elsif (/^To:\s+(.+)$/i) {
> 		$to = $1;
> 	} elsif (/^Cc:\s+(.+)$/i) {
> 		$cc = $1;
> 	} elsif (/^Message-Id:\s+(.+)$/i) {
> 		$references = $1;
> 	}

note that this misses multi-line headers.  multi-line headers are those 
where the second, and succeeding lines begin with whitespace.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: script to send changesets per mail
  2005-03-03 10:59 script to send changesets per mail Martin Waitz
  2005-03-03 18:23 ` Jeff Garzik
@ 2005-03-13 11:31 ` Sam Ravnborg
  1 sibling, 0 replies; 4+ messages in thread
From: Sam Ravnborg @ 2005-03-13 11:31 UTC (permalink / raw)
  To: linux-kernel, Martin Waitz

On Thu, Mar 03, 2005 at 11:59:50AM +0100, Martin Waitz wrote:
> hoi :)
> 
> I just tested my little script that can send changesets per mail.
> okok, it still had a bug when I first tested it but that should be
> fixed now.

Greg has a similar script - could you take a look and tell
which is the better (and why). We only want one in the kernel.

It is attached.

	Sam
	
send_lots_of_emails.pl:

#!/usr/bin/perl -w

# horrible hack of a script to send off a large number of email messages, one after
# each other, all chained together.  This is useful for large numbers of patches.
#
# Use at your own risk!!!!
#
# greg kroah-hartman Jan 8, 2002
# <greg@kroah.com>a
# 
# updated to give a valid subject and CC the owner of the patch - Jan 2005
# 

# change this to your email address.
$from = "SOMEONE <someone\@somewhere.com>";

# modify these options each time you run the script
$to = 'linux-kernel@vger.kernel.org';
$initial_reply_to = '<20050203173208.GA23964@foobar.com>';
$initial_subject = "[PATCH] XXX fixes for 2.6.11-rc3";
@files = (
"rev-1.2041.patch",
"rev-1.2042.patch",
"rev-1.2043.patch",
"rev-1.2044.patch",
"rev-1.2045.patch",
"rev-1.2046.patch",
);

use Mail::Sendmail;


# we make a "fake" message id by taking the current number
# of seconds since the beginning of Unix time and tacking on
# a random number to the end, in case we are called quicker than
# 1 second since the last time we were called.
sub make_message_id
{
	my $date = `date "+\%s"`;
	chomp($date);
	my $pseudo_rand = int (rand(4200));
	$message_id = "<$date$pseudo_rand\@kroah.com>";
	print "new message id = $message_id\n";
}



$cc = "";

sub send_message
{
	%mail = (	To	=>	$to,
			From	=>	$from,
			CC	=>	$cc,
			Subject	=>	$subject,
			Message	=>	$message,
			'Reply-to'	=>	"Greg K-H <greg\@kroah.com>",
			'In-Reply-To'	=>	$reply_to,
			'Message-ID'	=>	$message_id,
			'X-Mailer'	=>	"gregkh_patchbomb",
		);

	$mail{smtp} = 'localhost';

	sendmail(%mail) or die $Mail::Sendmail::error;

	print "OK. Log says:\n", $Mail::Sendmail::log;
	print "\n\n"
}


$reply_to = $initial_reply_to;
make_message_id();
$subject = $initial_subject;

foreach $t (@files) {
	$F = $t;
	open F or die "can't open file $t";

	# first line is the CC: list
	$cc = <F>;
	print "cc: $cc";
	
	# second line is the Subject:
	$subject = <F>;
	print "subject: $subject";

	undef $/;
	$message = <F>;	# slurp the whole file in
	close F;
	$/ = "\n";
	send_message();

	# set up for the next message
	$reply_to = $message_id;
	make_message_id();
#	$subject = "Re: ".$initial_subject;
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: script to send changesets per mail
       [not found] ` <fa.hdaug7i.n7qkqg@ifi.uio.no>
@ 2005-03-14 23:22   ` Bodo Eggert
  0 siblings, 0 replies; 4+ messages in thread
From: Bodo Eggert @ 2005-03-14 23:22 UTC (permalink / raw)
  To: Sam Ravnborg, linux-kernel, Martin Waitz

Sam Ravnborg <sam@ravnborg.org> wrote:

> sub make_message_id
> {
> my $date = `date "+\%s"`;
> chomp($date);
> my $pseudo_rand = int (rand(4200));
> $message_id = "<$date$pseudo_rand\@kroah.com>";
> print "new message id = $message_id\n";
> }

Why not

use Email::MessageID;
use Net::Domain qw(hostfqdn);

sub make_message_id()
{
        return Email::MessageID->new(host => hostfqdn());
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-03-14 23:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-03 10:59 script to send changesets per mail Martin Waitz
2005-03-03 18:23 ` Jeff Garzik
2005-03-13 11:31 ` Sam Ravnborg
     [not found] <fa.f2usg94.a5sd8q@ifi.uio.no>
     [not found] ` <fa.hdaug7i.n7qkqg@ifi.uio.no>
2005-03-14 23:22   ` Bodo Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox