Re: script to send changesets per mail

From: Jeff Garzik
Date: Thu Mar 03 2005 - 13:30:42 EST


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@xxxxxxxxxxxxxx>

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.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/