[sork] new features @ vacation
horde at humbapa.ch
horde at humbapa.ch
Mon Jan 5 05:51:36 PST 2004
> > 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)
>
> Sounds good.
>
> > - subject and message are now 2 formfields
>
> I suppose that is okay... Might make it more clear to the user...
Take a look:
host: http://mail.humbapa.ch
user: test at humbapa.ch
pass: 2004
>
> > - sql-driver: create new entry in table "vacation" if no record was
> > found
>
> Sounds good.
>
> > todo:
> > - update the translation-part for the subject-formfield
>
> Can you do this before submitting it?
I never worked with translations. could anybody else update this?
There is only one new word ("Subject" in vacation/templates/main/main.inc)
thanks
>
> > - 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)
>
> If possible this should be done before submitting it.
There is no need to update the other drivers
> > is it possible to submit this changes to the horde-cvs-repository?
> > if so, what is the best way to do this?
>
> Post a unified diff (diff -u), or a url pointing to the unified diff,
> to the sork mailing list (or dev mailing list).
see attachment
g. martin luethi
-------------- next part --------------
--- vacation/config/conf.php.dist 2004-01-05 14:18:57.000000000 +0100
+++ vacation.new/config/conf.php.dist 2004-01-05 14:18:25.000000000 +0100
@@ -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
-------------- next part --------------
--- vacation/templates/main/main.inc 2004-01-05 14:19:13.000000000 +0100
+++ vacation.new/templates/main/main.inc 2004-01-05 14:14:42.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 2004-01-05 14:18:57.000000000 +0100
+++ vacation.new/main.php 2004-01-05 14:14:42.000000000 +0100
@@ -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');
@@ -105,6 +116,12 @@
// "unknown", be inscrutable.
$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");
require VACATION_TEMPLATES . '/common-header.inc';
-------------- next part --------------
--- vacation/lib/Driver/sql.php 2004-01-05 14:18:59.000000000 +0100
+++ vacation.new/lib/Driver/sql.php 2004-01-05 14:14:42.000000000 +0100
@@ -40,15 +40,9 @@
/* _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(.+)$/s", $message, $m='')) {
+ $mysubject = $m[1];
+ $mymessage = $m[2];
} else {
$mysubject = '';
$mymessage = $message;
@@ -57,6 +51,19 @@
// Build username.
$myuser = $this->_buildUsername($user, $realm);
+ // Check if a 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 +116,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));
@@ -149,11 +155,12 @@
// Build username.
$myuser = $this->_buildUsername($user, $realm);
- /* Build the SQL query. */
+ /* 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 +170,7 @@
if (is_array($row)) {
$this->_disconnect();
+ $row['message'] = "Subject: $row[subject]\n".$row['message'];
return $row;
} else {
$this->_disconnect();
More information about the sork
mailing list