From 82faa1bd8768b9f4a670df51fc162b2ab3ca828e Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Fri, 9 Aug 2013 17:47:53 +0000 Subject: [PATCH] mail app-> sieve update --- mail/inc/class.mail_bosieve.inc.php | 50 + mail/inc/class.mail_compose.inc.php | 5 +- mail/inc/class.mail_sieve.inc.php | 857 ++++++++++++------ mail/js/app.js | 38 +- mail/templates/default/sieve.edit.xet | 15 +- mail/templates/default/sieve.editVacation.xet | 65 -- .../default/sieve.emailNotification.xet | 46 + mail/templates/default/sieve.index.xet | 4 +- mail/templates/default/sieve.vacation.xet | 71 ++ 9 files changed, 773 insertions(+), 378 deletions(-) create mode 100644 mail/inc/class.mail_bosieve.inc.php delete mode 100644 mail/templates/default/sieve.editVacation.xet create mode 100644 mail/templates/default/sieve.emailNotification.xet create mode 100644 mail/templates/default/sieve.vacation.xet diff --git a/mail/inc/class.mail_bosieve.inc.php b/mail/inc/class.mail_bosieve.inc.php new file mode 100644 index 0000000000..2bf44b903b --- /dev/null +++ b/mail/inc/class.mail_bosieve.inc.php @@ -0,0 +1,50 @@ + + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ + +/** + * Class containing callback to set/reset vacation notice in future (timed vacation) + * + * Rest of class is moved to emailadmin_sieve and accessible via incomming server object (IMAP). + */ +class mail_bosieve +{ + /** + * 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); + if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.'->LoginName:'.$icServer->loginName); + //error_log(__METHOD__.__LINE__.array2string($_vacation)); + try + { + $ret = $icServer->setVacationUser($icServer->loginName,$_vacation['scriptName'],$_vacation); + } + catch (Exception $e) { + error_log(__METHOD__.'::'.__LINE__.' call for '.$icServer->loginName.','.$_vacation['scriptName'].' failed for reason:'.$e->getMessage()); + $ret = false; + } + if ($ret) $icServer->setAsyncJob($_vacation); + if ($ret===false) $icServer->setAsyncJob($_vacation,null,true); //reschedule + return $ret; + } + +} diff --git a/mail/inc/class.mail_compose.inc.php b/mail/inc/class.mail_compose.inc.php index 001bd5fbf8..5c3ef5c8b0 100644 --- a/mail/inc/class.mail_compose.inc.php +++ b/mail/inc/class.mail_compose.inc.php @@ -2536,6 +2536,7 @@ $content['mailtext'] = 'garbage'; } public static function ajax_searchAddress() { + error_log(__METHOD__. "request from seachAddress" . $_REQUEST['query']); $_searchString = trim($_REQUEST['query']); if ($GLOBALS['egw_info']['user']['apps']['addressbook']) { //error_log(__METHOD__.__LINE__.array2string($_searchString)); @@ -2598,9 +2599,9 @@ $content['mailtext'] = 'garbage'; if(!empty($email) && in_array($completeMailString ,$results) === false) { $results[] = array( 'id'=>$completeMailString, - 'label' => htmlspecialchars($completeMailString), + 'label' => $completeMailString, // Add just name for nice display, with title for hover - 'name' => htmlspecialchars($contact['n_fn']), + 'name' => $contact['n_fn'], 'title' => $email ); } diff --git a/mail/inc/class.mail_sieve.inc.php b/mail/inc/class.mail_sieve.inc.php index a0d1b325c2..59aa5b0f52 100644 --- a/mail/inc/class.mail_sieve.inc.php +++ b/mail/inc/class.mail_sieve.inc.php @@ -25,7 +25,7 @@ class mail_sieve 'index' => True, 'edit' => True, 'updateRules' => True, - //'editEmailNotification'=> True, // Added email notifications + 'editEmailNotification'=> True, // Added email notifications ); /** * Flag if we can do a timed vaction message, requires Cyrus Admin User/Pw to enable/disable via async service @@ -44,8 +44,16 @@ class mail_sieve var $tmpl; + var $etmpl; + + var $vtmpl; + + var $eNotitmpl; + var $mailbo; + var $extraAddr; + /** * Constructor * @@ -86,10 +94,10 @@ class mail_sieve $this->mailConfig = config::read('mail'); $this->restoreSessionData(); - $icServer =& $this->mailbo->icServer; + $icServer = $this->mailbo->icServer; if(($icServer instanceof defaultimap) && $icServer->enableSieve) { - $this->bosieve =& $icServer; + $this->bosieve = $icServer; $serverclass = get_class($icServer); $classsupportstimedsieve = false; if (!empty($serverclass) && stripos(constant($serverclass.'::CAPABILITIES'),'timedsieve') !== false) $classsupportstimedsieve = true; @@ -112,17 +120,11 @@ class mail_sieve { //Initialize the Grid contents - $tmpl = new etemplate_new('mail.sieve.index'); - //$this->restoreSessionData(); - //if (isset($_GET['rule_id'])) $ruleID = $_GET['rule_id']; - if ($_GET['msg']) $msg = $_GET['msg']; - _debug_array($content); + $tmpl = new etemplate('mail.sieve.index'); - $content['rg']= $this->get_rows(); - //$content['rules'][''] - //error_log(__METHOD__. array2string($content)); - //_debug_array($readonlys); - _debug_array($content); + if ($_GET['msg']) $msg = $_GET['msg']; + + $content['rg']= $this->get_rows($rows,$readonlys); // Set content-menu actions $tmpl->set_cell_attribute('rg', 'actions',$this->get_actions()); @@ -134,14 +136,96 @@ class mail_sieve ) ); - //$tmpl->read('mail.sieve.index'); - //_debug_array($content); - //_debug_array($this->rules); - $tmpl->exec('mail.mail_sieve.index',$content,$sel_options,$readonlys); } + /** + * Email Notification Edit + * + * @param type $content + * @param type $msg + */ + function editEmailNotification($content=null, $msg='') + { + $eNotitmpl = new etemplate('mail.sieve.emailNotification'); + + $eNotification = $this->getEmailNotification(); + + if (!is_array($content)) + { + $content = $eNotification; + + if (!empty($eNotification['externalEmail'])) + { + $content['externalEmail'] = explode(",",$eNotification['externalEmail']); + } + } + else + { + $this->restoreSessionData(); + list($button) = @each($content['button']); + unset ($content['button']); + + switch($button) + { + 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 ) + { + 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)) + { + $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 update failed! You need to set an email address!'); + break; + } + if ($button === 'apply') break; + + case 'cancel': + egw::redirect_link('/mail/index.php'); + } + $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; + $eNotitmpl->exec('mail.mail_sieve.editEmailNotification', $content,$sel_options); + } + /** * Sieve rules edit * @@ -150,68 +234,83 @@ class mail_sieve function edit ($content=null) { $etmpl = new etemplate('mail.sieve.edit'); - //error_log(__METHOD__.array2string($content)); + error_log(__METHOD__.'() content before the action ' .array2string($content)); if (!is_array($content)) { if ( $this->getRules($_GET['ruleID']) && isset($_GET['ruleID'])) { $rules = $this->rulesByID; - $content= array_merge($rules); - _debug_array($rules); + $content= $rules; + $content['action']= array( + 0 => $rules['action'], + ); //$content['ruleID'] = $ruleID; switch ($rules['action']) { case 'folder': - $content['action_folder_text'] = $rules['action_arg']; + + $content['action_folder_text'][] =$rules['action_arg']; + break; case 'address': - $content['action_address_text'] = $rules['action_arg']; + + $content['action_address_text'][] = $rules['action_arg']; break; case 'reject': $content['action_reject_text'] = $rules['action_arg']; } - + //_debug_array($content); } else // Adding new rule { - $this->getRules(); + $this->getRules(null); $newRulePriority = count($this->rules)*2+1; - $newRules = $content; $newRules ['priority'] = $newRulePriority; $newRules ['status'] = 'ENABLED'; + $readonlys = array( + 'button[delete]' => 'true', + ); $this->rulesByID = $newRules; - _debug_array($this->rulesByID); + $content = $this->rulesByID; } $this->saveSessionData(); - } else { $this->restoreSessionData(); list($button) = @each($content['button']); + //$ruleID is calculated by priority from the selected rule and is an unique ID + $ruleID = ($this->rulesByID['priority'] -1) / 2; switch ($button) { - case 'apply': + case 'save': + case 'apply': if($content) { unset($content['button']); - //$ruleID is calculated by priority from the selected rule and is an unique ID - $ruleID = ($this->rulesByID['priority'] -1) / 2; + $newRule = $content; + $newRule ['action'] = $content ['action'][0]; $newRule['priority'] = $this->rulesByID['priority']; $newRule['status'] = $this->rulesByID['status']; - switch ($content['action']) + error_log(__METHOD__. 'folder=' . array2string($content)); + //_debug_array($content); + // switch ($content['action']) + switch ($content['action'][0]) { case 'folder': - $newRule['action_arg'] = $content['action_folder_text']; + $newRule['action_arg'] = implode($content['action_folder_text']); + //$sel_options['action_folder_text'] = $content['action_folder_text']; break; case 'address': - $newRule['action_arg'] = $content['action_address_text']; + //preg_match('/(?<=\<)[^<]+(?=\>)/', implode(array_values($content['action_address_text'])),$tagmail); + $newRule['action_arg'] = implode($content['action_address_text']);//implode($tagmail); + error_log(__METHOD__. '() newRules_address '. array2string($newRule['action_arg'])); break; case 'reject': $newRule['action_arg'] = $content['action_reject_text']; @@ -226,8 +325,7 @@ class mail_sieve if( $newRule['anyof'] ) { $newRule['flg'] += 4; } if( $newRule['keep'] ) { $newRule['flg'] += 8; } if( $newRule['regexp'] ) { $newRule['flg'] += 128; } - - _debug_array($newRule); + error_log(__METHOD__ . 'new rules= ' .array2string($newRule)); if($newRule['action'] && $this->rulesByID['priority']) { $this->rules[$ruleID] = $newRule; @@ -236,6 +334,10 @@ class mail_sieve { $msg .= lang("Saving the rule failed:")."
".$this->bosieve->error."
"; } + else + { + $msg .= lang("The rule with priority %1 successfully saved!",$ruleID); + } $this->saveSessionData(); } else @@ -243,26 +345,28 @@ class mail_sieve $msg .= "\n".lang("Error: Could not save rule").' '.lang("No action defined!"); $error++; } - if ($button == "apply") break; - //close the window and refresh the rules list - $this->sieve_refresh(); - } else { $msg .= "\n".lang("Error: Could not save rule").' '.lang("No action defined!"); $error++; } - case 'cancel': - break; + //refresh the rules list + $this->sieve_egw_refresh($msg); + if ($button == "apply") break; + //fall through case 'delete': - $this->sieve_refresh(); - break; + if ($button == "delete") + $this->ajax_action($button, $ruleID, $msg); + + case 'cancel': + $js = 'window.close();'; + echo "\n\n\n\n\n"; + common::egw_exit(); } } - - $sel_options = array( + $sel_options = array(//array_merge($sel_options,array( 'anyof' => array( 0 => lang('all of'), 1 => lang('any of'), @@ -278,18 +382,57 @@ class mail_sieve 'ctype' => emailadmin_script::$btransform_ctype_array, ); - - - //error_log(__METHOD__. array2string($content)); + //$preserv = $sel_options; + error_log(__METHOD__.'() content'. array2string($content)); return $etmpl->exec('mail.mail_sieve.edit',$content,$sel_options,$readonlys,$preserv,2); } - function editVacation($content=null) + /** + * Read email notification script from the sieve script from server + * + * @return type, returns array of email notification data, and in case of failure returns false + */ + function getEmailNotification() { - $vtmpl = new etemplate('mail.sieve.editVacation'); + $preferences =& $this->mailPreferences; + if(!(empty($preferences->preferences['prefpreventnotificationformailviaemail']) || $preferences->preferences['prefpreventnotificationformailviaemail'] == 0)) + die('You should not be here!'); + $boemailadmin = new emailadmin_bo(); + if($this->bosieve->getScript($this->scriptName)) + { + if(PEAR::isError($error = $this->bosieve->retrieveRules($this->scriptName)) ) + { + $rules = array(); + $emailNotification = array(); + } + else + { + $rules = $this->bosieve->getRules($this->scriptName); + $emailNotification = $this->bosieve->getEmailNotification($this->scriptName); + } + } + else + { + // something went wrong + error_log(__METHOD__.__LINE__.' failed'); + return false; + } + return $emailNotification; + } + + /** + * Fetch Vacation rules and predefined Addresses from mailserver + * + * @param type $vacation + * @param type $msg + * @return type + */ + function getVacation(&$vacation,&$msg) + { + //$response->call('app.mail.sieve_vac_response_addresses'); $preferences =& $this->mailPreferences; if(!(empty($preferences->preferences['prefpreventabsentnotice']) || $preferences->preferences['prefpreventabsentnotice'] == 0)) { @@ -306,300 +449,385 @@ class mail_sieve { if(PEAR::isError($error = $this->bosieve->retrieveRules($this->scriptName)) ) { - $rules = array(); $vacation = array(); } else { - $rules = $this->bosieve->getRules($this->scriptName); $vacation = $this->bosieve->getVacation($this->scriptName); } } else { // something went wrong - } - if (is_array($content)) - { - list($button) = @each($content['button']); - unset ($content['button']); - - switch($button) - { - case 'delete': - break; - case 'apply': - case 'save': - - } - } - _debug_array($content); - /* - if ($GLOBALS['egw_info']['user']['apps']['admin']) - { - // store text as default - if (isset($_POST['set_as_default'])) - { - config::save_value('default_vacation_text', $_POST['vacation_text'], 'felamimail'); - } - //$this->t->set_var('set_as_default',''); - //set as default - } - $checkAddresses=(get_var('check_mail_sent_to',array('POST'))=='off'?false:true); - - if ($content['vacationStatus']) - { + $msg = lang('Unable to fetch vacation!'); } - if(isset($_POST["vacationStatus"])) - { - $newVacation['text'] = get_var('vacation_text',array('POST')); - if (strpos($newVacation['text'],"\r\n")===false) $newVacation['text'] = str_replace("\n\n","\r\n",$newVacation['text']); - $newVacation['text'] = $this->botranslation->convert($newVacation['text'],$this->displayCharset,'UTF-8'); - $newVacation['days'] = get_var('days',array('POST')); - $newVacation['addresses'] = get_var('vacationAddresses',array('POST')); - $newVacation['status'] = get_var('vacationStatus',array('POST')); - if (empty($preferences->preferences['prefpreventforwarding']) || - $preferences->preferences['prefpreventforwarding'] == 0 ) # || - #($ogServer instanceof emailadmin_smtp) || $ogServer->editForwardingAddress) - { - $newVacation['forwards'] = get_var('vacation_forwards',array('POST')); - } - if (!in_array($newVacation['status'],array('on','off','by_date'))) $newVacation['status'] = 'off'; - if ($this->timed_vacation||isset($_POST['start_date']) || isset($_POST['end_date'])) - { - if (isset($_POST['start_date'])) - { - $date = $jscal->input2date($_POST['start_date']); - if ($date['raw']) $newVacation['start_date'] = $date['raw']-12*3600; - } - if (isset($_POST['end_date'])) - { - $date = $jscal->input2date($_POST['end_date']); - if ($date['raw']) $newVacation['end_date'] = $date['raw']-12*3600; - } - } - if(isset($_POST['save']) || isset($_POST['apply'])) - { - if($this->checkRule($newVacation,$checkAddresses)) - { - if (!$this->bosieve->setVacation($this->scriptName, $newVacation)) - { - print "vacation update failed
"; - #print $script->errstr."
"; - $this->t->set_var('validation_errors', lang('Vacation notice update failed').': '.$this->bosieve->error); - } - else - { - //error_log(__METHOD__.__LINE__.array2string($newVacation)); - if (!isset($newVacation['scriptName']) || empty($newVacation['scriptName'])) $newVacation['scriptName'] = $this->scriptName; - $this->bosieve->setAsyncJob($newVacation); - $this->t->set_var('validation_errors', lang('Vacation notice sucessful updated.')); - } - } - else - { - if(isset($_POST['save'])) unset($_POST['save']); - $this->t->set_var('validation_errors',implode('
',$this->errorStack)); - } - } - $vacation = $newVacation; - if(isset($_POST['save']) || isset($_POST['cancel'])) - { - $GLOBALS['egw']->redirect_link('/felamimail/index.php'); - } - } - $this->saveSessionData(); - // display the header - $this->display_app_header(); - // initialize the template - $this->t->set_file(array("filterForm" => "sieveForm.tpl")); - $this->t->set_block('filterForm','vacation'); - // translate most of the parts - $this->translate(); - // vacation status - if($vacation['status'] == 'on') - { - $this->t->set_var('checked_active', 'checked'); - } - elseif($vacation['status'] == 'off') - { - $this->t->set_var('checked_disabled', 'checked'); - } - if($checkAddresses) - { - $this->t->set_var('check_mail_sent_to_active', 'checked'); - } - else - { - $this->t->set_var('check_mail_sent_to_disabled', 'checked'); - } - // vacation text - if (empty($vacation['text'])) - { - $config = new config('felamimail'); - $config = $config->read_repository(); - $vacation['text'] = $config['default_vacation_text']; - } - $this->t->set_var('vacation_text',$this->botranslation->convert($vacation['text'],'UTF-8')); - //vacation days - if(empty($vacation)) - { - $this->t->set_var('selected_7', 'selected="selected"'); - // ToDO set default - } - else - { - $this->t->set_var('selected_'.($vacation['days']?$vacation['days']:'7'), 'selected="selected"'); - } - if (empty($preferences->preferences['prefpreventforwarding']) || $preferences->preferences['prefpreventforwarding'] == 0 ) - { - $this->t->set_var('vacation_forwards',''); - } - else - { - $this->t->set_var('vacation_forwards',lang('not allowed')); - unset($vacation['forwards']); - } - // vacation addresses - if(is_array($vacation['addresses'])) - { - foreach($vacation['addresses'] as $address) - { - $selectedAddresses[$address] = $address; - } - asort($selectedAddresses); - } $allIdentities = $preferences->getIdentity(); - //_debug_array($allIdentities); foreach($allIdentities as $key => $singleIdentity) { - if((empty($vacation) || empty($selectedAddresses))&& $singleIdentity->default === true) + if((empty($vacation))&& $singleIdentity->default === true) { $selectedAddresses[$singleIdentity->emailAddress] = $singleIdentity->emailAddress; } $predefinedAddresses[$singleIdentity->emailAddress] = $singleIdentity->emailAddress; } asort($predefinedAddresses); - $this->t->set_var('multiSelectBox',$uiwidgets->multiSelectBox( - $selectedAddresses, - $predefinedAddresses, - 'vacationAddresses', - '400px' - )); - $linkData = array ( - 'menuaction' => 'felamimail.uisieve.editVacation', - ); - - $this->t->set_var('vacation_action_url',$GLOBALS['egw']->link('/index.php',$linkData)); - - if ($this->timed_vacation) - { - $this->t->set_var('by_date',' : '. - $jscal->input('start_date',$vacation['start_date']).' - '.$jscal->input('end_date',$vacation['end_date'])); - $this->t->set_var('lang_help_start_end_replacement','
'.lang('You can use %1 for the above start-date and %2 for the end-date.','$$start$$','$$end$$')); - } - $this->t->pfp('out','vacation'); -*/ - $sel_options = array( - 'status' => array( - 'active' => lang('all of'), - 'disabled' => lang('any of'), - ), - ); - $vtmpl->exec('mail.mail_sieve.editVacation',$content,$sel_options); + return array( + 'vacation' =>$vacation, + 'aliases' => array_values($predefinedAddresses), + ); } + /** + * Convert the taglist-email contact address "account name" format to sieveRule "email" format + * + * @param type $addresses + */ + function email_address_converter($addresses) + { + error_log(__METHOD__. '() emailAddress '. array2string($addresses)); + $tagmail = array(); + foreach ($addresses as $key => $adr) + { + + if (preg_match('/(?<=\<)[^<]+(?=\>)/', $adr,$tagmail)) + { + $addressses = $tagmail; + error_log(__METHOD__. '() inside the foreach' . array2string($tagmail). 'key is' . $key); + } + } + if (!empty($addresses)) + { + error_log(__METHOD__. '() emailAddress '. array2string($addresses)); + return $addressses; + } + else + { + error_log(__METHOD__. '() No email address(es)'); + return false; + } + } + + /** + * Vacation edit + * + * @param type $content + * @param type $msg + */ + function editVacation($content=null, $msg='') + { + $vtmpl = new etemplate('mail.sieve.vacation'); + + $vacRules = $this->getVacation($vacation,$msg); + + if (!is_array($content)) + { + $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 + { + $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)); + $vtmpl->exec('mail.mail_sieve.editVacation',$content,$sel_options,$preserv); + } + + /** + * Checking vaction validation + * + * @param type $_vacation + * @param type $_checkAddresses + * @return boolean + */ + function checkRule($_vacation,$_checkAddresses=true) + { + $this->errorStack = array(); + + if (!$_vacation['text']) + { + $this->errorStack['text'] = lang('Please supply the message to send with auto-responses').'! '; + } + + if (!$_vacation['days']) + { + $this->errorStack['days'] = lang('Please select the number of days to wait between responses').'!'; + } + + if(is_array($_vacation['addresses'])) + { + $regexp="/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i"; + foreach ($_vacation['addresses'] as $addr) + { + if (!preg_match($regexp,$addr) && $_checkAddresses) + { + $this->errorStack['addresses'] = lang('One address is not valid').'!'; + } + } + } + else + { + $this->errorStack['addresses'] = lang('Please select a address').'!'; + } + if ($_vacation['status'] == 'by_date') + { + if (!$_vacation['start_date'] || !$_vacation['end_date']) + { + $this->errorStack['status'] = lang('Activating by date requires a start- AND end-date!'); + } + elseif($_vacation['start_date'] > $_vacation['end_date']) + { + $this->errorStack['status'] = lang('Vacation start-date must be BEFORE the end-date!'); + } + } + if ($_vacation['forwards']) + { + foreach(preg_split('/, ?/',$_vacation['forwards']) as $addr) + { + if (!preg_match($regexp,$addr) && $_checkAddresses) + { + $this->errorStack['forwards'] = lang('One address is not valid'.'!'); + } + } + } + error_log(__METHOD__. array2string($this->errorStack)); + if(count($this->errorStack) == 0) + { + return true; + } + else + { + $this->errorStack['message'] = lang('Vacation notice is not saved yet! (But we filled in some defaults to cover some of the above errors. Please correct and check your settings and save again.)'); + return false; + } + } /** * Move rule to an other position in list * - * @param int $from 0, 1, ... - * @param int $to 0, 1, ... + * @param type $objType + * @param type $orders */ function ajax_moveRule($objType, $orders) { - //$this->restoreSessionData(); + foreach ($orders as $keys => $val) $orders[$keys] = $orders[$keys] -1; - error_log(__METHOD__.array2string($orders)); + $this->getRules(null); //_debug_array($this->rules); $newrules = $this->rules; - $keyfound = 1; + $keyloc = 0; foreach($orders as $keys => $ruleID) { - //error_log(__METHOD__. $ruleID); + error_log(__METHOD__.'() ruleID= '. $ruleID); $newrules[$keys] = $this->rules[$ruleID]; - - error_log(__METHOD__. "keys +1:" . $orders[$keys +1]); - error_log(__METHOD__. "key:" . $orders[$keys]); - if ((($ruleID - $orders[$keys +1]) !== -1) && ($keyfound == 1)) - { - if ($orders[$keys +1] < ($orders[$keys] + 1) ) - { - $to = $orders[$keys]; - } - else - { - $from = $orders[$keys]; - } - $keyfound = 0; - error_log(__METHOD__. "from=" .$from); - error_log(__METHOD__. "to=" .$to); - } - - } - error_log(__METHOD__. "from=" .$from); - $msg = 'the rule with priority' . $from . 'moved to' . $to; - //$this->rules = $newrules; - _debug_array($newrules); + + $msg = 'the rule with priority moved from ' . $from . ' to ' . $to; + $this->rules = $newrules; $this->updateScript(); $this->saveSessionData(); - $this->sieve_refresh($msg); + + //Calling to referesh after move action + $this->sieve_egw_refresh($msg); } /** - * Handling actions over sieve rules list on gd + * call the client side refresh method + * + * @param type $msg + */ + function sieve_egw_refresh($msg) + { + $response = egw_json_response::get(); + $response->call('app.mail.sieve_egw_refresh',null,$msg); + } + + /** + * Ajax function to handle the server side content for refreshing the form + * + * @param type $execId, + * @param type $msg + */ + function ajax_sieve_egw_refresh($execId,$msg) + { + //Need to read the template to use for refreshing the form + $response = egw_json_response::get(); + $request= etemplate_request::read($execId); + + $content['rg'] = $this->get_rows($rows,$readonlys); + $content['msg'] = $msg; + $request->content = $content; + $data = array( + 'etemplate_exec_id' => $request->id(), + + 'app_header' => $request->app_header, + 'content' => $request->content, + 'sel_options' => $request->sel_options, + 'readonlys' => $request->readonlys, + 'modifications' => $request->modifications, + 'validation_errors' => $validation_errors, + ); + $response->generic('et2_load', array( + 'name' => 'mail.sieve.index', + 'url' => $GLOBALS['egw_info']['server']['webserver_url'].etemplate::relPath('mail.sieve.index'), + 'data' => $data, + 'DOMNodeID' => 'mail-sieve-index' + )); + } + + /** + * Ajax function to handle actions over sieve rules list on gd * * @param type $actions * @param type $checked * @param type $action_msg * @param type $msg */ - function ajax_action($action,$checked,$msg='') + function ajax_action($action,$checked,$msg) { - $this->getRules(); - $response = egw_json_response::get(); + $this->getRules(null); + switch ($action) { case 'delete': - $msg = lang('rule ') . $checked . lang(' deleted!'); + if ($checked === count($this->rules)-1) + { + $msg = lang('rule with priority ') . $checked . lang(' deleted!'); + }else + { + + $msg = lang('rule with priority ') . $checked . lang(' deleted!') . lang(' And the rule with priority %1, now got the priority %2',$checked+1,$checked); + } unset($this->rules[$checked]); $this->rules = array_values($this->rules); break; case 'enable': - $msg = lang('rule ') . $checked . lang(' enabled!'); + $msg = lang('rule with priority ') . $checked . lang(' enabled!'); $this->rules[$checked][status] = 'ENABLED'; break; case 'disable': - $msg = lang('rule ') . $checked . lang(' disabled!'); + $msg = lang('rule with priority ') . $checked . lang(' disabled!'); $this->rules[$checked][status] = 'DISABLED'; break; + case 'move': + break; } + $this->updateScript(); $this->saveSessionData(); - $this->sieve_refresh($msg); - $response->call('app.mail.action',$action,$checked,$msg); + + //Refresh the form + $this->sieve_egw_refresh($msg); } - /** + * Add script to sieve script * */ function addScript() @@ -612,9 +840,10 @@ class mail_sieve } /** + * Convert an script seive format rule to human readable format * * @param type $rule - * @return string + * @return string, return the rule as a string. */ function buildRule($rule) { @@ -658,6 +887,28 @@ class mail_sieve $complete .= "message " . $xthan . $rule['size'] . "KB'"; $started = 1; } + if ($rule['field_bodytransform']) + { + if ($started) $newruletext .= ", "; + $btransform = " :raw "; + $match = ' :contains'; + if ($rule['bodytransform']) $btransform = " :text "; + if (preg_match("/\*|\?/", $rule['field_bodytransform'])) $match = ':matches'; + if ($rule['regexp']) $match = ':regex'; + $complete .= " body " . $btransform . $match . " \"" . $rule['field_bodytransform'] . "\""; + $started = 1; + + } + if ($rule['ctype']!= '0') + { + if ($started) $newruletext .= ", "; + $btransform_ctype = emailadmin_script::$btransform_ctype_array[$rule['ctype']]; + $ctype_subtype = ""; + if ($rule['field_ctype_val']) $ctype_subtype = "/"; + $complete .= " body :content " . " \"" . $btransform_ctype . $ctype_subtype . $rule['field_ctype_val'] . "\"" . " :contains \"\""; + $started = 1; + //error_log(__CLASS__."::".__METHOD__.array2string(emailadmin_script::$btransform_ctype_array)); + } if (!$rule['unconditional']) $complete .= ' '.lang('THEN').' '; if (preg_match("/folder/i",$rule['action'])) $complete .= lang('file into')." '" . $rule['action_arg'] . "';"; @@ -700,7 +951,7 @@ class mail_sieve } /** - * + * Save sieve script */ function saveScript() { @@ -717,7 +968,7 @@ class mail_sieve } /** - * + * Save session data */ function saveSessionData() { @@ -728,7 +979,7 @@ class mail_sieve } /** - * + * Update the sieve script on mail server */ function updateScript() { @@ -776,7 +1027,7 @@ class mail_sieve /** - * + * Restore session data */ function restoreSessionData() { @@ -787,13 +1038,14 @@ class mail_sieve } /** + * Get the data for iterating the rows on rules list grid * * @return type */ function get_rows(&$rows,&$readonlys) { $rows = array(); - $this->getRules(); /* ADDED BY GHORTH */ + $this->getRules(null); /* ADDED BY GHORTH */ //$this->saveSessionData(); if (is_array($this->rules) && !empty($this->rules) ) @@ -806,7 +1058,7 @@ class mail_sieve $row['ruleID'] =(string)(($row['priority'] -1) / 2 ); if ($row ['status'] === 'ENABLED') { - + $row['class'] = 'mail_sieve_ENABLED'; } } @@ -827,7 +1079,7 @@ class mail_sieve * * * - * @return array + * @return array, returns defined actions as an array */ private function get_actions(array $query=array()) { @@ -840,14 +1092,13 @@ class mail_sieve ), 'add' => array( 'caption' => 'Add', - //'url' => 'menuaction=mail.mail_sieve.edit', 'onExecute' => 'javaScript:app.mail.action' ), 'enable' => array( 'caption' => 'Enable', 'onExecute' => 'javaScript:app.mail.action', - 'enableClass' => 'mail_sieve_ENABLED', - 'hideOnDisabled' => true, + //'enableClass' => 'mail_sieve_ENABLED', + //'hideOnDisabled' => true, ), 'disable' => array( 'caption' => 'Disable', @@ -866,13 +1117,41 @@ class mail_sieve return $actions; } - function sieve_refresh($msg) + /** + * sieve_refresh() + * Handling the refreshing form by updating the content on client side + * + * @param type $response, is egw_json_response + * @param type $request, is etemplate_request + * @param type $cnt, the new contents to be used for updating + * @param type $msg, messages + * @return type + */ + function sieve_refresh($response,$request,$cnt,$msg) { - $response = egw_json_response::get(); - $response->alert(''); - $this->get_rows($rows, $readonlys); - error_log(__METHOD__. count($rows)); - $response->call('app.mail.sieve_refresh',$rows, $msg); + + error_log(__METHOD__. '() read'. array2string($msg)); + //$content = $request->content; + $content['rg'] = $cnt; + $content['msg'] = $msg; + $request->content = $content; + $data = array( + 'etemplate_exec_id' => $request->id(), + + 'app_header' => $request->app_header, + 'content' => $request->content, + 'sel_options' => $request->sel_options, + 'readonlys' => $request->readonlys, + 'modifications' => $request->modifications, + 'validation_errors' => $validation_errors, + ); + $response->generic('et2_load', array( + 'name' => 'mail.sieve.index', + 'url' => $GLOBALS['egw_info']['server']['webserver_url'].etemplate::relPath('mail.sieve.index'), + 'data' => $data, + 'DOMNodeID' => 'mail-sieve-index' + )); + return; } } diff --git a/mail/js/app.js b/mail/js/app.js index 77b371aa50..f1125ca133 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -62,7 +62,7 @@ app.mail = AppJS.extend( { // call parent this._super.apply(this, arguments); - + this.et2_obj = et2; this.et2 = et2.widgetContainer; var isMainView = false; var isDisplay = false; @@ -1132,6 +1132,23 @@ app.mail = AppJS.extend( } }, + sieve_editRules_radiobtn: function() + { + console.log("hi i am radiobtn"); + }, + /** + * + */ + sieve_vac_all_aliases: function() + { + + var addr = this.et2.getWidgetById('addresses'); + + console.log('say something'); + addr.select_all(); + //addr.set_autocomplete_url('mail.mail_compose.ajax_searchAddress'); + }, + /** * action - handling actions on sieve rules * @@ -1186,24 +1203,21 @@ app.mail = AppJS.extend( }, - _do_action: function(_typeID, _data,_selectedID) + _do_action: function(_typeID, _data,_selectedID,_msg) { if (_typeID && _data) { - var request = new egw_json_request('mail.mail_sieve.ajax_action', [_typeID,_selectedID]); + var request = egw().json('mail.mail_sieve.ajax_action', [_typeID,_selectedID,_msg],null,null,true); console.log(request); - request.sendRequest(true,this._callback_do_action,this); + request.sendRequest(); } }, - sieve_refresh: function (_rows,_msg) + sieve_egw_refresh: function(_execid,_msg) { - var grid = this.et2.getWidgetById('rg'); - window.egw_refresh(_msg,this.appname); - if (grid) - { - grid.set_value(_rows); - } - + var request = egw().json('mail.mail_sieve.ajax_sieve_egw_refresh', [this.et2_obj.etemplate_exec_id,_msg],null,this.et2_obj,true); + console.log(request); + request.sendRequest(); }, + }); diff --git a/mail/templates/default/sieve.edit.xet b/mail/templates/default/sieve.edit.xet index 04a0f22727..a11c012be3 100644 --- a/mail/templates/default/sieve.edit.xet +++ b/mail/templates/default/sieve.edit.xet @@ -90,24 +90,23 @@ - + - - + - + - + - + - + @@ -140,7 +139,7 @@