diff --git a/felamimail/inc/class.bofelamimail.inc.php b/felamimail/inc/class.bofelamimail.inc.php index d042e6d7f7..2994052a77 100644 --- a/felamimail/inc/class.bofelamimail.inc.php +++ b/felamimail/inc/class.bofelamimail.inc.php @@ -224,12 +224,12 @@ { if ($this->mailPreferences) { $icServer = $this->mailPreferences->getIncomingServer(0); - if(is_a($icServer,'defaultimap')) { + if(($icServer instanceof defaultimap)) { $icServer->addAccount($_hookValues); } $ogServer = $this->mailPreferences->getOutgoingServer(0); - if(is_a($ogServer,'defaultsmtp')) { + if(($ogServer instanceof defaultsmtp)) { $ogServer->addAccount($_hookValues); } } @@ -534,12 +534,12 @@ { if ($this->mailPreferences) { $icServer = $this->mailPreferences->getIncomingServer(0); - if(is_a($icServer,'defaultimap')) { + if(($icServer instanceof defaultimap)) { $icServer->deleteAccount($_hookValues); } $ogServer = $this->mailPreferences->getOutgoingServer(0); - if(is_a($ogServer,'defaultsmtp')) { + if(($ogServer instanceof defaultsmtp)) { $ogServer->deleteAccount($_hookValues); } } @@ -1315,7 +1315,7 @@ // does the folder exist??? $folderInfo = $this->icServer->getMailboxes('', $_folderName, true); - if(is_a($folderInfo, 'PEAR_Error') || !is_array($folderInfo[0])) { + if(($folderInfo instanceof PEAR_Error) || !is_array($folderInfo[0])) { if (self::$debug) error_log(__METHOD__." returned Info for folder $_folderName:".print_r($folderInfo->message,true)); return false; } @@ -1896,7 +1896,7 @@ function getHierarchyDelimiter() { $HierarchyDelimiter = '/'; - if(is_a($this->icServer,'defaultimap')) + if(($this->icServer instanceof defaultimap)) { $HierarchyDelimiter = $this->icServer->getHierarchyDelimiter(); if (PEAR::isError($HierarchyDelimiter)) $HierarchyDelimiter = '/'; @@ -2642,10 +2642,10 @@ //try to connect if (!$this->icServer->_connected) $this->openConnection(); } - if(is_a($this->icServer,'defaultimap')) $folderInfo[$_folder] = $this->icServer->mailboxExist($_folder); + if(($this->icServer instanceof defaultimap)) $folderInfo[$_folder] = $this->icServer->mailboxExist($_folder); //error_log(__METHOD__.__LINE__.' Folder Exists:'.$folderInfo[$_folder]); - if(is_a($folderInfo[$_folder], 'PEAR_Error') || $folderInfo[$_folder] !== true) + if(($folderInfo[$_folder] instanceof PEAR_Error) || $folderInfo[$_folder] !== true) { return false; } else { @@ -2826,12 +2826,12 @@ function updateAccount($_hookValues) { if (is_object($this->mailPreferences)) $icServer = $this->mailPreferences->getIncomingServer(0); - if(is_a($icServer,'defaultimap')) { + if(($icServer instanceof defaultimap)) { $icServer->updateAccount($_hookValues); } if (is_object($this->mailPreferences)) $ogServer = $this->mailPreferences->getOutgoingServer(0); - if(is_a($ogServer,'defaultsmtp')) { + if(($ogServer instanceof defaultsmtp)) { $ogServer->updateAccount($_hookValues); } } diff --git a/felamimail/inc/class.bopreferences.inc.php b/felamimail/inc/class.bopreferences.inc.php new file mode 100644 index 0000000000..e396809712 --- /dev/null +++ b/felamimail/inc/class.bopreferences.inc.php @@ -0,0 +1,385 @@ + True, + ); + + // stores the users profile + var $profileData; + var $sessionData; + var $boemailadmin; + + function bopreferences($_restoreSession = true) + { + //error_log(__METHOD__." called ".print_r($_restoreSession,true).function_backtrace()); + parent::sopreferences(); + $this->boemailadmin = new emailadmin_bo(-1,$_restoreSession); + if ($_restoreSession && !(is_array($this->sessionData) && (count($this->sessionData)>0)) ) $this->restoreSessionData(); + if ($_restoreSession===false && (is_array($this->sessionData) && (count($this->sessionData)>0)) ) + { + //error_log(__METHOD__." Unset Session ".function_backtrace()); + //make sure session data will be reset + $this->sessionData = array(); + $this->profileData = array(); + self::saveSessionData(); + } + //error_log(__METHOD__.print_r($this->sessionData,true)); + if (isset($this->sessionData['profileData']) && ($this->sessionData['profileData'] instanceof ea_preferences)) { + $this->profileData = $this->sessionData['profileData']; + } + } + + function restoreSessionData() + { + //error_log(__METHOD__." Session restore ".function_backtrace()); + // set an own autoload function, search emailadmin for missing classes + $GLOBALS['egw_info']['flags']['autoload'] = array(__CLASS__,'autoload'); + + $this->sessionData = (array) unserialize($GLOBALS['egw']->session->appsession('fm_preferences','felamimail')); + } + + /** + * Autoload classes from emailadmin, 'til they get autoloading conform names + * + * @param string $class + */ + static function autoload($class) + { + if (file_exists($file=EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php')) + { + include_once($file); + //error_log(__METHOD__."($class) included $file"); + } + elseif (file_exists($file=EGW_INCLUDE_ROOT.'/felamimail/inc/class.'.$class.'.inc.php')) + { + include_once($file); + } + else + { + #error_log(__METHOD__."($class) failed!"); + } + } + + function saveSessionData() + { + $GLOBALS['egw']->session->appsession('fm_preferences','felamimail',serialize($this->sessionData)); + } + // get the first active user defined account + function getAccountData(&$_profileData, $_accountID=NULL) + { + #echo "

backtrace: ".function_backtrace()."

\n"; + if(!($_profileData instanceof ea_preferences)) + die(__FILE__.': '.__LINE__); + $accountData = parent::getAccountData($GLOBALS['egw_info']['user']['account_id'],$_accountID); + + // currently we use only the first profile available + $accountData = array_shift($accountData); + #_debug_array($accountData); + + $icServer = CreateObject('emailadmin.defaultimap'); + $icServer->encryption = isset($accountData['ic_encryption']) ? $accountData['ic_encryption'] : 1; + $icServer->host = $accountData['ic_hostname']; + $icServer->port = isset($accountData['ic_port']) ? $accountData['ic_port'] : 143; + $icServer->validatecert = isset($accountData['ic_validatecertificate']) ? (bool)$accountData['ic_validatecertificate'] : 1; + $icServer->username = $accountData['ic_username']; + $icServer->loginName = $accountData['ic_username']; + $icServer->password = $accountData['ic_password']; + $icServer->enableSieve = isset($accountData['ic_enable_sieve']) ? (bool)$accountData['ic_enable_sieve'] : 1; + $icServer->sieveHost = $accountData['ic_sieve_server']; + $icServer->sievePort = isset($accountData['ic_sieve_port']) ? $accountData['ic_sieve_port'] : 2000; + if ($accountData['ic_folderstoshowinhome']) $icServer->folderstoshowinhome = $accountData['ic_folderstoshowinhome']; + if ($accountData['ic_trashfolder']) $icServer->trashfolder = $accountData['ic_trashfolder']; + if ($accountData['ic_sentfolder']) $icServer->sentfolder = $accountData['ic_sentfolder']; + if ($accountData['ic_draftfolder']) $icServer->draftfolder = $accountData['ic_draftfolder']; + if ($accountData['ic_templatefolder']) $icServer->templatefolder = $accountData['ic_templatefolder']; + + $ogServer = CreateObject('emailadmin.defaultsmtp'); + $ogServer->host = $accountData['og_hostname']; + $ogServer->port = isset($accountData['og_port']) ? $accountData['og_port'] : 25; + $ogServer->smtpAuth = (bool)$accountData['og_smtpauth']; + if($ogServer->smtpAuth) { + $ogServer->username = $accountData['og_username']; + $ogServer->password = $accountData['og_password']; + } + + $identity = CreateObject('emailadmin.ea_identity'); + $identity->emailAddress = $accountData['emailaddress']; + $identity->realName = $accountData['realname']; + //$identity->default = true; + $identity->default = (bool)$accountData['active']; + $identity->organization = $accountData['organization']; + $identity->signature = $accountData['signatureid']; + $identity->id = $accountData['id']; + + $isActive = (bool)$accountData['active']; + + return array('icServer' => $icServer, 'ogServer' => $ogServer, 'identity' => $identity, 'active' => $isActive); + } + + function getAllAccountData(&$_profileData) + { + if(!($_profileData instanceof ea_preferences)) + die(__FILE__.': '.__LINE__); + $AllAccountData = parent::getAccountData($GLOBALS['egw_info']['user']['account_id'],'all'); + #_debug_array($accountData); + foreach ($AllAccountData as $key => $accountData) + { + $icServer = CreateObject('emailadmin.defaultimap'); + $icServer->encryption = isset($accountData['ic_encryption']) ? $accountData['ic_encryption'] : 1; + $icServer->host = $accountData['ic_hostname']; + $icServer->port = isset($accountData['ic_port']) ? $accountData['ic_port'] : 143; + $icServer->validatecert = isset($accountData['ic_validatecertificate']) ? (bool)$accountData['ic_validatecertificate'] : 1; + $icServer->username = $accountData['ic_username']; + $icServer->loginName = $accountData['ic_username']; + $icServer->password = $accountData['ic_password']; + $icServer->enableSieve = isset($accountData['ic_enable_sieve']) ? (bool)$accountData['ic_enable_sieve'] : 1; + $icServer->sieveHost = $accountData['ic_sieve_server']; + $icServer->sievePort = isset($accountData['ic_sieve_port']) ? $accountData['ic_sieve_port'] : 2000; + if ($accountData['ic_folderstoshowinhome']) $icServer->folderstoshowinhome = $accountData['ic_folderstoshowinhome']; + if ($accountData['ic_trashfolder']) $icServer->trashfolder = $accountData['ic_trashfolder']; + if ($accountData['ic_sentfolder']) $icServer->sentfolder = $accountData['ic_sentfolder']; + if ($accountData['ic_draftfolder']) $icServer->draftfolder = $accountData['ic_draftfolder']; + if ($accountData['ic_templatefolder']) $icServer->templatefolder = $accountData['ic_templatefolder']; + + $ogServer = CreateObject('emailadmin.defaultsmtp'); + $ogServer->host = $accountData['og_hostname']; + $ogServer->port = isset($accountData['og_port']) ? $accountData['og_port'] : 25; + $ogServer->smtpAuth = (bool)$accountData['og_smtpauth']; + if($ogServer->smtpAuth) { + $ogServer->username = $accountData['og_username']; + $ogServer->password = $accountData['og_password']; + } + + $identity = CreateObject('emailadmin.ea_identity'); + $identity->emailAddress = $accountData['emailaddress']; + $identity->realName = $accountData['realname']; + //$identity->default = true; + $identity->default = (bool)$accountData['active']; + $identity->organization = $accountData['organization']; + $identity->signature = $accountData['signatureid']; + $identity->id = $accountData['id']; + $isActive = (bool)$accountData['active']; + $out[] = array('icServer' => $icServer, 'ogServer' => $ogServer, 'identity' => $identity, 'active' => $isActive); + } + return $out; + } + + function getUserDefinedIdentities() + { + $profileData = $this->boemailadmin->getUserProfile('felamimail'); + if(!($profileData instanceof ea_preferences) || !($profileData->ic_server[0] instanceof defaultimap)) { + return false; + } + if($profileData->userDefinedAccounts || $profileData->userDefinedIdentities) { + // get user defined accounts + $allAccountData = $this->getAllAccountData($profileData); + if ($allAccountData) { + foreach ($allAccountData as $tmpkey => $accountData) + { + $accountArray[] = $accountData['identity']; + } + return $accountArray; + } + } + return array(); + } + + function getPreferences($getUserDefinedProfiles=true) + { + if (isset($this->sessionData['profileData']) && ($this->sessionData['profileData'] instanceof ea_preferences)) { + $this->profileData = $this->sessionData['profileData']; + } + if(!($this->profileData instanceof ea_preferences)) { + $imapServerTypes = $this->boemailadmin->getIMAPServerTypes(); + $profileData = $this->boemailadmin->getUserProfile('felamimail'); + + if(!($profileData instanceof ea_preferences) || !($profileData->ic_server[0] instanceof defaultimap)) { + return false; + } + if($profileData->userDefinedAccounts && $GLOBALS['egw_info']['user']['apps']['felamimail'] && $getUserDefinedProfiles) { + // get user defined accounts + $accountData = $this->getAccountData($profileData); + + if($accountData['active']) { + + // replace the global defined IMAP Server + if(($accountData['icServer'] instanceof defaultimap)) + $profileData->setIncomingServer($accountData['icServer'],0); + + // replace the global defined SMTP Server + if(($accountData['ogServer'] instanceof defaultsmtp)) + $profileData->setOutgoingServer($accountData['ogServer'],0); + + // replace the global defined identity + if(($accountData['identity'] instanceof ea_identity)) { + //_debug_array($profileData); + $rememberIdentities = $profileData->identities; + $profileData->setIdentity($accountData['identity'],0); + $rememberID = $accountData['identity']->id; + } + } + } + if($profileData->userDefinedIdentities && $GLOBALS['egw_info']['user']['apps']['felamimail']) + { + $allUserIdentities = $this->getUserDefinedIdentities(); + if (is_array($allUserIdentities)) + { + $i=count($allUserIdentities); + $y=-1; + foreach ($allUserIdentities as $tmpkey => $id) + { + if ($id->id != $rememberID) + { + $profileData->setIdentity($id,$i); + $i++; + } + else + { + foreach ($rememberIdentities as $adkey => $ident) + { + $profileData->setIdentity($ident,$i); + $profileData->identities[$i]->default = false; + $profileData->identities[$i]->id = $y; + $i++; + $y--; + } + } + } + } + } + + $GLOBALS['egw']->preferences->read_repository(); + $userPrefs = $GLOBALS['egw_info']['user']['preferences']['felamimail']; + # echo "

backtrace: ".function_backtrace()."

\n"; + if (is_array($profileData->ic_server[0]->folderstoshowinhome) && !empty($profileData->ic_server[0]->folderstoshowinhome[0])) { + $userPrefs['mainscreen_showfolders'] = implode(',',$profileData->ic_server[0]->folderstoshowinhome); + } + if (!empty($profileData->ic_server[0]->sentfolder)) $userPrefs['sentFolder'] = $profileData->ic_server[0]->sentfolder; + if (!empty($profileData->ic_server[0]->trashfolder)) $userPrefs['trashFolder'] = $profileData->ic_server[0]->trashfolder; + if (!empty($profileData->ic_server[0]->draftfolder)) $userPrefs['draftFolder'] = $profileData->ic_server[0]->draftfolder; + if (!empty($profileData->ic_server[0]->templatefolder)) $userPrefs['templateFolder'] = $profileData->ic_server[0]->templatefolder; + if(empty($userPrefs['deleteOptions'])) + $userPrefs['deleteOptions'] = 'mark_as_deleted'; + + if (!empty($userPrefs['trash_folder'])) + $userPrefs['move_to_trash'] = True; + if (!empty($userPrefs['sent_folder'])) + $userPrefs['move_to_sent'] = True; + + $userPrefs['signature'] = $userPrefs['email_sig']; + + unset($userPrefs['email_sig']); + + $profileData->setPreferences($userPrefs); + + #_debug_array($profileData);#exit; + + $this->sessionData['profileData'] = $this->profileData = $profileData; + $this->saveSessionData(); + #_debug_array($this->profileData); + } + return $this->profileData; + } + + function ggetSignature($_signatureID, $_unparsed = false) + { + if($_signatureID == -1) { + $profileData = $this->boemailadmin->getUserProfile('felamimail'); + + $systemSignatureIsDefaultSignature = !parent::getDefaultSignature($GLOBALS['egw_info']['user']['account_id']); + + $systemSignature = array( + 'signatureid' => -1, + 'description' => 'eGroupWare '. lang('default signature'), + 'signature' => ($_unparsed === true ? $profileData->ea_default_signature : $GLOBALS['egw']->preferences->parse_notify($profileData->ea_default_signature)), + 'defaultsignature' => $systemSignatureIsDefaultSignature, + ); + + return $systemSignature; + + } else { + require_once('class.felamimail_signatures.inc.php'); + $signature = new felamimail_signatures($_signatureID); + if($_unparsed === false) { + $signature->fm_signature = $GLOBALS['egw']->preferences->parse_notify($signature->fm_signature); + } + return $signature; + } + } + + function ggetDefaultSignature() + { + return parent::getDefaultSignature($GLOBALS['egw_info']['user']['account_id']); + } + + function ddeleteSignatures($_signatureID) + { + if(!is_array($_signatureID)) { + return false; + } + return parent::deleteSignatures($GLOBALS['egw_info']['user']['account_id'], $_signatureID); + } + + function saveAccountData($_icServer, $_ogServer, $_identity) + { + if(is_object($_icServer) && !isset($_icServer->validatecert)) { + $_icServer->validatecert = true; + } + if(isset($_icServer->host)) { + $_icServer->sieveHost = $_icServer->host; + } + $this->sessionData = array(); + $this->saveSessionData(); + return parent::saveAccountData($GLOBALS['egw_info']['user']['account_id'], $_icServer, $_ogServer, $_identity); + } + + function deleteAccountData($_identity) + { + if (is_array($_identity)) { + foreach ($_identity as $tmpkey => $id) + { + if ($id->id) { + $identity[] = $id->id; + } else { + $identity[] = $id; + } + } + } else { + $identity = $_identity; + } + $this->sessionData = array(); + $this->saveSessionData(); + parent::deleteAccountData($GLOBALS['egw_info']['user']['account_id'], $identity); + } + + function ssaveSignature($_signatureID, $_description, $_signature, $_isDefaultSignature) + { + return parent::saveSignature($GLOBALS['egw_info']['user']['account_id'], $_signatureID, $_description, $_signature, (bool)$_isDefaultSignature); + } + + function setProfileActive($_status, $_identity=NULL) + { + $this->sessionData = array(); + $this->saveSessionData(); + parent::setProfileActive($GLOBALS['egw_info']['user']['account_id'], $_status, $_identity); + } + } +?> diff --git a/felamimail/inc/class.felamimail_hooks.inc.php b/felamimail/inc/class.felamimail_hooks.inc.php index 6d04f93f1c..23c97d9fdb 100644 --- a/felamimail/inc/class.felamimail_hooks.inc.php +++ b/felamimail/inc/class.felamimail_hooks.inc.php @@ -708,7 +708,7 @@ class felamimail_hooks } if (is_object($preferences)) $icServer = $preferences->getIncomingServer(0); - if(is_a($icServer, 'defaultimap')) { + if(($icServer instanceof defaultimap)) { if($icServer->enableSieve) { $linkData = array @@ -737,7 +737,7 @@ class felamimail_hooks } if (is_object($preferences)) $ogServer = $preferences->getOutgoingServer(0); - if(is_a($ogServer, 'defaultsmtp')) { + if(($ogServer instanceof defaultsmtp)) { if($ogServer->editForwardingAddress) { $linkData = array diff --git a/felamimail/inc/class.uifelamimail.inc.php b/felamimail/inc/class.uifelamimail.inc.php index a47a4e40f0..d5e07d037e 100644 --- a/felamimail/inc/class.uifelamimail.inc.php +++ b/felamimail/inc/class.uifelamimail.inc.php @@ -528,7 +528,7 @@ $refreshURL = $GLOBALS['egw']->link('/index.php',$linkData); $this->t->set_var('reloadView',$refreshURL); // display a warning if vacation notice is active - if(is_a($imapServer,'defaultimap') && $imapServer->enableSieve) { + if(($imapServer instanceof defaultimap) && $imapServer->enableSieve) { $this->bosieve = CreateObject('felamimail.bosieve',$imapServer); $this->bosieve->retrieveRules($this->bosieve->scriptName); $vacation = $this->bosieve->getVacation($this->bosieve->scriptName); diff --git a/felamimail/inc/class.uipreferences.inc.php b/felamimail/inc/class.uipreferences.inc.php index 3fe173e3ac..a9912e4915 100644 --- a/felamimail/inc/class.uipreferences.inc.php +++ b/felamimail/inc/class.uipreferences.inc.php @@ -108,7 +108,7 @@ $mailPrefs = $this->bofelamimail->getMailPreferences(); $ogServer = $mailPrefs->getOutgoingServer(0); - if(!is_a($ogServer, 'defaultsmtp') || !$ogServer->editForwardingAddress) { + if(!($ogServer instanceof defaultsmtp) || !$ogServer->editForwardingAddress) { die('You should not be here!'); } diff --git a/felamimail/inc/class.uisieve.inc.php b/felamimail/inc/class.uisieve.inc.php new file mode 100644 index 0000000000..6ab4eeb243 --- /dev/null +++ b/felamimail/inc/class.uisieve.inc.php @@ -0,0 +1,1133 @@ + True, + 'addScript' => True, + 'deactivateScript' => True, + 'decreaseFilter' => True, + 'deleteScript' => True, + 'editRule' => True, + 'editScript' => True, + 'editVacation' => True, + 'increaseFilter' => True, + 'listScripts' => True, + 'listRules' => True, + 'updateRules' => True, + 'updateVacation' => True, + 'saveVacation' => True, + 'selectFolder' => True, + '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 + * + * @var boolean + */ + var $timed_vacation; + //var $scriptName = 'felamimail'; + + /** + * @var bosieve + */ + var $bosieve; + + var $errorStack; + + function uisieve() + { + if(empty($GLOBALS['egw_info']['user']['preferences']['felamimail']['sieveScriptName'])) { + $GLOBALS['egw']->preferences->add('felamimail','sieveScriptName','felamimail', 'forced'); + $GLOBALS['egw']->preferences->save_repository(); + } + $this->scriptName = (!empty($GLOBALS['egw_info']['user']['preferences']['felamimail']['sieveScriptName'])) ? $GLOBALS['egw_info']['user']['preferences']['felamimail']['sieveScriptName'] : 'felamimail' ; + + $this->displayCharset = $GLOBALS['egw']->translation->charset(); + + $this->t =& CreateObject('phpgwapi.Template',EGW_APP_TPL); + $this->botranslation = $GLOBALS['egw']->translation; + + $this->bopreferences =& CreateObject('felamimail.bopreferences'); + $this->mailPreferences = $this->bopreferences->getPreferences(); + + $this->felamimailConfig = config::read('felamimail'); + + $this->restoreSessionData(); + + $icServer = $this->mailPreferences->getIncomingServer(0); + + if(($icServer instanceof defaultimap) && $icServer->enableSieve) { + $this->bosieve =& CreateObject('felamimail.bosieve',$icServer); + $this->timed_vacation = ($icServer instanceof cyrusimap) && $icServer->enableCyrusAdmin && + $icServer->adminUsername && $icServer->adminPassword; + } else { + die('Sieve not activated'); + } + + $this->rowColor[0] = $GLOBALS['egw_info']["theme"]["bg01"]; + $this->rowColor[1] = $GLOBALS['egw_info']["theme"]["bg02"]; + } + + function addScript() { + if($scriptName = $_POST['newScriptName']) { + #$script =& CreateObject('felamimail.Script',$scriptName); + #$script->updateScript($this->sieve); + $this->bosieve->installScript($scriptName, ''); + + // always activate and then edit the first script added + #if ($this->sieve->listscripts() && count($this->sieve->scriptlist) == 1) + #{ + # if ($this->sieve->activatescript($scriptName)) + # { + # $GLOBALS['egw']->redirect_link('/index.php',array( + # 'menuaction' => 'felamimail.uisieve.editScript', + # 'scriptname' => $scriptName, + # )); + # } + #} + } + + $this->listScripts(); + } + +# function activateScript() +# { +# $scriptName = $_GET['scriptname']; +# if(!empty($scriptName)) +# { +# if($this->bosieve->setActive($scriptName)) +# { +# #print "Successfully changed active script!
"; +# } +# else +# { +# #print "Unable to change active script!
"; +# /* we could display the full output here */ +# } +# } +# +# $this->listScripts(); +# } + + function buildRule($rule) + { + $andor = ' '. lang('and') .' '; + $started = 0; + if ($rule['anyof']) $andor = ' '. lang('or') .' '; + $complete = lang('IF').' '; + if ($rule['unconditional']) $complete = "[Unconditional] "; + + if ($rule['from']) + { + $match = $this->setMatchType($rule['from'],$rule['regexp']); + $complete .= "'From:' " . $match . " '" . $rule['from'] . "'"; + $started = 1; + } + if ($rule['to']) + { + if ($started) $complete .= $andor; + $match = $this->setMatchType($rule['to'],$rule['regexp']); + $complete .= "'To:' " . $match . " '" . $rule['to'] . "'"; + $started = 1; + } + if ($rule['subject']) + { + if ($started) $complete .= $andor; + $match = $this->setMatchType($rule['subject'],$rule['regexp']); + $complete .= "'Subject:' " . $match . " '" . $rule['subject'] . "'"; + $started = 1; + } + if ($rule['field'] && $rule['field_val']) + { + if ($started) $complete .= $andor; + $match = $this->setMatchType($rule['field_val'],$rule['regexp']); + $complete .= "'" . $rule['field'] . "' " . $match . " '" . $rule['field_val'] . "'"; + $started = 1; + } + if ($rule['size']) + { + $xthan = " less than '"; + if ($rule['gthan']) $xthan = " greater than '"; + if ($started) $complete .= $andor; + $complete .= "message " . $xthan . $rule['size'] . "KB'"; + $started = 1; + } + if (!$rule['unconditional']) $complete .= ' '.lang('THEN').' '; + if (preg_match("/folder/i",$rule['action'])) + $complete .= lang('file into')." '" . $rule['action_arg'] . "';"; + if (preg_match("/reject/i",$rule['action'])) + $complete .= lang('reject with')." '" . $rule['action_arg'] . "'."; + if (preg_match("/address/i",$rule['action'])) + $complete .= lang('forward to').' ' . $rule['action_arg'] .'.'; + if (preg_match("/discard/i",$rule['action'])) + $complete .= lang('discard').'.'; + if ($rule['continue']) $complete .= " [Continue]"; + if ($rule['keep']) $complete .= " [Keep a copy]"; + + return $complete; + } + + function buildVacationString($_vacation) + { +# global $script; +# $vacation = $script->vacation; + $vacation_str = ''; + if (!is_array($_vacation)) + { + return @htmlspecialchars($vacation_str, ENT_QUOTES, $GLOBALS['egw']->translation->charset()); + } + + $vacation_str .= lang('Respond'); + if (is_array($_vacation['addresses']) && $_vacation['addresses'][0]) + { + $vacation_str .= ' ' . lang('to mail sent to') . ' '; + $first = true; + foreach ($_vacation['addresses'] as $addr) + { + if (!$first) $vacation_str .= ', '; + $vacation_str .= $addr; + $first = false; + } + } + if (!empty($_vacation['days'])) + { + $vacation_str .= ' ' . lang("every %1 days",$_vacation['days']); + } + $vacation_str .= ' ' . lang('with message "%1"',$_vacation['text']); + return @htmlspecialchars($vacation_str, ENT_QUOTES, $GLOBALS['egw']->translation->charset()); + } + + function checkRule($_vacation) + { + $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)) + { + $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)) + { + $this->errorStack['forwards'] = lang('One address is not valid'.'!'); + } + } + } + + if(count($this->errorStack) == 0) + { + return true; + } + else + { + return false; + } + } + +# // RalfBecker: that does obviously nothing +# function deactivateScript() +# { +# $scriptName = get_var('scriptname',array('GET')); +# if(!empty($scriptName)) +# { +# #if($this->sieve->activatescript($scriptName)) +# #{ +# # #print "Successfully changed active script!
"; +# #} +# #else +# #{ +# # #print "Unable to change active script!
"; +# # /* we could display the full output here */ +# #} +# } +# +# $this->listScripts(); +# } + + function decreaseFilter() + { + $this->getRules(); /* ADDED BY GHORTH */ + $ruleID = get_var('ruleID',array('GET')); + if ($this->rules[$ruleID] && $this->rules[$ruleID+1]) + { + $tmp = $this->rules[$ruleID+1]; + $this->rules[$ruleID+1] = $this->rules[$ruleID]; + $this->rules[$ruleID] = $tmp; + } + + $this->updateScript(); + + $this->saveSessionData(); + + $this->listRules(); + } + + function display_app_header() { + if(preg_match('/^(vacation|filter)$/',get_var('editmode',array('GET')))) + $editMode = get_var('editmode',array('GET')); + else + $editMode = 'filter'; + + $GLOBALS['egw']->js->validate_file('tabs','tabs'); + $GLOBALS['egw']->js->validate_file('jscode','editProfile','felamimail'); + $GLOBALS['egw']->js->validate_file('jscode','listSieveRules','felamimail'); + $GLOBALS['egw']->js->set_onload("javascript:initAll('$editMode');"); + if($_GET['menuaction'] == 'felamimail.uisieve.editRule') { + $GLOBALS['egw']->js->set_onunload('opener.fm_sieve_cancelReload();'); + } + $GLOBALS['egw_info']['flags']['include_xajax'] = True; + $GLOBALS['egw']->common->egw_header(); + + switch($_GET['menuaction']) { + case 'felamimail.uisieve.editRule': + break; + default: + echo parse_navbar(); + break; + } + } + + function displayRule($_ruleID, $_ruleData, $msg='') { + $preferences = $this->mailPreferences; + // display the header + $this->display_app_header(); + $msg = html::purify($msg); + // initialize the template + $this->t->set_file(array("filterForm" => "sieveEditForm.tpl")); + $this->t->set_block('filterForm','main'); + $this->t->set_var('message',$msg); + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editRule', + 'ruleID' => $_ruleID + ); + $this->t->set_var('action_url',$GLOBALS['egw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.selectFolder', + ); + $this->t->set_var('folder_select_url',$GLOBALS['egw']->link('/index.php',$linkData)); + + if(is_array($_ruleData)) + { + if($_ruleData['continue']) + $this->t->set_var('continue_checked','checked'); + if($_ruleData['keep']) + $this->t->set_var('keep_checked','checked'); + if($_ruleData['regexp']) + $this->t->set_var('regexp_checked','checked'); + if(intval($_ruleData['anyof'])==1) + $_ruleData['anyof'] = 4; // set the anyof to 4 if set at all, as the template var anyof_selected is anyof_selected0 or anyof_selected4 + $this->t->set_var('anyof_selected'.intval($_ruleData['anyof']),'selected'); + $this->t->set_var('value_from',htmlspecialchars($_ruleData['from'], ENT_QUOTES, $GLOBALS['egw']->translation->charset())); + $this->t->set_var('value_to',htmlspecialchars($_ruleData['to'], ENT_QUOTES, $GLOBALS['egw']->translation->charset())); + $this->t->set_var('value_subject',htmlspecialchars($_ruleData['subject'], ENT_QUOTES, $GLOBALS['egw']->translation->charset())); + $this->t->set_var('gthan_selected'.intval($_ruleData['gthan']),'selected'); + $this->t->set_var('value_size',$_ruleData['size']); + $this->t->set_var('value_field',htmlspecialchars($_ruleData['field'], ENT_QUOTES, $GLOBALS['egw']->translation->charset())); + $this->t->set_var('value_field_val',htmlspecialchars($_ruleData['field_val'], ENT_QUOTES, $GLOBALS['egw']->translation->charset())); + $this->t->set_var('checked_action_'.$_ruleData['action'],'checked'); + $this->t->set_var('value_'.$_ruleData['action'],$_ruleData['action_arg']); + if ($_ruleData['action'] == 'folder') + { + $this->t->set_var('folderName',$_ruleData['action_arg']); + } + if (($_ruleData['action'] == 'address') && + (!empty($preferences->preferences['prefpreventforwarding']) && + $preferences->preferences['prefpreventforwarding'] == 1 )) + { + $this->t->set_var('checked_action_address',''); + $this->t->set_var('value_address',lang('not allowed')); + } + } + $this->t->set_var('value_ruleID',$_ruleID); + + #$bofelamimail =& CreateObject('felamimail.bofelamimail',$this->displayCharset); + #$uiwidgets =& CreateObject('felamimail.uiwidgets'); + #$connectionStatus = $bofelamimail->openConnection(); + #$folders = $bofelamimail->getFolderObjects(false); + + #foreach($folders as $folderName => $folderDisplayName) + #{ + # $this->t->set_var('folderName',$folderName); + # $this->t->set_var('folderDisplayName',$folderDisplayName); + # $this->t->parse("folder_rows", 'folder', true); + #} + + // translate most of the parts + $this->translate(); + $this->t->pfp("out","main"); + } + + function editRule() + { + $preferences = $this->mailPreferences; + $msg = ''; + $error = 0; + $this->getRules(); /* ADDED BY GHORTH */ + + $ruleType = get_var('ruletype',array('GET')); + + if(isset($_POST['anyof'])) { + if(get_var('priority',array('POST')) != 'unset') { + $newRule['priority'] = get_var('priority',array('POST')); + } + $ruleID = get_var('ruleID',array('POST')); + if($ruleID == 'unset') + $ruleID = count($this->rules); + $newRule['priority'] = $ruleID*2+1; + $newRule['status'] = 'ENABLED'; + $newRule['from'] = get_var('from',array('POST')); + $newRule['to'] = get_var('to',array('POST')); + $newRule['subject'] = get_var('subject',array('POST')); + //$newRule['flg'] = get_var('???',array('POST')); + $newRule['field'] = get_var('field',array('POST')); + $newRule['field_val'] = get_var('field_val',array('POST')); + $newRule['size'] = intval(get_var('size',array('POST'))); + $newRule['continue'] = get_var('continue',array('POST')); + $newRule['gthan'] = intval(get_var('gthan',array('POST'))); + $newRule['anyof'] = intval(get_var('anyof',array('POST'))); + $newRule['keep'] = get_var('keep',array('POST')); + $newRule['regexp'] = get_var('regexp',array('POST')); + $newRule['unconditional'] = '0'; // what's this??? + + $newRule['flg'] = 0 ; + if( $newRule['continue'] ) { $newRule['flg'] += 1; } + if( $newRule['gthan'] ) { $newRule['flg'] += 2; } + if( $newRule['anyof'] ) { $newRule['flg'] += 4; } + if( $newRule['keep'] ) { $newRule['flg'] += 8; } + if( $newRule['regexp'] ) { $newRule['flg'] += 128; } + + switch(get_var('action',array('POST'))) + { + case 'reject': + $newRule['action'] = 'reject'; + $newRule['action_arg'] = get_var('reject',array('POST')); + break; + + case 'folder': + $newRule['action'] = 'folder'; + $newRule['action_arg'] = get_var('folder',array('POST')); + #$newRule['action_arg'] = $GLOBALS['egw']->translation->convert($newRule['action_arg'], $this->charset, 'UTF7-IMAP'); + break; + + case 'address': + if (empty($preferences->preferences['prefpreventforwarding']) || + $preferences->preferences['prefpreventforwarding'] == 0 ) + { + $newRule['action'] = 'address'; + $newRule['action_arg'] = get_var('address',array('POST')); + } + else + { + $msg .= lang('Error creating rule while trying to use forward/redirect.'); + $error++; + } + break; + + case 'discard': + $newRule[action] = 'discard'; + break; + } + if($newRule['action']) { + + $this->rules[$ruleID] = $newRule; + + $this->bosieve->setRules($this->scriptName, $this->rules); + + $this->saveSessionData(); + } else { + $msg .= "\n".lang("Error: Could not save rule"); + $error++; + } + // refresh the list + $js = "opener.location.href = '".addslashes(egw::link('/index.php','menuaction=felamimail.uisieve.listRules'))."';"; + if(isset($_POST['save']) && $error == 0) { + echo "\n"; + } else { + $GLOBALS['egw']->js->set_onload($js); + $this->displayRule($ruleID, $newRule, $msg); + } + } + else + { + if(isset($_GET['ruleID'])) + { + $ruleID = get_var('ruleID',Array('GET')); + $ruleData = $this->rules[$ruleID]; + $this->displayRule($ruleID, $ruleData); + } + else + { + $this->displayRule('unset', false); + } + #LK $this->sieve->disconnet(); + } + } + + function editVacation() { + $preferences = $this->mailPreferences; + if(!(empty($preferences->preferences['prefpreventabsentnotice']) || $preferences->preferences['prefpreventabsentnotice'] == 0)) + { + die('You should not be here!'); + } + $uiwidgets =& CreateObject('felamimail.uiwidgets',EGW_APP_TPL); + $boemailadmin = new emailadmin_bo(); + + if ($this->timed_vacation) + { + include_once(EGW_API_INC.'/class.jscalendar.inc.php'); + $jscal = new jscalendar(); + } + if($this->bosieve->getScript($this->scriptName)) + { + 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 ($GLOBALS['egw_info']['user']['apps']['admin']) + { + // store text as default + if (isset($_POST['set_as_default'])) + { + $config = new config('felamimail'); + $config->save_value('default_vacation_text',$_POST['vacation_text'],'felamimail'); + } + $this->t->set_var('set_as_default',''); + } + if(isset($_POST["vacationStatus"])) + { + $newVacation['text'] = get_var('vacation_text',array('POST')); + $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 defaultsmtp) || $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) + { + $date = $jscal->input2date($_POST['start_date']); + if ($date['raw']) $newVacation['start_date'] = $date['raw']-12*3600; + $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)) + { + if (!$this->bosieve->setVacation($this->scriptName, $newVacation)) + { + print "vacation update failed
"; + #print $script->errstr."
"; + } + } + else + { + $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'); + } + + // 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'], '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(); + foreach($allIdentities as $key => $singleIdentity) { + 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'); + + #LK $this->bosieve->disconnect(); + } + + function editEmailNotification() { + $preferences = ExecMethod('felamimail.bopreferences.getPreferences'); + if(!(empty($preferences->preferences['prefpreventnotificationformailviaemail']) || $preferences->preferences['prefpreventnotificationformailviaemail'] == 0)) + die('You should not be here!'); + + $uiwidgets =& CreateObject('felamimail.uiwidgets',EGW_APP_TPL); + $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 + } + + + // perform actions + if (isset($_POST["emailNotificationStatus"])) { + if (isset($_POST['save']) || isset($_POST['apply'])) { + //$newEmailNotification['text'] = $this->botranslation->convert($newVacation['text'],$this->displayCharset,'UTF-8'); + $newEmailNotification['status'] = get_var('emailNotificationStatus',array('POST')) == 'disabled' ? 'off' : 'on'; + $newEmailNotification['externalEmail'] = get_var('emailNotificationExternalEmail',array('POST')); + $newEmailNotification['displaySubject'] = get_var('emailNotificationDisplaySubject',array('POST')); + if (!$this->bosieve->setEmailNotification($this->scriptName, $newEmailNotification)) { + print lang("email notification update failed")."
"; + print $script->errstr."
"; + } + $emailNotification = $newEmailNotification; + } + 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','email_notification'); + + // translate most of the parts + $this->translate(); + $this->t->set_var("lang_yes",lang('yes')); + $this->t->set_var("lang_no",lang('no')); + + // email notification status + if ($emailNotification['status'] == 'on') $this->t->set_var('checked_active', ' checked'); + else $this->t->set_var('checked_disabled', ' checked'); + + // email notification display subject + if ($emailNotification['displaySubject'] == '1') $this->t->set_var('checked_yes', ' checked'); + else $this->t->set_var('checked_no', ' checked'); + + // email notification external email + $this->t->set_var('external_email', $emailNotification['externalEmail']); + + $this->t->set_var('email_notification_action_url',$GLOBALS['egw']->link('/index.php','menuaction=felamimail.uisieve.editEmailNotification')); + $this->t->pfp('out','email_notification'); + } + + function increaseFilter() + { + $this->getRules(); /* ADDED BY GHORTH */ + $ruleID = get_var('ruleID',array('GET')); + if ($this->rules[$ruleID] && $this->rules[$ruleID-1]) + { + $tmp = $this->rules[$ruleID-1]; + $this->rules[$ruleID-1] = $this->rules[$ruleID]; + $this->rules[$ruleID] = $tmp; + } + + $this->updateScript(); + + $this->saveSessionData(); + + $this->listRules(); + } + + function listRules() + { + $preferences = ExecMethod('felamimail.bopreferences.getPreferences'); + if(!(empty($preferences->preferences['prefpreventeditfilterrules']) || $preferences->preferences['prefpreventeditfilterrules'] == 0)) + die('You should not be here!'); + + $uiwidgets =& CreateObject('felamimail.uiwidgets', EGW_APP_TPL); + $boemailadmin = new emailadmin_bo(); + + $this->getRules(); /* ADDED BY GHORTH */ + + $this->saveSessionData(); + + // display the header + $this->display_app_header(); + + // initialize the template + $this->t->set_file(array('filterForm' => 'listRules.tpl')); + $this->t->set_block('filterForm','header'); + $this->t->set_block('filterForm','filterrow'); + + // translate most of the parts + $this->translate(); + + #if(!empty($this->scriptToEdit)) + #{ + $listOfImages = array( + 'up', + 'down' + ); + foreach ($listOfImages as $image) + { + $this->t->set_var('url_'.$image,$GLOBALS['egw']->common->image('felamimail',$image)); + } + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editRule', + 'ruletype' => 'filter' + ); + $this->t->set_var('url_add_rule',$GLOBALS['egw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editRule', + 'ruletype' => 'vacation' + ); + $this->t->set_var('url_add_vacation_rule',$GLOBALS['egw']->link('/index.php',$linkData)); + + foreach ($this->rules as $ruleID => $rule) + { + $this->t->set_var('filter_status',lang($rule[status])); + if($rule[status] == 'ENABLED') + { + $this->t->set_var('ruleCSS','sieveRowActive'); + } + else + { + $this->t->set_var('ruleCSS','sieveRowInActive'); + } + + $this->t->set_var('filter_text',htmlspecialchars($this->buildRule($rule),ENT_QUOTES,$GLOBALS['egw']->translation->charset())); + $this->t->set_var('ruleID',$ruleID); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editRule', + 'ruleID' => $ruleID, + ); + $this->t->set_var('url_edit_rule',$GLOBALS['egw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.increaseFilter', + 'ruleID' => $ruleID, + ); + $this->t->set_var('url_increase',$GLOBALS['egw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.decreaseFilter', + 'ruleID' => $ruleID, + ); + $this->t->set_var('url_decrease',$GLOBALS['egw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.updateRules', + ); + $this->t->set_var('action_rulelist',$GLOBALS['egw']->link('/index.php',$linkData)); + + $this->t->parse('filterrows','filterrow',true); + } + + #} + + $linkData = array ( + 'menuaction' => 'felamimail.uisieve.saveScript' + ); + $this->t->set_var('formAction',$GLOBALS['egw']->link('/index.php',$linkData)); + + $linkData = array ( + 'menuaction' => 'felamimail.uisieve.listRules' + ); + $this->t->set_var('refreshURL',$GLOBALS['egw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.listScripts', + 'scriptname' => $scriptName + ); + $this->t->set_var('url_back',$GLOBALS['egw']->link('/index.php',$linkData)); + + $this->t->pfp("out","header"); + + #LK $this->bosieve->disconnect(); + } + + function restoreSessionData() + { + $sessionData = $GLOBALS['egw']->session->appsession('sieve_session_data'); + + $this->rules = $sessionData['sieve_rules']; + $this->scriptToEdit = $sessionData['sieve_scriptToEdit']; + } + + function selectFolder() + { + $GLOBALS['egw']->js->validate_file('dhtmlxtree','js/dhtmlXCommon'); + $GLOBALS['egw']->js->validate_file('dhtmlxtree','js/dhtmlXTree'); + $GLOBALS['egw']->js->validate_file('jscode','editSieveRule','felamimail'); + $GLOBALS['egw']->common->egw_header(); + + $bofelamimail =& CreateObject('felamimail.bofelamimail',$this->displayCharset); + $uiwidgets =& CreateObject('felamimail.uiwidgets'); + $connectionStatus = $bofelamimail->openConnection(); + + $folderObjects = $bofelamimail->getFolderObjects(true,false); + $folderTree = $uiwidgets->createHTMLFolder + ( + $folderObjects, + 'INBOX', + 0, + lang('IMAP Server'), + $mailPreferences['username'].'@'.$mailPreferences['imapServerAddress'], + 'divFolderTree', + false, + true + ); + print '
'; + print $folderTree; + } + + function setMatchType (&$matchstr, $regex = false) + { + $match = lang('contains'); + if (preg_match("/\s*!/", $matchstr)) + $match = lang('does not contain'); + if (preg_match("/\*|\?/", $matchstr)) + { + $match = lang('matches'); + if (preg_match("/\s*!/", $matchstr)) + $match = lang('does not match'); + } + if ($regex) + { + $match = lang('matches regexp'); + if (preg_match("/\s*!/", $matchstr)) + $match = lang('does not match regexp'); + } + $matchstr = preg_replace("/^\s*!/","",$matchstr); + + return $match; + } + + function saveScript() + { + $scriptName = $_POST['scriptName']; + $scriptContent = $_POST['scriptContent']; + if(isset($scriptName) and isset($scriptContent)) + { + if($this->sieve->sieve_sendscript($scriptName, stripslashes($scriptContent))) + { + #print "Successfully loaded script onto server. (Remember to set it active!)
"; + } + else + { +/* print "Unable to load script to server. See server response below:
"; + if(is_array($sieve->error_raw)) + foreach($sieve->error_raw as $error_raw) + print $error_raw."
"; + else + print $sieve->error_raw."
"; + print "
"; + $textarea=stripslashes($script); + $textname=$scriptname; + $titleline="Try editing the script again! Create new script";*/ + } + } + $this->mainScreen(); + } + + function saveSessionData() + { + $sessionData['sieve_rules'] = $this->rules; + $sessionData['sieve_scriptToEdit'] = $this->scriptToEdit; + + $GLOBALS['egw']->session->appsession('sieve_session_data','',$sessionData); + } + + function translate() + { + $this->t->set_var("lang_message_list",lang('Message List')); + $this->t->set_var("lang_from",lang('from')); + $this->t->set_var("lang_to",lang('to')); + $this->t->set_var("lang_save",lang('save')); + $this->t->set_var("lang_apply",lang('apply')); + $this->t->set_var("lang_cancel",lang('cancel')); + $this->t->set_var("lang_active",lang('active')); + $this->t->set_var('lang_disabled',lang('disabled')); + $this->t->set_var('lang_status',lang('status')); + $this->t->set_var("lang_edit",lang('edit')); + $this->t->set_var("lang_delete",lang('delete')); + $this->t->set_var("lang_enable",lang('enable')); + $this->t->set_var("lang_rule",lang('rule')); + $this->t->set_var("lang_disable",lang('disable')); + $this->t->set_var("lang_action",lang('action')); + $this->t->set_var("lang_condition",lang('condition')); + $this->t->set_var("lang_subject",lang('subject')); + $this->t->set_var("lang_filter_active",lang('filter active')); + $this->t->set_var("lang_filter_name",lang('filter name')); + $this->t->set_var("lang_new_filter",lang('new filter')); + $this->t->set_var("lang_no_filter",lang('no filter')); + $this->t->set_var("lang_add_rule",lang('add rule')); + $this->t->set_var("lang_add_script",lang('add script')); + $this->t->set_var("lang_back",lang('back')); + $this->t->set_var("lang_days",lang('days')); + $this->t->set_var("lang_save_changes",lang('save changes')); + $this->t->set_var("lang_extended",lang('extended')); + $this->t->set_var("lang_edit_vacation_settings",lang('edit vacation settings')); + $this->t->set_var("lang_every",lang('every')); + $this->t->set_var('lang_respond_to_mail_sent_to',lang('respond to mail sent to')); + $this->t->set_var('lang_filter_rules',lang('filter rules')); + $this->t->set_var('lang_vacation_notice',lang('vacation notice')); + $this->t->set_var("lang_with_message",lang('with message')); + $this->t->set_var("lang_script_name",lang('script name')); + $this->t->set_var("lang_script_status",lang('script status')); + $this->t->set_var("lang_delete_script",lang('delete script')); + $this->t->set_var("lang_check_message_against_next_rule_also",lang('check message against next rule also')); + $this->t->set_var("lang_keep_a_copy_of_the_message_in_your_inbox",lang('keep a copy of the message in your inbox')); + $this->t->set_var("lang_use_regular_expressions",lang('use regular expressions')); + $this->t->set_var("lang_match",lang('match')); + $this->t->set_var("lang_all_of",lang('all of')); + $this->t->set_var("lang_any_of",lang('any of')); + $this->t->set_var("lang_if_from_contains",lang('if from contains')); + $this->t->set_var("lang_if_to_contains",lang('if to contains')); + $this->t->set_var("lang_if_subject_contains",lang('if subject contains')); + $this->t->set_var("lang_if_message_size",lang('if message size')); + $this->t->set_var("lang_less_than",lang('less than')); + $this->t->set_var("lang_greater_than",lang('greater than')); + $this->t->set_var("lang_kilobytes",lang('kilobytes')); + $this->t->set_var("lang_if_mail_header",lang('if mail header')); + $this->t->set_var("lang_file_into",lang('file into')); + $this->t->set_var("lang_forward_to_address",lang('forward to address')); + $this->t->set_var("lang_send_reject_message",lang('send a reject message')); + $this->t->set_var("lang_discard_message",lang('discard message')); + $this->t->set_var("lang_select_folder",lang('select folder')); + $this->t->set_var("lang_vacation_forwards",lang('Forward messages to').'
'.lang('(separate multiple addresses by comma)').":"); + + $this->t->set_var("bg01",$GLOBALS['egw_info']["theme"]["bg01"]); + $this->t->set_var("bg02",$GLOBALS['egw_info']["theme"]["bg02"]); + $this->t->set_var("bg03",$GLOBALS['egw_info']["theme"]["bg03"]); + } + + function updateRules() + { + $this->getRules(); /* ADDED BY GHORTH */ + $action = get_var('rulelist_action',array('POST')); + $ruleIDs = get_var('ruleID',array('POST')); + $scriptName = get_var('scriptname',array('GET')); + + switch($action) + { + case 'enable': + if(is_array($ruleIDs)) + { + foreach($ruleIDs as $ruleID) + { + $this->rules[$ruleID][status] = 'ENABLED'; + } + } + break; + + case 'disable': + if(is_array($ruleIDs)) + { + foreach($ruleIDs as $ruleID) + { + $this->rules[$ruleID][status] = 'DISABLED'; + } + } + break; + + case 'delete': + if(is_array($ruleIDs)) + { + foreach($ruleIDs as $ruleID) + { + unset($this->rules[$ruleID]); + } + } + $this->rules = array_values($this->rules); + break; + } + + $this->updateScript(); + + $this->saveSessionData(); + + $this->listRules(); + } + + function updateScript() + { + if (!$this->bosieve->setRules($this->scriptToEdit, $this->rules)) { + print "update failed
";exit; + #LK print $script->errstr."
"; + } + } + + /* ADDED BY GHORTH */ + function getRules() + { + if($script = $this->bosieve->getScript($this->scriptName)) { + $this->scriptToEdit = $this->scriptName; + if(PEAR::isError($error = $this->bosieve->retrieveRules($this->scriptName)) ) { + $this->rules = array(); + $this->vacation = array(); + } else { + $this->rules = $this->bosieve->getRules($this->scriptName); + $this->vacation = $this->bosieve->getVacation($this->scriptName); + } + } else { + // something went wrong + } + } + } +?>