* * See the enclosed file LICENSE for license information (BSD). If you * did not receive this file, see http://www.horde.org/bsdl.php. * * Forwards_Driver_qmail:: implements the Forwards_Driver API for ftp driven * qmail mail servers. * * @author Eric Rostetter * @version $Revision: 1.3 $ * @since Forwards 2.2 * @package forwards */ ## NOTE: BIZARRE LACK OF SEMICOLONS AT THE END OF MANY LINES... REPLACED BY ME... - Rob class Forwards_Driver_qmail extends Forwards_Driver { /** The FTP stream we open via the Horde_VFS class */ var $_vfs; /** The error string returned to the user if an error occurs. */ var $err_str; /** Hash containing configuration data. */ var $params; /** * Constructs a new ftp qmail Forwards_Driver object. * * @param array $params A hash containing connection parameters. */ function Forwards_Driver_qmail($params = array()) { $this->params = $params; } /** * Check if the realm has a specific configuration. If not, try to fall * back on the default configuration. If still not a valid configuration * then exit with an error. * * @param string $realm The realm of the user, or "default" if none. * Note: passed by reference so we can change * it's value! * */ function check_config(&$realm) { // If no realm passed in, or no host config for the realm passed in, // then we fall back to the default realm if ( empty($realm) || empty($this->params[$realm]['host']) ) { $realm = "default"; } // If still no host/port, then we have a misconfigured module if (empty($this->params[$realm]['host']) || empty($this->params[$realm]['port']) ) { $this->err_str = _("The module is not properly configured!"); return false; } return true; } /** * Begins forwarding of mail for a user. * * @param string $user The username to enable forwarding for. * @param string $realm The realm of the user, or "default" if none. * @param string $target The email address that mail should be * forwarded to. * @param optional boolean $keeplocal A flag that, when true, causes a copy of * forwarded email to be kept in the local * mailbox. * * @return boolean Returns true on success, false on error. */ function enableForwarding($user, $realm = 'default', $pass, $where, $metoo = false) { // Make sure the configuration file is correct if (!$this->check_config($realm)) { return false; } if (isset($_SESSION["__auth"]) && $_SESSION["__auth"]["authenticated"] && !empty($_SESSION["__auth"]["userID"])) { list(,$site_domain) = explode("@",$_SESSION["__auth"]["userID"]); $splitted = explode('@', $site_domain); $imapuser = $user . '@' . @$splitted[0]; } else { return false; } $userdir = trim(`sudo /var/vpopmail/bin/vuserinfo -d $imapuser`); if ($metoo != "on") { $metoo = "off"; } $result = `sudo /var/vpopmail/bin/vpopimpforward fwset $userdir $where $metoo`; return true; } /** * Stops forwarding of mail for a user. * * @param string $user The username of the user to disable forwarding. * @param string $realm The realm of the user. * @param string $pass The password of the user. * * @return boolean Returns true on success, false on error. */ function disableForwarding($user, $realm = 'default', $pass) { if (!$this->check_config($realm)) { return false; } if (isset($_SESSION["__auth"]) && $_SESSION["__auth"]["authenticated"] && !empty($_SESSION["__auth"]["userID"])) { list(,$site_domain) = explode("@",$_SESSION["__auth"]["userID"]); $splitted = explode('@', $site_domain); $imapuser = $user . '@' . @$splitted[0]; } else { return false; } $userdir = trim(`sudo /var/vpopmail/bin/vuserinfo -d $imapuser`); $result = `sudo /var/vpopmail/bin/vpopimpforward fwdel $userdir`; return true; } /** * Retrieves current target of mail redirection * * @param string $user The username of the user to get forward of. * @param string $realm The realm of the user. * * @return mixed A string of current forwarding mail address, or false. */ function currentTarget($user, $realm = 'default', $pass) { // Make sure the configuration file is correct if (!$this->check_config($realm)) { return false; } if (isset($_SESSION["__auth"]) && $_SESSION["__auth"]["authenticated"] && !empty($_SESSION["__auth"]["userID"])) { list(,$site_domain) = explode("@",$_SESSION["__auth"]["userID"]); $splitted = explode('@', $site_domain); $imapuser = $user . '@' . @$splitted[0]; } else { return false; } $userdir = trim(`sudo /var/vpopmail/bin/vuserinfo -d $imapuser`); $result = trim(`sudo /var/vpopmail/bin/vpopimpforward fwcheck $userdir`); if ($result == '@none@') { return false; } return $result; } /** * Retrieves current state of mail redirection * * @param string $user The username to check forwarding for. * @param string $realm The realm of the user. * @return boolean Returns true/false based on if forwarding is enabled. */ /* This function is implemented poorly, and should be rewritten */ function isEnabledForwarding($user, $realm, $password) { return $this->currentTarget($user, $realm, $password) != false; } } ?>