gunnar: server/php-kolab/Kolab_Filter/Filter Content.php, 1.1, 1.2 Incoming.php, 1.5, 1.6 Outlook.php, 1.3, 1.4 Resource.php, 1.3, 1.4 Transport.php, 1.1, 1.2

cvs at kolab.org cvs at kolab.org
Wed Nov 28 07:06:15 CET 2007


Author: gunnar

Update of /kolabrepository/server/php-kolab/Kolab_Filter/Filter
In directory doto:/tmp/cvs-serv10688/php-kolab/Kolab_Filter/Filter

Modified Files:
	Content.php Incoming.php Outlook.php Resource.php 
	Transport.php 
Log Message:
kolab/issue2177 (Better logging in kolabfilter and kolabmailboxfilter)

Index: Content.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Filter/Filter/Content.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Content.php	27 Nov 2007 15:31:44 -0000	1.1
+++ Content.php	28 Nov 2007 06:06:12 -0000	1.2
@@ -88,7 +88,7 @@
                 if ($from && $verify_from_header) {
                     $rc = verify_sender($this->_sasl_username, $this->_sender, 
                                         $from, $this->_client_address);
-                    if (is_a($rc, 'PEAR_Error')) {
+                    if ($rc instanceof PEAR_Error) {
                         return $rc;
                     } else if ($rc === true) {
                         /* All OK, do nothing */
@@ -169,7 +169,7 @@
                 require_once('Kolab/Filter/Outlook.php');
                 $rc = olhacks_embedical($this->_fqhostname, $this->_sender, $this->_recipients, 
                                         $from, $subject, $this->_tmpfname);
-                if (is_a($rc, 'PEAR_Error')) {
+                if ($rc instanceof PEAR_Error) {
                     return $rc;
                 } else if ($rc === true) {
                     return;
@@ -182,7 +182,7 @@
         }
 
         $result = $this->deliver($rewrittenfrom);
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             return $result;
         }
     }
@@ -213,7 +213,7 @@
         }
 
         $result = $transport->start($this->_sender, $this->_recipients);
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             return $this->_rewriteCode($result);
         }
 
@@ -223,7 +223,7 @@
             if ($rewrittenfrom) {
                 if (eregi( '^From: (.*)', $buffer)) {
                     $result = $transport->data($rewrittenfrom);
-                    if (is_a($result, 'PEAR_Error')) {
+                    if ($result instanceof PEAR_Error) {
                         return $this->_rewriteCode($result);
                     }
                     $state = RM_STATE_READING_FROM;
@@ -240,7 +240,7 @@
                 $state = RM_STATE_READING_HEADER;
             }
             $result = $transport->data($buffer);
-            if (is_a($result, 'PEAR_Error')) {
+            if ($result instanceof PEAR_Error) {
                 return $this->_rewriteCode($result);
             }
         }
@@ -257,7 +257,7 @@
                 $len++;
             }
             $result = $transport->data($buffer);
-            if (is_a($result, 'PEAR_Error')) {
+            if ($result instanceof PEAR_Error) {
                 return $this->_rewriteCode($result);
             }
         }
@@ -454,7 +454,7 @@
     
     if ($sasluser) {
         $allowed_addrs = addrs_for_uid($sasluser);
-        if (is_a($allowed_addrs, 'PEAR_Error')) {
+        if ($allowed_addrs instanceof PEAR_Error) {
             return $allowed_addrs;
         }
     } else {

Index: Incoming.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Filter/Filter/Incoming.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Incoming.php	27 Nov 2007 14:21:15 -0000	1.5
+++ Incoming.php	28 Nov 2007 06:06:12 -0000	1.6
@@ -45,19 +45,20 @@
     {
         Filter::Filter($transport, $debug);
     }
-    
+
     function _parse($inh = STDIN)
     {
         $ical = false;
         $add_headers = array();
         $headers_done = false;
 
-        while (!feof($inh) && !$headers_done) {
+        /* High speed section START */
+        while (!feof($inh)) {
             $buffer = fgets($inh, 8192);
             $line = rtrim( $buffer, "\r\n");
             if ($line == '') {
                 /* Done with headers */
-                $headers_done = true;
+                break;
             } else if (eregi('^Content-Type: text/calendar', $line)) {
                 Horde::logMessage(_("Found iCal data in message"), 
                                   __FILE__, __LINE__, PEAR_LOG_DEBUG);
@@ -73,15 +74,39 @@
             }
         }
 
-        while (!feof($inh)) {
-            $buffer = fread($inh, 8192);
-            if (@fwrite($this->_tmpfh, $buffer) === false) {
-                $msg = $php_errormsg;
-                return PEAR::raiseError(sprintf(_("Error: Could not write to %s: %s"),
-                                                $this->_tmpfile, $msg),
-                                        OUT_LOG | EX_TEMPFAIL);
+        if ($ical) {
+            /* iCal already identified. So let's just pipe the rest of
+             * the message through.
+             */
+            while (!feof($inh)) {
+                $buffer = fread($inh, 8192);
+                if (@fwrite($this->_tmpfh, $buffer) === false) {
+                    $msg = $php_errormsg;
+                    return PEAR::raiseError(sprintf(_("Error: Could not write to %s: %s"),
+                                                    $this->_tmpfile, $msg),
+                                            OUT_LOG | EX_TEMPFAIL);
+                }
+            }
+        } else {
+            /* No ical yet? Let's try to identify the string
+             * "text/calendar". It's likely that we have a mime
+             * multipart message including iCal then.
+             */
+            while (!feof($inh)) {
+                $buffer = fread($inh, 8192);
+                if (@fwrite($this->_tmpfh, $buffer) === false) {
+                    $msg = $php_errormsg;
+                    return PEAR::raiseError(sprintf(_("Error: Could not write to %s: %s"),
+                                                    $this->_tmpfile, $msg),
+                                            OUT_LOG | EX_TEMPFAIL);
+                }
+                if (strpos($buffer, 'text/calendar')) {
+                    $ical = true;
+                }
             }
         }
+        /* High speed section END */
+        
 
         if (@fclose($this->_tmpfh) === false) {
             $msg = $php_errormsg;
@@ -101,7 +126,7 @@
                 $rc = resmgr_filter($this->_fqhostname, $this->_sender, $recip,
                                     $this->_tmpfile);
 
-                if (is_a($rc, 'PEAR_Error')) {
+                if ($rc instanceof PEAR_Error) {
                     return $rc;
                 } else if ($rc === true) {
                     $newrecips[] = $recip;
@@ -120,7 +145,7 @@
             return;
         } else {
             $result = $this->deliver();
-            if (is_a($result, 'PEAR_Error')) {
+            if ($result instanceof PEAR_Error) {
                 return $result;
             }
         }
@@ -155,7 +180,7 @@
         }
 
         $result = $transport->start($this->_sender, $this->_recipients);
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             return $this->_rewriteCode($result);
         }
         
@@ -166,13 +191,13 @@
                 $headers_done = true;
                 foreach ($this->_add_headers as $h) {
                     $result = $transport->data("$h\r\n");
-                    if (is_a($result, 'PEAR_Error')) {
+                    if ($result instanceof PEAR_Error) {
                         return $this->_rewriteCode($result);
                     }
                 }
             }
             $result = $transport->data($buffer);
-            if (is_a($result, 'PEAR_Error')) {
+            if ($result instanceof PEAR_Error) {
                 return $this->_rewriteCode($result);
             }
         }
@@ -190,7 +215,7 @@
                 $len++;
             }
             $result = $transport->data($buffer);
-            if (is_a($result, 'PEAR_Error')) {
+            if ($result instanceof PEAR_Error) {
                 return $this->_rewriteCode($result);
             }
         }

Index: Outlook.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Filter/Filter/Outlook.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Outlook.php	27 Nov 2007 12:35:23 -0000	1.3
+++ Outlook.php	28 Nov 2007 06:06:12 -0000	1.4
@@ -220,7 +220,7 @@
     }
 
     $result = $mailer->send($recipients, $headerArray, $msg);
-    if (is_a($result, 'PEAR_Error')) {
+    if ($result instanceof PEAR_Error) {
         $append = sprintf(_(", original code %s"), $result->getCode());
         $result->message = $result->getMessage() . $append;
         $result->code = OUT_LOG | OUT_STDOUT | EX_TEMPFAIL;

Index: Resource.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Filter/Filter/Resource.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Resource.php	27 Nov 2007 14:21:15 -0000	1.3
+++ Resource.php	28 Nov 2007 06:06:12 -0000	1.4
@@ -860,7 +860,7 @@
     }  else {
         $date = gmstrftime('%Y-%m-%dT%H:%M:%SZ', $ical_date);
     }
-    Horde::logMessage(sprintf(_("To <%s>"), $date)),
+    Horde::logMessage(sprintf(_("To <%s>"), $date),
                       __FILE__, __LINE__, PEAR_LOG_DEBUG);
     return $date;
 }
@@ -877,7 +877,7 @@
         $epoch=gmmktime($temp['hour'],$temp['minute'],$temp['second'],$temp['month'],$temp['mday'],$temp['year']);
     } else { $epoch=$values;} 
     
-    Horde::logMessage(sprintf(_("Converted <%s>"), $epoch)),
+    Horde::logMessage(sprintf(_("Converted <%s>"), $epoch),
                       __FILE__, __LINE__, PEAR_LOG_DEBUG);
     return $epoch;
 }
@@ -1516,7 +1516,7 @@
         // Delete any old events that we updated
         if( !empty( $updated_messages ) ) {
             Horde::logMessage(sprintf(_("Deleting %s because of update."), 
-                                      join(', ',$deleted_messages))
+                                      join(', ',$deleted_messages)),
                               __FILE__, __LINE__, PEAR_LOG_DEBUG);
             $imap->deleteMessages( $updated_messages );
             $imap->expunge();

Index: Transport.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Filter/Filter/Transport.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Transport.php	26 Nov 2007 16:35:21 -0000	1.1
+++ Transport.php	28 Nov 2007 06:06:12 -0000	1.2
@@ -53,7 +53,7 @@
     function start($sender, $recips)
     {
         $transport = $this->createTransport();
-        if (is_a($transport, 'PEAR_Error')) {
+        if ($transport instanceof PEAR_Error) {
             return $transport;
         }
         $this->transport = $transport;
@@ -62,12 +62,12 @@
         $this->got_newline = true;
 
         $result = $this->transport->connect();
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             return $result;
         }
         
         $result = $this->transport->mailFrom($sender);
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             $resp = $this->transport->getResponse();
             return PEAR::raiseError(sprintf(_("Failed to set sender: %s, code=%s"),
                                             $resp[1], $resp[0]), $resp[0]);
@@ -80,7 +80,7 @@
         $reciperrors = array();
         foreach ($recips as $recip) {
             $result = $this->transport->rcptTo($recip);
-            if (is_a($result, 'PEAR_Error')) {
+            if ($result instanceof PEAR_Error) {
                 $resp = $this->transport->getResponse();
                 $reciperrors[] = PEAR::raiseError(sprintf(_("Failed to set recipient: %s, code=%s"),
                                                           $resp[1], $resp[0]), $resp[0]);
@@ -99,12 +99,12 @@
         }
 
         $result = $this->transport->_put('DATA');
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             return $result;
         }
 
         $result = $this->transport->_parseResponse(354);
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             return $result;
         }
         
@@ -149,7 +149,7 @@
          * Because a single leading period (.) signifies an end to the data,
          * legitimate leading periods need to be "doubled" (e.g. '..').
          */
-        if ($this->got_newline && $data[0] == '.') {
+        if ($this->got_newline && !empty($data) && $data[0] == '.') {
             $data = '.'.$data;
         }
         
@@ -163,7 +163,7 @@
     function data($data) {
         $this->quotedataline($data);
         $result = $this->transport->_send($data);
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             return $result;
         }
         return true;
@@ -178,11 +178,11 @@
         }
         
         $result = $this->transport->_send($dot);
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             return $result;
         }
         $result = $this->transport->_parseResponse(250);
-        if (is_a($result, 'PEAR_Error')) {
+        if ($result instanceof PEAR_Error) {
             return $result;
         }
         $this->transport->disconnect();
@@ -261,6 +261,24 @@
     }
 }
 
+class DropWrapper extends StdOutWrapper
+{
+    function mailFrom($sender)
+    {
+        return true;
+    }
+
+    function rcptTo($recipient)
+    {
+        return true;
+    }
+
+    function _send($data)
+    {
+        return true;
+    }
+}
+
 class Transport_StdOut extends Transport
 {
 
@@ -271,6 +289,20 @@
     function &createTransport()
     {
         $transport = &new StdOutWrapper();
+        return $transport;
+    }
+}
+
+class Transport_Drop extends Transport
+{
+
+    function Transport_SMTP($host = 'irrelevant', $port = 0)
+    {
+    }
+
+    function &createTransport()
+    {
+        $transport = &new DropWrapper();
         return $transport;
     }
 }





More information about the commits mailing list