[vhffs-dev] [877] Added support for a batched smtp

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 877
Author:   gradator
Date:     2007-09-08 18:10:07 +0000 (Sat, 08 Sep 2007)

Log Message:
-----------
Added support for a batched smtp

Modified Paths:
--------------
    trunk/vhffs-backend/conf/vhffs.conf.dist.in
    trunk/vhffs-listengine/src/listengine.pl


Modified: trunk/vhffs-backend/conf/vhffs.conf.dist.in
===================================================================
--- trunk/vhffs-backend/conf/vhffs.conf.dist.in	2007-09-08 02:13:58 UTC (rev 876)
+++ trunk/vhffs-backend/conf/vhffs.conf.dist.in	2007-09-08 18:10:07 UTC (rev 877)
@@ -449,8 +449,11 @@
 	# Listengine will send HELO domain to the SMTP sever
 	domain		=	"myhost.tld"
 
-	# SMTP Server to bounce listengine mails
-	smtp_server	=	"localhost"
+	# You have to use only one of these options, comment the unused one
+	#   You can set a SMTP server to bounce mails (not recommended)
+	#smtp_server	=	"localhost"
+	#   or a path to a batched smtp tool ( ex, "/usr/sbin/exim4 -bS", "/usr/sbin/sendmail -bs" )
+	sendmail_path	=	"/usr/sbin/exim4 -bS"
 </listengine>
 
 

Modified: trunk/vhffs-listengine/src/listengine.pl
===================================================================
--- trunk/vhffs-listengine/src/listengine.pl	2007-09-08 02:13:58 UTC (rev 876)
+++ trunk/vhffs-listengine/src/listengine.pl	2007-09-08 18:10:07 UTC (rev 877)
@@ -41,6 +41,7 @@
 use Vhffs::Main;
 use Vhffs::Services::MailingList;
 use Vhffs::Listengine::Intl;
+use Vhffs::Functions;
 
 #		open (MYFILE, '>/tmp/grunt');
 #		print MYFILE "FROM: '$from'  FROMPERM: '$subs->{$from}{'perm'}'   SUB: '$subscriber'   SUBPERM:  '$subs->{$subscriber}{'perm'}'   SUBHASH: '$subs->{$subscriber}{'hash'}'    HASH:  '$hash'\n";
@@ -60,16 +61,17 @@
 
 my $listengineconfig = $vhffs->get_config->get_listengine;
 
-my $DOMAIN	= $listengineconfig->{'domain'};
-my $LISTMASTER	= $listengineconfig->{'listmaster'};
-my $ADMIN	= $listengineconfig->{'listmaster'};
-my $SMTP_SERVER = $listengineconfig->{'smtp_server'};
+my $DOMAIN	  = $listengineconfig->{'domain'};
+my $LISTMASTER	  = $listengineconfig->{'listmaster'};
+my $ADMIN	  = $listengineconfig->{'listmaster'};
+my $SMTP_SERVER   = $listengineconfig->{'smtp_server'};
+my $SENDMAIL_PATH = $listengineconfig->{'sendmail_path'};
 
 # Be careful, listengine will create /data/listengine/archives for archives
 # and /data/listengine/tomoderate for moderation
 my $DIRECTORY	= $listengineconfig->{'datadir'};
 
-exit 2 unless( defined $DOMAIN && defined $LISTMASTER && defined $ADMIN && defined $SMTP_SERVER && defined $DIRECTORY );
+exit 2 unless( defined $DOMAIN && defined $LISTMASTER && defined $ADMIN && ( defined $SMTP_SERVER ^ defined $SENDMAIL_PATH ) && defined $DIRECTORY );
 
 
 sub add_list_header
@@ -85,6 +87,9 @@
     $header->replace( 'List-Id' , $list->get_localpart.".".$list->get_domain );
     $header->replace( 'List-Post' , '<mailto:'.$list->get_localpart."@".$list->get_domain.'>' );
     $header->replace( 'List-Archive' , '<'.$mailinglistconfig->{'url_archives'}.'/'.$list->get_domain.'/'.$list->get_localpart.'>' ) if( $mailinglistconfig->{'url_archives'} );
+
+    #Replace the Reply-To field if selected in the panel  
+    $header->replace( 'Reply-To' , $list->get_localpart ."\@" . $list->get_domain ) if( $list->get_replyto == 1 );
 }
 
 
@@ -94,16 +99,10 @@
     my $mail  = shift;
     my $addrs = shift;
     my @tos;
-    my $line;
-    my $adr;
-    my $smtp;
-    my $header_pass = 0;
 
-
     if( ref($addrs) eq "ARRAY" )
     {
-	my $v;
-	foreach $v ( @{$addrs} )
+	foreach my $v ( @{$addrs} )
 	{
 	    push @tos , $v;
 	}
@@ -111,19 +110,51 @@
     else
     {
 	push @tos , $addrs;
-   }
+    }
 
-	foreach $adr (@tos)
-	{
-		$smtp = Net::SMTP->new( $SMTP_SERVER,
-			Hello => $DOMAIN,
-		);
+	if( defined $SENDMAIL_PATH )  {
 
-		$smtp->mail( $mail->get('From') );
-		$smtp->to( $adr );
-		$smtp->data( $mail->as_string );
-		$smtp->quit;
+		my $dir = $DIRECTORY.'/errors/';
+		Vhffs::Functions::create_dir( $dir ) if( ! -d $dir );
+		my $errorf = '/dev/null';
+		$errorf = $dir.time() if( -d $dir );  # not perfect but should be sufficient to fix errors
+
+		open(SENDMAIL, "| $SENDMAIL_PATH 2> $errorf > /dev/null" ) or die( "Error - cannot open BSMTP input" );
+		print SENDMAIL 'HELO '.$DOMAIN."\n";
+
+		foreach my $adr (@tos)
+		{
+			my $from = $mail->get('From');
+			chomp $from;
+			chomp $adr;
+
+			print SENDMAIL 'RSET'."\n";
+			print SENDMAIL 'MAIL FROM:'.$from."\n";
+			print SENDMAIL 'RCPT TO:<'.$adr.'>'."\n";
+			print SENDMAIL 'DATA'."\n";
+			print SENDMAIL $mail->as_string;
+			print SENDMAIL "\n.\n";
+		}
+
+		print SENDMAIL 'QUIT'."\n";
+		close(SENDMAIL);
+
+		# delete the error file if it is empty
+		unlink $errorf if ( -f $errorf  &&  ! -s $errorf );
 	}
+	else {
+		foreach my $adr (@tos)
+		{
+			my $smtp = Net::SMTP->new( $SMTP_SERVER,
+				Hello => $DOMAIN,
+			);
+
+			$smtp->mail( $mail->get('From') );
+			$smtp->to( $adr );
+			$smtp->data( $mail->as_string );
+			$smtp->quit;
+		}
+	}
 }
 
 
@@ -140,12 +171,13 @@
     $day = '0'.$day if( $day <= 9 );
 
     my $message_id = $mail->get( 'Message-Id' );
+
+    #Don't archive if message-id is not found
+    return unless( defined $message_id  &&  $message_id ne '' );
+
     $message_id =~ s/^<//;
     $message_id =~ s/>$//;
 
-    #Don't archive if message-id is not found
-    return if( ( ! defined $message_id ) || ( $message_id eq "" ) );
-
     my $directory = $DIRECTORY.'/archives/'.$list->get_domain.'/'.$list->get_localpart.'/'.$year.'/'.$month.'/'.$day;
     Vhffs::Functions::create_dir( $directory ) if( ! -d $directory );
 
@@ -607,11 +639,8 @@
    
 	my @tos;
 
-	#Replace the Reply-To field if selected in the panel  
 	add_list_header( $mail , $list );
-	$mail->replace( 'Reply-To' , $list->get_localpart ."\@" . $list->get_domain ) if( $list->get_replyto == 1 );
 
-
 	#Add prefix if not null
 	my $subject = $mail->get('Subject');
 	my $tsubject = $subject;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/