mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-17 02:41:02 +01:00
same for rules, eg. rejection mail can be multiple lines too
This commit is contained in:
parent
70082d917b
commit
36a04fcc89
510
felamimail/inc/class.Script.inc.php
Normal file
510
felamimail/inc/class.Script.inc.php
Normal file
@ -0,0 +1,510 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright 2002 Stephen Grier <stephengrier@users.sourceforge.net>
|
||||
*
|
||||
* See the inclosed smartsieve-NOTICE file for conditions of use and distribution.
|
||||
*/
|
||||
|
||||
class Script {
|
||||
|
||||
var $name; /* filename of script. */
|
||||
var $script; /* full ascii text of script from server. */
|
||||
var $size; /* size of script in bytes. */
|
||||
var $so; /* boolean: is it safe to overwrite script?
|
||||
* only safe if we recognise encoding. */
|
||||
var $mode; /* basic or advanced. Smartsieve can only read/write basic. */
|
||||
var $rules; /* array of sieve rules. */
|
||||
var $vacation; /* vacation settings. */
|
||||
var $emailNotification; /* email notification settings. */
|
||||
var $pcount; /* highest priority value in ruleset. */
|
||||
var $errstr; /* error text. */
|
||||
/**
|
||||
* Switch on some error_log debug messages
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
var $debug=false;
|
||||
|
||||
// class constructor
|
||||
function Script ($scriptname) {
|
||||
$this->name = $scriptname;
|
||||
$this->script = '';
|
||||
$this->size = 0;
|
||||
$this->so = true;
|
||||
$this->mode = '';
|
||||
$this->rules = array();
|
||||
$this->vacation = array();
|
||||
$this->emailNotification = array(); // Added email notifications
|
||||
$this->pcount = 0;
|
||||
$this->errstr = '';
|
||||
}
|
||||
|
||||
// get sieve script rules for this user
|
||||
/**
|
||||
* Retrieve the rules
|
||||
*
|
||||
* @param bosieve $connection
|
||||
* @return boolean true, if script written successfull
|
||||
*/
|
||||
function retrieveRules ($connection) {
|
||||
#global $_SESSION;
|
||||
$continuebit = 1;
|
||||
$sizebit = 2;
|
||||
$anyofbit = 4;
|
||||
$keepbit = 8;
|
||||
$regexbit = 128;
|
||||
|
||||
if (!isset($this->name)){
|
||||
$this->errstr = 'retrieveRules: no script name specified';
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": no script name specified");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_object($connection)) {
|
||||
$this->errstr = "retrieveRules: no sieve session open";
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": no sieve session open");
|
||||
return false;
|
||||
}
|
||||
|
||||
// if script doesn't yet exist, nothing to retrieve.
|
||||
// safe to write to this script file.
|
||||
#LK if (!AppSession::scriptExists($this->name)) {
|
||||
#LK $this->so = true;
|
||||
#LK return true;
|
||||
#LK }
|
||||
|
||||
#print "<br><br><br><br>get Script ". $this->name ."<bR>";
|
||||
|
||||
if(PEAR::isError($script = $connection->getScript($this->name))) {
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": error retrieving script: ".$script->getMessage());
|
||||
return $script;
|
||||
}
|
||||
|
||||
#print "<br>AAA: Script is ". htmlentities($script) ."<br>";
|
||||
$lines = array();
|
||||
$lines = preg_split("/\n/",$script); //,PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
$rules = array();
|
||||
$vacation = array();
|
||||
$emailNotification = array(); // Added email notifications
|
||||
$regexps = array('^ *##PSEUDO','^ *#rule','^ *#vacation','^ *#mode');
|
||||
$regexps[] = '^ *#notify'; // Added email notifications
|
||||
|
||||
/* first line should be the script size. eg: {123}. */
|
||||
#$line = array_shift($lines);
|
||||
#if (!preg_match("/^\{(\d+)\}$/", $line, $bits)){
|
||||
# print 'retrieveRules: unexpected value: ' . $line .'<br>';
|
||||
# $this->errstr = 'retrieveRules: unexpected value: ' . $line;
|
||||
# return false;
|
||||
#}
|
||||
#LK $this->size = $bits[1];
|
||||
|
||||
/* next line should be the recognised encoded head. if not, the script
|
||||
* is of an unrecognised format, and we should not overwrite it. */
|
||||
$line = array_shift($lines);
|
||||
if (!preg_match("/^# ?Mail(.*)rules for/", $line)){
|
||||
$this->errstr = 'retrieveRules: encoding not recognised';
|
||||
$this->so = false;
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": encoding not recognised");
|
||||
return false;
|
||||
}
|
||||
$this->so = true;
|
||||
|
||||
$line = array_shift($lines);
|
||||
|
||||
while (isset($line)){
|
||||
foreach ($regexps as $regexp){
|
||||
if (preg_match("/$regexp/i",$line)){
|
||||
$line = rtrim($line);
|
||||
if (preg_match("/^ *#rule&&(.*)&&(.*)&&(.*)&&(.*)&&(.*)&&(.*)&&(.*)&&(.*)&&(.*)&&(.*)&&(.*)$/i",$line,$bits)){
|
||||
$rule = array();
|
||||
$rule['priority'] = $bits[1];
|
||||
$rule['status'] = $bits[2];
|
||||
$rule['from'] = stripslashes($bits[3]);
|
||||
$rule['to'] = stripslashes($bits[4]);
|
||||
$rule['subject'] = stripslashes($bits[5]);
|
||||
$rule['action'] = $bits[6];
|
||||
$rule['action_arg'] = $bits[7];
|
||||
// <crnl>s will be encoded as \\n. undo this.
|
||||
$rule['action_arg'] = preg_replace("/\\\\n/","\r\n",$rule['action_arg']);
|
||||
$rule['action_arg'] = stripslashes($rule['action_arg']);
|
||||
$rule['flg'] = $bits[8]; // bitwise flag
|
||||
$rule['field'] = stripslashes($bits[9]);
|
||||
$rule['field_val'] = stripslashes($bits[10]);
|
||||
$rule['size'] = $bits[11];
|
||||
$rule['continue'] = ($bits[8] & $continuebit);
|
||||
$rule['gthan'] = ($bits[8] & $sizebit); // use 'greater than'
|
||||
$rule['anyof'] = ($bits[8] & $anyofbit);
|
||||
$rule['keep'] = ($bits[8] & $keepbit);
|
||||
$rule['regexp'] = ($bits[8] & $regexbit);
|
||||
$rule['unconditional'] = 0;
|
||||
if (!$rule['from'] && !$rule['to'] && !$rule['subject'] &&
|
||||
!$rule['field'] && !$rule['size'] && $rule['action']) {
|
||||
$rule['unconditional'] = 1;
|
||||
}
|
||||
|
||||
array_push($rules,$rule);
|
||||
|
||||
if ($rule['priority'] > $this->pcount) {
|
||||
$this->pcount = $rule['priority'];
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match("/^ *#vacation&&(.*)&&(.*)&&(.*)&&(.*)&&(.*)/i",$line,$bits) ||
|
||||
preg_match("/^ *#vacation&&(.*)&&(.*)&&(.*)&&(.*)/i",$line,$bits)) {
|
||||
$vacation['days'] = $bits[1];
|
||||
$vaddresslist = $bits[2];
|
||||
$vaddresslist = preg_replace("/\"|\s/","",$vaddresslist);
|
||||
$vaddresses = array();
|
||||
$vaddresses = preg_split("/,/",$vaddresslist);
|
||||
$vacation['text'] = $bits[3];
|
||||
|
||||
// <crnl>s will be encoded as \\n. undo this.
|
||||
$vacation['text'] = preg_replace("/\\\\n/","\r\n",$vacation['text']);
|
||||
|
||||
if (strpos($bits[4],'-')!== false)
|
||||
{
|
||||
$vacation['status'] = 'by_date';
|
||||
list($vacation['start_date'],$vacation['end_date']) = explode('-',$bits[4]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$vacation['status'] = $bits[4];
|
||||
}
|
||||
$vacation['addresses'] = &$vaddresses;
|
||||
|
||||
$vacation['forwards'] = $bits[5];
|
||||
}
|
||||
|
||||
if (preg_match("/^ *#notify&&(.*)&&(.*)&&(.*)/i",$line,$bits)) {
|
||||
$emailNotification['status'] = $bits[1];
|
||||
$emailNotification['externalEmail'] = $bits[2];
|
||||
$emailNotification['displaySubject'] = $bits[3];
|
||||
}
|
||||
|
||||
if (preg_match("/^ *#mode&&(.*)/i",$line,$bits)){
|
||||
if ($bits[1] == 'basic')
|
||||
$this->mode = 'basic';
|
||||
elseif ($bits[1] == 'advanced')
|
||||
$this->mode = 'advanced';
|
||||
else
|
||||
$this->mode = 'unknown';
|
||||
}
|
||||
}
|
||||
}
|
||||
$line = array_shift($lines);
|
||||
}
|
||||
|
||||
$this->script = $script;
|
||||
$this->rules = $rules;
|
||||
$this->vacation = $vacation;
|
||||
$this->emailNotification = $emailNotification; // Added email notifications
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": Script succesful retrieved: ".print_r($vacation,true));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// update and save sieve script
|
||||
function updateScript ($connection)
|
||||
{
|
||||
#global $_SESSION,$default,$sieve;
|
||||
global $default,$sieve;
|
||||
|
||||
$activerules = 0;
|
||||
$regexused = 0;
|
||||
$rejectused = 0;
|
||||
|
||||
$username = $GLOBALS['egw_info']['user']['account_lid'];
|
||||
$version = $GLOBALS['egw_info']['apps']['felamimail']['version'];
|
||||
|
||||
//include "$default->lib_dir/version.php";
|
||||
|
||||
if (!is_object($connection))
|
||||
{
|
||||
$this->errstr = "updateScript: no sieve session open";
|
||||
return false;
|
||||
}
|
||||
|
||||
// don't overwrite a file if not created by SmartSieve,
|
||||
// unless configured to do so.
|
||||
#LK if (!$this->so && !$default->allow_write_unrecognised_scripts) {
|
||||
#LK $this->errstr = 'updateScript: encoding not recognised: not safe to overwrite ' . $this->name;
|
||||
#LK return false;
|
||||
#LK }
|
||||
|
||||
// lets generate the main body of the script from our rules
|
||||
|
||||
$newscriptbody = "";
|
||||
$continue = 1;
|
||||
|
||||
foreach ($this->rules as $rule) {
|
||||
$newruletext = "";
|
||||
|
||||
// don't print this rule if disabled.
|
||||
if ($rule['status'] != 'ENABLED') {
|
||||
} else {
|
||||
|
||||
$activerules = 1;
|
||||
|
||||
// conditions
|
||||
|
||||
$anyall = "allof";
|
||||
if ($rule['anyof']) $anyall = "anyof";
|
||||
if ($rule['regexp']) {
|
||||
$regexused = 1;
|
||||
}
|
||||
$started = 0;
|
||||
|
||||
if (!$rule['unconditional']) {
|
||||
if (!$continue) $newruletext .= "els";
|
||||
$newruletext .= "if " . $anyall . " (";
|
||||
if ($rule['from']) {
|
||||
if (preg_match("/^\s*!/", $rule['from'])){
|
||||
$newruletext .= 'not ';
|
||||
$rule['from'] = preg_replace("/^\s*!/","",$rule['from']);
|
||||
}
|
||||
$match = ':contains';
|
||||
if (preg_match("/\*|\?/", $rule['from'])) $match = ':matches';
|
||||
if ($rule['regexp']) $match = ':regex';
|
||||
$newruletext .= "address " . $match . " [\"From\"]";
|
||||
$newruletext .= " \"" . addslashes($rule['from']) . "\"";
|
||||
$started = 1;
|
||||
}
|
||||
if ($rule['to']) {
|
||||
if ($started) $newruletext .= ", ";
|
||||
if (preg_match("/^\s*!/", $rule['to'])){
|
||||
$newruletext .= 'not ';
|
||||
$rule['to'] = preg_replace("/^\s*!/","",$rule['to']);
|
||||
}
|
||||
$match = ':contains';
|
||||
if (preg_match("/\*|\?/", $rule['to'])) $match = ':matches';
|
||||
if ($rule['regexp']) $match = ':regex';
|
||||
$newruletext .= "address " . $match . " [\"To\",\"TO\",\"Cc\",\"CC\"]";
|
||||
$newruletext .= " \"" . addslashes($rule['to']) . "\"";
|
||||
$started = 1;
|
||||
}
|
||||
if ($rule['subject']) {
|
||||
if ($started) $newruletext .= ", ";
|
||||
if (preg_match("/^\s*!/", $rule['subject'])){
|
||||
$newruletext .= 'not ';
|
||||
$rule['subject'] = preg_replace("/^\s*!/","",$rule['subject']);
|
||||
}
|
||||
$match = ':contains';
|
||||
if (preg_match("/\*|\?/", $rule['subject'])) $match = ':matches';
|
||||
if ($rule['regexp']) $match = ':regex';
|
||||
$newruletext .= "header " . $match . " \"subject\"";
|
||||
$newruletext .= " \"" . addslashes($rule['subject']) . "\"";
|
||||
$started = 1;
|
||||
}
|
||||
if ($rule['field'] && $rule['field_val']) {
|
||||
if ($started) $newruletext .= ", ";
|
||||
if (preg_match("/^\s*!/", $rule['field_val'])){
|
||||
$newruletext .= 'not ';
|
||||
$rule['field_val'] = preg_replace("/^\s*!/","",$rule['field_val']);
|
||||
}
|
||||
$match = ':contains';
|
||||
if (preg_match("/\*|\?/", $rule['field_val'])) $match = ':matches';
|
||||
if ($rule['regexp']) $match = ':regex';
|
||||
$newruletext .= "header " . $match . " \"" . addslashes($rule['field']) . "\"";
|
||||
$newruletext .= " \"" . addslashes($rule['field_val']) . "\"";
|
||||
$started = 1;
|
||||
}
|
||||
if ($rule['size']) {
|
||||
$xthan = " :under ";
|
||||
if ($rule['gthan']) $xthan = " :over ";
|
||||
if ($started) $newruletext .= ", ";
|
||||
$newruletext .= "size " . $xthan . $rule['size'] . "K";
|
||||
$started = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// actions
|
||||
|
||||
if (!$rule['unconditional']) $newruletext .= ") {\n\t";
|
||||
|
||||
if (preg_match("/folder/i",$rule['action'])) {
|
||||
$newruletext .= "fileinto \"" . $rule['action_arg'] . "\";";
|
||||
}
|
||||
if (preg_match("/reject/i",$rule['action'])) {
|
||||
$newruletext .= "reject text: \n" . $rule['action_arg'] . "\n.\n;";
|
||||
$rejectused = 1;
|
||||
}
|
||||
if (preg_match("/address/i",$rule['action'])) {
|
||||
$newruletext .= "redirect \"" . $rule['action_arg'] . "\";";
|
||||
}
|
||||
if (preg_match("/discard/i",$rule['action'])) {
|
||||
$newruletext .= "discard;";
|
||||
}
|
||||
if ($rule['keep']) $newruletext .= "\n\tkeep;";
|
||||
if (!$rule['unconditional']) $newruletext .= "\n}";
|
||||
|
||||
$continue = 0;
|
||||
if ($rule['continue']) $continue = 1;
|
||||
if ($rule['unconditional']) $continue = 1;
|
||||
|
||||
$newscriptbody .= $newruletext . "\n\n";
|
||||
|
||||
} // end 'if ! ENABLED'
|
||||
}
|
||||
|
||||
// vacation rule
|
||||
|
||||
if ($this->vacation) {
|
||||
$vacation = $this->vacation;
|
||||
if (!$vacation['days']) $vacation['days'] = $default->vacation_days;
|
||||
if (!$vacation['text']) $vacation['text'] = $default->vacation_text;
|
||||
if (!$vacation['status']) $vacation['status'] = 'on';
|
||||
|
||||
// filter out invalid addresses.
|
||||
$ok_vaddrs = array();
|
||||
foreach($vacation['addresses'] as $addr){
|
||||
if ($addr != '' && preg_match("/\@/",$addr))
|
||||
array_push($ok_vaddrs,$addr);
|
||||
}
|
||||
$vacation['addresses'] = $ok_vaddrs;
|
||||
|
||||
if (!$vacation['addresses'][0]){
|
||||
$defaultaddr = $sieve->user . '@' . $sieve->maildomain;
|
||||
array_push($vacation['addresses'],$defaultaddr);
|
||||
}
|
||||
if ($vacation['status'] == 'on' || $vacation['status'] == 'by_date' &&
|
||||
$vacation['start_date'] <= time() && time() < $vacation['end_date']+24*3600) // +24*3600 to include the end_date day
|
||||
{
|
||||
if (trim($vacation['forwards'])) {
|
||||
$if = array();
|
||||
foreach($vacation['addresses'] as $addr) {
|
||||
$if[] = 'address :contains ["To","TO","Cc","CC"] "'.$addr.'"';
|
||||
}
|
||||
$newscriptbody .= 'if anyof ('.implode(', ',$if).") {\n";
|
||||
foreach(preg_split('/, ?/',$vacation['forwards']) as $addr) {
|
||||
$newscriptbody .= "\tredirect \"".$addr."\";\n";
|
||||
}
|
||||
$newscriptbody .= "\tkeep;\n}\n";
|
||||
}
|
||||
$vacation_active = true;
|
||||
$newscriptbody .= "vacation :days " . $vacation['days'] . " :addresses [";
|
||||
$first = 1;
|
||||
foreach ($vacation['addresses'] as $vaddress) {
|
||||
if (!$first) $newscriptbody .= ", ";
|
||||
$newscriptbody .= "\"" . $vaddress . "\"";
|
||||
$first = 0;
|
||||
}
|
||||
$message = $vacation['text'];
|
||||
if ($vacation['start_date'] || $vacation['end_date'])
|
||||
{
|
||||
$message = str_replace(array('$$start$$','$$end$$'),array(
|
||||
date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$vacation['start_date']),
|
||||
date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$vacation['end_date']),
|
||||
),$message);
|
||||
}
|
||||
$newscriptbody .= "] text:\n" . $message . "\n.\n;\n\n";
|
||||
}
|
||||
|
||||
// update with any changes.
|
||||
$this->vacation = $vacation;
|
||||
}
|
||||
|
||||
if ($this->emailNotification && $this->emailNotification['status'] == 'on') {
|
||||
// format notification email header components
|
||||
$notification_email = $this->emailNotification['externalEmail'];
|
||||
|
||||
// format notification body
|
||||
$egw_site_title = $GLOBALS['egw_info']['server']['site_title'];
|
||||
$notification_body = lang("You have received a new message on the")." {$egw_site_title}"."\n";
|
||||
$notification_body .= "\n";
|
||||
$notification_body .= 'From: $from$'."\n";
|
||||
if ($this->emailNotification['displaySubject']) {
|
||||
$notification_body .= 'Subject: $subject$'."\n";
|
||||
}
|
||||
//$notification_body .= 'Size: $size$'."\n";
|
||||
|
||||
$newscriptbody .= 'notify :message "'.$notification_body.'" :method "mailto" :options "'.$notification_email.'";'."\n";
|
||||
//$newscriptbody .= 'notify :message "'.$notification_body.'" :method "mailto" :options "'.$notification_email.'?subject='.$notification_subject.'";'."\n";
|
||||
$newscriptbody .= 'keep;'."\n\n";
|
||||
}
|
||||
|
||||
// generate the script head
|
||||
|
||||
$newscripthead = "";
|
||||
$newscripthead .= "#Mail filter rules for " . $username . "\n";
|
||||
$newscripthead .= '#Generated by ' . $username . ' using FeLaMiMail ' . $version . ' ' . date($default->script_date_format);
|
||||
$newscripthead .= "\n";
|
||||
|
||||
if ($activerules) {
|
||||
$newscripthead .= "require [\"fileinto\"";
|
||||
if ($regexused) $newscripthead .= ",\"regex\"";
|
||||
if ($rejectused) $newscripthead .= ",\"reject\"";
|
||||
if ($this->vacation && $vacation_active) {
|
||||
$newscripthead .= ",\"vacation\"";
|
||||
}
|
||||
if ($this->emailNotification && $this->emailNotification['status'] == 'on') $newscripthead .= ',"notify"'; // Added email notifications
|
||||
$newscripthead .= "];\n\n";
|
||||
} else {
|
||||
// no active rules, but might still have an active vacation rule
|
||||
if ($this->vacation && $vacation_active)
|
||||
$newscripthead .= "require [\"vacation\"];\n\n";
|
||||
if ($this->emailNotification && $this->emailNotification['status'] == 'on') $newscripthead .= "require [\"notify\"];\n\n"; // Added email notifications
|
||||
}
|
||||
|
||||
|
||||
// generate the encoded script foot
|
||||
|
||||
$newscriptfoot = "";
|
||||
$pcount = 1;
|
||||
$newscriptfoot .= "##PSEUDO script start\n";
|
||||
foreach ($this->rules as $rule) {
|
||||
// only add rule to foot if status != deleted. this is how we delete a rule.
|
||||
if ($rule['status'] != 'DELETED') {
|
||||
$rule['action_arg'] = addslashes($rule['action_arg']);
|
||||
// we need to handle \r\n here.
|
||||
$rule['action_arg'] = preg_replace("/\r?\n/","\\n",$rule['action_arg']);
|
||||
/* reset priority value. note: we only do this
|
||||
* for compatibility with Websieve. */
|
||||
$rule['priority'] = $pcount;
|
||||
$newscriptfoot .= "#rule&&" . $rule['priority'] . "&&" . $rule['status'] . "&&" .
|
||||
addslashes($rule['from']) . "&&" . addslashes($rule['to']) . "&&" . addslashes($rule['subject']) . "&&" . $rule['action'] . "&&" .
|
||||
addslashes($rule['action_arg']) . "&&" . $rule['flg'] . "&&" . addslashes($rule['field']) . "&&" . addslashes($rule['field_val']) . "&&" . $rule['size'] . "\n";
|
||||
$pcount = $pcount+2;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->vacation) {
|
||||
$vacation = $this->vacation;
|
||||
$newscriptfoot .= "#vacation&&" . $vacation['days'] . "&&";
|
||||
$first = 1;
|
||||
foreach ($vacation['addresses'] as $address) {
|
||||
if (!$first) $newscriptfoot .= ", ";
|
||||
$newscriptfoot .= "\"" . $address . "\"";
|
||||
$first = 0;
|
||||
}
|
||||
|
||||
$vacation['text'] = preg_replace("/\r?\n/","\\n",$vacation['text']);
|
||||
$newscriptfoot .= "&&" . $vacation['text'] . "&&" .
|
||||
($vacation['status']=='by_date' ? $vacation['start_date'].'-'.$vacation['end_date'] : $vacation['status']);
|
||||
if ($vacation['forwards']) $newscriptfoot .= '&&' . $vacation['forwards'];
|
||||
$newscriptfoot .= "\n";
|
||||
}
|
||||
if ($this->emailNotification) {
|
||||
$emailNotification = $this->emailNotification;
|
||||
$newscriptfoot .= "#notify&&" . $emailNotification['status'] . "&&" . $emailNotification['externalEmail'] . "&&" . $emailNotification['displaySubject'] . "\n";
|
||||
}
|
||||
|
||||
$newscriptfoot .= "#mode&&basic\n";
|
||||
|
||||
$newscript = $newscripthead . $newscriptbody . $newscriptfoot;
|
||||
$this->script = $newscript;
|
||||
#print "<pre>$newscript</pre>"; exit;
|
||||
$scriptfile = $this->name;
|
||||
#print "<hr><pre>".htmlentities($newscript)."</pre><hr>";
|
||||
if (!$connection->installScript($this->name, $newscript, true)) {
|
||||
$this->errstr = 'updateScript: putscript failed: ' . $connection->errstr;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
201
felamimail/inc/class.bosieve.inc.php
Normal file
201
felamimail/inc/class.bosieve.inc.php
Normal file
@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/***************************************************************************\
|
||||
* eGroupWare - FeLaMiMail *
|
||||
* http://www.linux-at-work.de *
|
||||
* http://www.phpgw.de *
|
||||
* http://www.egroupware.org *
|
||||
* Written by : Lars Kneschke [lkneschke@linux-at-work.de] *
|
||||
* ------------------------------------------------- *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU General Public License as published by the *
|
||||
* Free Software Foundation; version 2 of the License. *
|
||||
\***************************************************************************/
|
||||
/* $Id: class.uisieve.inc.php,v 1.24 2005/11/30 08:29:45 ralfbecker Exp $ */
|
||||
|
||||
#include_once(EGW_SERVER_ROOT. '/felamimail/inc/Sieve.php');
|
||||
include_once('Net/Sieve.php');
|
||||
|
||||
class bosieve extends Net_Sieve {
|
||||
/**
|
||||
* @var object $icServer object containing the information about the imapserver
|
||||
*/
|
||||
var $icServer;
|
||||
|
||||
/**
|
||||
* @var object $icServer object containing the information about the imapserver
|
||||
*/
|
||||
var $scriptName;
|
||||
|
||||
/**
|
||||
* @var object $error the last PEAR error object
|
||||
*/
|
||||
var $error;
|
||||
|
||||
/**
|
||||
* Switch on some error_log debug messages
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
var $debug = false;
|
||||
|
||||
function bosieve($_icServer=null)
|
||||
{
|
||||
parent::Net_Sieve();
|
||||
|
||||
$this->scriptName = (!empty($GLOBALS['egw_info']['user']['preferences']['felamimail']['sieveScriptName']) ? $GLOBALS['egw_info']['user']['preferences']['felamimail']['sieveScriptName'] : 'felamimail');
|
||||
|
||||
$this->displayCharset = $GLOBALS['egw']->translation->charset();
|
||||
|
||||
if (!is_null($_icServer) && $this->_connect($_icServer) === 'die') {
|
||||
die('Sieve not activated');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open connection to the sieve server
|
||||
*
|
||||
* @param defaultimap $_icServer
|
||||
* @param string $euser='' effictive user, if given the Cyrus admin account is used to login on behalf of $euser
|
||||
* @return mixed 'die' = sieve not enabled, false=connect or login failure, true=success
|
||||
*/
|
||||
function _connect($_icServer,$euser='')
|
||||
{
|
||||
if(is_a($_icServer,'defaultimap') && $_icServer->enableSieve) {
|
||||
$sieveHost = $_icServer->host;
|
||||
$sievePort = $_icServer->sievePort;
|
||||
$useTLS = $_icServer->encryption > 0;
|
||||
if ($euser) {
|
||||
$username = $_icServer->adminUsername;
|
||||
$password = $_icServer->adminPassword;
|
||||
} else {
|
||||
$username = $_icServer->loginName;
|
||||
$password = $_icServer->password;
|
||||
}
|
||||
$this->icServer = $_icServer;
|
||||
} else {
|
||||
return 'die';
|
||||
}
|
||||
|
||||
if(PEAR::isError($this->error = $this->connect($sieveHost , $sievePort, null, $useTLS) ) ){
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": error in connect($sieveHost,$sievePort): ".$this->error->getMessage());
|
||||
return false;
|
||||
}
|
||||
if(PEAR::isError($this->error = $this->login($username, $password, null, $euser) ) ){
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": error in login($username,$password,null,$euser): ".$this->error->getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function getRules($_scriptName) {
|
||||
return $this->rules;
|
||||
}
|
||||
|
||||
function getVacation($_scriptName) {
|
||||
return $this->vacation;
|
||||
}
|
||||
|
||||
function getEmailNotification($_scriptName) {
|
||||
return $this->emailNotification;
|
||||
}
|
||||
|
||||
function setRules($_scriptName, $_rules)
|
||||
{
|
||||
$script =& CreateObject('felamimail.Script',$_scriptName);
|
||||
$script->debug = $this->debug;
|
||||
|
||||
if($script->retrieveRules($this)) {
|
||||
$script->rules = $_rules;
|
||||
$script->updateScript($this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function setVacation($_scriptName, $_vacation)
|
||||
{
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__."($_scriptName,".print_r($_vacation,true).')');
|
||||
$script =& CreateObject('felamimail.Script',$_scriptName);
|
||||
$script->debug = $this->debug;
|
||||
|
||||
if($script->retrieveRules($this)) {
|
||||
$script->vacation = $_vacation;
|
||||
if (($ret = $script->updateScript($this)))
|
||||
{
|
||||
// setting up an async job to enable/disable the vacation message
|
||||
include_once(EGW_API_INC.'/class.asyncservice.inc.php');
|
||||
$async = new asyncservice();
|
||||
$user = $GLOBALS['egw_info']['user']['account_id'];
|
||||
$async->delete($async_id ="felamimail-vacation-$user");
|
||||
$end_date = $_vacation['end_date'] + 24*3600; // end-date is inclusive, so we have to add 24h
|
||||
if ($_vacation['status'] == 'by_date' && time() < $end_date)
|
||||
{
|
||||
$time = time() < $_vacation['start_date'] ? $_vacation['start_date'] : $end_date;
|
||||
$async->set_timer($time,$async_id,'felamimail.bosieve.async_vacation',$_vacation+array('scriptName'=>$_scriptName),$user);
|
||||
}
|
||||
}
|
||||
$this->error = $script->errstr;
|
||||
return $ret;
|
||||
}
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__."($_scriptName,".print_r($_vacation,true).') could not retrieve rules!');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for the async job to enable/disable the vacation message
|
||||
*
|
||||
* @param array $_vacation
|
||||
*/
|
||||
function async_vacation($_vacation)
|
||||
{
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.'('.print_r($_vacation,true).')');
|
||||
// unset the fm_preferences session object, to force the reload/rebuild
|
||||
$GLOBALS['egw']->session->appsession('fm_preferences','felamimail',serialize(array()));
|
||||
$GLOBALS['egw']->session->appsession('session_data','emailadmin',serialize(array()));
|
||||
|
||||
$_restoreSession = false; // as in async, each call may be for a different user
|
||||
$bopreferences = CreateObject('felamimail.bopreferences',$_restoreSession);
|
||||
$mailPreferences = $bopreferences->getPreferences();
|
||||
$icServer = $mailPreferences->getIncomingServer(0);
|
||||
//error_log(__METHOD__.$icServer->loginName);
|
||||
if ($this->_connect($icServer,$icServer->loginName) === true) {
|
||||
$ret = $this->setVacation($_vacation['scriptName'],$_vacation);
|
||||
// we need to logout, so further vacation's get processed
|
||||
$error = $this->_cmdLogout();
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.' logout '.(PEAR::isError($error) ? 'failed: '.$ret->getMessage() : 'successful'));
|
||||
return $ret;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function setEmailNotification($_scriptName, $_emailNotification) {
|
||||
if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail'])) {
|
||||
$_emailNotification['status'] = 'off';
|
||||
$_emailNotification['externalEmail'] = '';
|
||||
}
|
||||
|
||||
$script =& CreateObject('felamimail.Script',$_scriptName);
|
||||
if ($script->retrieveRules($this)) {
|
||||
$script->emailNotification = $_emailNotification;
|
||||
return $script->updateScript($this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function retrieveRules($_scriptName) {
|
||||
$script =& CreateObject('felamimail.Script',$_scriptName);
|
||||
|
||||
if($script->retrieveRules($this)) {
|
||||
$this->rules = $script->rules;
|
||||
$this->vacation = $script->vacation;
|
||||
$this->emailNotification = $script->emailNotification; // Added email notifications
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
@ -589,6 +589,11 @@
|
||||
{
|
||||
print "vacation update failed<br>";
|
||||
#print $script->errstr."<br>";
|
||||
$this->t->set_var('validation_errors', lang('Vacation notice update failed').': '.$this->bosieve->error);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->t->set_var('validation_errors', lang('Vacation notice sucessful updated.'));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user