[Popcon-developers] Bug#239097: patch: popularity-contest without a working MTA

Emanuele Rocca Emanuele Rocca <ema@debian.org>, 239097@bugs.debian.org
Tue, 10 Aug 2004 16:34:26 +0200


--2fHTh5uZTiUOsy+g
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: Quoted-Printable

Hi,
the attached patch allows to send popularity-contest emails without a
working MTA on the sender machine, using the Mail::Sender Perl module.

The patch installs the popularity-contest-sendmail Perl script in=20
/usr/sbin, perhaps installing it in /usr/lib/popularity-contest/ would=20
be a better choice?

Any feedback is obviously welcome.

ciao,
	ema

--
Questo =E8 il domani di cui ti preoccupavi ieri. E ora sai perch=E9.

--2fHTh5uZTiUOsy+g
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="popcon-no-mta.diff"
Content-Transfer-Encoding: 7Bit

diff -Nur popularity-contest-1.23/debian/control popularity-contest-1.24/debian/control
--- popularity-contest-1.23/debian/control	2004-01-23 19:40:41.000000000 +0100
+++ popularity-contest-1.24/debian/control	2004-08-10 16:17:02.000000000 +0200
@@ -8,7 +8,7 @@
 
 Package: popularity-contest
 Architecture: all
-Depends: dpkg (>= 1.10), exim4 | mail-transport-agent, debconf, ${perl:Depends}
+Depends: dpkg (>= 1.10), exim4 | mail-transport-agent | libmail-sender-perl, debconf, ${perl:Depends}
 Recommends: cron
 Provides: popcon
 Description: Vote for your favourite packages automatically
diff -Nur popularity-contest-1.23/debian/cron.weekly popularity-contest-1.24/debian/cron.weekly
--- popularity-contest-1.23/debian/cron.weekly	2004-02-10 12:56:26.000000000 +0100
+++ popularity-contest-1.24/debian/cron.weekly	2004-08-10 15:50:05.000000000 +0200
@@ -9,6 +9,7 @@
 unset MAILTO
 unset MY_HOSTID
 unset PARTICIPATE
+unset MTA
 
 # get configuration information
 . /usr/share/popularity-contest/default.conf
@@ -27,20 +28,24 @@
 
 run_popcon()
 {
-	if [ -n "$MAILFROM" ]; then
-		echo "From: <$MAILFROM>"
-		echo "Sender: <$MAILFROM>"
+	if [ -z "$MTA" ]; then
+		if [ -n "$MAILFROM" ]; then
+			echo "From: <$MAILFROM>"
+			echo "Sender: <$MAILFROM>"
+		fi
+		echo "To: $MAILTO"
+		echo "Subject: popularity-contest submission"
+		echo
 	fi
-	echo "To: $MAILTO"
-	echo "Subject: popularity-contest submission"
-	echo
 	# Set HOME to avoid bug #212013.
 	HOME=/tmp su nobody -pc "sh -c /usr/sbin/popularity-contest"
 }
 
 do_sendmail()
 {
-	if [ -n "$MAILFROM" ]; then
+	if [ -n "$MTA" ]; then
+		/usr/sbin/popularity-contest-sendmail "$MAILFROM" "$MAILTO" "$MTA"
+	elif [ -n "$MAILFROM" ]; then
 		sendmail -oi -f "$MAILFROM" "$MAILTO"
 	else
 		sendmail -oi "$MAILTO"
@@ -48,7 +53,6 @@
 }
 
 # generate and transmit the popularity contest data
-
 run_popcon \
 	| tee /var/log/popularity-contest \
 	| do_sendmail
diff -Nur popularity-contest-1.23/debian/rules popularity-contest-1.24/debian/rules
--- popularity-contest-1.23/debian/rules	2004-06-16 00:16:27.000000000 +0200
+++ popularity-contest-1.24/debian/rules	2004-08-10 15:52:49.000000000 +0200
@@ -27,6 +27,7 @@
 	install -d debian/tmp/usr/share/popularity-contest/
 	install popularity-contest debian/tmp/usr/sbin/
 	install popcon-largest-unused debian/tmp/usr/sbin/
+	install popularity-contest-sendmail debian/tmp/usr/sbin/
 	install -m 644 default.conf debian/tmp/usr/share/popularity-contest/
 
 # Build architecture-independent files here.
diff -Nur popularity-contest-1.23/default.conf popularity-contest-1.24/default.conf
--- popularity-contest-1.23/default.conf	2004-01-26 21:59:18.000000000 +0100
+++ popularity-contest-1.24/default.conf	2004-08-10 16:03:07.000000000 +0200
@@ -36,3 +36,12 @@
 # leave it alone.
 #
 #MY_HOSTID="_ID_"
+
+# MTA is the FQDN of your provider mailserver.
+# You must set this variable if your system is not able to send 
+# mail by its own.
+#
+# Please note that if you set this variable you must set the
+# MAILFROM variable too.
+#
+#MTA="mail.example-provider.org"
diff -Nur popularity-contest-1.23/popularity-contest-sendmail popularity-contest-1.24/popularity-contest-sendmail
--- popularity-contest-1.23/popularity-contest-sendmail	1970-01-01 01:00:00.000000000 +0100
+++ popularity-contest-1.24/popularity-contest-sendmail	2004-08-10 15:58:38.000000000 +0200
@@ -0,0 +1,30 @@
+#!/usr/bin/perl -w
+#
+# Copyright (C) 2004 by Emanuele Rocca <ema@debian.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+use strict;
+use Mail::Sender;
+
+my ($mailfrom, $mailto, $mta) = @ARGV;
+
+if ($mailfrom eq "" || $mailto eq "" || $mta eq "") {
+	print STDERR "Not enough parameters";
+	exit 1;
+}
+
+my $sender = new Mail::Sender {smtp => $mta, from => $mailfrom};
+$sender->MailMsg({to => $mailto, subject => 'popularity-contest submission', msg => join (' ', <STDIN>) });

--2fHTh5uZTiUOsy+g--