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 @@
true
+ normal
+
+ normal
+ full
+
+
+ ./Maildir/
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;
+ }
}