From: Stephen Gran Date: Sat, 10 May 2008 14:25:31 +0000 (+0100) Subject: Rewrite the send_mail() function in debianqueued to not use mailx (blech). X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96e77022c8fe1d4a6021a7b4d797506a5a47381a;p=dak Rewrite the send_mail() function in debianqueued to not use mailx (blech). Doing it this way also gives us an easy way to add arbitrary headers, so I've added X-Debian-Package while I was there. --- diff --git a/ChangeLog b/ChangeLog index 2aaa4a21..b4fd48ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-05-10 Stephen Gran + * tools/debianqueued-0.9/debianqueued: First pass at a send_mail + implementation that sucks less + 2008-05-09 Joerg Jaspert * dak/override.py (main): substitute value in X-Debian-Package diff --git a/tools/debianqueued-0.9/ChangeLog b/tools/debianqueued-0.9/ChangeLog index d979a501..77267d99 100644 --- a/tools/debianqueued-0.9/ChangeLog +++ b/tools/debianqueued-0.9/ChangeLog @@ -1,3 +1,7 @@ +2008-05-10 Stephen Gran + * debianqueued: First pass at a send_mail implementation that + sucks less. This also gives us X-Debian-Package + 2008-05-08 Joerg Jaspert * debianqueued: added header X-Debian: DAK diff --git a/tools/debianqueued-0.9/debianqueued b/tools/debianqueued-0.9/debianqueued index e84d3852..97359b0f 100755 --- a/tools/debianqueued-0.9/debianqueued +++ b/tools/debianqueued-0.9/debianqueued @@ -281,6 +281,8 @@ package main; ($main::progname = $0) =~ s,.*/,,; +my %packages = (); + # extract -r and -k args $main::arg = ""; if (@ARGV == 1 && $ARGV[0] =~ /^-[rk]$/) { @@ -790,6 +792,7 @@ sub process_changes($\@) { elsif (/^Source:\s*/i) { chomp( $pkgname = $' ); $pkgname =~ s/\s+$//; + $main::packages{$pkgname}++; } elsif (/^Files:/i) { while( ) { @@ -2078,6 +2081,7 @@ sub init_mail(;$) { $main::mail_addr = ""; $main::mail_text = ""; + %main::packages = (); $main::mail_subject = $file ? "Processing of $file" : ""; } @@ -2120,19 +2124,34 @@ sub send_mail($$$) { my $subject = shift; my $text = shift; - debug( "Sending mail to $addr" ); - debug( "executing $conf::mail -s '$subject' -a 'X-Debian: DAK' '$addr'" ); - if (!open( MAIL, "|$conf::mail -s '$subject' -a 'X-Debian: DAK' '$addr'" )) { - msg( "log", "Could not open pipe to $conf::mail: $!\n" ); - return 0; - } - print MAIL $text; - print MAIL "\nGreetings,\n\n\tYour Debian queue daemon\n"; - if (!close( MAIL )) { - msg( "log", "$conf::mail failed (exit status ", $? >> 8, ")\n" ); - return 0; - } - return 1; + my $package = join(' ', keys %main::packages); + + use Email::Send; + + my $message = <<'__MESSAGE__'; + To: $addr + From: dak@ftp-master.debian.org + Subject: $subject + X-Debian: DAK +__MESSAGE__ + + if (length $package) { + $message .= "X-Debian-Package: $package\n"; + } + + $message .= "\n$text"; + + my $mail = Email::Send->new; + for ( qw[Sendmail SMTP] ) { + $mail->mailer($_) and last if $mail->mailer_available($_); + } + + my $ret = $mail->send($message); + if ($ret && $ret !~ /Message sent/) { + return 0; + } + + return 1; } #