diff options
author | Sascha Wilde <wilde@intevation.de> | 2008-08-01 10:54:49 (GMT) |
---|---|---|
committer | Sascha Wilde <wilde@intevation.de> | 2008-08-01 10:54:49 (GMT) |
commit | e0da7554fd2f8f4faab9de8d62eeff3742cfe3ba (patch) | |
tree | 7caa3ff3ba82b89d4fb655caa24da45b594d5167 /php-kolab/Kolab_Filter | |
parent | 46bf0a0ea886a70dde2272d6d891129c57322c27 (diff) | |
download | server-e0da7554fd2f8f4faab9de8d62eeff3742cfe3ba.tar.gz |
Added new simple Dovecot LDA backend for kolabfilter/kolabmailboxfilter.
Diffstat (limited to 'php-kolab/Kolab_Filter')
-rw-r--r-- | php-kolab/Kolab_Filter/AUTHORS | 3 | ||||
-rw-r--r-- | php-kolab/Kolab_Filter/ChangeLog | 8 | ||||
-rw-r--r-- | php-kolab/Kolab_Filter/Filter/DovecotLDA.php | 148 | ||||
-rw-r--r-- | php-kolab/Kolab_Filter/Filter/Transport.php | 10 | ||||
-rw-r--r-- | php-kolab/Kolab_Filter/package.xml.in | 7 |
5 files changed, 176 insertions, 0 deletions
diff --git a/php-kolab/Kolab_Filter/AUTHORS b/php-kolab/Kolab_Filter/AUTHORS index 38ac31e..da5340f 100644 --- a/php-kolab/Kolab_Filter/AUTHORS +++ b/php-kolab/Kolab_Filter/AUTHORS @@ -20,6 +20,9 @@ Portions based on work by the following companies: (c) 2006 - 2008 Intevation GmbH (c) 2006 - 2008 p@rdus +Dovecot LDA backend: + + (c) 2008 Intevation GmbH Contributions by the following people: diff --git a/php-kolab/Kolab_Filter/ChangeLog b/php-kolab/Kolab_Filter/ChangeLog index 20c3b99..985f6bc 100644 --- a/php-kolab/Kolab_Filter/ChangeLog +++ b/php-kolab/Kolab_Filter/ChangeLog @@ -1,3 +1,11 @@ +2008-08-01 Sascha Wilde <wilde@intevation.de> + + * Filter/DovecotLDA.php: New file: simple Dovecot LDA backend with + API similar to Net_LMTP, so it can be used as drop-in replacement. + + * Filter/Transport.php (Transport): Added wrapper transport class + for new Dovecot LDA backend. + 2008-07-11 Gunnar Wrobel <p@rdus.de> * Filter/recurrence.class.php: diff --git a/php-kolab/Kolab_Filter/Filter/DovecotLDA.php b/php-kolab/Kolab_Filter/Filter/DovecotLDA.php new file mode 100644 index 0000000..eef755b --- /dev/null +++ b/php-kolab/Kolab_Filter/Filter/DovecotLDA.php @@ -0,0 +1,148 @@ +<?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$ + * + * 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.")); + } + } +} diff --git a/php-kolab/Kolab_Filter/Filter/Transport.php b/php-kolab/Kolab_Filter/Filter/Transport.php index ab0a8f5..34b4950 100644 --- a/php-kolab/Kolab_Filter/Filter/Transport.php +++ b/php-kolab/Kolab_Filter/Filter/Transport.php @@ -223,6 +223,16 @@ class Transport_SMTP extends Transport } } +class Transport_LDA extends Transport +{ + function &createTransport() + { + require_once 'Kolab/Filter/DovecotLDA.php'; + $transport = &new Dovecot_LDA(); + return $transport; + } +} + class StdOutWrapper { function connect() diff --git a/php-kolab/Kolab_Filter/package.xml.in b/php-kolab/Kolab_Filter/package.xml.in index 9b06f4b..426e076 100644 --- a/php-kolab/Kolab_Filter/package.xml.in +++ b/php-kolab/Kolab_Filter/package.xml.in @@ -49,6 +49,12 @@ http://pear.php.net/dtd/package-2.0.xsd"> <active>yes</active> </developer> <developer> + <name>Sascha Wilde</name> + <user>wilde</user> + <email>wilde@intevation.de</email> + <active>yes</active> + </developer> + <developer> <name>Marcus Huewe</name> <user>marcus</user> <email>suse-tux@gmx.de</email> @@ -96,6 +102,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> <file name="Resource.php" role="php" /> <file name="recurrence.class.php" role="php" /> <file name="Transport.php" role="php" /> + <file name="DovecotLDA.php" role="php" /> </dir> <!-- /Filter --> </dir> <!-- / --> </contents> |