wilde: server/php-kolab/Kolab_Filter/Filter DovecotLDA.php, NONE, 1.1 Transport.php, 1.2, 1.3

cvs at kolab.org cvs at kolab.org
Fri Aug 1 12:54:51 CEST 2008


Author: wilde

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

Modified Files:
	Transport.php 
Added Files:
	DovecotLDA.php 
Log Message:
Added new simple Dovecot LDA backend for kolabfilter/kolabmailboxfilter.


--- NEW FILE: DovecotLDA.php ---
<?PHP
/*
 *  COPYRIGHT
 *  ---------
 *
 *  See ../AUTHORS file
 *
 *
 *  LICENSE
 *  -------
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  $Revision: 1.1 $
 *
 *  ABOUT
 *  -----
 *
 *  Simple Net_LMTP like backend for dovecot LDA delivery.
 *
 */

class Dovecot_LDA
{
    var $envelopeSender;
    var $envelopeTo;
    var $status;
    var $deliver_fh;

    function Dovecot_LDA()
    {
        $this->envelopeTo = false;
        $this->status = 220;
    }

    function mailFrom($sender)
    {
        $this->envelopeSender = $sender;
        $this->status = 250;
    }

    function rcptTo($rcpt)
    {
        // We can only handle one recipient, so bail out if more than one is tried!
        if ( ! $this->envelopeTo ) {
            $this->envelopeTo = $rcpt;
            $this->status = 250;
        } else {
            $this->status = 451;  	// Requested action aborted: local error in processing
            return PEAR::raiseError(_("Configuration error!  Dovecot LDA Backend can only handle one recipient at a time."));
        }
    }

    function connect()
    {
        return true;
    }

    function disconnect()
    {
        return true;
    }

    function _put($cmd)
    {
        if ( $cmd == "DATA" ) {
            $this->__start_deliver();
            $this->status = 354;
        } else {
            $this->status = 500;
            return PEAR::raiseError(_("Dovecot LDA Backend received unknow command."));
        }
        return true;
    }

    function _parseResponse($code)
    {
        if ( $code ) {
            if ( $this->status == $code ) {
                return true;
            } else {
                return PEAR::raiseError(_("Dovecot LDA status is not the expected!."));
            }
        } else {
            return $this->status;
        }
    }

    function _send($data)
    {
        if ( $data == ".\r\n" or $data == "\r\n.\r\n" ) {
            $this->__stop_deliver();
            # FIXEME: error checking would be nice!
            $this->status = 250;
        } else {
            $this->__deliver($data);
        }
    }

    # Private functions:

    function __start_deliver()
    {
        Horde::logMessage(sprintf(_("Starting Dovecot deliver process with UID %d, GID %d (sender=%s, recipient=%s) ..."),
                                  getmyuid(), getmygid(),
                                  $this->envelopeSender, $this->envelopeTo),
                          __FILE__, __LINE__, PEAR_LOG_DEBUG);
        # FIXME: path to deliver should be configurable.
        $this->deliver_fh = popen("/kolab/libexec/dovecot/deliver" .
                                  " -f $this->envelopeSender" .
                                  " -d $this->envelopeTo", "w");
    }

    function __stop_deliver()
    {
        Horde::logMessage("Stoping Dovecot deliver process ...",
                          __FILE__, __LINE__, PEAR_LOG_DEBUG);
        $retval = pclose($this->deliver_fh);
        Horde::logMessage(sprintf(_("... returnvalue was %d\n"), $retval),
                          __FILE__, __LINE__, PEAR_LOG_DEBUG);
        if ( $retval != 0 )
            return PEAR::raiseError(_("Dovecot LDA Backend deliver process signaled error."));
        return true;
    }

    function __deliver($data)
    {
        // Horde::logMessage("Writing data line to Dovecot deliver process ...",
        //                   __FILE__, __LINE__, PEAR_LOG_DEBUG);
        if ( fwrite($this->deliver_fh, $data) ) {
            return true;
        } else {
            return PEAR::raiseError(_("Dovecot LDA Backend can't write to deliver process."));
       }
    }
}

Index: Transport.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Filter/Filter/Transport.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Transport.php	28 Nov 2007 06:06:12 -0000	1.2
+++ Transport.php	1 Aug 2008 10:54:49 -0000	1.3
@@ -223,6 +223,16 @@
     }
 }
 
+class Transport_LDA extends Transport
+{
+    function &createTransport()
+    {
+        require_once 'Kolab/Filter/DovecotLDA.php';
+        $transport = &new Dovecot_LDA();
+        return $transport;
+    }
+}
+
 class StdOutWrapper
 {
     function connect()





More information about the commits mailing list