Patch for qmail driver

Dmitriy MiksIr <[email protected]>
Newsgroups gmane.comp.horde.sork
Message-ID <[email protected]>
Hi!
I write a little patch for qmail driver.

First, patch conf.xml for new two options.
Option "Type of FTP login" set type of login on FTP server for users 
with user@domain usernames; in "normal" state FTP login = horde login 
before @; in "full" state use for FTP login full horde auth (user@domain).
Option "Path for local copy delivery" set path, which will be placed in 
.qmail for local copy delivery. Default (hardcoded in current version) 
is ./Maildir/; two reason for change this: first, mailboxes can be in 
mbox type, and second - it can be useful for qmailadmin compatibility 
(qmailadmin set full path to maildir - /usr/local/vpopmail/... - and 
check this path for display current options; if we're set path same as 
qmailadmin set, both can work together).

Also, patch qmail.php driver. Added support of multiple forwards 
(comma-separated list). Added isKeepLocal method.

Path for 3.0 final version.

-- 
Sork mailing list - Join the hunt: http://horde.org/bounties/#sork
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]
forwards-qmail-3.0f.patch.txt (text/plain, 8.1 KB)
diff -ur forwards-h3-3.0/config/conf.xml forwards/config/conf.xml
--- forwards-h3-3.0/config/conf.xml	2005-04-13 22:06:16.000000000 +0400
+++ forwards/config/conf.xml	2006-04-18 15:04:58.000000000 +0400
@@ -47,6 +47,13 @@
         <value desc="Yes">true</value>
        </values>
       </configenum>
+      <configenum name="hauth" desc="Type of FTP login">normal
+       <values>
+        <value desc="user only and domain as realm">normal</value>
+        <value desc="full login (user@domain)">full</value>
+       </values>
+      </configenum>
+      <configstring name="localpath" desc="Path for local copy delivery (%u - username, %d - domain/realm)">./Maildir/</configstring>
      </configsection>
     </configsection>
    </case>
diff -ur forwards-h3-3.0/lib/Driver/qmail.php forwards/lib/Driver/qmail.php
--- forwards-h3-3.0/lib/Driver/qmail.php	2006-02-16 19:34:43.000000000 +0300
+++ forwards/lib/Driver/qmail.php	2006-04-18 16:02:23.000000000 +0400
@@ -23,6 +23,14 @@
      */
     var $_vfs;
 
+
+    /**
+     * Content of .qmail file
+     *
+     * @var string
+     */
+    var $_status;
+
     /**
      * Checks if the realm has a specific configuration.
      *
@@ -66,6 +74,7 @@
     function enableForwarding($user, $realm = 'default', $password, $target,
                               $keeplocal = false)
     {
+        $domain = $realm;
         // Make sure the configuration file is correct.
         if (!$this->checkConfiguration($realm)) {
             return false;
@@ -75,7 +84,7 @@
         $_args = array('hostspec' => $this->_params[$realm]['host'],
                        'port' => $this->_params[$realm]['port'],
                        'pasv' => $this->_params[$realm]['pasv'],
-                       'username' => $user,
+                       'username' => ($this->_params[$realm]['hauth'] == 'full' ? $user . '@' . $domain : $user),
                        'password' => $password);
 
         // Create the VFS ftp driver.
@@ -93,9 +102,15 @@
         }
 
         // Create the forwarding information.
-        $address = '&' . $target;
+        $addrs = preg_split("/,\s*/", $target);
+        foreach ($addrs as $addr) { 
+           $address .= '&' . $addr . "\n";
+        }
         if ($keeplocal == 'on') {
-            $address .= "\n./Maildir/";
+            $localpath = $this->_params[$realm]['localpath'];
+            $localpath = str_replace("%u", $user, $localpath);
+            $localpath = str_replace("%d", $domain, $localpath);
+            $address .= $localpath . "\n";
         }
 
         // Set the forward.
@@ -122,6 +137,7 @@
      */
     function disableForwarding($user, $realm = 'default', $password)
     {
+        $domain = $realm;
         if (!$this->checkConfiguration($realm)) {
             return false;
         }
@@ -129,7 +145,7 @@
         $_args = array('hostspec' => $this->_params[$realm]['host'],
                        'port' => $this->_params[$realm]['port'],
                        'pasv' => $this->_params[$realm]['pasv'],
-                       'username' => $user,
+                       'username' => ($this->_params[$realm]['hauth'] == 'full' ? $user . '@' . $domain : $user),
                        'password' => $password);
 
         require_once 'VFS.php';
@@ -154,27 +170,38 @@
         return true;
     }
 
+
     /**
-     * Retrieves current target of mail redirection for a user.
+     * Retrieves current state of mail redirection for a user.
+     *
+     * @todo This function is implemented poorly, and should be rewritten.
      *
      * @param string $user      The username of the user.
      * @param string $realm     The realm of the user.
      * @param string $password  The password of the user.
      *
-     * @return mixed  The current forwarding mail address, or false.
+     * @return mixed  'Y' if forwarding is enabled, or false otherwise.
      */
-    function currentTarget($user, $realm = 'default', $password)
+    function isEnabledForwarding($user, $realm, $password)
     {
         // Make sure the configuration file is correct.
+        $domain = $realm;
         if (!$this->checkConfiguration($realm)) {
             return false;
         }
 
+        // if $_status already set - do not retrive status again
+        if (isset($this->$_status) && $this->$_status{0} == '&') {
+           return 'Y';
+        } elseif (isset($this->$_status)) {
+           return 'N';
+        }
+
         // Build the ftp array to pass to VFS.
         $_args = array('hostspec' => $this->_params[$realm]['host'],
                        'port' => $this->_params[$realm]['port'],
                        'pasv' => $this->_params[$realm]['pasv'],
-                       'username' => $user,
+                       'username' => ($this->_params[$realm]['hauth'] == 'full' ? $user . '@' . $domain : $user),
                        'password' => $password);
 
         // Create the VFS ftp driver.
@@ -195,28 +222,96 @@
             $this->_error = $status->getMessage();
             return false;
         }
-        return $status;
+
+        if ($status{0} == '&') {
+            $this->$_status = $status;
+            return 'Y';
+        } else {
+            $this->$_status = '';
+            return 'N';
+        }
     }
 
     /**
-     * Retrieves current state of mail redirection for a user.
-     *
-     * @todo This function is implemented poorly, and should be rewritten.
+     * Retrieves current target of mail redirection for a user.
      *
      * @param string $user      The username of the user.
      * @param string $realm     The realm of the user.
      * @param string $password  The password of the user.
      *
-     * @return mixed  'Y' if forwarding is enabled, or false otherwise.
+     * @return mixed  The current forwarding mail address, or false.
      */
-    function isEnabledForwarding($user, $realm, $password)
+    function currentTarget($user, $realm = 'default', $password)
     {
-        $yn = $this->currentTarget($user, $realm, $password);
-        if ($yn) {
-            return 'Y';
-        } else {
+
+        // Make sure the configuration file is correct.
+        $domain = $realm;
+        if (!$this->checkConfiguration($realm)) {
             return false;
         }
+
+        if (!isset($this->$_status)) {
+           // get .qmail content
+           if ($this->isEnabledForwarding($user, $realm, $password) != 'Y') {
+              return false;
+           }
+        } else {
+           if ($this->$_status == '') {
+              return false;
+           }
+        }
+         
+        $lines = explode("\n", $this->$_status);
+        if ($lines[0]{0} == '&') {
+           foreach ($lines as $line) {
+              if ($line{0} == '&') {
+                 if ($address) $address .= ', ';
+                 $address .= substr($line, 1);
+              }
+           }
+          return $address;
+        }
+        return '';
     }
 
+    /**
+     * Checks if user is keeping a local copy of forwarded mail.
+     *
+     * @param string $user      The username of the user.
+     * @param string $realm     The realm of the user.
+     * @param string $password  The password of the user.
+     *
+     * @return boolean  True if user is keeping a local copy of mail,
+     *                  otherwise false.
+     */
+    function isKeepLocal($user, $realm = 'default', $password)
+    {
+
+        // Make sure the configuration file is correct.
+        $domain = $realm;
+        if (!$this->checkConfiguration($realm)) {
+            return false;
+        }
+
+        if (!isset($this->$_status)) {
+           // get .qmail content
+           if ($this->isEnabledForwarding($user, $realm, $password) != 'Y') {
+              return false;
+           }
+        } else {
+           if ($this->$_status == '') {
+              return false;
+           }
+        }
+
+        $localpath = $this->_params[$realm]['localpath'];
+        $localpath = str_replace("%u", $user, $localpath);
+        $localpath = str_replace("%d", $domain, $localpath);
+
+        $lines = explode("\n", $this->$_status);
+        foreach ($lines as $line) {
+           if ($localpath && $line == $localpath) return true;
+        }
+        return false;
+    } 
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.