From 190a98499a4e9f0cd257be7ff12daf2fcec04de0 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Fri, 11 Oct 2013 11:43:01 +0000 Subject: [PATCH] sieve sidebox entrys always visible if one or more IMAP profiles support sieve; check if sieve enabled on rules-index, vacation notice and sieve forwarding --- mail/inc/class.mail_hooks.inc.php | 59 ++- mail/inc/class.mail_sieve.inc.php | 370 ++++++++++-------- .../default/sieve.emailNotification.xet | 8 +- mail/templates/default/sieve.index.xet | 2 +- mail/templates/default/sieve.vacation.xet | 10 +- 5 files changed, 245 insertions(+), 204 deletions(-) diff --git a/mail/inc/class.mail_hooks.inc.php b/mail/inc/class.mail_hooks.inc.php index 9af8d7fb2f..6656e4889c 100644 --- a/mail/inc/class.mail_hooks.inc.php +++ b/mail/inc/class.mail_hooks.inc.php @@ -737,6 +737,17 @@ class mail_hooks $mail_bo = mail_bo::getInstance(true,$profileID); $profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $mail_bo->profileID; $preferences =& $mail_bo->mailPreferences; + $serverCounter = $sieveEnabledServerCounter = 0; + if (count($preferences->ic_server)) { + foreach ($preferences->ic_server as $tmpkey => $accountData) + { + if ($tmpkey==0) continue; + $icServer =& $accountData; + if (empty($icServer->host)) continue; + if ($icServer->enableSieve && $icServer->sievePort) $sieveEnabledServerCounter++; + $serverCounter++; + } + } $showMainScreenStuff = false; if (!$showMainScreenStuff) { @@ -835,29 +846,37 @@ class mail_hooks $menu_title = lang('Sieve'); if (is_object($preferences)) $icServer = $preferences->getIncomingServer($profileID); - if(($icServer instanceof defaultimap)) { - if($icServer->enableSieve) - { - $linkData = array - ( - 'menuaction' => 'mail.mail_sieve.index', - ); - if(empty($preferences->preferences['prefpreventeditfilterrules']) || $preferences->preferences['prefpreventeditfilterrules'] == 0) - $file['filter rules'] = egw::link('/index.php',$linkData); + $linkData = array + ( + 'menuaction' => 'mail.mail_sieve.index', + ); + if(empty($preferences->preferences['prefpreventeditfilterrules']) || $preferences->preferences['prefpreventeditfilterrules'] == 0) + $file['filter rules'] = egw::link('/index.php',$linkData); - $linkData = array - ( - 'menuaction' => 'mail.mail_sieve.editVacation', - ); - if(empty($preferences->preferences['prefpreventabsentnotice']) || $preferences->preferences['prefpreventabsentnotice'] == 0) + $linkData = array + ( + 'menuaction' => 'mail.mail_sieve.editVacation', + ); + if(empty($preferences->preferences['prefpreventabsentnotice']) || $preferences->preferences['prefpreventabsentnotice'] == 0) + { + $file['vacation notice'] = egw::link('/index.php',$linkData); + } + if((empty($preferences->preferences['prefpreventnotificationformailviaemail']) || + $preferences->preferences['prefpreventnotificationformailviaemail'] == 0)) + { + $file['email notification'] = egw::link('/index.php','menuaction=mail.mail_sieve.editEmailNotification'); //Added email notifications + } + if ($sieveEnabledServerCounter>=1) + { + if($sieveEnabledServerCounter==1 && ($icServer instanceof defaultimap)) { + if($icServer->enableSieve) { - $file['vacation notice'] = egw::link('/index.php',$linkData); - } - if((empty($preferences->preferences['prefpreventnotificationformailviaemail']) || - $preferences->preferences['prefpreventnotificationformailviaemail'] == 0)) - { - $file['email notification'] = egw::link('/index.php','menuaction=mail.mail_sieve.editEmailNotification'); //Added email notifications + if (count($file)) display_sidebox($appname,$menu_title,$file); + unset($file); } + } + else + { if (count($file)) display_sidebox($appname,$menu_title,$file); unset($file); } diff --git a/mail/inc/class.mail_sieve.inc.php b/mail/inc/class.mail_sieve.inc.php index 4b376c2c4e..31f5f9a661 100644 --- a/mail/inc/class.mail_sieve.inc.php +++ b/mail/inc/class.mail_sieve.inc.php @@ -106,7 +106,8 @@ class mail_sieve } else { - die(lang('Sieve not activated')); + // we intend to die in index, to be able to die graciously + //die(lang('Sieve not activated')); } } @@ -123,22 +124,28 @@ class mail_sieve $tmpl = new etemplate_new('mail.sieve.index'); if ($_GET['msg']) $msg = $_GET['msg']; + $content['msg'] = $msg; + if ($this->mailbo->icServer->enableSieve) + { + //Initializes the Grid contents + $content['rg']= $this->get_rows($rows,$readonlys); - //Initializes the Grid contents - $content['rg']= $this->get_rows($rows,$readonlys); - - // Set content-menu actions - $tmpl->set_cell_attribute('rg', 'actions',$this->get_actions()); - - $sel_options = array( - 'status' => array( - 'ENABLED' => lang('Enabled'), - 'DISABLED' => lang('Disabled'), - ) - ); + // Set content-menu actions + $tmpl->set_cell_attribute('rg', 'actions',$this->get_actions()); + $sel_options = array( + 'status' => array( + 'ENABLED' => lang('Enabled'), + 'DISABLED' => lang('Disabled'), + ) + ); + } + else + { + $content['msg'] = lang('error').':'.lang('Serverside Filterrules (Sieve) are not activated').'. '.lang('Please contact your Administrator to validate if your Server supports Serverside Filterrules, and how to enable them in EGroupware for your active Account (%1) with ID:%2.',mail_bo::generateIdentityString($this->mailPreferences->identities[$this->mailbo->profileID],true),$this->mailbo->profileID); + $content['hideIfSieveDisabled']='mail_DisplayNone'; + } $tmpl->exec('mail.mail_sieve.index',$content,$sel_options,$readonlys); - } /** @@ -152,79 +159,87 @@ class mail_sieve //Instantiate an etemplate_new object, representing sieve.emailNotification $eNotitmpl = new etemplate_new('mail.sieve.emailNotification'); - $eNotification = $this->getEmailNotification(); - - if (!is_array($content)) + if ($this->mailbo->icServer->enableSieve) { - $content = $eNotification; + $eNotification = $this->getEmailNotification(); - if (!empty($eNotification['externalEmail'])) + if (!is_array($content)) { - $content['externalEmail'] = explode(",",$eNotification['externalEmail']); + $content = $eNotification; + + if (!empty($eNotification['externalEmail'])) + { + $content['externalEmail'] = explode(",",$eNotification['externalEmail']); + } } - } - else - { - $this->restoreSessionData(); - list($button) = @each($content['button']); - unset ($content['button']); - - switch($button) + else { - case 'save': - case 'apply': - if (isset($content['status'])) - { - //error_log(__METHOD__. 'content:' . array2string($content)); - $newEmailNotification = $content; - if (empty($preferences->preferences['prefpreventforwarding']) || - $preferences->preferences['prefpreventforwarding'] == 0 ) + $this->restoreSessionData(); + list($button) = @each($content['button']); + unset ($content['button']); + + switch($button) + { + case 'save': + case 'apply': + if (isset($content['status'])) { - if (is_array($content['externalEmail']) && !empty($content['externalEmail'])) + //error_log(__METHOD__. 'content:' . array2string($content)); + $newEmailNotification = $content; + if (empty($preferences->preferences['prefpreventforwarding']) || + $preferences->preferences['prefpreventforwarding'] == 0 ) { - $newEmailNotification['externalEmail'] = implode(",",$content['externalEmail']); + if (is_array($content['externalEmail']) && !empty($content['externalEmail'])) + { + $newEmailNotification['externalEmail'] = implode(",",$content['externalEmail']); + } } } - } - if (isset($content['externalEmail']) && !empty($content['externalEmail'])) - { - if (!$this->bosieve->setEmailNotification($this->scriptName, $newEmailNotification)) + if (isset($content['externalEmail']) && !empty($content['externalEmail'])) { - $msg = lang("email notification update failed")."
"; - $msg .= $script->errstr. "
"; - break; + if (!$this->bosieve->setEmailNotification($this->scriptName, $newEmailNotification)) + { + $msg = lang("email notification update failed")."
"; + $msg .= $script->errstr. "
"; + break; + } + else + { + $msg .= lang("email notification successfully updated!"); + } + //error_log(__METHOD__. '() new email notification : ' . array2string($newEmailNotification)); } else { - $msg .= lang("email notification successfully updated!"); + $msg .= lang('email notification update failed! You need to set an email address!'); + break; } - //error_log(__METHOD__. '() new email notification : ' . array2string($newEmailNotification)); - } - else - { - $msg .= lang('email notification update failed! You need to set an email address!'); - break; - } - if ($button === 'apply') break; + if ($button === 'apply') break; - case 'cancel': - egw::redirect_link('/mail/index.php'); + case 'cancel': + egw::redirect_link('/mail/index.php'); + } + $this->saveSessionData(); } - $this->saveSessionData(); - } - $sel_options = array( - 'status' => array( - 'on' => lang('Active'), - 'off' => lang('Deactive'), - ), - 'displaySubject' => array( - 0 => lang('No'), - 1 => lang('Yes'), - ), - ); - //error_log(__METHOD__. '() new email notification : ' . array2string($content)); - $content['msg'] = $msg; + $sel_options = array( + 'status' => array( + 'on' => lang('Active'), + 'off' => lang('Deactive'), + ), + 'displaySubject' => array( + 0 => lang('No'), + 1 => lang('Yes'), + ), + ); + //error_log(__METHOD__. '() new email notification : ' . array2string($content)); + $content['msg'] = $msg; + } + else + { + $content['msg'] = lang('error').':'.lang('Serverside Filterrules (Sieve) are not activated').'. '.lang('Please contact your Administrator to validate if your Server supports Serverside Filterrules, and how to enable them in EGroupware for your active Account (%1) with ID:%2.',mail_bo::generateIdentityString($this->mailPreferences->identities[$this->mailbo->profileID],true),$this->mailbo->profileID); + $content['hideIfSieveDisabled']='mail_DisplayNone'; + } $eNotitmpl->exec('mail.mail_sieve.editEmailNotification', $content,$sel_options); } @@ -514,120 +529,127 @@ class mail_sieve //Instantiate an etemplate_new object, representing the sieve.vacation template $vtmpl = new etemplate_new('mail.sieve.vacation'); - - $vacRules = $this->getVacation($vacation,$msg); - - if (!is_array($content)) + if ($this->mailbo->icServer->enableSieve) { - $content = $vacation = $vacRules['vacation']; - //$content['addresses'] = array_merge($vacRules['allAlliances'],$content['addresses']); - //$vacRules['predefinedAddresses'] = array_merge($content['addresses'],$vacRules['predefinedAddresses']); - if (empty($vacation['addresses'])) $content['addresses']=''; - if (!empty($vacation['forwards'])) + $vacRules = $this->getVacation($vacation,$msg); + + if (!is_array($content)) { - $content['forwards'] = explode(",",$vacation['forwards']); + $content = $vacation = $vacRules['vacation']; + //$content['addresses'] = array_merge($vacRules['allAlliances'],$content['addresses']); + //$vacRules['predefinedAddresses'] = array_merge($content['addresses'],$vacRules['predefinedAddresses']); + if (empty($vacation['addresses'])) $content['addresses']=''; + if (!empty($vacation['forwards'])) + { + $content['forwards'] = explode(",",$vacation['forwards']); + } + else + { + $content['forwards'] = ''; + } } else { - $content['forwards'] = ''; + $this->restoreSessionData(); + list($button) = @each($content['button']); + unset ($content['button']); + + switch($button) + { + + case 'save': + + case 'apply': + if ($GLOBALS['egw_info']['user']['apps']['admin']) + { + // store text as default + if ($content['set_as_default'] == 1) + { + config::save_value('default_vacation_text', $content['text'], 'mail'); + } + } + if (isset($content['status'])) + { + //error_log(__METHOD__. 'content:' . array2string($content)); + $newVacation = $content; + $newVacation ['status'] = $content ['status']; + if (empty($preferences->preferences['prefpreventforwarding']) || + $preferences->preferences['prefpreventforwarding'] == 0 ) + { + if (is_array($content['forwards']) && !empty($content['forwards'])) + { + + $newVacation['forwards'] = implode(",",$content['forwards']); + } + else + { + $newVacation ['forwards'] = ''; + } + } + else + { + unset($newVacation ['forwards']); + } + + if (!in_array($newVacation['status'],array('on','off','by_date'))) $newVacation['status'] = 'off'; + + $checkAddresses = (isset($content['check_mail_sent_to']) && ($content['check_mail_sent_to']) != 0) ? true: false; + if ($content['addresses']) + { + $newVacation ['addresses'] = $content['addresses']; + error_log(__METHOD__. '() Respond addresses :'. __LINE__. array2string($content['addresses'])); + } + else + { + + } + //_debug_array($newVacation); + + if($this->checkRule($newVacation,$checkAddresses)) + { + if (!$this->bosieve->setVacation($this->scriptName, $newVacation)) + { + $msg = lang('vacation update failed') . "\n" . lang('Vacation notice update failed') . ":" . $this->bosieve->error; + break; + } + else + { + //error_log(__METHOD__.__LINE__.array2string($newVacation)); + if (!isset($newVacation['scriptName']) || empty($newVacation['scriptName'])) $newVacation['scriptName'] = $this->scriptName; + $this->bosieve->setAsyncJob($newVacation); + $msg = lang('Vacation notice sucessfully updated.'); + } + } + else + { + $msg .= implode("\n",$this->errorStack); + } + if ($button === 'apply') break; + } + case 'cancel': + egw::redirect_link('/mail/index.php'); + } + $vacation = $newVacation; + + $this->saveSessionData(); } + + $sel_options = array( + 'status' => array( + 'on' => lang('Active'), + 'off' => lang('Deactive'), + ), + 'addresses' => array_combine($vacRules['aliases'],$vacRules['aliases']), + ); + + $content['msg'] = $msg; + error_log(__METHOD__. '() sel_option ' . array2string($sel_options)); } else { - $this->restoreSessionData(); - list($button) = @each($content['button']); - unset ($content['button']); - - switch($button) - { - - case 'save': - - case 'apply': - if ($GLOBALS['egw_info']['user']['apps']['admin']) - { - // store text as default - if ($content['set_as_default'] == 1) - { - config::save_value('default_vacation_text', $content['text'], 'mail'); - } - } - if (isset($content['status'])) - { - //error_log(__METHOD__. 'content:' . array2string($content)); - $newVacation = $content; - $newVacation ['status'] = $content ['status']; - if (empty($preferences->preferences['prefpreventforwarding']) || - $preferences->preferences['prefpreventforwarding'] == 0 ) - { - if (is_array($content['forwards']) && !empty($content['forwards'])) - { - - $newVacation['forwards'] = implode(",",$content['forwards']); - } - else - { - $newVacation ['forwards'] = ''; - } - } - else - { - unset($newVacation ['forwards']); - } - - if (!in_array($newVacation['status'],array('on','off','by_date'))) $newVacation['status'] = 'off'; - - $checkAddresses = (isset($content['check_mail_sent_to']) && ($content['check_mail_sent_to']) != 0) ? true: false; - if ($content['addresses']) - { - $newVacation ['addresses'] = $content['addresses']; - error_log(__METHOD__. '() Respond addresses :'. __LINE__. array2string($content['addresses'])); - } - else - { - - } - //_debug_array($newVacation); - - if($this->checkRule($newVacation,$checkAddresses)) - { - if (!$this->bosieve->setVacation($this->scriptName, $newVacation)) - { - $msg = lang('vacation update failed') . "\n" . lang('Vacation notice update failed') . ":" . $this->bosieve->error; - break; - } - else - { - //error_log(__METHOD__.__LINE__.array2string($newVacation)); - if (!isset($newVacation['scriptName']) || empty($newVacation['scriptName'])) $newVacation['scriptName'] = $this->scriptName; - $this->bosieve->setAsyncJob($newVacation); - $msg = lang('Vacation notice sucessfully updated.'); - } - } - else - { - $msg .= implode("\n",$this->errorStack); - } - if ($button === 'apply') break; - } - case 'cancel': - egw::redirect_link('/mail/index.php'); - } - $vacation = $newVacation; - - $this->saveSessionData(); + $content['msg'] = lang('error').':'.lang('Serverside Filterrules (Sieve) are not activated').'. '.lang('Please contact your Administrator to validate if your Server supports Serverside Filterrules, and how to enable them in EGroupware for your active Account (%1) with ID:%2.',mail_bo::generateIdentityString($this->mailPreferences->identities[$this->mailbo->profileID],true),$this->mailbo->profileID); + $content['hideIfSieveDisabled']='mail_DisplayNone'; } - - $sel_options = array( - 'status' => array( - 'on' => lang('Active'), - 'off' => lang('Deactive'), - ), - 'addresses' => array_combine($vacRules['aliases'],$vacRules['aliases']), - ); - - $content['msg'] = $msg; - error_log(__METHOD__. '() sel_option ' . array2string($sel_options)); $vtmpl->exec('mail.mail_sieve.editVacation',$content,$sel_options,$preserv); } diff --git a/mail/templates/default/sieve.emailNotification.xet b/mail/templates/default/sieve.emailNotification.xet index e6cfaab485..d99c690e67 100644 --- a/mail/templates/default/sieve.emailNotification.xet +++ b/mail/templates/default/sieve.emailNotification.xet @@ -34,13 +34,13 @@ -