steffen: server/kolab-resource-handlers/kolab-resource-handlers/resmgr kolabmailtransport.php, 1.3, 1.3.2.1

cvs at intevation.de cvs at intevation.de
Thu Jul 28 04:20:38 CEST 2005


Author: steffen

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

Modified Files:
      Tag: kolab_2_0_branch
	kolabmailtransport.php 
Log Message:
backport of LMTP error handling from HEAD (issue825)

Index: kolabmailtransport.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr/kolabmailtransport.php,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -d -r1.3 -r1.3.2.1
--- kolabmailtransport.php	17 May 2005 10:25:18 -0000	1.3
+++ kolabmailtransport.php	28 Jul 2005 02:20:36 -0000	1.3.2.1
@@ -46,13 +46,23 @@
     
     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;
@@ -63,6 +73,18 @@
     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 +150,4 @@
   }
 };
 
-?>
\ No newline at end of file
+?>





More information about the commits mailing list