[sork] new features @ vacation

horde at humbapa.ch horde at humbapa.ch
Fri Dec 19 03:06:39 PST 2003


Zitat von Jan Schneider <jan at horde.org>:

> Zitat von horde at humbapa.ch:
>
> > Zitat von Jan Schneider <jan at horde.org>:
> >
> > > Zitat von horde at humbapa.ch:
> > >
> > > > hi all
> > > >
> > > > I made some changes to 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 now 2 formfields
> > > > - sql-driver: create new entry in table "vacation" if no record was
> > > >   found
> > > >
> > > > todo:
> > > > - update the translation-part for the subject-formfield
> > > > - update the forwards-, ldap- and qmail-drivers if needed (the
> > subject is
> > > >   still part of the message, I did not change the parameterlist of
> > any
> > > > function)
> > > >
> > > > is it possible to submit this changes to the horde-cvs-repository?
> > > > if so, what is the best way to do this?
> > >
> > > Send a unified diff to the dev@ mailing list or here.
> >
> > 3 files (vacation/main.php, vacation/templates/main/main.inc,
> > vacation/lib/Driver/sql.php): unified diff to cvs (2003-12-19)
>
> Please resend them as text/plain attachments, so that the email client don't
> break the lines.
>
> Jan.
>
> --
> http://www.horde.org - The Horde Project
> http://www.ammma.de - discover your knowledge
> http://www.tip4all.de - Deine private Tippgemeinschaft
> --
> Sork mailing list
> Frequently Asked Questions: http://horde.org/faq/
> To unsubscribe, mail: sork-unsubscribe at lists.horde.org
>
>
-------------- next part --------------
--- vacation/templates/main/main.inc	2003-12-19 12:00:54.000000000 +0100
+++ vacation/templates/main/main.inc.new	2003-12-16 12:28:43.000000000 +0100
@@ -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>
-------------- next part --------------
--- vacation/main.php	2003-12-19 12:00:53.000000000 +0100
+++ vacation/main.php.new	2003-12-19 10:00:32.000000000 +0100
@@ -17,11 +17,15 @@

 // Get the current login username and realm.
 $split = explode('@', Auth::getAuth());
-$user = @$split[0];
 $realm = @$split[1];
 if (empty($realm)) {
     $realm = 'default';
 }
+if ($driver->getParam('hordeauth', $realm)==="full") {
+    $user = Auth::getAuth();
+} else {
+    $user = @$split[0];
+}

 $submit = Util::getFormData('submit', false);

@@ -52,7 +56,9 @@
     switch ($vacationmode) {
     case 'set':
         $alias = Util::getFormData('alias', '');
+	$vacationsubject = trim(Util::getFormData('subject', false));
         $vacationmsg = Util::getFormData('mess', false);
+        $vacationmsg = "Subject: $vacationsubject\n".$vacationmsg;
         if (!$vacationmsg) {
             $notification->push(_("You must give a vacation message."),
                                 'horde.warning');
@@ -96,9 +102,21 @@
 $pass = Auth::getCredential('password');
 if ($driver->isEnabled($user, $realm, $pass)) {
     $curmessage = $driver->currentMessage($user, $realm, $pass);
+    if (preg_match("/^Subject: ([^\n]+)\n(.+)$/s", $curmessage, $m='')) {
+    	$cursubject = $m[1];
+    	$curmessage = $m[2];
+    } else {
+	$cursubject = '';
+    }
     $notification->push(_("Your vacation notice is currently enabled."), 'horde.success');
 } else {
     $curmessage = $conf['vacation']['default'];
+    if (preg_match("/^Subject: ([^\n]+)\n(.+)$/s", $curmessage, $m='')) {
+        $cursubject = $m[1];
+        $curmessage = $m[2];
+    } else {
+        $cursubject = '';
+    }
 }

 $title = _("Change Vacation Notices");
-------------- next part --------------
--- vacation/lib/Driver/sql.php	2003-12-19 11:49:40.000000000 +0100
+++ vacation/lib/Driver/sql.php.new 2003-12-19 11:48:26.000000000 +0100
@@ -40,19 +40,15 @@
         /* _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);
-        } else {
-            $mysubject = '';
+	if (preg_match("/^Subject: ([^\n]+)\n(.+)$/s", $message, $m='')) {
+	    $mysubject = $m[1];
+	    $mymessage = $m[2];
+	} else {
+	    $mysubject = '';
             $mymessage = $message;
-        }
+	}

         /* Build the SQL query. */
         $query = 'UPDATE ' . $this->params['table'];
@@ -141,10 +137,10 @@
         $this->_connect();

         /* Build the SQL query. */
-        $query = 'SELECT ' . $this->params['vacation'] . ' . AS vacation, ' . $this->params['message'] . ' AS message';
+        $query = 'SELECT ' . $this->params['vacation'] . ' AS vacation, ' . $this->params['message'] . ' AS message, ' . $this->params['subject'] . ' AS subject ';
         $query .= ' FROM ' . $this->params['table'];
         $query .= ' WHERE ' . $this->params['user_col'] . ' = ' . $this->_db->quote($user);
-        $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);
@@ -154,10 +150,15 @@

             if (is_array($row)) {
                 $this->_disconnect();
+		$row["message"] = "Subject: $row[subject]\n".$row["message"];
                 return $row;
             } else {
+		$result->free();
+		$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);
                 $this->_disconnect();
-                $result->free();
                 return false;
             }
         }


More information about the sork mailing list