[vhffs-dev] [1384] improved sendmail() sub, don't start the batch (or smtp) if To: list is empty, removed useless checks before calling this sub

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


Revision: 1384
Author:   gradator
Date:     2009-03-17 09:10:58 +0100 (Tue, 17 Mar 2009)

Log Message:
-----------
improved sendmail() sub, don't start the batch (or smtp) if To: list is empty, removed useless checks before calling this sub

Modified Paths:
--------------
    trunk/vhffs-listengine/src/listengine.pl


Modified: trunk/vhffs-listengine/src/listengine.pl
===================================================================
--- trunk/vhffs-listengine/src/listengine.pl	2009-03-16 20:02:18 UTC (rev 1383)
+++ trunk/vhffs-listengine/src/listengine.pl	2009-03-17 08:10:58 UTC (rev 1384)
@@ -98,33 +98,29 @@
 
 sub sendmail
 {
-    my $mail  = shift;
-    my $addrs = shift;
-    my @tos;
+	my $mail  = shift;
+	my $addrs = shift;
+	return 1 unless( defined $mail && defined $addrs );
 
-    if( ref($addrs) eq "ARRAY" )
-    {
-	foreach my $v ( @{$addrs} )
-	{
-	    push @tos , $v;
+	# single to
+	if( ref($addrs) ne 'ARRAY' ) {
+		my @to = ( $addrs );
+		$addrs = \@to;
 	}
-    }
-    else
-    {
-	push @tos , $addrs;
-    }
 
+	return 1 unless @{$addrs};
+
 	if( defined $SENDMAIL_PATH )  {
 
 		my $dir = $DIRECTORY.'/errors/';
-		Vhffs::Functions::create_dir( $dir ) if( ! -d $dir );
+		Vhffs::Functions::create_dir( $dir ) unless -d $dir;
 		my $errorf = '/dev/null';
-		$errorf = $dir.time().'_'.$$ if( -d $dir );
+		$errorf = $dir.time().'_'.$$ if -d $dir;
 
 		open(SENDMAIL, "| $SENDMAIL_PATH 2> $errorf 1>&2" ) or die( "Error - cannot open BSMTP input" );
 		print SENDMAIL 'HELO '.$DOMAIN."\n";
 
-		foreach my $adr (@tos)
+		foreach my $adr ( @{$addrs} )
 		{
 			chomp $adr;
 
@@ -143,7 +139,7 @@
 		unlink $errorf if ( -f $errorf  &&  ! -s $errorf );
 	}
 	else {
-		foreach my $adr (@tos)
+		foreach my $adr ( @{$addrs} )
 		{
 			my $smtp = Net::SMTP->new( $SMTP_SERVER,
 				Hello => $DOMAIN,
@@ -155,6 +151,8 @@
 			$smtp->quit;
 		}
 	}
+
+	return 0;
 }
 
 
@@ -225,7 +223,7 @@
 				   Body => Vhffs::Listengine::mail_moderate_message( $list , $filehash , $from , $subject )
 				   );
     
-    sendmail( $email , \@tos ) if( ( defined $email ) && ( $#tos >= 0 ) );
+    sendmail( $email , \@tos );
 }
 
 
@@ -292,7 +290,7 @@
 	}
     }
 
-    sendmail( $email , $from ) if( defined $email );
+    sendmail( $email , $from );
 }
 
 
@@ -398,7 +396,7 @@
 				   Body => Vhffs::Listengine::mail_moderate_subscriber( $list , $from , $pass )
 				   );
     
-			sendmail( $email , \@tos ) if( ( defined $email ) && ( $#tos >= 0 ) );
+			sendmail( $email , \@tos );
 		}
 		else  {
 
@@ -530,7 +528,7 @@
 			   Body => Vhffs::Listengine::mail_moderate_subscription_accept_ack( $list , $subscriber )
 			   );
     
-		sendmail( $email , \@tos ) if( ( defined $email ) && ( $#tos >= 0 ) );		
+		sendmail( $email , \@tos );	
     }
     else
     {
@@ -602,7 +600,7 @@
 			   Body => Vhffs::Listengine::mail_moderate_subscription_refuse_ack( $list , $subscriber )
 			   );
     
-		sendmail( $email , \@tos ) if( ( defined $email ) && ( $#tos >= 0 ) );		
+		sendmail( $email , \@tos );	
     }
     else
     {


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