steffen: server/kolab-resource-handlers/kolab-resource-handlers/resmgr kolabfilter.php, 1.17, 1.18 misc.php, 1.3, 1.4 resmgr.php, 1.66, 1.67 smtp.php, 1.3, 1.4

cvs at intevation.de cvs at intevation.de
Sat Apr 2 04:47:36 CEST 2005


Author: steffen

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

Modified Files:
	kolabfilter.php misc.php resmgr.php smtp.php 
Log Message:
support for multiple recipients

Index: kolabfilter.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr/kolabfilter.php,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- kolabfilter.php	9 Mar 2005 02:49:35 -0000	1.17
+++ kolabfilter.php	2 Apr 2005 02:47:34 -0000	1.18
@@ -89,7 +89,7 @@
   return true;
 }
 
-$options = getopt("s:r:c:h:");
+$options = parse_args( array( 's', 'r', 'c', 'h' ), $_SERVER['argv']); //getopt("s:r:c:h:");
 
 if (!array_key_exists('r', $options) || !array_key_exists('s', $options)) {
     fwrite(STDOUT, "Usage is $argv[0] -s sender at domain -r recip at domain\n");
@@ -97,11 +97,22 @@
 }
 
 $sender = strtolower($options['s']);
-$recipient = strtolower($options['r']);
+$recipients = $options['r'];
 $client_address = $options['c'];
 $fqhostname = strtolower($options['h']);
 
-myLog("Kolabfilter starting up, sender=$sender, recipient=$recipient, client_address=$client_address", RM_LOG_DEBUG);
+// make sure recipients is an array
+if( !is_array($recipients) ) {
+  $recipients = array( $recipients );
+}
+
+// make recipients lowercase
+for( $i = 0; $i < count($recipients); $i++ ) {
+  $recipients[$i] = strtolower($recipients[$i]);
+}
+
+myLog("Kolabfilter starting up, sender=$sender, recipients=".join(',', $recipients)
+      .", client_address=$client_address", RM_LOG_DEBUG);
 
 $ical = false;
 $add_headers = array();
@@ -135,12 +146,18 @@
 fclose($tmpf);
 if( $ical ) {
   require_once 'kolabfilter/resmgr.php';
-  myLog("Calling resmgr_filter( $sender, $recipient, $tmpfname )", RM_LOG_DEBUG);
-  $rc = resmgr_filter( $fqhostname, $sender, $recipient, $tmpfname );
-  if( PEAR::isError( $rc ) ) {
-    fwrite(STDOUT,"Filter failed: ".$rc->getMessage()."\n");
-    exit(EX_TEMPFAIL);
+  $newrecips = array();
+  foreach( $recipients as $recip ) {
+    myLog("Calling resmgr_filter( $sender, $recip, $tmpfname )", RM_LOG_DEBUG);
+    $rc = resmgr_filter( $fqhostname, $sender, $recip, $tmpfname );
+    if( PEAR::isError( $rc ) ) {
+      fwrite(STDOUT,"Filter failed: ".$rc->getMessage()."\n");
+      exit(EX_TEMPFAIL);
+    } else if( $rc === true ) {
+      $newrecips[] = $recip;
+    }
   }
+  $recipients = $newrecips;
   $add_headers[] = "X-Kolab-Scheduling-Message: TRUE";
 } else {
   $add_headers[] = "X-Kolab-Scheduling-Message: FALSE";
@@ -152,7 +169,7 @@
   fwrite(STDOUT, $smtp->getMessage()."\n"); exit(EX_TEMPFAIL);
 }
 //myLog("Calling smtp->start( $sender, $recipient, $tmpfname )", RM_LOG_DEBUG);
-if( PEAR::isError( $error = $smtp->start($sender,$recipient) ) ) {
+if( PEAR::isError( $error = $smtp->start($sender,$recipients) ) ) {
   fwrite(STDOUT, $error->getMessage()."\n"); exit(EX_TEMPFAIL);  
 }
 

Index: misc.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr/misc.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- misc.php	21 Dec 2004 13:30:46 -0000	1.3
+++ misc.php	2 Apr 2005 02:47:34 -0000	1.4
@@ -151,4 +151,40 @@
         $_SERVER['REMOTE_HOST'] = $params['server'];
     }
 }
+
+/* Since getopt() in php can't parse the options the way
+ * postfix gives them to us, we write our own option
+ * handling:
+ *
+ * Inputs:
+ *  $opts:  array('a','b','c'), a list of wanted options
+ *  $args:  the argv list
+ * Output:
+ *  array of options and values. For example, the input
+ *  "-a foo -b bar baz" would result in 
+ *  array( 'a' => 'foo', 'b' => array('bar','baz') )
+ */
+function parse_args( $opts, $args )
+{
+  $ret = array();
+  for( $i = 0; $i < count($args); ++$i ) {
+    $arg = $args[$i];
+    if( $arg[0] == '-' ) {
+      if( in_array( $arg[1], $opts ) ) {
+	$val = array();
+	$i++;
+	while( $i < count($args) && $args[$i][0] != '-' ) {
+	  $val[] = $args[$i];
+	  $i++;
+	}
+	$i--;
+	if( is_array( $ret[$arg[1]] ) ) $ret[$arg[1]] = array_merge($ret[$arg[1]] ,$val);
+	else if( count($val) == 1 ) $ret[$arg[1]] = $val[0];
+	else $ret[$arg[1]] = $val;
+      }
+    }
+  }
+  return $ret;
+}
+
 ?>

Index: resmgr.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr/resmgr.php,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- resmgr.php	10 Mar 2005 15:49:41 -0000	1.66
+++ resmgr.php	2 Apr 2005 02:47:34 -0000	1.67
@@ -1077,7 +1077,7 @@
   if ($params['action'] == RM_ACT_ALWAYS_REJECT) {
     myLog("Rejecting $method method");
     sendITipReply($cn,$resource,$itip,RM_ITIP_DECLINE);
-    shutdown(0);
+    return false;//shutdown(0);
   }
 
   $is_update = false;
@@ -1120,7 +1120,7 @@
       $vfb = &getFreeBusy($resource);
 
       if (!$vfb) {
-	shutdown(1, "Error building free/busy list");
+	return new PEAR_Error("Error building free/busy list");
       }
 
       $vfbstart = $vfb->getAttributeDefault('DTSTART', 0);
@@ -1164,7 +1164,7 @@
 	} else if ($params['action'] == RM_ACT_REJECT_IF_CONFLICTS) {
 	  myLog("Conflict detected; rejecting");
 	  sendITipReply($cn,$resource,$itip,RM_ITIP_DECLINE);
-	  shutdown(0);
+	  return false;//shutdown(0);
 	}
       }
     }
@@ -1251,7 +1251,7 @@
     if( !triggerFreeBusy($resource,false) ) {
       myLog("Error updating fblist", RM_LOG_SUPER );
     }
-    shutdown(0);
+    return false;//shutdown(0);
 
   case 'CANCEL':
     myLog("Removing event $sid");
@@ -1316,7 +1316,7 @@
     //$status = $mime->send($organiser, $msg_headers);
     if (is_a($status, 'PEAR_Error')) {
       myLog("Unable to send cancellation reply: " . $status->getMessage(), RM_LOG_ERROR);
-      shutdown(1, "Unable to send cancellation reply: " . $status->getMessage());
+      return new PEAR_Error("Unable to send cancellation reply: " . $status->getMessage());
     } else {
       myLog("Successfully sent cancellation reply");
     }
@@ -1335,14 +1335,14 @@
     if( !triggerFreeBusy($resource,false) ) {
       myLog("Error updating fblist", RM_LOG_SUPER );
     }
-    shutdown(0);
+    return false;;
 
   default:
     // We either don't currently handle these iTip methods, or they do not
     // apply to what we're trying to accomplish here
     if (!$params['group']) {
       myLog("Ignoring $method method");
-      shutdown(0);
+      return false;
     }
   }
 

Index: smtp.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr/smtp.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- smtp.php	11 Jan 2005 12:43:49 -0000	1.3
+++ smtp.php	2 Apr 2005 02:47:34 -0000	1.4
@@ -25,7 +25,7 @@
     $this->smtp = false;
   }
 
-  function start($sender,$recip) {
+  function start($sender,$recips) {
     require_once 'Net/SMTP.php';
 	
     $this->smtp = &new Net_SMTP($this->host, $this->port);
@@ -40,10 +40,14 @@
       return new PEAR_Error('Failed to set sender: ' . $error->getMessage());
     }
     
-    if (PEAR::isError($error = $this->smtp->rcptTo($recip))) {
-      $msg = 'Failed to set recipient: ' . $error->getMessage();
-      myLog($msg, RM_LOG_ERROR);
-      return false;
+    if( !is_array( $recips ) ) $recips = array($recips);
+
+    foreach( $recips as $recip ) {
+      if (PEAR::isError($error = $this->smtp->rcptTo($recip))) {
+	$msg = 'Failed to set recipient: ' . $error->getMessage();
+	myLog($msg, RM_LOG_ERROR);
+	return false;
+      }
     }
 
     if (PEAR::isError($error = $this->smtp->_put('DATA'))) {      





More information about the commits mailing list