[sork] vacation patch

John Dalbec jpdalbec at ysu.edu
Thu Mar 13 12:25:49 PST 2003


Against 3/12 RELENG CVS.

The attached patch copies some features from the "forwards" module.  It 
loads the current vacation message (if any, otherwise it uses the 
default message) and alias address (if any) into the web form.  It also 
reports whether a vacation message is enabled.
-------------- next part --------------
--- vacation/lib/Driver/forwards.php	Wed Feb 19 18:24:46 2003
+++ vacation/lib/Driver/forwards.php	Thu Mar 13 11:42:47 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 _ftpGet($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,77 @@
         $this->_ftpDelete($user, $realm, $pass, ".vacation.dir");
         $this->_ftpDelete($user, $realm, $pass, ".vacation.db");
         return true;
+    }
+
+/**
+ * Retrieves current vacation message
+ *
+ * @param string    $user       The username of the user.
+ * @param string    $realm      The realm of the user.
+ *
+ * @return mixed    A string of current vacation message, or false.
+ */
+
+    function currentMessage($user, $realm = 'default', $pass) {
+
+        // 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->_ftpGet($user, $realm, $pass, ".vacation.msg", $myFile);
+        @unlink($myFile);
+        return $status;
+    }
+
+/**
+ * Retrieves current state of vacation messages
+ *
+ * @param string    $user       The username to check vacation for.
+ * @param string    $realm      The realm of the user.
+ * @return boolean  Returns true/false based on if vacation is enabled.
+ */
+
+/* This function is implemented poorly, and should be rewritten */
+
+    function isEnabledVacation($user, $realm, $password) {
+        return $this->currentMessage($user, $realm, $password) != false;
+    }
+
+/**
+ * Retrieves current vacation alias address
+ *
+ * @param string    $user       The username of the user.
+ * @param string    $realm      The realm of the user.
+ *
+ * @return mixed    A string of current vacation alias address, or false.
+ */
+
+    function currentAlias($user, $realm = 'default', $pass) {
+
+        // 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->_ftpGet($user, $realm, $pass, ".forward", $myFile);
+        @unlink($myFile);
+
+        $conf = &$GLOBALS['conf'];
+	$pattern = "/" . preg_quote($conf['vacation']['path'], "/") .
+	    " -a (\S+)/";
+	$matches = array();
+	if (!preg_match($pattern, $status, $matches)) return "";
+
+	return $matches[1];
     }
 
 }
--- vacation/templates/main/main.inc	Mon Jan 20 14:34:33 2003
+++ vacation/templates/main/main.inc	Thu Mar 13 10:56:44 2003
@@ -2,6 +2,20 @@
 // $Horde: vacation/templates/main/main.inc,v 1.12.2.3 2003/01/20 19:34:33 ericr Exp $ 
 
 include_once VACATION_BASE . '/templates/menu/menu.inc';
+
+// Get the horde password so we can try to check for existing forwards
+$hordePassword = Auth::getCredential('password');
+
+// Check for existing forwards
+if ($isVacation = $driver->isEnabledVacation($user, $realm, $hordePassword)) {
+    $current_message = $driver->currentMessage($user, $realm, $hordePassword);
+    $current_alias = $driver->currentAlias($user, $realm, $hordePassword);
+} else {
+    $current_message = "Subject: " . _("On vacation message") . "\n"
+	. _("I'm on vacation and will not be reading my mail for a while.")
+	. "\n" . _("Your mail will be dealt with when I return.") . "\n";
+    $current_alias = '';
+}
 ?>
 
 <table class="light">
@@ -32,12 +46,7 @@
   <br />
 
   <textarea name="mess" rows="8" cols="70">
-<?php echo "Subject: " . _("On vacation message") ?>
-
-<?php echo _("I'm on vacation and will not be reading my mail for a while.") ?>
-
-<?php echo _("Your mail will be dealt with when I return.") ?>
-
+<?php echo $current_message ?>
   </textarea>
   </div>
 
@@ -45,7 +54,7 @@
 <br />
 <?php echo ("Alias address to also forward (optional): "); ?>
 <br />
-<input name="alias" type="text" size="70">
+<input name="alias" type="text" size="70" value="<?php echo $current_alias ?>">
 <?php echo ($conf['user']['online_help'] && $browser->hasFeature('javascript'))
 ? Help::link('vacation', 'vacation-alias') : '&nbsp;' ?>
 <br />
--- vacation/main.php	Mon Jan 20 01:18:10 2003
+++ vacation/main.php	Thu Mar 13 10:59:49 2003
@@ -75,6 +75,14 @@
     }
 }
 
+// If we can tell if vacation messages are enabled, then say so. But if
+// this fails, it could be because it is disabled, or just because we
+// can't tell, so just be quiet about it.
+if ($driver->isEnabledVacation($user, $realm, Auth::getCredential('password'))) {
+            Horde::raiseMessage( _("Vacation messages are currently enabled."),
+                    HORDE_ERROR);
+}
+
     include $registry->getTemplatePath() . '/common-header.inc';
     include_once $registry->getTemplatePath('horde') . '/javascript/open_help_win.js';
     require $registry->getFileRoot() . '/status.php';


More information about the sork mailing list