[dev] patch for vacation module

Martin Luethi horde at humbapa.ch
Wed Jan 21 00:18:45 PST 2004


hi list,

attached is a patch with some new features for the vacation module

- hordeauth can also be set to "full" (the username will be used
  unmodified, see gollem/config/backends.php)
- subject and message are 2 formfields
- sql-driver: create new entry in table "vacation" if no record was
  found

you can test it under:
host: http://mail.humbapa.ch
user: test at humbapa.ch
pass: 2004


g. martin luethi
-------------- next part --------------
Index: main.php
===================================================================
RCS file: /repository/vacation/main.php,v
retrieving revision 1.37
diff -u -r1.37 main.php
--- main.php	1 Jan 2004 16:17:55 -0000	1.37
+++ main.php	16 Jan 2004 07:09:59 -0000
@@ -23,6 +23,16 @@
     $realm = 'default';
 }
 
+// Fallback to 'default' if no realm was found
+if ($driver->getParam('hordeauth', $realm)==null && $realm!='default') {
+    $realm = 'default';
+}
+
+// Set $user to full username if hordeauth is 'full'
+if ($driver->getParam('hordeauth', $realm)==='full') {
+    $user = Auth::getAuth();
+}
+
 $submit = Util::getFormData('submit', false);
 
 if ($submit) {
@@ -52,7 +62,8 @@
     switch ($vacationmode) {
     case 'set':
         $alias = Util::getFormData('alias', '');
-        $vacationmsg = Util::getFormData('mess', false);
+        $vacationsubject = Util::getFormData('subject', false);
+        $vacationmsg = "Subject: $vacationsubject\n".Util::getFormData('mess', false);
         if (!$vacationmsg) {
             $notification->push(_("You must give a vacation message."),
                                 'horde.warning');
@@ -104,6 +115,12 @@
     // If the driver can't tell the difference between "disabled" and
     // "unknown", be inscrutable.
     $curmessage = $conf['vacation']['default'];
+}
+if (preg_match("/^Subject: ([^\n]+)\n(.*)$/is", $curmessage, $m='')) {
+    $cursubject = $m[1];
+    $curmessage = $m[2];
+} else {
+    $cursubject = '';
 }
 
 $title = _("Change Vacation Notices");
Index: config/conf.php.dist
===================================================================
RCS file: /repository/vacation/config/conf.php.dist,v
retrieving revision 1.18
diff -u -r1.18 conf.php.dist
--- config/conf.php.dist	11 Jul 2003 12:21:48 -0000	1.18
+++ config/conf.php.dist	16 Jan 2004 07:09:59 -0000
@@ -61,6 +61,9 @@
 // The special parameter 'hordeauth' may be set to true on any realm,
 // including the default realm, to tell Vacation to use the password
 // that the user logged in to Horde with, instead of prompting for it.
+// If this parameter is 'full', the username will be used unmodified;
+// otherwise, everything after and including the first @ in the
+// username will be stripped before attempting authentication.
 //
 // The special parameter 'norealm' may be set to true on any realm,
 // including the default realm, to tell Vacation to NOT add any domain
Index: lib/Driver/sql.php
===================================================================
RCS file: /repository/vacation/lib/Driver/sql.php,v
retrieving revision 1.16
diff -u -r1.16 sql.php
--- lib/Driver/sql.php	3 Jan 2004 14:38:35 -0000	1.16
+++ lib/Driver/sql.php	16 Jan 2004 07:10:01 -0000
@@ -40,15 +40,11 @@
         /* _connect() will die with Horde::fatal() upon failure. */
         $this->_connect();
 
-        // Split message into parts to get subject.
-        $myarray = explode("\n", $message);
-
         /* Determine if $message contains Subject: and if it does
          * split it. */
-        if (strstr($myarray[0], 'Subject:')) {
-            $mysubject = $myarray[0];
-            $myarray[0] = '';
-            $mymessage = implode('', $myarray);
+        if (preg_match("/^Subject: ([^\n]+)\n(.+)$/is", $message, $m='')) {
+            $mysubject = $m[1];
+            $mymessage = $m[2];
         } else {
             $mysubject = '';
             $mymessage = $message;
@@ -57,6 +53,19 @@
         // Build username.
         $myuser = $this->_buildUsername($user, $realm);
 
+	// Check if an entry already exists and create one otherwise
+        $query = 'SELECT ' . $this->params['vacation'] . ' AS vacation';
+        $query .= ' FROM ' . $this->params['table'];
+        $query .= ' WHERE ' . $this->params['user_col'] . ' = ' . $this->_db->quote($myuser);
+        $query .= ' AND ' . $this->params['pass_col'] . ' = ' . $this->_db->quote(md5($password));
+        $result = $this->_db->query($query);
+        if (!is_a($result, 'PEAR_Error')) {
+	    $query = 'INSERT INTO ' . $this->params['table'];
+            $query .= ' ( ' . $this->params['user_col'] . ' ,  ' . $this->params['pass_col'] . ' ) ';
+            $query .= ' VALUES ( ' . $this->_db->quote($user) . ' ,  ' . $this->_db->quote(md5($password)) . ' ) ';
+            $result = $this->_db->query($query);
+	}
+
         /* Build the SQL query. */
         $query = 'UPDATE ' . $this->params['table'];
         $query .= ' SET ' . $this->params['vacation'] . ' = ' . $this->_db->quote('y');
@@ -109,7 +118,6 @@
         /* Build the SQL query. */
         $query = 'UPDATE ' . $this->params['table'];
         $query .= ' SET ' . $this->params['vacation'] . ' = ' . $this->_db->quote('n');
-        $query .= ' ,  ' . $this->params['message'] . ' = ' . $this->_db->quote('');
         $query .= ' WHERE ' . $this->params['user_col'] . ' = ' . $this->_db->quote($myuser);
         $query .= ' AND ' . $this->params['pass_col'] . ' = ' . $this->_db->quote(md5($password));
 
@@ -151,9 +159,10 @@
 
         /* Build the SQL query. */
         $query = 'SELECT ' . $this->params['vacation'] . ' AS vacation, ' . $this->params['message'] . ' AS message';
+        $query .= ', ' . $this->params['subject'] . ' AS subject';
         $query .= ' FROM ' . $this->params['table'];
         $query .= ' WHERE ' . $this->params['user_col'] . ' = ' . $this->_db->quote($myuser);
-        $query .= ' AND password = ' . $this->_db->quote(md5($password));
+        $query .= ' AND ' . $this->params['pass_col']  . ' = ' . $this->_db->quote(md5($password));
 
         /* Execute the query. */
         $result = $this->_db->query($query);
@@ -163,6 +172,7 @@
 
             if (is_array($row)) {
                 $this->_disconnect();
+                $row['message'] = "Subject: $row[subject]\n".$row['message'];
                 return $row;
             } else {
                 $this->_disconnect();
Index: templates/main/main.inc
===================================================================
RCS file: /repository/vacation/templates/main/main.inc,v
retrieving revision 1.21
diff -u -r1.21 main.inc
--- templates/main/main.inc	16 Sep 2003 23:08:48 -0000	1.21
+++ templates/main/main.inc	16 Jan 2004 07:10:11 -0000
@@ -47,6 +47,13 @@
 
 <div>
 <br />
+<?php echo _("Subject:") ?>
+<br />
+<input name="subject" type="text" size="70" value="<?php echo htmlspecialchars($cursubject) ?>">
+</div>
+
+<div>
+<br />
 <?php echo _("Message:") ?>
 <br />
 <textarea name="mess" rows="8" cols="70"><?php echo htmlspecialchars($curmessage) ?></textarea>


More information about the dev mailing list