There is a slight bug in new_log_accum. We got new_log_accum from your CVS tree (and I'm glad hop decided to use it instead of the slightly custom log_accum I sent him back when he asked about such things, because new_log_accum is much better all around..)
We've been using it for many months and I assure you that we all feel extremely lame for not spotting this bug until very recently. However, as lame as we feel, we're not going to feel too bad because you've been using it longer and haven't spotted the bug either. So here's the patch. The changes: - month is no longer off by one - diffs are MIME attached The MIME attachment allows for the diffs to be stripped off if you want to save the messages but not the long diffs. We have plans at some point to offer two lists, one with diffs attached, the other with a bit of file info (similar to the original log_accum) and a URL for the diff stored on the server. That hasn't happened, but if it ever does, I'll be sure to offer a diff for that too. -- Joseph Carter <[EMAIL PROTECTED]> Have chainsaw will travel We've upped our standards, so up yours!
Index: CVSROOT/new_log_accum
===================================================================
RCS file: /home/cvs/repository/CVSROOT/new_log_accum,v
retrieving revision 1.3
diff -u -r1.3 new_log_accum
--- CVSROOT/new_log_accum 2001/10/11 16:10:55 1.3
+++ CVSROOT/new_log_accum 2002/02/18 01:07:34
@@ -20,15 +20,17 @@
# Script to accumulate log messages for an entire tree and send them along
# with the diffs; deals correctly with all manner of branching (I hope)
#
-# $Id: new_log_accum,v 1.3 2001/10/11 16:10:55 jnelson Exp $
+# $Id: new_log_accum,v 1.32 2002/02/05 02:51:24 raineth Exp $
+#
use strict;
-use vars qw($MAILER $CVS $debug);
+use vars qw($MAILER $CVS $debug $boundary);
+use MD5;
-# Set this to the full path of a mailer that takes -s <subject> and a list
+# Set this to the full path of a mailer that takes a list
# of email addresses as arguments...
-$MAILER = "/usr/bin/mail";
+$MAILER = "/usr/sbin/sendmail -oi -oeq";
# Set this to the path of the CVS binary responsible for this tree...
$CVS = "/usr/bin/cvs";
@@ -36,6 +38,9 @@
# Don't touch this; use the -d command line option
$debug = 0;
+# This is initialized by build_mailheader()
+$boundary = '';
+
use POSIX qw(setsid);
# We have to dissociate from our parent, so that the CVS commit can
@@ -311,28 +316,59 @@
# Build the header of the commit message: CVSROOT, module name, any
# branch tags, and the commit time
sub build_header ($@) {
- my ($module, @branch_tags) = @_;
- my (@text);
- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time());
- my ($user);
-
- $user = getpwuid($<);
- push(@text, "Commiter : $user");
- push(@text, "CVSROOT : $ENV{CVSROOT}");
- push(@text, "Module : $module");
- push(@text, "Branch tags: " . join(' ', @branch_tags[1..$#branch_tags]))
+ my ($module, $subject, $mailto, @branch_tags) = @_;
+ my (@text, @mailto);
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time());
+ my ($user, $dummy, $gecos);
+ my ($digest);
+
+ ($user, $dummy, $dummy, $dummy, $dummy, $dummy, $gecos) = getpwuid($<);
+
+ @mailto = @{$mailto};
+
+ # generate a unique boundary by calculating the md5sum of the
+ # current time
+ $digest = new MD5;
+ $digest->reset();
+ $digest->add(time() . rand());
+ $boundary = "----=MIME." . unpack("H*", $digest->digest());
+
+ # Build the mail header
+ push(@text, "From: $gecos <$user>");
+ push(@text, "To: " . join(' ', @mailto));
+ push(@text, "Subject: $subject");
+ push(@text, "MIME-Version: 1.0");
+ push(@text, "Content-Type: multipart/mixed; boundary=\"$boundary\"");
+ push(@text, "");
+ push(@text, "This is a multipart message as defined by RFC2049 (MIME)");
+ push(@text, "");
+ push(@text, "--$boundary");
+ push(@text, "Content-Type: text/plain; charset=us-ascii");
+ push(@text, "Content-Disposition: inline");
+ push(@text, "");
+
+ # Build the commit message header
+ push(@text, "Commiter : $user");
+ push(@text, "CVSROOT : $ENV{CVSROOT}");
+ push(@text, "Module : $module");
+ push(@text, "Branch tags: " . join(' ', @branch_tags[1..$#branch_tags]))
if (@branch_tags > 0);
- push(@text, sprintf("Commit time: %04d-%02d-%02d %02d:%02d:%02d UTC",
- $year + 1900, $mon, $mday, $hour, $min, $sec));
+ push(@text, sprintf("Commit time: %04d-%02d-%02d %02d:%02d:%02d UTC",
+ $year + 1900, $mon + 1, $mday, $hour, $min, $sec));
- return @text, "";
+ return @text, "";
}
# Send the mail message
-sub send_mail (\@$@) {
- my ($mailto, $subject, @text) = @_;
+sub send_mail {
+ my ($mailto, $text) = @_;
+ my (@mailto, @text);
+ # I <heart> perl
+ @mailto = @{$mailto};
+ @text = @{$text};
- open(MAIL, "|$MAILER -s \"$subject\" " . join(' ', @{$mailto}));
+ open(MAIL, "|$MAILER " . join(' ', @mailto));
+ push(@text, "--$boundary--", "");
print MAIL join("\n", @text), "\n";
close(MAIL);
}
@@ -557,11 +593,12 @@
}
# Build the message...
- push(@text, build_header($modname, @branch_tags));
+ push(@text, build_header($modname, "Module $modname: New directory $dir",
+ \@mailto, @branch_tags));
push(@text, "Log message:", "", @log);
# and send it (synchronously)
- send_mail(@mailto, "[CVS] Module $modname: New directory $dir", @text);
+ send_mail(\@mailto, \@text);
# Clean up after ourselves and exit.
cleanup_dir($tmpdir);
@@ -575,11 +612,12 @@
my (@text) = ();
# Build the message...
- push(@text, build_header($modname, @branch_tags));
+ push(@text, build_header($modname, "Module $modname: Imported $dir",
+ \@mailto, @branch_tags));
push(@text, "Log message:", "", @log);
# and send it (synchronously)
- send_mail(@mailto, "[CVS] Module $modname: Imported $dir", @text);
+ send_mail(\@mailto, \@text);
# Clean up after ourselves and exit.
cleanup_dir($tmpdir);
@@ -649,6 +687,16 @@
last
if (!-e "$tmpdir/logfile.$i");
+ # read and insert the log message
+ open(FILE, "<$tmpdir/logfile.$i");
+ push(@text, "Log message:", "");
+ while (<FILE>) {
+ chomp;
+ push(@text, $_);
+ }
+ push(@text, "");
+ close(FILE);
+
# read modified list and list all modified files if non-empty
@modified = file_to_names(@branch_tags, "$tmpdir/modified.$i");
push(@text, "Modified files:", name_to_list(@branch_tags, @modified), "")
@@ -664,28 +712,31 @@
push(@text, "Removed files:", name_to_list(@branch_tags, @removed), "")
if (@removed > 0);
- # read and insert the log message
- open(FILE, "<$tmpdir/logfile.$i");
- push(@text, "Log message:", "");
- while (<FILE>) {
- chomp;
- push(@text, $_);
- }
- push(@text, "");
- close(FILE);
-
# remember all the files we looked at
push(@files, @modified, @added, @removed);
}
# Now that name_to_list has rebuilt our list of branch tags, we can build the
# header and prepend it to the message
-unshift(@text, build_header($modname, @branch_tags));
+unshift(@text, build_header($modname, "Module $modname: Change committed",
+ \@mailto, @branch_tags));
# sort the files out for our diff
@files = sort { $a->{name} cmp $b->{name} } @files;
+
+my ($user, $filename);
+my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time());
+$user = getpwuid($<);
+
+$filename = sprintf("%s.%04d%02d%02d.%02d%02d%02d.%s.diff", $modname,
+ $year + 1900, $mon + 1, $mday, $hour, $min, $sec, $user);
+
+push(@text, "--$boundary");
+push(@text, "Content-Type: text/plain; name=\"$filename\"");
+push(@text, "Content-Disposition: attachment; filename=\"$filename\"");
+push(@text, "Content-Transfer-Encoding: 8bit");
+push(@text, "");
-push(@text, "---------------------- diff included ----------------------");
foreach my $file (@files) {
debug "Diffing file $file->{name}...\n";
@@ -698,10 +749,9 @@
}
close(DIFF);
}
-push(@text, "----------------------- End of diff -----------------------");
# send the mail...
-send_mail(@mailto, "[CVS] Module $modname: Change committed", @text);
+send_mail(\@mailto, \@text);
# and clean up after ourselves
cleanup_dir($tmpdir);
msg00152/pgp00000.pgp
Description: PGP signature
