create the default script, if there is none; fix problem on trying to save/create vacation when there is NO rule or vacation existing beforehand

This commit is contained in:
Klaus Leithoff 2015-04-23 08:38:47 +00:00
parent 0c91565dfb
commit a88c169974

View File

@ -92,14 +92,12 @@ class emailadmin_script {
return false; return false;
} }
// if script doesn't yet exist, nothing to retrieve. // If the called script name is not exist then create it
// safe to write to this script file. // otherwise we might get error due to non existance script
#LK if (!AppSession::scriptExists($this->name)) { if (!in_array($this->name, $connection->listScripts()))
#LK $this->so = true; {
#LK return true; $this->updateScript($connection);
#LK } }
#print "<br><br><br><br>get Script ". $this->name ."<bR>";
if(self::isError($script = $connection->getScript($this->name))) { if(self::isError($script = $connection->getScript($this->name))) {
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": error retrieving script: ".$script->getMessage()); if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": error retrieving script: ".$script->getMessage());
@ -249,7 +247,7 @@ class emailadmin_script {
$vacation_active = false; $vacation_active = false;
$username = $GLOBALS['egw_info']['user']['account_lid']; $username = $GLOBALS['egw_info']['user']['account_lid'];
$version = $GLOBALS['egw_info']['apps']['felamimail']['version']; $version = $GLOBALS['egw_info']['apps']['mail']['version'];
//include "$default->lib_dir/version.php"; //include "$default->lib_dir/version.php";
@ -432,7 +430,7 @@ class emailadmin_script {
$defaultaddr = $sieve->user . '@' . $sieve->maildomain; $defaultaddr = $sieve->user . '@' . $sieve->maildomain;
array_push($vacation['addresses'],$defaultaddr); array_push($vacation['addresses'],$defaultaddr);
} }
if ($vacation['status'] == 'on' || $vacation['status'] == 'by_date' && if (($vacation['status'] == 'on' && strlen(trim($vacation['text']))>0)|| $vacation['status'] == 'by_date' &&
$vacation['start_date'] <= time() && time() < $vacation['end_date']+24*3600) // +24*3600 to include the end_date day $vacation['start_date'] <= time() && time() < $vacation['end_date']+24*3600) // +24*3600 to include the end_date day
{ {
if (trim($vacation['forwards'])) { if (trim($vacation['forwards'])) {
@ -447,17 +445,20 @@ class emailadmin_script {
$newscriptbody .= "\tkeep;\n}\n"; $newscriptbody .= "\tkeep;\n}\n";
} }
$vacation_active = true; $vacation_active = true;
if ($regexsupported) if ($vacation['text'])
{ {
$newscriptbody .= "if header :regex ".'"X-Spam-Status" '.'"\\\\bYES\\\\b"'."{\n\tstop;\n}\n"; //stop vacation reply if it is spam if ($regexsupported)
$regexused = 1; {
} $newscriptbody .= "if header :regex ".'"X-Spam-Status" '.'"\\\\bYES\\\\b"'."{\n\tstop;\n}\n"; //stop vacation reply if it is spam
else $regexused = 1;
{ }
// if there are no regex'es supported use a different Anti-Spam Rule: if X-Spam-Status holds else
// additional spamscore information (e.g. BAYES) this rule may prevent Vacation notification {
// TODO: refine rule without using regex // if there are no regex'es supported use a different Anti-Spam Rule: if X-Spam-Status holds
$newscriptbody .= "if header :contains ".'"X-Spam-Status" '.'"YES"'."{\n\tstop;\n}\n"; //stop vacation reply if it is spam // additional spamscore information (e.g. BAYES) this rule may prevent Vacation notification
// TODO: refine rule without using regex
$newscriptbody .= "if header :contains ".'"X-Spam-Status" '.'"YES"'."{\n\tstop;\n}\n"; //stop vacation reply if it is spam
}
} }
$newscriptbody .= "vacation :days " . $vacation['days'] . " :addresses ["; $newscriptbody .= "vacation :days " . $vacation['days'] . " :addresses [";
$first = 1; $first = 1;
@ -530,7 +531,7 @@ class emailadmin_script {
$newscripthead = ""; $newscripthead = "";
$newscripthead .= "#Mail filter rules for " . $username . "\n"; $newscripthead .= "#Mail filter rules for " . $username . "\n";
$newscripthead .= '#Generated by ' . $username . ' using FeLaMiMail ' . $version . ' ' . date($default->script_date_format); $newscripthead .= '#Generated by ' . $username . ' using Mail ' . $version . ' ' . date($default->script_date_format);
$newscripthead .= "\n"; $newscripthead .= "\n";
if ($activerules) { if ($activerules) {
@ -545,9 +546,25 @@ class emailadmin_script {
$newscripthead .= "];\n\n"; $newscripthead .= "];\n\n";
} else { } else {
// no active rules, but might still have an active vacation rule // no active rules, but might still have an active vacation rule
$closeRequired = false;
if ($this->vacation && $vacation_active) if ($this->vacation && $vacation_active)
$newscripthead .= "require [\"vacation\"];\n\n"; {
if ($this->emailNotification && $this->emailNotification['status'] == 'on') $newscripthead .= "require [\"".($enotify?'e':'')."notify\"".($variables?',"variables"':'')."];\n\n"; // Added email notifications $newscripthead .= "require [\"vacation\"";
if ($regexsupported && $regexused) $newscripthead .= ",\"regex\"";
$closeRequired=true;
}
if ($this->emailNotification && $this->emailNotification['status'] == 'on')
{
if ($this->vacation && $vacation_active)
{
$newscripthead .= ",\"".($enotify?'e':'')."notify\"".($variables?',"variables"':'')."];\n\n"; // Added email notifications
}
else
{
$newscripthead .= "require [\"".($enotify?'e':'')."notify\"".($variables?',"variables"':'')."];\n\n"; // Added email notifications
}
}
if ($closeRequired) $newscripthead .= "];\n\n";
} }
// generate the encoded script foot // generate the encoded script foot