mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2024-09-19 19:22:14 +02:00
Merge jan-kruis's vacation interval reply behaviour - see SF patch 3508083 - https://sourceforge.net/tracker/?func=detail&aid=3508083&group_id=191583&atid=937966 ; Thank you
git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1373 a1433add-5e2c-0410-b055-b7f2511e0802
This commit is contained in:
parent
76efcb2c47
commit
ef80736445
@ -67,12 +67,15 @@
|
||||
# 2009-08-10 Sebastian <reg9009 at yahoo dot de>
|
||||
# Adjust SQL query for vacation timeframe. It is now possible to set from/until date for vacation message.
|
||||
#
|
||||
# 2012-04-19 Nikolaos Topp <info at ichier.de>
|
||||
# 2012-04-1 Nikolaos Topp <info at ichier.de>
|
||||
# Add configuration parameter $smtp_client in order to get mails through
|
||||
# postfix helo-checks, using check_helo_access whitelist without permitting 'localhost' default style stuff
|
||||
# 2012-03-16 Jan Kruis <jan at crossreferenc dot nl>
|
||||
# change SQL query for vacation into function.
|
||||
#
|
||||
# 2012-04-19 Jan Kruis <jan at crossreferenc dot nl>
|
||||
# change SQL query for vacation into function.
|
||||
# Add sub get_interval()
|
||||
# Gives the user the option to set the interval time ( 0 = one reply, 1 = autoreply, > 1 = Delay reply )
|
||||
# See https://sourceforge.net/tracker/?func=detail&aid=3508083&group_id=191583&atid=937966
|
||||
|
||||
# Requirements - the following perl modules are required:
|
||||
# DBD::Pg or DBD::mysql
|
||||
@ -269,6 +272,25 @@ if ($db_type eq 'mysql') {
|
||||
# used to detect infinite address lookup loops
|
||||
my $loopcount=0;
|
||||
|
||||
#
|
||||
# Get interval_time for email user from the vacation table
|
||||
#
|
||||
sub get_interval {
|
||||
my ($to) = @_;
|
||||
my $query = qq{SELECT interval_time FROM vacation WHERE email=? };
|
||||
my $stm = $dbh->prepare($query) or panic_prepare($query);
|
||||
$stm->execute($to) or panic_execute($query," 'email='$to'");
|
||||
my $rv = $stm->rows;
|
||||
if ($rv == 1) {
|
||||
my @row = $stm->fetchrow_array;
|
||||
my $interval = $row[0] ;
|
||||
return $interval ;
|
||||
} else {
|
||||
return 0 ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub already_notified {
|
||||
my ($to, $from) = @_;
|
||||
my $logger = get_logger();
|
||||
@ -300,6 +322,9 @@ sub already_notified {
|
||||
# Let's play safe and notify anyway
|
||||
return 1;
|
||||
}
|
||||
|
||||
$interval = get_interval($to);
|
||||
|
||||
if ($interval) {
|
||||
$query = qq{SELECT NOW()-notified_at FROM vacation_notification WHERE on_vacation=? AND notified=?};
|
||||
$stm = $dbh->prepare($query) or panic_prepare($query);
|
||||
|
@ -299,6 +299,8 @@ $CONF['transport_options'] = array (
|
||||
// You should define default transport. It must be in array above.
|
||||
$CONF['transport_default'] = 'virtual';
|
||||
|
||||
$CONF['usercontol'] = 'YES';
|
||||
|
||||
// Virtual Vacation
|
||||
// If you want to use virtual vacation for you mailbox users set this to 'YES'.
|
||||
// NOTE: Make sure that you install the vacation module. (See VIRTUAL-VACATION/)
|
||||
@ -316,6 +318,23 @@ $CONF['vacation_control'] ='YES';
|
||||
// Set to 'YES' if your domain admins should be able to edit user vacation.
|
||||
$CONF['vacation_control_admin'] = 'YES';
|
||||
|
||||
// Get the user ofr Admin a chioce of reply
|
||||
$CONF['choice_of_reply'] = array (
|
||||
'One Reply', // Only Reply ones on a email
|
||||
'Auto Reply', // Only Reply to this Sender if last email from this sender
|
||||
'Interval Reply' // same as above but delay time is
|
||||
);
|
||||
|
||||
$CONF['replytype_default'] = 'One Reply';
|
||||
$CONF['autoreplydelay_default'] = '10'; // Send no email if last email was send within 10 sec.
|
||||
$CONF['intervaldelay_default'] = '3600'; // Send only a reply to a email if the last 1 hour ago.
|
||||
|
||||
// Users Control for Domain Admin
|
||||
// Set to "Yes" if your doamain admins schould be able to edit field userscontrole in table domain
|
||||
// Userscontrol is edited in admin_create-domain.tpl and admin_edit-domain.tpl
|
||||
// Userscontrol is default set to on when creating a domain
|
||||
$CONF['users_domain_controle'] = 'YES';
|
||||
|
||||
// Alias Control
|
||||
// Postfix Admin inserts an alias in the alias table for every mailbox it creates.
|
||||
// The reason for this is that when you want catch-all and normal mailboxes
|
||||
|
@ -194,6 +194,9 @@ $PALANG['pEdit_vacation_remove'] = 'Remove away message';
|
||||
$PALANG['pVacation_result_error'] = 'Unable to update auto response settings!';
|
||||
$PALANG['pVacation_result_removed'] = 'Auto response for %s has been disabled!';
|
||||
$PALANG['pVacation_result_added'] = 'Auto response for %s has been enabled!';
|
||||
$PALANG['pVacation_reply_type'] = 'Choice of reply';
|
||||
$PALANG['pVacation_reply_delay_time'] = 'Interval time';
|
||||
$PALANG['pVacation_reply_delay_time_text'] = 'Time in seconds';
|
||||
|
||||
$PALANG['pViewlog_welcome'] = 'View the last 10 actions for ';
|
||||
$PALANG['pViewlog_timestamp'] = 'Timestamp';
|
||||
@ -261,6 +264,7 @@ $PALANG['pAdminList_domain_maxquota'] = 'Quota (MB)'; # obsolete
|
||||
$PALANG['pAdminList_domain_quota'] = 'Domain quota (MB)';
|
||||
$PALANG['pAdminList_domain_transport'] = 'Transport';
|
||||
$PALANG['pAdminList_domain_backupmx'] = 'Backup MX';
|
||||
$PALANG['pAdminList_domain_usercontrol'] = 'User Control';
|
||||
$PALANG['pAdminList_domain_modified'] = 'Last Modified';
|
||||
$PALANG['pAdminList_domain_active'] = 'Active';
|
||||
|
||||
@ -294,6 +298,7 @@ $PALANG['pAdminCreate_domain_transport_text'] = 'Define transport'; # obsolete
|
||||
$PALANG['pAdminCreate_domain_defaultaliases'] = 'Add default mail aliases';
|
||||
$PALANG['pAdminCreate_domain_defaultaliases_text'] = '';
|
||||
$PALANG['pAdminCreate_domain_backupmx'] = 'Mail server is backup MX'; # obsolete
|
||||
$PALANG['pAdminCreate_domain_usercontrol'] = 'Allow user control';
|
||||
$PALANG['pAdminCreate_domain_button'] = 'Add Domain';
|
||||
$PALANG['pAdminCreate_domain_result_error'] = 'Unable to add domain!';
|
||||
$PALANG['pAdminCreate_domain_result_success'] = 'Domain has been added!';
|
||||
@ -315,6 +320,7 @@ $PALANG['pAdminEdit_domain_quota'] = 'Domain Quota';
|
||||
$PALANG['pAdminEdit_domain_transport'] = 'Transport';
|
||||
$PALANG['pAdminEdit_domain_transport_text'] = 'Define transport';
|
||||
$PALANG['pAdminEdit_domain_backupmx'] = 'Mail server is backup MX';
|
||||
$PALANG['pAdminEdit_domain_usercontrol'] = 'Allow user control';
|
||||
$PALANG['pAdminEdit_domain_active'] = 'Active';
|
||||
$PALANG['pAdminEdit_domain_button'] = 'Edit Domain'; # text no longer used
|
||||
$PALANG['pAdminEdit_domain_result_error'] = 'Unable to modify domain!';
|
||||
|
@ -191,6 +191,10 @@ $PALANG['pEdit_vacation_remove'] = 'Verwijder beantwoorden tekst';
|
||||
$PALANG['pVacation_result_error'] = 'Niet in staat automatisch beantwoorden te wijzigen!';
|
||||
$PALANG['pVacation_result_removed'] = 'Automatisch beantwoorden is voor %s gedeactiveerd!';
|
||||
$PALANG['pVacation_result_added'] = 'Automatisch beantwoorden is voor %s geactiveerd!';
|
||||
$PALANG['pVacation_result_added'] = 'Automatisch beantwoorden is geactiveerd!';
|
||||
$PALANG['pVacation_reply_type'] = 'Keuze van beantwoording';
|
||||
$PALANG['pVacation_reply_delay_time'] = 'Interval tijd';
|
||||
$PALANG['pVacation_reply_delay_time_text'] = 'Tijd in seconds';
|
||||
|
||||
$PALANG['pViewlog_welcome'] = 'Laat de laatste 10 actie\'s zien van ';
|
||||
$PALANG['pViewlog_timestamp'] = 'Tijd';
|
||||
@ -272,6 +276,7 @@ $PALANG['pAdminList_virtual_mailbox_name'] = 'Naam';
|
||||
$PALANG['pAdminList_virtual_mailbox_quota'] = 'Quota (MB)';
|
||||
$PALANG['pAdminList_virtual_mailbox_modified'] = 'Laatst bewerkt';
|
||||
$PALANG['pAdminList_virtual_mailbox_active'] = 'Actief';
|
||||
$PALANG['pAdminList_domain_userscontrol'] = 'Gebruikers<br />Beheer';
|
||||
|
||||
$PALANG['pAdminCreate_domain_welcome'] = 'Voeg een nieuw domein toe';
|
||||
$PALANG['pAdminCreate_domain_domain'] = 'Domein'; # obsolete
|
||||
@ -313,6 +318,7 @@ $PALANG['pAdminEdit_domain_backupmx'] = 'Mail server is back-up MX';
|
||||
$PALANG['pAdminEdit_domain_active'] = 'Actief';
|
||||
$PALANG['pAdminEdit_domain_button'] = 'Bewerk domein'; # XXX text no longer used
|
||||
$PALANG['pAdminEdit_domain_result_error'] = 'Mislukt het domein te bewerken.';
|
||||
$PALANG['pAdminEdit_domain_userscontrol'] = 'Sta contorle door gebruikers toe';
|
||||
|
||||
$PALANG['pAdminCreate_admin_welcome'] = 'Voeg een nieuw domein beheerder toe';
|
||||
$PALANG['pAdminCreate_admin_username'] = 'Beheerder'; # obsolete
|
||||
|
@ -16,15 +16,15 @@ class VacationHandler {
|
||||
function remove() {
|
||||
if (!$this->updateAlias(0)) return false;
|
||||
|
||||
// tidy up vacation table.
|
||||
$vacation_data = array(
|
||||
// tidy up vacation table.
|
||||
$vacation_data = array(
|
||||
'active' => db_get_boolean(false),
|
||||
);
|
||||
$result = db_update('vacation', 'email', $this->username, $vacation_data);
|
||||
$result = db_delete('vacation_notification', 'on_vacation', $this->username);
|
||||
# TODO db_log() call (maybe except if called from set_away?)
|
||||
/* crap error handling; oh for exceptions... */
|
||||
return true;
|
||||
);
|
||||
$result = db_update('vacation', 'email', $this->username, $vacation_data);
|
||||
$result = db_delete('vacation_notification', 'on_vacation', $this->username);
|
||||
# TODO db_log() call (maybe except if called from set_away?)
|
||||
/* crap error handling; oh for exceptions... */
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,6 +81,8 @@ class VacationHandler {
|
||||
'subject' => $row['subject'],
|
||||
'body' => $row['body'],
|
||||
'active' => $boolean ,
|
||||
'reply_type' => $row['reply_type'],
|
||||
'interval_time' => $row['interval_time'],
|
||||
'activeFrom' => $row['activefrom'],
|
||||
'activeUntil' => $row['activeuntil'],
|
||||
);
|
||||
@ -88,10 +90,12 @@ class VacationHandler {
|
||||
/**
|
||||
* @param string $subject
|
||||
* @param string $body
|
||||
* @param string $reply_type
|
||||
* @param string $interval_time
|
||||
* @param date $activeFrom
|
||||
* @param date $activeUntil
|
||||
*/
|
||||
function set_away($subject, $body, $activeFrom, $activeUntil) {
|
||||
function set_away($subject, $body, $reply_type, $interval_time, $activeFrom, $activeUntil) {
|
||||
$this->remove(); // clean out any notifications that might already have been sent.
|
||||
|
||||
$E_username = escape_string($this->username);
|
||||
@ -104,6 +108,8 @@ class VacationHandler {
|
||||
'domain' => $domain,
|
||||
'subject' => $subject,
|
||||
'body' => $body,
|
||||
'reply_type' => $reply_type,
|
||||
'interval_time' => $interval_time,
|
||||
'active' => db_get_boolean(true),
|
||||
'activefrom' => $activeFrom,
|
||||
'activeuntil' => $activeUntil,
|
||||
@ -117,13 +123,13 @@ class VacationHandler {
|
||||
} else {
|
||||
$result = db_insert('vacation', $vacation_data);
|
||||
}
|
||||
# TODO error check
|
||||
# TODO wrap whole function in db_begin / db_commit (or rollback)?
|
||||
# TODO error check
|
||||
# TODO wrap whole function in db_begin / db_commit (or rollback)?
|
||||
|
||||
return $this->updateAlias(1);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* add/remove the vacation alias
|
||||
* @param int $vacationActive
|
||||
*/
|
||||
@ -137,7 +143,7 @@ class VacationHandler {
|
||||
|
||||
$values = array (
|
||||
'on_vacation' => $vacationActive,
|
||||
);
|
||||
);
|
||||
|
||||
if (!$handler->set($values)) {
|
||||
# print_r($handler->errormsg); # TODO: error handling
|
||||
|
@ -42,6 +42,19 @@
|
||||
</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="label"><label>{$PALANG.pVacation_reply_type}:</label></td>
|
||||
<td><select class="flat" name="fReply_Type">{$select_options}</select></td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label"><label>{$PALANG.pVacation_reply_delay_time}:</label></td>
|
||||
<td><input class="flat" type="text" name="fInterval_Time" value="{$tInterval_Time}" /></td>
|
||||
<td>{$PALANG.pVacation_reply_delay_time_text}</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="label"><label>{$PALANG.pUsersVacation_subject}:</label></td>
|
||||
<td><textarea class="flat" rows="3" cols="60" name="fSubject" >{$tSubject}</textarea></td>
|
||||
|
@ -1322,6 +1322,12 @@ function upgrade_1284() {
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_1345_mysql() {
|
||||
$table_vacation = table_by_key('vacation');
|
||||
db_query_parsed("ALTER TABLE `$table_vacation` ADD `reply_type` VARCHAR( 20 ) NOT NULL AFTER `domain` ");
|
||||
db_query_parsed("ALTER TABLE `$table_vacation` ADD `interval_time` INT NOT NULL DEFAULT '0' AFTER `reply_type` ");
|
||||
}
|
||||
|
||||
|
||||
# TODO MySQL:
|
||||
# - various varchar fields do not have a default value
|
||||
|
26
vacation.php
26
vacation.php
@ -76,11 +76,15 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") {
|
||||
$tActiveFrom = '';
|
||||
$tActiveUntil = '';
|
||||
$tUseremail = $fUsername;
|
||||
$tReply_Type = '';
|
||||
$tInterval_Time = '';
|
||||
|
||||
$details = $vh->get_details();
|
||||
if($details != false) {
|
||||
$tSubject = $details['subject'];
|
||||
$tBody = $details['body'];
|
||||
$tReply_Type = $details['reply_type'];
|
||||
$tInterval_Time = $details['interval_time'];
|
||||
$tActiveFrom = $details['activeFrom'];
|
||||
$tActiveUntil = $details['activeUntil'];
|
||||
}
|
||||
@ -93,6 +97,13 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") {
|
||||
//set a default, reset fields for coming back selection
|
||||
if ($tSubject == '') { $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8'); }
|
||||
if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); }
|
||||
|
||||
if ($tReply_Type =='') { $tReply_Type = $CONF['replytype_default'];}
|
||||
if ($tReply_Type =='One Reply') { $tInterval_Time = '0';}
|
||||
if ($tReply_Type =='Auto Reply') { $tInterval_Time = $CONF['autoreplydelay_default'];}
|
||||
if (($tReply_Type =='Interval Reply') and ($tInterval_Time =='')) { $tInterval_Time = $CONF['intervaldelay_default'];}
|
||||
if (($tReply_Type =='Interval Reply') and ($tInterval_Time <= $CONF['autoreplydelay_default'])) { $tInterval_Time = $CONF['intervaldelay_default'];}
|
||||
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == "POST")
|
||||
@ -110,6 +121,9 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
|
||||
$tBody = safepost('fBody');
|
||||
$fBody = $tBody;
|
||||
|
||||
$tReply_Type = safepost('fReply_Type');
|
||||
$tInterval_Time = safepost('fInterval_Time');
|
||||
|
||||
$fChange = escape_string (safepost('fChange'));
|
||||
$fBack = escape_string (safepost('fBack'));
|
||||
|
||||
@ -118,6 +132,14 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
|
||||
//set a default, reset fields for coming back selection
|
||||
if ($tSubject == '') { $tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8'); }
|
||||
if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); }
|
||||
if ($tReply_Type =='') { $tReply_Type = $CONF['replytype_default'];}
|
||||
if ($tReply_Type =='One Reply') { $tInterval_Time = '0';}
|
||||
if ($tReply_Type =='Auto Reply') { $tInterval_Time = $CONF['autoreplydelay_default'];}
|
||||
if (($tReply_Type =='Interval Reply') and ($tInterval_Time =='')) { $tInterval_Time = $CONF['intervaldelay_default'];}
|
||||
if (($tReply_Type =='Interval Reply') and ($tInterval_Time <= $CONF['autoreplydelay_default'])) { $tInterval_Time = $CONF['intervaldelay_default'];}
|
||||
|
||||
$fReply_Type = $tReply_Type ;
|
||||
$fInterval_Time = $tInterval_Time;
|
||||
|
||||
// if they've set themselves change OR back, delete any record of vacation emails.
|
||||
// the user is going away - set the goto alias and vacation table as necessary.
|
||||
@ -125,7 +147,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
|
||||
//Set the vacation data for $fUsername
|
||||
if (!empty ($fChange))
|
||||
{
|
||||
if(!$vh->set_away($fSubject, $fBody, $tActiveFrom, $tActiveUntil)) {
|
||||
if(!$vh->set_away($fSubject, $fBody, $fReply_Type, $fInterval_Time, $tActiveFrom, $tActiveUntil)) {
|
||||
$error = 1;
|
||||
}
|
||||
}
|
||||
@ -165,6 +187,8 @@ $smarty->assign ('tSubject', $tSubject);
|
||||
$smarty->assign ('tBody', $tBody);
|
||||
$smarty->assign ('tActiveFrom', date ("d.m.Y", strtotime ($tActiveFrom)));
|
||||
$smarty->assign ('tActiveUntil', date ("d.m.Y", strtotime ($tActiveUntil)));
|
||||
$smarty->assign ('select_options', select_options ( $CONF ['choice_of_reply'], array ($tReply_Type)),false);
|
||||
$smarty->assign ('tInterval_Time', $tInterval_Time);
|
||||
$smarty->assign ('smarty_template', 'vacation');
|
||||
$smarty->display ('index.tpl');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user