[sork] Vacation patch, take 2
John Dalbec
jpdalbec at ysu.edu
Mon Mar 17 17:08:22 PST 2003
My earlier patch seems to have been given the cold shoulder, so here's a
revised attempt. This patch is also against RELENG cvs 3/12.
This patch implements the "isEnabled" and "currentMessage" functions in
vacation/lib/Driver/{forwards,qmail}.php. The comments and function
declarations are taken from vacation/lib/Driver/sql.php. The function
logic is adapted from the matching files in the forwards module.
John Dalbec
-------------- next part --------------
diff -urN vacation-RELENG.orig/lib/Driver/forwards.php vacation-RELENG/lib/Driver/forwards.php
--- vacation-RELENG.orig/lib/Driver/forwards.php Wed Feb 19 18:24:46 2003
+++ vacation-RELENG/lib/Driver/forwards.php Mon Mar 17 16:55:54 2003
@@ -147,6 +147,43 @@
}
/**
+ * Get a remote file via ftp.
+ *
+ * @param $user The username to login as via ftp.
+ * @param $realm The realm (domain) of the user, or "default" if none.
+ * @param $pass The password to login with via ftp.
+ * @param $src The source file specification to copy.
+ * @param $dst The destination file specification to write.
+ * @param $mode The ftp transfer mode (binary or text).
+ *
+ * @return boolean True or False depending on success of the copy.
+ */
+
+function _ftpGetFile($user, $realm, $pass, $src, $dst, $mode=FTP_ASCII)
+{
+ if (!($ftpConnection = @ftp_connect($this->params[$realm]['host'],
+ $this->params[$realm]['port']))) {
+ $this->err_str = _("Server connection failed");
+ return "";
+ }
+
+ if (!(@ftp_login($ftpConnection, $user, $pass))) {
+ $this->err_str = _("Could not login - check password!");
+ @ftp_quit($ftpConnection);
+ return "";
+ }
+ // should probably do a cwd to their home, but we don't...
+ //ftp_chdir($ftpConnection, "/home/eric/");
+ if (!(@ftp_get($ftpConnection, $dst, $src, $mode))) {
+ $this->err_str = _("Could not get forwarding!");
+ @ftp_quit($ftpConnection);
+ return "";
+ }
+ @ftp_quit($ftpConnection);
+ return implode('',file($dst));
+}
+
+/**
* 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.
@@ -268,6 +305,68 @@
$this->_ftpDelete($user, $realm, $pass, ".vacation.dir");
$this->_ftpDelete($user, $realm, $pass, ".vacation.db");
return true;
+ }
+
+ /**
+ * Retrieves status of mail redirection for a user
+ *
+ * @param string $user The username of the user to check.
+ * @param string $realm The realm of the user to check.
+ *
+ * @return boolean Returns true if forwarding is enabled for the user
+ * or false if forwarding is currently disabled.
+ */
+
+ function isEnabled($user, $realm, $password)
+ {
+
+ // Make sure the configuration file is correct
+ if ( !$this->check_config($realm) ) {
+ return false;
+ }
+
+ $myFile = $this->_writeTempFile($user);
+ if (!file_exists($myFile)) return "";
+ @unlink($myFile);
+
+ $status = $this->_ftpGetFile($user, $realm, $password,
+ ".forward", $myFile);
+ @unlink($myFile);
+
+ $conf = &$GLOBALS['conf'];
+ if ( strpos($status, $conf['vacation']['path']) === false ) {
+ return false;
+ }
+ return true;
+
+ }
+
+ /**
+ * Retrieves current target of mail redirection
+ *
+ * @param string $user The username of the user.
+ * @param string $realm The realm of the user.
+ *
+ * @return string A string of current forwarding mail address or false.
+ */
+
+ function currentMessage($user, $realm, $password)
+ {
+
+ // Make sure the configuration file is correct
+ if ( !$this->check_config($realm) ) {
+ return false;
+ }
+
+ $myFile = $this->_writeTempFile($user);
+ if (!file_exists($myFile)) return "";
+ @unlink($myFile);
+
+ $message = $this->_ftpGetFile($user, $realm, $password,
+ ".vacation.msg", $myFile);
+ @unlink($myFile);
+ return $message;
+
}
}
diff -urN vacation-RELENG.orig/lib/Driver/qmail.php vacation-RELENG/lib/Driver/qmail.php
--- vacation-RELENG.orig/lib/Driver/qmail.php Mon Jan 20 01:03:03 2003
+++ vacation-RELENG/lib/Driver/qmail.php Mon Mar 17 16:56:32 2003
@@ -215,6 +215,100 @@
$_vfs->_disconnect();
return true;
}
+
+ /**
+ * Retrieves status of mail redirection for a user
+ *
+ * @param string $user The username of the user to check.
+ * @param string $realm The realm of the user to check.
+ *
+ * @return boolean Returns true if forwarding is enabled for the user
+ * or false if forwarding is currently disabled.
+ */
+
+ function isEnabled($user, $realm, $password)
+ {
+
+ // Make sure the configuration file is correct
+ if (!$this->check_config($realm)) {
+ return false;
+ }
+
+ // Build the ftp array to pass to VFS
+ $_args = array( 'hostspec' => $this->params[$realm]['host'],
+ 'port' => $this->params[$realm]['port'],
+ 'username' => $user,
+ 'password' => $password );
+
+ // Create the VFS ftp driver
+ $_vfs = &Horde_VFS::singleton('ftp', $_args);
+ $_vfs->setParams($_args);
+
+ // Try to login with the username/password, no realm
+ $status = $_vfs->checkCredentials();
+ if (PEAR::isError($status)) {
+ $this->err_str = $status->getMessage();
+ $this->err_str .= ' ' . _("Check your username and password");
+ return false;
+ }
+
+ $status = $_vfs->read('', '.qmail');
+ if (PEAR::isError($status)) {
+ $this->err_str = $status->getMessage();
+ return false;
+ }
+
+ $conf = &$GLOBALS['conf'];
+ if ( strpos($status, $conf['vacation']['path']) === false ) {
+ return false;
+ }
+ return true;
+
+ }
+
+ /**
+ * Retrieves current target of mail redirection
+ *
+ * @param string $user The username of the user.
+ * @param string $realm The realm of the user.
+ *
+ * @return string A string of current forwarding mail address or false.
+ */
+
+ function currentMessage($user, $realm, $password)
+ {
+
+ // Make sure the configuration file is correct
+ if (!$this->check_config($realm)) {
+ return false;
+ }
+
+ // Build the ftp array to pass to VFS
+ $_args = array( 'hostspec' => $this->params[$realm]['host'],
+ 'port' => $this->params[$realm]['port'],
+ 'username' => $user,
+ 'password' => $password );
+
+ // Create the VFS ftp driver
+ $_vfs = &Horde_VFS::singleton('ftp', $_args);
+ $_vfs->setParams($_args);
+
+ // Try to login with the username/password, no realm
+ $status = $_vfs->checkCredentials();
+ if (PEAR::isError($status)) {
+ $this->err_str = $status->getMessage();
+ $this->err_str .= ' ' . _("Check your username and password");
+ return false;
+ }
+
+ $message = $_vfs->read('', '.vacation.msg');
+ if (PEAR::isError($message)) {
+ $this->err_str = $message->getMessage();
+ return false;
+ }
+ return $message;
+
+ }
}
?>
More information about the sork
mailing list