steffen: server/kolab-resource-handlers/kolab-resource-handlers/resmgr kolabfilter.php, 1.26, 1.27 kolabmailtransport.php, 1.3, 1.4

cvs at intevation.de cvs at intevation.de
Fri Jul 1 13:59:47 CEST 2005


Author: steffen

Update of /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr
In directory doto:/tmp/cvs-serv2398/kolab-resource-handlers/resmgr

Modified Files:
	kolabfilter.php kolabmailtransport.php 
Log Message:
Errorhandling for multiple recipients (Issue825)

Index: kolabfilter.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr/kolabfilter.php,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- kolabfilter.php	15 Jun 2005 11:05:45 -0000	1.26
+++ kolabfilter.php	1 Jul 2005 11:59:45 -0000	1.27
@@ -267,9 +267,9 @@
     $headers_done = true;
     foreach( $add_headers as $h ) {
       if( PEAR::isError($error = $smtp->data( "$h\r\n" )) ) {
-	fwrite(STDOUT, $error->getMessage().", code ".$error->getCode()."\n"); 
-	if( $error->getCode() < 500 ) exit(EX_TEMPFAIL);
-	else exit(EX_UNAVAILABLE);
+		fwrite(STDOUT, $error->getMessage().", code ".$error->getCode()."\n"); 
+		if( $error->getCode() < 500 ) exit(EX_TEMPFAIL);
+		else exit(EX_UNAVAILABLE);
       }
     }
   }

Index: kolabmailtransport.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr/kolabmailtransport.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- kolabmailtransport.php	17 May 2005 10:25:18 -0000	1.3
+++ kolabmailtransport.php	1 Jul 2005 11:59:45 -0000	1.4
@@ -46,23 +46,47 @@
     
     if( !is_array( $recips ) ) $recips = array($recips);
 
+	$reciperrors = array();
     foreach( $recips as $recip ) {
       if (PEAR::isError($error = $this->transport->rcptTo($recip))) {
-	$msg = 'Failed to set recipient: ' . $error->getMessage();
-	myLog($msg, RM_LOG_ERROR);
-	return new PEAR_Error('Failed to set recipient: '.$error->getMessage(), $this->transport->_code);
+		$msg = "Failed to set recipient $recip: " . $error->getMessage(). ", code=".$this->transport->_code;;
+		myLog($msg, RM_LOG_ERROR);
+		$reciperrors[] = new PEAR_Error('Failed to set recipient: '.$error->getMessage(), $this->transport->_code);
       }
     }
-
+	if( count($reciperrors) == count($recips) ) {
+	  // OK, all failed, just give up
+	  if( count($reciperrors) == 1 ) {
+		// Only one failure, just return that
+		return $reciperrors[0];
+	  }
+	  // Multiple errors
+	  return $this->createErrorObject( $reciperrors, 'Delivery to all recipients failed' );
+	}
     if (PEAR::isError($error = $this->transport->_put('DATA'))) {      
       return $error;
     }
     if (PEAR::isError($error = $this->transport->_parseResponse(354))) {
       return $error;
     }
+	if( !empty($reciperrors) ) {
+	  return $this->createErrorObject( $reciperrors, 'Delivery to some recipients failed' );
+	}
     return true;
   }
 
+  // Encapsulate multiple errors in one
+  function createErrorObject( $reciperrors, $msg = null ) {
+	// Return the lowest errorcode to not bounce more
+	// than we have to
+	if($msg == null) $msg = 'Delivery to recipients failed.';
+	$code = 1000;
+	foreach( $reciperrors as $err ) {
+	  if( $err->code < $code ) $code = $err->code;
+	}
+	return new PEAR_Error( $msg, $code, null, null, $reciperrors);	
+  }
+
   /* Modified implementation from Net_SMTP that supports
    * dotstuffing even when getting the mail line-by line */
   function quotedataline(&$data) {
@@ -128,4 +152,4 @@
   }
 };
 
-?>
\ No newline at end of file
+?>





More information about the commits mailing list