diff --git a/felamimail/inc/class.uicompose.inc.php b/felamimail/inc/class.uicompose.inc.php new file mode 100644 index 0000000000..810400145b --- /dev/null +++ b/felamimail/inc/class.uicompose.inc.php @@ -0,0 +1,310 @@ + 'True', + 'reply' => 'True', + 'replyAll' => 'True', + 'forward' => 'True', + 'action' => 'True' + ); + + function uicompose() + { + $this->displayCharset = $GLOBALS['phpgw']->translation->charset(); + if (!isset($GLOBALS['HTTP_POST_VARS']['composeid']) && !isset($GLOBALS['HTTP_GET_VARS']['composeid'])) + { + // create new compose session + $this->bocompose = CreateObject('felamimail.bocompose','',$this->displayCharset); + $this->composeID = $this->bocompose->getComposeID(); + } + else + { + // reuse existing compose session + if (isset($GLOBALS['HTTP_POST_VARS']['composeid'])) + $this->composeID = $GLOBALS['HTTP_POST_VARS']['composeid']; + else + $this->composeID = $GLOBALS['HTTP_GET_VARS']['composeid']; + $this->bocompose = CreateObject('felamimail.bocompose',$this->composeID,$this->displayCharset); + } + $this->t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); + $this->bofelamimail = CreateObject('felamimail.bofelamimail',$this->displayCharset); + $this->mailPreferences = ExecMethod('felamimail.bopreferences.getPreferences'); + + $this->t->set_unknowns('remove'); + + $this->rowColor[0] = $GLOBALS['phpgw_info']["theme"]["bg01"]; + $this->rowColor[1] = $GLOBALS['phpgw_info']["theme"]["bg02"]; + + + } + + function unhtmlentities ($string) + { + $trans_tbl = get_html_translation_table (HTML_ENTITIES); + $trans_tbl = array_flip ($trans_tbl); + return strtr ($string, $trans_tbl); + } + + function action() + { + $formData['to'] = $this->bocompose->stripSlashes($GLOBALS['HTTP_POST_VARS']['to']); + $formData['cc'] = $this->bocompose->stripSlashes($GLOBALS['HTTP_POST_VARS']['cc']); + $formData['bcc'] = $this->bocompose->stripSlashes($GLOBALS['HTTP_POST_VARS']['bcc']); + $formData['reply_to'] = $this->bocompose->stripSlashes($GLOBALS['HTTP_POST_VARS']['reply_to']); + $formData['subject'] = $this->bocompose->stripSlashes($GLOBALS['HTTP_POST_VARS']['subject']); + $formData['body'] = $this->bocompose->stripSlashes($GLOBALS['HTTP_POST_VARS']['body']); + $formData['priority'] = $this->bocompose->stripSlashes($GLOBALS['HTTP_POST_VARS']['priority']); + $formData['signature'] = $this->bocompose->stripSlashes($GLOBALS['HTTP_POST_VARS']['signature']); + $formData['mailbox'] = $GLOBALS['HTTP_GET_VARS']['mailbox']; + + if (isset($GLOBALS['HTTP_POST_VARS']['send'])) + { + $action="send"; + } + elseif (isset($GLOBALS['HTTP_POST_VARS']['addfile'])) + { + $action="addfile"; + } + elseif (isset($GLOBALS['HTTP_POST_VARS']['removefile'])) + { + $action="removefile"; + } + + switch ($action) + { + case "addfile": + $formData['name'] = $GLOBALS['HTTP_POST_FILES']['attachfile']['name']; + $formData['type'] = $GLOBALS['HTTP_POST_FILES']['attachfile']['type']; + $formData['file'] = $GLOBALS['HTTP_POST_FILES']['attachfile']['tmp_name']; + $formData['size'] = $GLOBALS['HTTP_POST_FILES']['attachfile']['size']; + $this->bocompose->addAttachment($formData); + $this->compose(); + break; + + case "removefile": + $formData['removeAttachments'] = $GLOBALS['HTTP_POST_VARS']['attachment']; + $this->bocompose->removeAttachment($formData); + $this->compose(); + break; + + case "send": + if(!$this->bocompose->send($formData)) + { + $this->compose(); + return; + } + + #$linkData = array + #( + # 'mailbox' => $GLOBALS['HTTP_GET_VARS']['mailbox'], + # 'startMessage' => '1' + #); + #$link = $GLOBALS['phpgw']->link('/felamimail/index.php',$linkData); + #$GLOBALS['phpgw']->redirect($link); + #$GLOBALS['phpgw']->common->phpgw_exit(); + if($this->mailPreferences['messageNewWindow']) + { + print ""; + } + else + { + ExecMethod('felamimail.uifelamimail.viewMainScreen'); + } + break; + } + } + + function compose($_focusElement="to") + { + // read the data from session + // all values are empty for a new compose window + $sessionData = $this->bocompose->getSessionData(); + $preferences = ExecMethod('felamimail.bopreferences.getPreferences'); + #_debug_array($preferences); + + // is the to address set already? + if (!empty($GLOBALS['HTTP_GET_VARS']['send_to'])) + { + $sessionData['to'] = base64_decode($_GET['send_to']); + } + + $this->display_app_header(); + + $this->t->set_file(array("composeForm" => "composeForm.tpl")); + $this->t->set_block('composeForm','header','header'); + $this->t->set_block('composeForm','body_input'); + $this->t->set_block('composeForm','attachment','attachment'); + $this->t->set_block('composeForm','attachment_row','attachment_row'); + $this->t->set_block('composeForm','attachment_row_bold'); + + $this->translate(); + + $this->t->set_var("link_addressbook",$GLOBALS['phpgw']->link('/felamimail/addressbook.php')); + $this->t->set_var("focusElement",$_focusElement); + + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.viewMainScreen' + ); + if($this->mailPreferences['messageNewWindow']) + { + $this->t->set_var("link_message_list","javascript:window.close();"); + } + else + { + $this->t->set_var("link_message_list",$GLOBALS['phpgw']->link('/felamimail/index.php',$linkData)); + } + + $linkData = array + ( + 'menuaction' => 'felamimail.uicompose.action', + 'composeid' => $this->composeID + ); + $this->t->set_var("link_action",$GLOBALS['phpgw']->link('/index.php',$linkData)); + $this->t->set_var('folder_name',$this->bofelamimail->sessionData['mailbox']); + + // check for some error messages from last posting attempt + if($errorInfo = $this->bocompose->getErrorInfo()) + { + $this->t->set_var('errorInfo',"$errorInfo"); + } + else + { + $this->t->set_var('errorInfo',' '); + } + + // header + $displayFrom = @htmlentities($preferences['emailAddress'][0][name].' <'.$preferences['emailAddress'][0][address].'>',ENT_QUOTES,$this->displayCharset); + $this->t->set_var("from",$displayFrom); + $this->t->set_var("to",@htmlentities($sessionData['to'],ENT_QUOTES,$this->displayCharset)); + $this->t->set_var("cc",@htmlentities($sessionData['cc'],ENT_QUOTES,$this->displayCharset)); + $this->t->set_var("bcc",@htmlentities($sessionData['bcc'],ENT_QUOTES,$this->displayCharset)); + $this->t->set_var("reply_to",@htmlentities($sessionData['reply_to'],ENT_QUOTES,$this->displayCharset)); + $this->t->set_var("subject",@htmlentities($sessionData['subject'],ENT_QUOTES,$this->displayCharset)); + $this->t->set_var('addressbookImage',$GLOBALS['phpgw']->common->image('phpgwapi/templates/phpgw_website','users')); + $this->t->pparse("out","header"); + + // body + $this->t->set_var("body",$sessionData['body']); + $this->t->set_var("signature",$sessionData['signature']); + $this->t->pparse("out","body_input"); + + // attachments + if (is_array($sessionData['attachments']) && count($sessionData['attachments']) > 0) + { + $this->t->set_var('row_color',$this->rowColor[0]); + $this->t->set_var('name',lang('name')); + $this->t->set_var('type',lang('type')); + $this->t->set_var('size',lang('size')); + $this->t->parse('attachment_rows','attachment_row_bold',True); + while (list($key,$value) = each($sessionData['attachments'])) + { + #print "$key : $value
"; + $this->t->set_var('row_color',$this->rowColor[($key+1)%2]); + $this->t->set_var('name',$value['name']); + $this->t->set_var('type',$value['type']); + $this->t->set_var('size',$value['size']); + $this->t->set_var('attachment_number',$key); + $this->t->parse('attachment_rows','attachment_row',True); + } + } + else + { + $this->t->set_var('attachment_rows',''); + } + + $this->t->pparse("out","attachment"); + } + + function display_app_header() + { + $GLOBALS['phpgw']->common->phpgw_header(); + if(!$this->mailPreferences['messageNewWindow']) + echo parse_navbar(); + } + + function forward() + { + $replyID = $GLOBALS['HTTP_GET_VARS']['reply_id']; + $partID = $_GET['part_id']; + + if (!empty($replyID)) + { + // this fill the session data with the values from the original email + $this->bocompose->getForwardData($replyID, $partID, + $this->bofelamimail->sessionData['mailbox']); + } + $this->compose(); + } + + function reply() + { + $replyID = $_GET['reply_id']; + $partID = $_GET['part_id']; + if (!empty($replyID)) + { + // this fill the session data with the values from the original email + $this->bocompose->getReplyData('single', $replyID, $partID); + } + $this->compose(@htmlentities('body')); + } + + function replyAll() + { + $replyID = $GLOBALS['HTTP_GET_VARS']['reply_id']; + $partID = $_GET['part_id']; + if (!empty($replyID)) + { + // this fill the session data with the values from the original email + $this->bocompose->getReplyData('all', $replyID, $partID); + } + $this->compose('body'); + } + + function translate() + { + $this->t->set_var("lang_message_list",lang('Message List')); + $this->t->set_var("lang_to",lang('to')); + $this->t->set_var("lang_cc",lang('cc')); + $this->t->set_var("lang_bcc",lang('bcc')); + $this->t->set_var("lang_from",lang('from')); + $this->t->set_var("lang_reply_to",lang('reply to')); + $this->t->set_var("lang_subject",lang('subject')); + $this->t->set_var("lang_addressbook",lang('addressbook')); + $this->t->set_var("lang_search",lang('search')); + $this->t->set_var("lang_send",lang('send')); + $this->t->set_var("lang_back_to_folder",lang('back to folder')); + $this->t->set_var("lang_attachments",lang('attachments')); + $this->t->set_var("lang_add",lang('add')); + $this->t->set_var("lang_remove",lang('remove')); + $this->t->set_var("lang_priority",lang('priority')); + $this->t->set_var("lang_normal",lang('normal')); + $this->t->set_var("lang_high",lang('high')); + $this->t->set_var("lang_low",lang('low')); + $this->t->set_var("lang_signature",lang('signature')); + + $this->t->set_var("th_bg",$GLOBALS['phpgw_info']["theme"]["th_bg"]); + $this->t->set_var("bg01",$GLOBALS['phpgw_info']["theme"]["bg01"]); + $this->t->set_var("bg02",$GLOBALS['phpgw_info']["theme"]["bg02"]); + $this->t->set_var("bg03",$GLOBALS['phpgw_info']["theme"]["bg03"]); + } +} + +?> diff --git a/felamimail/inc/class.uidisplay.inc.php b/felamimail/inc/class.uidisplay.inc.php new file mode 100644 index 0000000000..6c31ffd11d --- /dev/null +++ b/felamimail/inc/class.uidisplay.inc.php @@ -0,0 +1,927 @@ + + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + */ + + /* $Id$ */ + + class uidisplay + { + + var $public_functions = array + ( + 'display' => 'True', + 'showHeader' => 'True', + 'getAttachment' => 'True' + ); + + function uidisplay() + { + $this->t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); + $this->displayCharset = $GLOBALS['phpgw']->translation->charset(); + $this->bofelamimail = CreateObject('felamimail.bofelamimail',$this->displayCharset); + $this->bofilter = CreateObject('felamimail.bofilter'); + $this->bopreferences = CreateObject('felamimail.bopreferences'); + $this->kses = CreateObject('phpgwapi.kses'); + $this->botranslation = CreateObject('phpgwapi.translation'); + + $this->mailPreferences = $this->bopreferences->getPreferences(); + + $this->bofelamimail->openConnection(); + + $this->mailbox = $this->bofelamimail->sessionData['mailbox']; + $this->sort = $this->bofelamimail->sessionData['sort']; + + $this->uid = $GLOBALS['HTTP_GET_VARS']['uid']; + + if(isset($GLOBALS['HTTP_GET_VARS']['part']) && + is_numeric($GLOBALS['HTTP_GET_VARS']['part'])) + { + $this->partID = $GLOBALS['HTTP_GET_VARS']['part']; + } + else + { + $this->partID = 0; + } + + $this->bocaching = CreateObject('felamimail.bocaching', + $this->mailPreferences['imapServerAddress'], + $this->mailPreferences['username'], + $this->mailbox); + + $this->rowColor[0] = $GLOBALS['phpgw_info']["theme"]["bg01"]; + $this->rowColor[1] = $GLOBALS['phpgw_info']["theme"]["bg02"]; + + if($GLOBALS['HTTP_GET_VARS']['showHeader'] == "false") + { + $this->bofelamimail->sessionData['showHeader'] = 'False'; + $this->bofelamimail->saveSessionData(); + } + + } + + function createLinks($_data) + { + + } + + function highlightQuotes($text, $level = 5) + { + // Use a global var since the class is called statically. + $GLOBALS['_tmp_maxQuoteChars'] = 0; + + // Tack a newline onto the beginning of the string so that we + // correctly highlight when the first character in the string + // is a quote character. + $text = "\n$text"; + + preg_replace_callback("/^\s*((>\s?)+)/m", array(&$this, '_countQuoteChars'), $text); + + // Go through each level of quote block and put the + // appropriate style around it. Important to work downwards so + // blocks with fewer quote chars aren't matched until their + // turn. + for ($i = $GLOBALS['_tmp_maxQuoteChars']; $i > 0; $i--) + { + $text = preg_replace( + // Finds a quote block across multiple newlines. + "/(\n)( *(>\s?)\{$i}(?! ?>).*?)(\n|$)(?! *(> ?)\{$i})/s", + '\1\2\4',$text); + } + + /* Unset the global variable. */ + unset($GLOBALS['_tmp_maxQuoteChars']); + + /* Remove the leading newline we added above. */ + return substr($text, 1); + } + + function _countQuoteChars($matches) + { + $num = count(preg_split('/>\s?/', $matches[1])) - 1; + if ($num > $GLOBALS['_tmp_maxQuoteChars']) + { + $GLOBALS['_tmp_maxQuoteChars'] = $num; + } + } + + function display() + { + $partID = $_GET['part']; + $transformdate = CreateObject('felamimail.transformdate'); + $htmlFilter = CreateObject('felamimail.htmlfilter'); + + $headers = $this->bofelamimail->getMessageHeader($this->uid, $partID); + $rawheaders = $this->bofelamimail->getMessageRawHeader($this->uid, $partID); + $bodyParts = $this->bofelamimail->getMessageBody($this->uid,'',$partID); + $attachments = $this->bofelamimail->getMessageAttachments($this->uid,$partID); + $filterList = $this->bofilter->getFilterList(); + $activeFilter = $this->bofilter->getActiveFilter(); + $filter = $filterList[$activeFilter]; + $nextMessage = $this->bocaching->getNextMessage($this->uid, $this->sort, $filter); + + $webserverURL = $GLOBALS['phpgw_info']['server']['webserver_url']; + + #print "
";print_r($rawheaders);print"
";exit; + + // add line breaks to $rawheaders + $newRawHeaders = explode("\n",$rawheaders); + reset($newRawHeaders); + // find the Organization header + // the header can also span multiple rows + while(is_array($newRawHeaders) && list($key,$value) = each($newRawHeaders)) + { + #print $value."
"; + if(preg_match("/Organization: (.*)/",$value,$matches)) + { + $organization = $this->bofelamimail->decode_header(chop($matches[1])); + #$organization = chop($matches[1]); + continue; + } + if(!empty($organization) && preg_match("/^\s+(.*)/",$value,$matches)) + { + $organization .= $this->bofelamimail->decode_header(chop($matches[1])); + break; + } + elseif(!empty($organization)) + { + break; + } + } + + // reset $rawheaders + $rawheaders = ""; + // create it new, with good line breaks + reset($newRawHeaders); + while(list($key,$value) = @each($newRawHeaders)) + { + $rawheaders .= wordwrap($value,90,"\n "); + } + + $this->bofelamimail->closeConnection(); + + if(!isset($_GET['printable'])) + { + $this->display_app_header(); + $this->t->set_file(array("displayMsg" => "view_message.tpl")); + } + else + { + $this->t->set_file(array("displayMsg" => "view_message_printable.tpl")); + $this->t->set_var('charset',$GLOBALS['phpgw']->translation->charset()); + } + + $this->t->set_block('displayMsg','message_main'); + $this->t->set_block('displayMsg','message_header'); + $this->t->set_block('displayMsg','message_raw_header'); + $this->t->set_block('displayMsg','message_navbar'); + $this->t->set_block('displayMsg','message_onbehalfof'); + $this->t->set_block('displayMsg','message_cc'); + $this->t->set_block('displayMsg','message_attachement_row'); + $this->t->set_block('displayMsg','previous_message_block'); + $this->t->set_block('displayMsg','next_message_block'); + $this->t->set_block('displayMsg','message_org'); + + $this->t->egroupware_hack = False; + + $this->translate(); + +// if(!isset($GLOBALS['HTTP_GET_VARS']['printable'])) +// { + // navbar + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.viewMainScreen' + ); + if($this->mailPreferences['messageNewWindow']) + { + $this->t->set_var("link_message_list","javascript:window.close();"); + } + else + { + $this->t->set_var("link_message_list",$GLOBALS['phpgw']->link('/felamimail/index.php',$linkData)); + } + + $linkData = array + ( + 'menuaction' => 'felamimail.uicompose.compose' + ); + $this->t->set_var("link_compose",$GLOBALS['phpgw']->link('/index.php',$linkData)); + $this->t->set_var('folder_name',$this->bofelamimail->sessionData['mailbox']); + + // return link to main message + if($partID != '') + { + $linkData = array + ( + 'menuaction' => 'felamimail.uidisplay.display', + 'showHeader' => 'false', + 'uid' => $this->uid + ); + $this->t->set_var('link_mainmessage',''.lang('mainmessage').''); + } + else + { + $this->t->set_var('link_mainmessage',''); + } + + $linkData = array + ( + 'menuaction' => 'felamimail.uicompose.reply', + 'reply_id' => $this->uid, + ); + if($partID != '') + $linkData['part_id'] = $partID; + $this->t->set_var("link_reply",$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uicompose.replyAll', + 'reply_id' => $this->uid, + ); + if($partID != '') + $linkData['part_id'] = $partID; + $this->t->set_var("link_reply_all",$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uicompose.forward', + 'reply_id' => $this->uid + ); + if($partID != '') + $linkData['part_id'] = $partID; + $this->t->set_var("link_forward",$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.deleteMessage', + 'message' => $this->uid + ); + $this->t->set_var("link_delete",$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uidisplay.showHeader', + 'uid' => $this->uid + ); + $this->t->set_var("link_header",$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uidisplay.display', + 'printable' => 1, + 'uid' => $this->uid + ); + if($partID != '') + $linkData['part'] = $partID; + $this->t->set_var("link_printable",$GLOBALS['phpgw']->link('/index.php',$linkData)); + + if($nextMessage['previous']) + { + $linkData = array + ( + 'menuaction' => 'felamimail.uidisplay.display', + 'showHeader' => 'false', + 'uid' => $nextMessage['previous'] + ); + $this->t->set_var('previous_url',$GLOBALS['phpgw']->link('/index.php',$linkData)); + $this->t->parse('previous_message','previous_message_block',True); + } + else + { + $this->t->set_var('previous_message',lang('previous message')); + } + + if($nextMessage['next']) + { + $linkData = array + ( + 'menuaction' => 'felamimail.uidisplay.display', + 'showHeader' => 'false', + 'uid' => $nextMessage['next'] + ); + $this->t->set_var('next_url',$GLOBALS['phpgw']->link('/index.php',$linkData)); + $this->t->parse('next_message','next_message_block',True); + } + else + { + $this->t->set_var('next_message',lang('next message')); + } + + $langArray = array + ( + 'lang_messagelist' => lang('Message List'), + 'lang_compose' => lang('Compose'), + 'lang_delete' => lang('Delete'), + 'lang_forward' => lang('Forward'), + 'lang_reply' => lang('Reply'), + 'lang_reply_all' => lang('Reply All'), + 'lang_back_to_folder' => lang('back to folder'), + 'print_navbar' => '', + 'app_image_path' => PHPGW_IMAGES + ); + $this->t->set_var($langArray); + $this->t->parse('navbar','message_navbar',True); +/* } + else + { + $langArray = array + ( + 'lang_print_this_page' => lang('print this page'), + 'lang_close_this_page' => lang('close this page'), + 'lang_printable' => '', + 'lang_reply' => lang('Reply'), + 'lang_reply_all' => lang('Reply All'), + 'lang_back_to_folder' => lang('back to folder'), + 'navbar' => '', + 'app_image_path' => PHPGW_IMAGES + ); + $this->t->set_var($langArray); + $this->t->parse('print_navbar','message_navbar_print',True); + }*/ + + // header + // sent by a mailinglist?? + // parse the from header + if($headers->senderaddress != $headers->fromaddress) + { + $senderAddress = $this->emailAddressToHTML($headers->senderaddress); + $fromAddress = $this->emailAddressToHTML($headers->fromaddress); + $this->t->set_var("from_data",$senderAddress); + # " ".lang('on behalf of')." ". + # $fromAddress); + $this->t->set_var("onbehalfof_data",$fromAddress); + $this->t->parse('on_behalf_of_part','message_onbehalfof',True); + } + else + { + $fromAddress = $this->emailAddressToHTML($headers->fromaddress); + $this->t->set_var("from_data", $fromAddress); + $this->t->set_var('on_behalf_of_part',''); + } + + // parse the to header + $toAddress = $this->emailAddressToHTML($headers->toaddress); + $this->t->set_var("to_data",$toAddress); + + // parse the cc header + if($headers->ccaddress) + { + $ccAddress = $this->emailAddressToHTML($headers->ccaddress); + $this->t->set_var("cc_data",$ccAddress); + $this->t->parse('cc_data_part','message_cc',True); + } + else + { + $this->t->set_var("cc_data_part",''); + } + + // parse the cc header + if(!empty($organization)) + { + $this->t->set_var("organization_data",$organization); + $this->t->parse('org_part','message_org',True); + } + else + { + $this->t->set_var("org_part",''); + } + + if (isset($headers->date)) + { + $headers->date = ereg_replace(' ', ' ', $headers->date); + $tmpdate = explode(' ', trim($headers->date)); + } + else + { + $tmpdate = $date = array("","","","","",""); + } + + $this->t->set_var("date_data", + @htmlspecialchars($GLOBALS['phpgw']->common->show_date($transformdate->getTimeStamp($tmpdate)), + ENT_QUOTES,$this->displayCharset)); + $this->t->set_var("subject_data", + @htmlspecialchars($this->bofelamimail->decode_header($headers->subject), + ENT_QUOTES,$this->displayCharset)); + //if(isset($organization)) exit; + $this->t->parse("header","message_header",True); + + $this->t->set_var("rawheader",@htmlentities($rawheaders,ENT_QUOTES,$this->displayCharset)); + + #$this->kses->AddProtocol("http"); + $this->kses->AddHTML( + "p",array( + 'align' => array("minlen" => 1, 'maxlen' => 10) + ) + ); + $this->kses->AddHTML("tbody"); + $this->kses->AddHTML("tt"); + $this->kses->AddHTML("br"); + $this->kses->AddHTML("b"); + $this->kses->AddHTML("i"); + $this->kses->AddHTML("strike"); + $this->kses->AddHTML("center"); + $this->kses->AddHTML( + "font",array( + "color" => array('maxlen' => 10) + ) + ); + $this->kses->AddHTML( + "hr",array( + "class" => array('maxlen' => 20) + ) + ); + $this->kses->AddHTML("div"); + $this->kses->AddHTML("ul"); + $this->kses->AddHTML( + "ol",array( + "type" => array('maxlen' => 20) + ) + ); + $this->kses->AddHTML("li"); + $this->kses->AddHTML("h1"); + $this->kses->AddHTML("h2"); + $this->kses->AddHTML( + "style",array( + "type" => array('maxlen' => 20) + ) + ); + $this->kses->AddHTML("select"); + $this->kses->AddHTML( + "option",array( + "value" => array('maxlen' => 45), + "selected" => array() + ) + ); + + $this->kses->AddHTML( + "a", array( + "href" => array('maxlen' => 145, 'minlen' => 10), + "name" => array('minlen' => 2), + 'target' => array('maxlen' => 10) + ) + ); + + $this->kses->AddHTML( + "pre", array( + "wrap" => array('maxlen' => 10) + ) + ); + + // Allows 'td' tag with colspan|rowspan|class|style|width|nowrap attributes, + // colspan has minval of 2 and maxval of 5 + // rowspan has minval of 3 and maxval of 6 + // class has minlen of 1 char and maxlen of 10 chars + // style has minlen of 10 chars and maxlen of 100 chars + // width has maxval of 100 + // nowrap is valueless + $this->kses->AddHTML( + "table",array( + "class" => array("minlen" => 1, 'maxlen' => 20), + "border" => array("minlen" => 1, 'maxlen' => 10), + "cellpadding" => array("minlen" => 0, 'maxlen' => 10), + "cellspacing" => array("minlen" => 0, 'maxlen' => 10), + "width" => array("maxlen" => 5), + "style" => array('minlen' => 10, 'maxlen' => 100), + "bgcolor" => array('maxlen' => 10), + "align" => array('maxlen' => 10), + "valign" => array('maxlen' => 10), + "bordercolor" => array('maxlen' => 10) + ) + ); + $this->kses->AddHTML( + "tr",array( + "colspan" => array('minval' => 2, 'maxval' => 5), + "rowspan" => array('minval' => 3, 'maxval' => 6), + "class" => array("minlen" => 1, 'maxlen' => 20), + "width" => array("maxlen" => 5), + "style" => array('minlen' => 10, 'maxlen' => 100), + "align" => array('maxlen' => 10), + 'bgcolor' => array('maxlen' => 10), + "valign" => array('maxlen' => 10), + "nowrap" => array('valueless' => 'y') + ) + ); + $this->kses->AddHTML( + "td",array( + "colspan" => array('minval' => 2, 'maxval' => 5), + "rowspan" => array('minval' => 3, 'maxval' => 6), + "class" => array("minlen" => 1, 'maxlen' => 20), + "width" => array("maxlen" => 5), + "style" => array('minlen' => 10, 'maxlen' => 100), + "align" => array('maxlen' => 10), + 'bgcolor' => array('maxlen' => 10), + "valign" => array('maxlen' => 10), + "nowrap" => array('valueless' => 'y') + ) + ); + $this->kses->AddHTML( + "th",array( + "colspan" => array('minval' => 2, 'maxval' => 5), + "rowspan" => array('minval' => 3, 'maxval' => 6), + "class" => array("minlen" => 1, 'maxlen' => 20), + "width" => array("maxlen" => 5), + "style" => array('minlen' => 10, 'maxlen' => 100), + "align" => array('maxlen' => 10), + "valign" => array('maxlen' => 10), + "nowrap" => array('valueless' => 'y') + ) + ); + $this->kses->AddHTML( + "span",array( + "class" => array("minlen" => 1, 'maxlen' => 20) + ) + ); + $this->kses->AddHTML( + "blockquote",array( + "class" => array("minlen" => 1, 'maxlen' => 20), + "style" => array("minlen" => 1), + "cite" => array('maxlen' => 30), + "type" => array('maxlen' => 10), + "dir" => array("minlen" => 1, 'maxlen' => 10) + ) + ); + + + + for($i=0; $ibotranslation->convert($bodyParts[$i]['body'], + strtolower($bodyParts[$i]['charSet'])); + + if($bodyParts[$i]['mimeType'] == 'text/plain') + { + $newBody = $bodyParts[$i]['body']; + + $newBody = @htmlentities($bodyParts[$i]['body'],ENT_QUOTES,$this->displayCharset); + $newBody = $this->bofelamimail->wordwrap($newBody,90,"\n"); + + // search http[s] links and make them as links available again + // to understand what's going on here, have a look at + // http://www.php.net/manual/en/function.preg-replace.php + + // create links for websites + $newBody = preg_replace("/((http(s?):\/\/)|(www\.))([\w,\-,\/,\?,\=,\.,&,!\n,!>,\%,@,\*,#,:,~,\+]+)/ie", + "'displayCharset\").'\" target=\"_blank\">$2$4$5'", $newBody); + + // create links for ftp sites + $newBody = preg_replace("/((ftp:\/\/)|(ftp\.))([\w\.,-.,\/.,\?.,\=.,&]+)/i", + "$1$3$4", $newBody); + + // create links for email addresses + $linkData = array + ( + 'menuaction' => 'felamimail.uicompose.compose' + ); + $link = $GLOBALS['phpgw']->link('/index.php',$linkData); + $newBody = preg_replace("/(?<=\s{1}|<)(([\w\.,-.,_.,0-9.]+)(@)([\w\.,-.,_.,0-9.]+))/ie", + "'$0'", $newBody); + + $newBody = $this->highlightQuotes($newBody); + $newBody = "
".$newBody."
"; + } + else + { + $newBody = $bodyParts[$i]['body']; + $newBody = $this->highlightQuotes($newBody); + $newBody = $this->kses->Parse($newBody); + + // create links for websites + #$newBody = preg_replace("/(?)((http(s?):\/\/)|(www\.))([\w,\-,\/,\?,\=,\.,&,!\n,\%,@,\*,#,:,~,\+]+)/ie", + # "'displayCharset\").'\" target=\"_blank\">$2$4$5'", $newBody); + $newBody = preg_replace("/(?|\/|\")((http(s?):\/\/)|(www\.))([\w,\-,\/,\?,\=,\.,&,!\n,\%,@,\*,#,:,~,\+]+)/ie", + "'displayCharset\").'\" target=\"_blank\">$2$4$5'", $newBody); + + // create links for websites + $newBody = preg_replace("/href=(\"|\')((http(s?):\/\/)|(www\.))([\w,\-,\/,\?,\=,\.,&,!\n,\%,@,\(,\),\*,#,:,~,\+]+)(\"|\')/ie", + "'href=\"$webserverURL/redirect.php?go='.@htmlentities(urlencode('http$4://$5$6'),ENT_QUOTES,\"$this->displayCharset\").'\" target=\"_blank\"'", $newBody); + + // create links for ftp sites + $newBody = preg_replace("/href=(\"|\')((ftp:\/\/)|(ftp\.))([\w\.,-.,\/.,\?.,\=.,&]+)(\"|\')/i", + "href=\"ftp://$4$5\" target=\"_blank\"", $newBody); + + // create links for email addresses + $linkData = array + ( + 'menuaction' => 'felamimail.uicompose.compose' + ); + $link = $GLOBALS['phpgw']->link('/index.php',$linkData); + $newBody = preg_replace("/href=(\"|\')mailto:([\w,\-,\/,\?,\=,\.,&,!\n,\%,@,\*,#,:,~,\+]+)(\"|\')/ie", + "'href=\"$link&send_to='.base64_encode('$2').'\"'", $newBody); + #print "
".htmlentities($newBody)."

"; + + $link = $GLOBALS['phpgw']->link('/index.php',$linkData); + #$newBody = preg_replace("/(?$0'", $newBody); + } + $body .= $newBody; + #print "
$body

"; + } + + // create links for windows shares + // \\\\\\\\ == '\\' in real life!! :) + $body = preg_replace("/(\\\\\\\\)([\w,\\\\,-]+)/i", + "$1$2", $body); + + + $this->t->set_var("body",$body); + $this->t->set_var("signature",$sessionData['signature']); + + // attachments + if(is_array($attachments)) + $this->t->set_var('attachment_count',count($attachments)); + else + $this->t->set_var('attachment_count','0'); + + if (is_array($attachments) && count($attachments) > 0) + { + $this->t->set_var('row_color',$this->rowColor[0]); + $this->t->set_var('name',lang('name')); + $this->t->set_var('type',lang('type')); + $this->t->set_var('size',lang('size')); + #$this->t->parse('attachment_rows','attachment_row_bold',True); + foreach ($attachments as $key => $value) + { + $this->t->set_var('row_color',$this->rowColor[($key+1)%2]); + $this->t->set_var('filename',@htmlentities($this->bofelamimail->decode_header($value['name']),ENT_QUOTES,$this->displayCharset)); + $this->t->set_var('mimetype',$value['mimeType']); + $this->t->set_var('size',$value['size']); + $this->t->set_var('attachment_number',$key); + + switch($value['mimeType']) + { + case 'message/rfc822': + $linkData = array + ( + 'menuaction' => 'felamimail.uidisplay.display', + 'uid' => $this->uid, + 'part' => $value['partID'] + ); + $target = ''; + break; + case 'image/jpeg': + case 'image/png': + case 'image/gif': + case 'application/pdf': + $linkData = array + ( + 'menuaction' => 'felamimail.uidisplay.getAttachment', + 'uid' => $this->uid, + 'part' => $value['partID'] + ); + $target = '_blank'; + break; + default: + $linkData = array + ( + 'menuaction' => 'felamimail.uidisplay.getAttachment', + 'uid' => $this->uid, + 'part' => $value['partID'] + ); + $target = ''; + break; + } + $this->t->set_var("link_view",$GLOBALS['phpgw']->link('/index.php',$linkData)); + $this->t->set_var("target",$target); + + $linkData = array + ( + 'menuaction' => 'felamimail.uidisplay.getAttachment', + 'mode' => 'save', + 'uid' => $this->uid, + 'part' => $value['partID'] + ); + $this->t->set_var("link_save",$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $this->t->parse('attachment_rows','message_attachement_row',True); + } + } + else + { + $this->t->set_var('attachment_rows',''); + } + + #$this->t->pparse("out","message_attachment_rows"); + + // print it out + $this->t->pparse("out","message_main"); + + } + + function display_app_header() + { + if(!@is_object($GLOBALS['phpgw']->js)) + { + $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); + } + $GLOBALS['phpgw']->js->validate_file('tabs','tabs'); + $GLOBALS['phpgw']->js->validate_file('jscode','view_message','felamimail'); + $GLOBALS['phpgw']->js->set_onload('javascript:initAll();'); + + $GLOBALS['phpgw']->common->phpgw_header(); + if(!$this->mailPreferences['messageNewWindow']) + { + echo parse_navbar(); + } + } + + function emailAddressToHTML($_emailAddress) + { + // create some nice formated HTML for senderaddress + if($_emailAddress == 'undisclosed-recipients: ;') + return $_emailAddress; + + $addressData = imap_rfc822_parse_adrlist + ($this->bofelamimail->decode_header($_emailAddress),''); + if(is_array($addressData)) + { + $senderAddress = ''; + while(list($key,$val)=each($addressData)) + { + if(!empty($senderAddress)) $senderAddress .= ", "; + if(!empty($val->personal)) + { + $tempSenderAddress = $val->mailbox."@".$val->host; + $newSenderAddress = imap_rfc822_write_address($val->mailbox, + $val->host, + $val->personal); + $linkData = array + ( + 'menuaction' => 'felamimail.uicompose.compose', + 'send_to' => base64_encode($newSenderAddress) + ); + $link = $GLOBALS['phpgw']->link('/index.php',$linkData); + $senderAddress .= sprintf('%s', + $link, + @htmlentities($newSenderAddress,ENT_QUOTES,$this->displayCharset), + @htmlentities($val->personal,ENT_QUOTES,$this->displayCharset)); + $linkData = array + ( + 'menuaction' => 'addressbook.uiaddressbook.add_email', + 'add_email' => $tempSenderAddress, + 'name' => $val->personal, + 'referer' => $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'] + ); + $urlAddToAddressbook = $GLOBALS['phpgw']->link('/index.php',$linkData); + $image = $GLOBALS['phpgw']->common->image('felamimail','sm_envelope'); + $senderAddress .= sprintf(' + %s', + $urlAddToAddressbook, + $image, + lang('add to addressbook'), + lang('add to addressbook')); + } + else + { + $tempSenderAddress = $val->mailbox."@".$val->host; + $linkData = array + ( + 'menuaction' => 'felamimail.uicompose.compose', + 'send_to' => base64_encode($tempSenderAddress) + ); + $link = $GLOBALS['phpgw']->link('/index.php',$linkData); + $senderAddress .= sprintf('%s', + $link,@htmlentities($tempSenderAddress,ENT_QUOTES,$this->displayCharset)); + $linkData = array + ( + 'menuaction' => 'addressbook.uiaddressbook.add_email', + 'add_email' => $tempSenderAddress, + 'referer' => $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'] + ); + $urlAddToAddressbook = $GLOBALS['phpgw']->link('/index.php',$linkData); + $image = $GLOBALS['phpgw']->common->image('felamimail','sm_envelope'); + $senderAddress .= sprintf(' + %s', + $urlAddToAddressbook, + $image, + lang('add to addressbook'), + lang('add to addressbook')); + } + } + return $senderAddress; + } + + // if something goes wrong, just return the original address + return $_emailAddress; + } + + function getAttachment() + { + + $part = $GLOBALS['HTTP_GET_VARS']['part']; + + $attachment = $this->bofelamimail->getAttachment($this->uid,$part); + + $this->bofelamimail->closeConnection(); + + header ("Content-Type: ".$attachment['type']."; name=\"".$attachment['filename']."\""); + if($GLOBALS['HTTP_GET_VARS']['mode'] == "save") + { + // ask for download + header ("Content-Disposition: attachment; filename=\"".$attachment['filename']."\""); + } + else + { + // display it + header ("Content-Disposition: inline; filename=\"".$attachment['filename']."\""); + } + header("Expires: 0"); + // the next headers are for IE and SSL + header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); + header("Pragma: public"); + + echo $attachment['attachment']; + + $GLOBALS['phpgw']->common->phpgw_exit(); + exit; + + } + + function showHeader() + { + if($this->bofelamimail->sessionData['showHeader'] == 'True') + { + $this->bofelamimail->sessionData['showHeader'] = 'False'; + } + else + { + $this->bofelamimail->sessionData['showHeader'] = 'True'; + } + $this->bofelamimail->saveSessionData(); + + $this->display(); + } + + function translate() + { + $this->t->set_var("lang_message_list",lang('Message List')); + $this->t->set_var("lang_to",lang('to')); + $this->t->set_var("lang_cc",lang('cc')); + $this->t->set_var("lang_bcc",lang('bcc')); + $this->t->set_var("lang_from",lang('from')); + $this->t->set_var("lang_reply_to",lang('reply to')); + $this->t->set_var("lang_subject",lang('subject')); + $this->t->set_var("lang_addressbook",lang('addressbook')); + $this->t->set_var("lang_search",lang('search')); + $this->t->set_var("lang_send",lang('send')); + $this->t->set_var("lang_back_to_folder",lang('back to folder')); + $this->t->set_var("lang_attachments",lang('attachments')); + $this->t->set_var("lang_add",lang('add')); + $this->t->set_var("lang_remove",lang('remove')); + $this->t->set_var("lang_priority",lang('priority')); + $this->t->set_var("lang_normal",lang('normal')); + $this->t->set_var("lang_high",lang('high')); + $this->t->set_var("lang_low",lang('low')); + $this->t->set_var("lang_signature",lang('signature')); + $this->t->set_var("lang_compose",lang('compose')); + $this->t->set_var("lang_date",lang('date')); + $this->t->set_var("lang_view",lang('view')); + $this->t->set_var("lang_organization",lang('organization')); + $this->t->set_var("lang_save",lang('save')); + $this->t->set_var("lang_printable",lang('print it')); + $this->t->set_var("lang_reply",lang('reply')); + $this->t->set_var("lang_reply_all",lang('reply all')); + $this->t->set_var("lang_forward",lang('forward')); + $this->t->set_var("lang_delete",lang('delete')); + $this->t->set_var("lang_previous_message",lang('previous message')); + $this->t->set_var("lang_next_message",lang('next message')); + $this->t->set_var("lang_organisation",lang('organisation')); + $this->t->set_var("lang_on_behalf_of",lang('on behalf of')); + + $this->t->set_var("th_bg",$GLOBALS['phpgw_info']["theme"]["th_bg"]); + $this->t->set_var("bg01",$GLOBALS['phpgw_info']["theme"]["bg01"]); + $this->t->set_var("bg02",$GLOBALS['phpgw_info']["theme"]["bg02"]); + $this->t->set_var("bg03",$GLOBALS['phpgw_info']["theme"]["bg03"]); + } +} + +?> diff --git a/felamimail/inc/class.uifelamimail.inc.php b/felamimail/inc/class.uifelamimail.inc.php new file mode 100644 index 0000000000..2b92932c8f --- /dev/null +++ b/felamimail/inc/class.uifelamimail.inc.php @@ -0,0 +1,1201 @@ + True, + 'changeFilter' => True, + 'changeFolder' => True, + 'changeSorting' => True, + 'compressFolder' => True, + 'deleteMessage' => True, + 'handleButtons' => True, + 'hookAdmin' => True, + 'toggleFilter' => True, + 'viewMainScreen' => True + ); + + var $mailbox; // the current folder in use + var $startMessage; // the first message to show + var $sort; // how to sort the messages + var $moveNeeded; // do we need to move some messages? + + function uifelamimail() + { + if(isset($GLOBALS['HTTP_POST_VARS']["mark_unread_x"])) + $GLOBALS['HTTP_POST_VARS']["mark_unread"] = "true"; + if(isset($GLOBALS['HTTP_POST_VARS']["mark_read_x"])) + $GLOBALS['HTTP_POST_VARS']["mark_read"] = "true"; + if(isset($GLOBALS['HTTP_POST_VARS']["mark_unflagged_x"])) + $GLOBALS['HTTP_POST_VARS']["mark_unflagged"] = "true"; + if(isset($GLOBALS['HTTP_POST_VARS']["mark_flagged_x"])) + $GLOBALS['HTTP_POST_VARS']["mark_flagged"] = "true"; + if(isset($GLOBALS['HTTP_POST_VARS']["mark_deleted_x"])) + $GLOBALS['HTTP_POST_VARS']["mark_deleted"] = "true"; + + $this->displayCharset = $GLOBALS['phpgw']->translation->charset(); + $this->bofelamimail = CreateObject('felamimail.bofelamimail',$this->displayCharset); + $this->bofilter = CreateObject('felamimail.bofilter'); + $this->bopreferences = CreateObject('felamimail.bopreferences'); + $this->preferences = $this->bopreferences->getPreferences(); + $this->botranslation = CreateObject('phpgwapi.translation'); + + if(isset($GLOBALS['HTTP_POST_VARS']["mailbox"]) && + $GLOBALS['HTTP_GET_VARS']["menuaction"] == "felamimail.uifelamimail.handleButtons" && + empty($GLOBALS['HTTP_POST_VARS']["mark_unread"]) && + empty($GLOBALS['HTTP_POST_VARS']["mark_read"]) && + empty($GLOBALS['HTTP_POST_VARS']["mark_unflagged"]) && + empty($GLOBALS['HTTP_POST_VARS']["mark_flagged"]) && + empty($GLOBALS['HTTP_POST_VARS']["mark_deleted"])) + { + if ($GLOBALS['HTTP_POST_VARS']["folderAction"] == "changeFolder") + { + // change folder + $this->bofelamimail->sessionData['mailbox'] = $GLOBALS['HTTP_POST_VARS']["mailbox"]; + $this->bofelamimail->sessionData['startMessage']= 1; + $this->bofelamimail->sessionData['sort'] = $this->preferences['sortOrder']; + $this->bofelamimail->sessionData['activeFilter']= -1; + } + elseif($GLOBALS['HTTP_POST_VARS']["folderAction"] == "moveMessage") + { + //print "move messages
"; + $this->bofelamimail->sessionData['mailbox'] = urldecode($GLOBALS['HTTP_POST_VARS']["oldMailbox"]); + $this->bofelamimail->sessionData['startMessage']= 1; + if (is_array($GLOBALS['HTTP_POST_VARS']["msg"])) + { + // we need to initialize the classes first + $this->moveNeeded = "1"; + } + } + } + elseif(isset($GLOBALS['HTTP_POST_VARS']["mailbox"]) && + $GLOBALS['HTTP_GET_VARS']["menuaction"] == "felamimail.uifelamimail.handleButtons" && + !empty($GLOBALS['HTTP_POST_VARS']["mark_deleted"])) + { + // delete messages + $this->bofelamimail->sessionData['startMessage']= 1; + } + elseif($GLOBALS['HTTP_GET_VARS']["menuaction"] == "felamimail.uifelamimail.deleteMessage") + { + // delete 1 message from the mail reading window + $this->bofelamimail->sessionData['startMessage']= 1; + } + elseif(isset($GLOBALS['HTTP_POST_VARS']["filter"]) || isset($GLOBALS['HTTP_GET_VARS']["filter"])) + { + // new search filter defined, lets start with message 1 + $this->bofelamimail->sessionData['startMessage']= 1; + } + + // navigate for and back + if(isset($GLOBALS['HTTP_GET_VARS']["startMessage"])) + { + $this->bofelamimail->sessionData['startMessage'] = $GLOBALS['HTTP_GET_VARS']["startMessage"]; + } + + $this->bofelamimail->saveSessionData(); + + $this->mailbox = $this->bofelamimail->sessionData['mailbox']; + $this->startMessage = $this->bofelamimail->sessionData['startMessage']; + $this->sort = $this->bofelamimail->sessionData['sort']; + #$this->filter = $this->bofelamimail->sessionData['activeFilter']; + + #$this->cats = CreateObject('phpgwapi.categories'); + #$this->nextmatchs = CreateObject('phpgwapi.nextmatchs'); + $this->t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); + #$this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE; + // this need to fixed + // this does not belong to here + if($_GET['menuaction'] != 'felamimail.uifelamimail.hookAdmin' && + $_GET['menuaction'] != 'felamimail.uifelamimail.changeFolder') + { + $this->connectionStatus = $this->bofelamimail->openConnection(); + } + + $this->rowColor[0] = $GLOBALS['phpgw_info']["theme"]["row_on"]; + $this->rowColor[1] = $GLOBALS['phpgw_info']["theme"]["row_off"]; + + $this->dataRowColor[0] = $GLOBALS['phpgw_info']["theme"]["bg01"]; + $this->dataRowColor[1] = $GLOBALS['phpgw_info']["theme"]["bg02"]; + } + + function addVcard() + { + $messageID = $GLOBALS['HTTP_GET_VARS']['messageID']; + $partID = $GLOBALS['HTTP_GET_VARS']['partID']; + $attachment = $this->bofelamimail->getAttachment($messageID,$partID); + + $tmpfname = tempnam ($GLOBALS['phpgw_info']['server']['temp_dir'], "phpgw_"); + $fp = fopen($tmpfname, "w"); + fwrite($fp, $attachment['attachment']); + fclose($fp); + + $vcard = CreateObject('phpgwapi.vcard'); + $entry = $vcard->in_file($tmpfname); + $entry['owner'] = $GLOBALS['phpgw_info']['user']['account_id']; + $entry['access'] = 'private'; + $entry['tid'] = 'n'; + + #_debug_array($entry); + #print "

"; + + print quoted_printable_decode($entry['fn'])."
"; + + #$boaddressbook = CreateObject('addressbook.boaddressbook'); + #$soaddressbook = CreateObject('addressbook.soaddressbook'); + #$soaddressbook->add_entry($entry); + #$ab_id = $boaddressbook->get_lastid(); + + unlink($tmpfname); + + $GLOBALS['phpgw']->common->phpgw_exit(); + } + + function changeFilter() + { + if(isset($GLOBALS['HTTP_POST_VARS']["filter"])) + { + $data['quickSearch'] = $GLOBALS['HTTP_POST_VARS']["quickSearch"]; + $data['filter'] = $GLOBALS['HTTP_POST_VARS']["filter"]; + $this->bofilter->updateFilter($data); + } + elseif(isset($GLOBALS['HTTP_GET_VARS']["filter"])) + { + $data['filter'] = $GLOBALS['HTTP_GET_VARS']["filter"]; + $this->bofilter->updateFilter($data); + } + $this->viewMainScreen(); + } + + function changeFolder() + { + // change folder + $this->bofelamimail->sessionData['mailbox'] = urldecode($_GET["mailbox"]); + $this->bofelamimail->sessionData['startMessage']= 1; + $this->bofelamimail->sessionData['sort'] = $this->preferences['sortOrder']; + $this->bofelamimail->sessionData['activeFilter']= -1; + + $this->bofelamimail->saveSessionData(); + + $this->mailbox = $this->bofelamimail->sessionData['mailbox']; + $this->startMessage = $this->bofelamimail->sessionData['startMessage']; + $this->sort = $this->bofelamimail->sessionData['sort']; + + $this->connectionStatus = $this->bofelamimail->openConnection(); + + $this->viewMainScreen(); + } + + function changeSorting() + { + // change sorting + if(isset($_GET["sort"])) + { + $this->bofelamimail->sessionData['sort'] = $_GET["sort"]; + $this->sort = $_GET["sort"]; + + $this->bofelamimail->saveSessionData(); + } + + $this->viewMainScreen(); + } + + function compressFolder() + { + $this->bofelamimail->compressFolder(); + $this->viewMainScreen(); + } + + function deleteMessage() + { + $preferences = ExecMethod('felamimail.bopreferences.getPreferences'); + + $message[] = $GLOBALS['HTTP_GET_VARS']["message"]; + + $this->bofelamimail->deleteMessages($message); + + // set the url to open when refreshing + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.viewMainScreen' + ); + $refreshURL = $GLOBALS['phpgw']->link('/index.php',$linkData); + + if($preferences['messageNewWindow']) + { + print ""; + } + else + { + $this->viewMainScreen(); + } + } + + function display_app_header() + { + if(!@is_object($GLOBALS['phpgw']->js)) + { + $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); + } + $GLOBALS['phpgw']->js->validate_file('foldertree','foldertree'); + $GLOBALS['phpgw']->common->phpgw_header(); + echo parse_navbar(); + } + + function handleButtons() + { + if($this->moveNeeded == "1") + { + $this->bofelamimail->moveMessages($GLOBALS['HTTP_POST_VARS']["mailbox"], + $GLOBALS['HTTP_POST_VARS']["msg"]); + } + + elseif(!empty($GLOBALS['HTTP_POST_VARS']["mark_deleted"]) && + is_array($GLOBALS['HTTP_POST_VARS']["msg"])) + { + $this->bofelamimail->deleteMessages($GLOBALS['HTTP_POST_VARS']["msg"]); + } + + elseif(!empty($GLOBALS['HTTP_POST_VARS']["mark_unread"]) && + is_array($GLOBALS['HTTP_POST_VARS']["msg"])) + { + $this->bofelamimail->flagMessages("unread",$GLOBALS['HTTP_POST_VARS']["msg"]); + } + + elseif(!empty($GLOBALS['HTTP_POST_VARS']["mark_read"]) && + is_array($GLOBALS['HTTP_POST_VARS']["msg"])) + { + $this->bofelamimail->flagMessages("read",$GLOBALS['HTTP_POST_VARS']["msg"]); + } + + elseif(!empty($GLOBALS['HTTP_POST_VARS']["mark_unflagged"]) && + is_array($GLOBALS['HTTP_POST_VARS']["msg"])) + { + $this->bofelamimail->flagMessages("unflagged",$GLOBALS['HTTP_POST_VARS']["msg"]); + } + + elseif(!empty($GLOBALS['HTTP_POST_VARS']["mark_flagged"]) && + is_array($GLOBALS['HTTP_POST_VARS']["msg"])) + { + $this->bofelamimail->flagMessages("flagged",$GLOBALS['HTTP_POST_VARS']["msg"]); + } + + + $this->viewMainScreen(); + } + + function hookAdmin() + { + if(!$GLOBALS['phpgw']->acl->check('run',1,'admin')) + { + $GLOBALS['phpgw']->common->phpgw_header(); + echo parse_navbar(); + echo lang('access not permitted'); + $GLOBALS['phpgw']->log->message('F-Abort, Unauthorized access to felamimail.uifelamimail.hookAdmin'); + $GLOBALS['phpgw']->log->commit(); + $GLOBALS['phpgw']->common->phpgw_exit(); + } + + if(!empty($_POST['profileID']) && is_int(intval($_POST['profileID']))) + { + $profileID = intval($_POST['profileID']); + $this->bofelamimail->setEMailProfile($profileID); + } + + $boemailadmin = CreateObject('emailadmin.bo'); + + $profileList = $boemailadmin->getProfileList(); + $profileID = $this->bofelamimail->getEMailProfile(); + + $this->display_app_header(); + + $this->t->set_file(array("body" => "selectprofile.tpl")); + $this->t->set_block('body','main'); + $this->t->set_block('body','select_option'); + + $this->t->set_var('lang_select_email_profile',lang('select emailprofile')); + $this->t->set_var('lang_site_configuration',lang('site configuration')); + $this->t->set_var('lang_save',lang('save')); + $this->t->set_var('lang_back',lang('back')); + + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.hookAdmin' + ); + $this->t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'emailadmin.ui.listProfiles' + ); + $this->t->set_var('emailadmin_url',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $this->t->set_var('back_url',$GLOBALS['phpgw']->link('/admin/index.php')); + + if(isset($profileList) && is_array($profileList)) + { + foreach($profileList as $key => $value) + { + #print "$key => $value
"; + #_debug_array($value); + $this->t->set_var('profileID',$value['profileID']); + $this->t->set_var('description',$value['description']); + if(is_int($profileID) && $profileID == $value['profileID']) + { + $this->t->set_var('selected','selected'); + } + else + { + $this->t->set_var('selected',''); + } + $this->t->parse('select_options','select_option',True); + } + } + + $this->t->parse("out","main"); + print $this->t->get('out','main'); + + } + + function viewMainScreen() + { + #printf ("this->uifelamimail->viewMainScreen() start: %s
",date("H:i:s",mktime())); + $bopreferences = CreateObject('felamimail.bopreferences'); + $preferences = $bopreferences->getPreferences(); + $bofilter = CreateObject('felamimail.bofilter'); + $mailPreferences = $bopreferences->getPreferences(); + + $urlMailbox = urlencode($this->mailbox); + + $maxMessages = $GLOBALS['phpgw_info']["user"]["preferences"]["common"]["maxmatchs"]; + + + $this->display_app_header(); + + $this->t->set_file(array("body" => 'mainscreen.tpl')); + $this->t->set_block('body','main'); + $this->t->set_block('body','status_row_tpl'); + $this->t->set_block('body','header_row'); + $this->t->set_block('body','error_message'); + $this->t->set_block('body','quota_block'); + $this->t->set_block('body','subject_same_window'); + $this->t->set_block('body','subject_new_window'); + + $this->translate(); + + $this->t->set_var('oldMailbox',$urlMailbox); + $this->t->set_var('image_path',PHPGW_IMAGES); + #printf ("this->uifelamimail->viewMainScreen() Line 272: %s
",date("H:i:s",mktime())); + // ui for the quotas + if($quota = $this->bofelamimail->getQuotaRoot()) + { + if($quota['limit'] == 0) + { + $quotaPercent=100; + } + else + { + $quotaPercent=round(($quota['usage']*100)/$quota['limit']); + } + $quotaLimit=$this->show_readable_size($quota['limit']*1024); + $quotaUsage=$this->show_readable_size($quota['usage']*1024); + + $this->t->set_var('leftWidth',$quotaPercent); + if($quotaPercent > 90) + { + $this->t->set_var('quotaBG','red'); + } + elseif($quotaPercent > 80) + { + $this->t->set_var('quotaBG','yellow'); + } + else + { + $this->t->set_var('quotaBG','#66ff66'); + } + + if($quotaPercent > 50) + { + $this->t->set_var('quotaUsage_right',' '); + $this->t->set_var('quotaUsage_left',$quotaUsage .'/'.$quotaLimit); + } + else + { + $this->t->set_var('quotaUsage_left',' '); + $this->t->set_var('quotaUsage_right',$quotaUsage .'/'.$quotaLimit); + } + + $this->t->parse('quota_display','quota_block',True); + } + else + { + $this->t->set_var('quota_display',' '); + } + + // set the images + $listOfImages = array( + 'read_small', + 'unread_small', + 'unread_flagged_small', + 'read_flagged_small', + 'trash', + 'sm_envelope', + 'write_mail', + 'manage_filter', + 'msg_icon_sm', + 'mail_find', + 'new' + ); + + foreach ($listOfImages as $image) + { + $this->t->set_var($image,$GLOBALS['phpgw']->common->image('felamimail',$image)); + } + // refresh settings + $refreshTime = $preferences['refreshTime']; + if($refreshTime > 0) + { + $this->t->set_var('refreshTime',sprintf("aktiv = window.setTimeout( \"refresh()\", %s );",$refreshTime*60*1000)); + } + else + { + $this->t->set_var('refreshTime',''); + } + // set the url to open when refreshing + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.viewMainScreen' + ); + $this->t->set_var('refresh_url',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + // define the sort defaults + $dateSort = '0'; + $dateCSS = 'text_small'; + $fromSort = '3'; + $fromCSS = 'text_small'; + $subjectSort = '5'; + $subjectCSS = 'text_small'; + $sizeSort = '6'; + $sizeCSS = 'text_small'; + + // and no overwrite the defaults + switch($this->sort) + { + // sort by date newest first + case '0': + $dateSort = '1'; + $dateCSS = 'text_small_bold'; + break; + // sort by date oldest first + case '1': + $dateSort = '0'; + $dateCSS = 'text_small_bold'; + break; + + // sort by from z->a + case '2': + $fromSort = '3'; + $fromCSS = 'text_small_bold'; + break; + // sort by from a->z + case '3': + $fromSort = '2'; + $fromCSS = 'text_small_bold'; + break; + + // sort by subject z->a + case '4': + $subjectSort = '5'; + $subjectCSS = 'text_small_bold'; + break; + // sort by subject a->z + case '5': + $subjectSort = '4'; + $subjectCSS = 'text_small_bold'; + break; + + // sort by size z->a + case '6': + $sizeSort = '7'; + $sizeCSS = 'text_small_bold'; + break; + // sort by subject a->z + case '7': + $sizeSort = '6'; + $sizeCSS = 'text_small_bold'; + break; + } + + // sort by date + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.changeSorting', + 'startMessage' => 1, + 'sort' => $dateSort + ); + $this->t->set_var('url_sort_date',$GLOBALS['phpgw']->link('/index.php',$linkData)); + $this->t->set_var('css_class_date',$dateCSS); + + // sort by from + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.changeSorting', + 'startMessage' => 1, + 'sort' => $fromSort + ); + $this->t->set_var('url_sort_from',$GLOBALS['phpgw']->link('/index.php',$linkData)); + $this->t->set_var('css_class_from',$fromCSS); + + // sort by subject + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.changeSorting', + 'startMessage' => 1, + 'sort' => $subjectSort + ); + $this->t->set_var('url_sort_subject',$GLOBALS['phpgw']->link('/index.php',$linkData)); + $this->t->set_var('css_class_subject',$subjectCSS); + + // sort by size + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.changeSorting', + 'startMessage' => 1, + 'sort' => $sizeSort + ); + $this->t->set_var('url_sort_size',$GLOBALS['phpgw']->link('/index.php',$linkData)); + $this->t->set_var('css_class_size',$sizeCSS); + + // create the filter ui + $filterList = $bofilter->getFilterList(); + $activeFilter = $bofilter->getActiveFilter(); + // -1 == no filter selected + if($activeFilter == -1) + $filterUI .= ""; + else + $filterUI .= ""; + while(list($key,$value) = @each($filterList)) + { + $selected=""; + if($activeFilter == $key) $selected="selected"; + $filterUI .= ""; + } + $this->t->set_var('filter_options',$filterUI); + // 0 == quicksearch + if($activeFilter == '0') + $this->t->set_var('quicksearch',$filterList[0]['subject']); + + if($this->connectionStatus != 'True') + { + $this->t->set_var('message',$this->connectionStatus); + $this->t->parse('header_rows','error_message',True); + } + else + { + $folders = $this->bofelamimail->getFolderList('true'); + + $headers = $this->bofelamimail->getHeaders($this->startMessage, $maxMessages, $this->sort); + + + $headerCount = count($headers['header']); + + if ($mailPreferences['sent_folder'] == $this->mailbox) + { + $this->t->set_var('lang_from',lang("to")); + } + else + { + $this->t->set_var('lang_from',lang("from")); + } + $msg_icon_sm = $GLOBALS['phpgw']->common->image('felamimail','msg_icon_sm'); + for($i=0; $i<$headerCount; $i++) + { + // create the listing of subjects + $maxSubjectLength = 60; + $maxAddressLength = 20; + $maxSubjectLengthBold = 50; + $maxAddressLengthBold = 14; + + $flags = ""; + if(!empty($headers['header'][$i]['recent'])) $flags .= "R"; + if(!empty($headers['header'][$i]['flagged'])) $flags .= "F"; + if(!empty($headers['header'][$i]['answered'])) $flags .= "A"; + if(!empty($headers['header'][$i]['deleted'])) $flags .= "D"; + if(!empty($headers['header'][$i]['seen'])) $flags .= "S"; + + switch($flags) + { + case "": + $this->t->set_var('imageName','unread_small.png'); + $this->t->set_var('row_text',lang('new')); + $maxAddressLength = $maxAddressLengthBold; + $maxSubjectLength = $maxSubjectLengthBold; + break; + case "D": + case "DS": + case "ADS": + $this->t->set_var('imageName','unread_small.png'); + $this->t->set_var('row_text',lang('deleted')); + break; + case "F": + $this->t->set_var('imageName','unread_flagged_small.png'); + $this->t->set_var('row_text',lang('new')); + $maxAddressLength = $maxAddressLengthBold; + break; + case "FS": + $this->t->set_var('imageName','read_flagged_small.png'); + $this->t->set_var('row_text',lang('replied')); + break; + case "FAS": + $this->t->set_var('imageName','read_answered_flagged_small.png'); + $this->t->set_var('row_text',lang('replied')); + break; + case "S": + case "RS": + $this->t->set_var('imageName','read_small.png'); + $this->t->set_var('row_text',lang('read')); + break; + case "R": + $this->t->set_var('imageName','recent_small.gif'); + $this->t->set_var('row_text','*'.lang('recent').'*'); + $maxAddressLength = $maxAddressLengthBold; + break; + case "RAS": + case "AS": + $this->t->set_var('imageName','read_answered_small.png'); + $this->t->set_var('row_text',lang('replied')); + #$maxAddressLength = $maxAddressLengthBold; + break; + default: + $this->t->set_var('row_text',$flags); + break; + } + #_debug_array($GLOBALS[phpgw_info]); + if (!empty($headers['header'][$i]['subject'])) + { + // make the subject shorter if it is to long + $fullSubject = $headers['header'][$i]['subject']; + #if(strlen($headers['header'][$i]['subject']) > $maxSubjectLength) + #{ + # $headers['header'][$i]['subject'] = substr($headers['header'][$i]['subject'],0,$maxSubjectLength)."..."; + #} + $headers['header'][$i]['subject'] = @htmlspecialchars($headers['header'][$i]['subject'],ENT_QUOTES,$this->displayCharset); + if($headers['header'][$i]['attachments'] == "true") + { + $image = ''; +//modified NDEE 29-12-03 for +//separate attachment icon + //$headers['header'][$i]['subject'] = "$image ".$headers['header'][$i]['subject']; + $headers['header'][$i]['attachment'] = $image; + } + $this->t->set_var('header_subject', $headers['header'][$i]['subject']); +// added + $this->t->set_var('attachments', $headers['header'][$i]['attachment']); + $this->t->set_var('full_subject',@htmlspecialchars($fullSubject,ENT_QUOTES,$this->displayCharset)); + } + else + { + $this->t->set_var('header_subject',@htmlentities("(".lang('no subject').")",ENT_QUOTES,$this->displayCharset)); + } + + if ($mailPreferences['sent_folder'] == $this->mailbox) + { + if (!empty($headers['header'][$i]['to_name'])) + { + $sender_name = $headers['header'][$i]['to_name']; + $full_address = + $headers['header'][$i]['to_name']. + " <". + $headers['header'][$i]['to_address']. + ">"; + } + else + { + $sender_name = $headers['header'][$i]['to_address']; + $full_address = $headers['header'][$i]['to_address']; + } + #$this->t->set_var('lang_from',lang("to")); + } + else + { + if (!empty($headers['header'][$i]['sender_name'])) + { + $sender_name = $headers['header'][$i]['sender_name']; + $full_address = @htmlentities( + $headers['header'][$i]['sender_name']. + " <". + $headers['header'][$i]['sender_address']. + ">",ENT_QUOTES,$this->displayCharset); + } + else + { + $sender_name = $headers['header'][$i]['sender_address']; + $full_address = $headers['header'][$i]['sender_address']; + } + #$this->t->set_var('lang_from',lang("from")); + } + #if(strlen($sender_name) > $maxAddressLength) + #{ + # $sender_name = substr($sender_name,0,$maxAddressLength)."..."; + #} + $this->t->set_var('sender_name',@htmlentities($sender_name, + ENT_QUOTES,$this->displayCharset)); + $this->t->set_var('full_address',$full_address); + + if($GLOBALS['HTTP_GET_VARS']["select_all"] == "select_all") + { + $this->t->set_var('row_selected',"checked"); + } + + $this->t->set_var('message_counter',$i); + $this->t->set_var('message_uid',$headers['header'][$i]['uid']); +// HINT: date style should be set according to preferences! + $this->t->set_var('date',$headers['header'][$i]['date']); + $this->t->set_var('size',$this->show_readable_size($headers['header'][$i]['size'])); + + $linkData = array + ( + 'menuaction' => 'felamimail.uidisplay.display', + 'showHeader' => 'false', + 'uid' => $headers['header'][$i]['uid'] + ); + if($preferences['messageNewWindow']) + { + $this->t->set_var('url_read_message',"javascript:displayMessage('".$GLOBALS['phpgw']->link('/index.php',$linkData)."');"); + } + else + { + $this->t->set_var('url_read_message',$GLOBALS['phpgw']->link('/index.php',$linkData)); + } + + if(!empty($headers['header'][$i]['sender_name'])) + { + list($mailbox, $host) = explode('@',$headers['header'][$i]['sender_address']); + $senderAddress = imap_rfc822_write_address($mailbox, + $host, + $headers['header'][$i]['sender_name']); + $linkData = array + ( + 'menuaction' => 'felamimail.uicompose.compose', + 'send_to' => base64_encode($senderAddress) + ); + } + else + { + $linkData = array + ( + 'menuaction' => 'felamimail.uicompose.compose', + 'send_to' => base64_encode($headers['header'][$i]['sender_address']) + ); + } + if($preferences['messageNewWindow']) + { + $this->t->set_var('url_compose',"javascript:displayMessage('".$GLOBALS['phpgw']->link('/index.php',$linkData)."');"); + } + else + { + $this->t->set_var('url_compose',$GLOBALS['phpgw']->link('/index.php',$linkData)); + } + + $linkData = array + ( + 'menuaction' => 'addressbook.uiaddressbook.add_email', + 'add_email' => urlencode($headers['header'][$i]['sender_address']), + 'name' => urlencode($headers['header'][$i]['sender_name']), + 'referer' => urlencode($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']) + ); + $this->t->set_var('url_add_to_addressbook',$GLOBALS['phpgw']->link('/index.php',$linkData)); + $this->t->set_var('msg_icon_sm',$msg_icon_sm); + + $this->t->set_var('phpgw_images',PHPGW_IMAGES); + $this->t->set_var('row_css_class','header_row_'.$flags); + + $this->t->parse('header_rows','header_row',True); + } + $firstMessage = $headers['info']['first']; + $lastMessage = $headers['info']['last']; + $totalMessage = $headers['info']['total']; + $langTotal = lang("total"); + } + + $this->t->set_var('maxMessages',$i); + if($GLOBALS['HTTP_GET_VARS']["select_all"] == "select_all") + { + $this->t->set_var('checkedCounter',$i); + } + else + { + $this->t->set_var('checkedCounter','0'); + } + + // set the select all/nothing link + if($GLOBALS['HTTP_GET_VARS']["select_all"] == "select_all") + { + // link to unselect all messages + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.viewMainScreen' + ); + $selectLink = sprintf("%s", + $GLOBALS['phpgw']->link('/index.php',$linkData), + lang("Unselect All")); + $this->t->set_var('change_folder_checked',''); + $this->t->set_var('move_message_checked','checked'); + } + else + { + // link to select all messages + $linkData = array + ( + 'select_all' => 'select_all', + 'menuaction' => 'felamimail.uifelamimail.viewMainScreen' + ); + $selectLink = sprintf("%s", + $GLOBALS['phpgw']->link('/index.php',$linkData), + lang("Select all")); + $this->t->set_var('change_folder_checked','checked'); + $this->t->set_var('move_message_checked',''); + } + $this->t->set_var('select_all_link',$selectLink); + + + // create the links for the delete options + // "delete all" in the trash folder + // "compress folder" in normal folders + if ($mailPreferences['trash_folder'] == $this->mailbox && + $mailPreferences['deleteOptions'] == "move_to_trash") + { + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.compressFolder' + ); + $trashLink = sprintf("%s", + $GLOBALS['phpgw']->link('/index.php',$linkData), + lang("delete all")); + + $this->t->set_var('trash_link',$trashLink); + } + elseif($mailPreferences['deleteOptions'] == "mark_as_deleted") + { + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.compressFolder' + ); + $trashLink = sprintf("%s", + $GLOBALS['phpgw']->link('/index.php',$linkData), + lang("compress folder")); + $this->t->set_var('trash_link',$trashLink); + } + + + $this->t->set_var('message',lang("Viewing messages")." $firstMessage - $lastMessage ($totalMessage $langTotal)"); + if($firstMessage > 1) + { + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.viewMainScreen', + 'startMessage' => $this->startMessage - $maxMessages + ); + $link = $GLOBALS['phpgw']->link('/index.php',$linkData); + $this->t->set_var('link_previous',"".lang("previous").""); + } + else + { + $this->t->set_var('link_previous',lang("previous")); + } + + if($totalMessage > $lastMessage) + { + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.viewMainScreen', + 'startMessage' => $this->startMessage + $maxMessages + ); + $link = $GLOBALS['phpgw']->link('/index.php',$linkData); + $this->t->set_var('link_next',"".lang("next").""); + } + else + { + $this->t->set_var('link_next',lang("next")); + } + $this->t->parse('status_row','status_row_tpl',True); + + @reset($folders); + +// Start of the new folder tree system +// 29-12-2003 NDEE +// ToDo +// check how many mails in folder +// different style of parsing folders into file +// open to active folder on reload + + $folderImageDir = substr($GLOBALS['phpgw']->common->image('phpgwapi','foldertree_line.gif'),0,-19); + + // careful! "d = new..." MUST be on a new line!!! + $folder_tree_new = ""; + + $this->t->set_var('current_mailbox',$current_mailbox); + $this->t->set_var('folder_tree',$folder_tree_new); + $this->t->set_var('foldertree_image_path',PHPGW_IMAGES_DIR.'/foldertree/'); + +// Finish of the new folder tree system + + $this->t->set_var('options_folder',$options_folder); + + $linkData = array + ( + 'menuaction' => 'felamimail.uicompose.compose' + ); + if($preferences['messageNewWindow']) + { + $this->t->set_var('url_compose_empty',"javascript:displayMessage('".$GLOBALS['phpgw']->link('/index.php',$linkData)."');"); + } + else + { + $this->t->set_var('url_compose_empty',$GLOBALS['phpgw']->link('/index.php',$linkData)); + } + + + $linkData = array + ( + 'menuaction' => 'felamimail.uifilter.mainScreen' + ); + $this->t->set_var('url_filter',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.handleButtons' + ); + $this->t->set_var('url_change_folder',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uifelamimail.changeFilter' + ); + $this->t->set_var('url_search_settings',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $this->t->set_var('lang_mark_messages_as',lang('mark messages as')); + $this->t->set_var('lang_delete',lang('delete')); + + $this->t->parse("out","main"); + print $this->t->get('out','main'); + + if($this->connectionStatus == 'True') + { + $this->bofelamimail->closeConnection(); + } + $GLOBALS['phpgw']->common->phpgw_footer(); + + } + +function array_merge_replace( $array, $newValues ) { + foreach ( $newValues as $key => $value ) { + if ( is_array( $value ) ) { + if ( !isset( $array[ $key ] ) ) { + $array[ $key ] = array(); + } + $array[ $key ] = $this->array_merge_replace( $array[ $key ], $value ); + } else { + if ( isset( $array[ $key ] ) && is_array( $array[ $key ] ) ) { + $array[ $key ][ 0 ] = $value; + } else { + if ( isset( $array ) && !is_array( $array ) ) { + $temp = $array; + $array = array(); + $array[0] = $temp; + } + $array[ $key ] = $value; + } + } + } + return $array; +} + + /* Returns a string showing the size of the message/attachment */ + function show_readable_size($bytes, $_mode='short') + { + $bytes /= 1024; + $type = 'k'; + + if ($bytes / 1024 > 1) + { + $bytes /= 1024; + $type = 'M'; + } + + if ($bytes < 10) + { + $bytes *= 10; + settype($bytes, 'integer'); + $bytes /= 10; + } + else + settype($bytes, 'integer'); + + return $bytes . ' ' . $type ; + } + + function toggleFilter() + { + $this->bofelamimail->toggleFilter(); + $this->viewMainScreen(); + } + + function translate() + { + $this->t->set_var('th_bg',$GLOBALS['phpgw_info']["theme"]["th_bg"]); + $this->t->set_var('bg_01',$GLOBALS['phpgw_info']["theme"]["bg01"]); + $this->t->set_var('bg_02',$GLOBALS['phpgw_info']["theme"]["bg02"]); + + $this->t->set_var('lang_compose',lang('compose')); + $this->t->set_var('lang_edit_filter',lang('edit filter')); + $this->t->set_var('lang_move_selected_to',lang('move selected to')); + $this->t->set_var('lang_doit',lang('do it!')); + $this->t->set_var('lang_change_folder',lang('change folder')); + $this->t->set_var('lang_move_message',lang('move messages')); + $this->t->set_var('desc_read',lang("mark selected as read")); + $this->t->set_var('desc_unread',lang("mark selected as unread")); + $this->t->set_var('desc_important',lang("mark selected as flagged")); + $this->t->set_var('desc_unimportant',lang("mark selected as unflagged")); + $this->t->set_var('desc_deleted',lang("delete selected")); + $this->t->set_var('lang_date',lang("date")); + $this->t->set_var('lang_size',lang("size")); + $this->t->set_var('lang_quicksearch',lang("Quicksearch")); + $this->t->set_var('lang_replied',lang("replied")); + $this->t->set_var('lang_read',lang("read")); + $this->t->set_var('lang_unread',lang("unread")); + $this->t->set_var('lang_deleted',lang("deleted")); + $this->t->set_var('lang_recent',lang("recent")); + $this->t->set_var('lang_flagged',lang("flagged")); + $this->t->set_var('lang_unflagged',lang("unflagged")); + $this->t->set_var('lang_subject',lang("subject")); + $this->t->set_var('lang_add_to_addressbook',lang("add to addressbook")); + $this->t->set_var('lang_no_filter',lang("no filter")); + $this->t->set_var('lang_connection_failed',lang("The connection to the IMAP Server failed!!")); + $this->t->set_var('lang_select_target_folder',lang("Simply click the target-folder")); + $this->t->set_var('lang_open_all',lang("open all")); + $this->t->set_var('lang_close_all',lang("close all")); + } + } +?> diff --git a/felamimail/inc/class.uisieve.inc.php b/felamimail/inc/class.uisieve.inc.php new file mode 100644 index 0000000000..53a4fbf38f --- /dev/null +++ b/felamimail/inc/class.uisieve.inc.php @@ -0,0 +1,1177 @@ + True, + 'addScript' => True, + 'deactivateScript' => True, + 'decreaseFilter' => True, + 'deleteScript' => True, + 'editRule' => True, + 'editScript' => True, + 'increaseFilter' => True, + 'listScripts' => True, + 'updateRules' => True, + 'updateVacation' => True, + 'saveVacation' => True + ); + + function uisieve() + { + $this->displayCharset = $GLOBALS['phpgw']->translation->charset(); + + $this->t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); + + $this->bopreferences = CreateObject('felamimail.bopreferences'); + $this->mailPreferences = $this->bopreferences->getPreferences(); + + #$this->bopreferences = CreateObject('felamimail.bopreferences'); + #$this->mailPreferences = $this->bopreferences->getPreferences(); + + + $config = CreateObject('phpgwapi.config','felamimail'); + $config->read_repository(); + $this->felamimailConfig = $config->config_data; + unset($config); + + $this->restoreSessionData(); + + $sieveHost = $this->mailPreferences["imapSieveServer"]; + $sievePort = $this->mailPreferences["imapSievePort"]; + $username = $this->mailPreferences['username']; + $password = $this->mailPreferences['key']; + $this->sieve = CreateObject('felamimail.SieveSession',$sieveHost, $sievePort, $username, $password); + if(!$this->sieve->start()) + { + print "bad thing!!
"; + } + + $this->rowColor[0] = $GLOBALS['phpgw_info']["theme"]["bg01"]; + $this->rowColor[1] = $GLOBALS['phpgw_info']["theme"]["bg02"]; + + } + + function addScript() + { + if($scriptName = get_var('newScriptName',Array('POST'))) + { + $script = CreateObject('felamimail.Script',$scriptName); + $script->updateScript($this->sieve); + } + + $this->listScripts(); + } + + function activateScript() + { + $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 buildRule($rule) + { + $andor = " AND "; + $started = 0; + if ($rule['anyof']) $andor = " 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 .= "reject '" . $rule['action_arg'] . "';"; + if (preg_match("/address/i",$rule['action'])) + $complete .= "forward to '" . $rule['action_arg'] . "';"; + if (preg_match("/discard/i",$rule['action'])) + $complete .= "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); + } + + $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); + } + + 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(count($this->errorStack) == 0) + { + return true; + } + else + { + return false; + } + } + + 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() + { + $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->editScript(); + } + + function deleteScript() + { + $scriptName = get_var('scriptname',array('GET')); + if(!empty($scriptName)) + { + if($this->sieve->deletescript($scriptName)) + { + # alles ok! + } + } + + $this->listScripts(); + } + + function display_app_header() + { + if(!@is_object($GLOBALS['phpgw']->js)) + { + $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript'); + } + if(preg_match('/^(vacation|filter)$/',get_var('editmode',array('GET')))) + $editMode = get_var('editmode',array('GET')); + else + $editMode = 'filter'; + + $GLOBALS['phpgw']->js->validate_file('tabs','tabs'); +# switch($_GET['menuaction']) +# { +# case 'felamimail.uisieve.editScript': +# case 'felamimail.uisieve.editRule': +# case 'felamimail.uisieve.updateRules': + $GLOBALS['phpgw']->js->validate_file('jscode','editProfile','felamimail'); + $GLOBALS['phpgw']->js->set_onload("javascript:initAll('$editMode');"); +# +# break; +# } + $GLOBALS['phpgw']->common->phpgw_header(); + echo parse_navbar(); + } + + function displayRule($_scriptName, $_ruleID, $_ruleData) + { + // display the header + $this->display_app_header(); + + // initialize the template + $this->t->set_file(array("filterForm" => "sieveEditForm.tpl")); + $this->t->set_block('filterForm','main'); + $this->t->set_block('filterForm','folder'); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editRule', + 'scriptname' => $_scriptName + ); + $this->t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editScript', + 'scriptname' => $_scriptName + ); + $this->t->set_var('url_back',$GLOBALS['phpgw']->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'); + $this->t->set_var('anyof_selected'.intval($_ruleData['anyof']),'selected'); + $this->t->set_var('value_from',$_ruleData['from']); + $this->t->set_var('value_to',$_ruleData['to']); + $this->t->set_var('value_subject',$_ruleData['subject']); + $this->t->set_var('gthan_selected'.intval($_ruleData['gthan']),'selected'); + $this->t->set_var('value_size',$_ruleData['size']); + $this->t->set_var('value_field',$_ruleData['field']); + $this->t->set_var('value_field_val',$_ruleData['field_val']); + $this->t->set_var('checked_action_'.$_ruleData['action'],'checked'); + $this->t->set_var('value_'.$_ruleData['action'],$_ruleData['action_arg']); + } + $this->t->set_var('value_ruleID',$_ruleID); + + $bofelamimail = CreateObject('felamimail.bofelamimail',$this->displayCharset); + $connectionStatus = $bofelamimail->openConnection(); + $folders = $bofelamimail->getFolderList(false); + #if($connectionStatus == 'True') + #{ + # $this->bofelamimail->closeConnection(); + #} + + #_debug_array($folders); + 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() + { + $scriptName = get_var('scriptname',array('GET')); + $ruleType = get_var('ruletype',array('GET')); + + if(isset($_POST[anyof])) + { + if(get_var('priority',array('POST')) != 'unset') + { + $newRule[prioritiy] = get_var('priority',array('POST')); + } + $ruleID = get_var('ruleID',array('POST')); + if($ruleID == 'unset') + $ruleID = count($this->rules); + $newRule[prioritiy] = $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??? + + 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')); + break; + + case 'address': + $newRule[action] = 'address'; + $newRule[action_arg] = get_var('address',array('POST')); + break; + + case 'discard': + $newRule[action] = 'discard'; + break; + } + + if($newRule[action]) + { + $this->rules[$ruleID] = $newRule; + + $this->updateScript(); + + $this->saveSessionData(); + } + + $this->editScript(); + } + else + { + if(isset($_GET['ruleID'])) + { + $ruleID = get_var('ruleID',Array('GET')); + $ruleData = $this->rules[$ruleID]; + $this->displayRule($scriptName, $ruleID, $ruleData); + } + else + { + $this->displayRule($scriptName, 'unset', false); + } + $this->sieve->close(); + } + } + + function editScript() + { + $scriptName = get_var('scriptname',array('GET')); + if(empty($scriptName)) + { + $this->sieve->listscripts(); + if(!empty($this->sieve->activescript)) + { + $scriptName = $this->sieve->activescript; + } + else + { + $this->listScripts(); + $GLOBALS['phpgw']->common->phpgw_exit(); + } + } + + $uiwidgets = CreateObject('felamimail.uiwidgets',PHPGW_APP_TPL); + $script = CreateObject('felamimail.Script',$scriptName); + $boemailadmin = CreateObject('emailadmin.bo'); + + + if($this->sieve->getscript($scriptName)) + { + $this->scriptToEdit = $scriptName; + if (!$script->retrieveRules($this->sieve)) + { + print "can't receive script
"; + } + else + { + $this->rules = $script->rules; + $this->vacation = $script->vacation; + } + } + else + { + #print "Unable to change active script!
"; + /* we could display the full output here */ + $this->listScripts(); + $GLOBALS['phpgw']->common->phpgw_exit(); + } + + $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','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['phpgw']->common->image('felamimail',$image)); + } + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editRule', + 'scriptname' => $scriptName, + 'ruletype' => 'filter' + ); + $this->t->set_var('url_add_rule',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editRule', + 'scriptname' => $scriptName, + 'ruletype' => 'vacation' + ); + $this->t->set_var('url_add_vacation_rule',$GLOBALS['phpgw']->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',$this->buildRule($rule)); + $this->t->set_var('ruleID',$ruleID); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editRule', + 'ruleID' => $ruleID, + 'scriptname' => $scriptName + ); + $this->t->set_var('url_edit_rule',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.increaseFilter', + 'ruleID' => $ruleID, + 'scriptname' => $scriptName + ); + $this->t->set_var('url_increase',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.decreaseFilter', + 'ruleID' => $ruleID, + 'scriptname' => $scriptName + ); + $this->t->set_var('url_decrease',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.updateRules', + 'scriptname' => $scriptName + ); + $this->t->set_var('action_rulelist',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $this->t->parse('filterrows','filterrow',true); + } + + // vacation settings + + // vacation status + if($this->vacation[status] == 'on') + { + $this->t->set_var('ruleCSS','sieveRowActive'); + $this->t->set_var('lang_vacation_status',lang('enabled')); + $this->t->set_var('css_enabled','sieveRowInActive'); + $this->t->set_var('css_disabled','sieveRowActive'); + } + else + { + $this->t->set_var('ruleCSS','sieveRowInActive'); + $this->t->set_var('lang_vacation_status',lang('disabled')); + $this->t->set_var('css_enabled','sieveRowActive'); + $this->t->set_var('css_disabled','sieveRowInActive'); + } + + // vacation text + $this->t->set_var('vacation_text',$this->vacation['text']); + + //vacation days + $this->t->set_var('selected_'.$this->vacation['days'],'selected="selected"'); + + // vacation addresses + if(is_array($this->vacation['addresses'])) + { + foreach($this->vacation['addresses'] as $address) + { + $selectedAddresses[$address] = $address; + } + asort($selectedAddresses); + } + + // all local addresses + if($emailAddresses = $boemailadmin->getAccountEmailAddress($GLOBALS['phpgw_info']['user']['userid'], $this->felamimailConfig['profileID'])) + { + foreach($emailAddresses as $addressData) + { + $predefinedAddresses[$addressData['address']] = $addressData['address']; + } + asort($predefinedAddresses); + } + + $this->t->set_var('multiSelectBox',$uiwidgets->multiSelectBox( + $selectedAddresses, + $predefinedAddresses, + 'vacationAddresses', + '400px' + ) + ); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.updateVacation', + 'editmode' => 'vacation', + 'scriptname' => $scriptName + ); + $this->t->set_var('vacation_action_url',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + } + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.saveScript' + ); + $this->t->set_var('formAction',$GLOBALS['phpgw']->link('/index.php',$linkData)); + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.mainScreen' + ); + $this->t->set_var('link_newScript',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.listScripts', + 'scriptname' => $scriptName + ); + $this->t->set_var('url_back',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $this->t->pfp("out","header"); + + $this->sieve->close(); + } + + function increaseFilter() + { + $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->editScript(); + } + + function listScripts() + { + $this->display_app_header(); + + $this->t->set_file(array("filterForm" => "sieveScriptList.tpl")); + $this->t->set_block('filterForm','header'); + $this->t->set_block('filterForm','scriptrow'); + + // translate most of the parts + $this->translate(); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.addScript' + ); + $this->t->set_var('action_add_script',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + if($this->sieve->listscripts()) + { + foreach($this->sieve->scriptlist as $scriptID => $scriptName) + { + $this->t->set_var("scriptnumber",$scriptID); + $this->t->set_var("scriptname",$scriptName); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.deleteScript', + 'scriptname' => $scriptName + ); + $this->t->set_var('link_deleteScript',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editScript', + 'scriptname' => $scriptName + ); + $this->t->set_var('link_editScript',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + if($this->sieve->activescript == $scriptName) + { + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.deactivateScript', + 'scriptname' => $scriptName + ); + $this->t->set_var('lang_activate',lang('deactivate script')); + $this->t->set_var('ruleCSS','sieveRowActive'); + } + else + { + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.activateScript', + 'scriptname' => $scriptName + ); + $this->t->set_var('lang_activate',lang('activate script')); + $this->t->set_var('ruleCSS','sieveRowInActive'); + } + $this->t->set_var('link_activateScript',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $this->t->parse('scriptrows','scriptrow',true); + } + } + #else + #{ + # $this->t->set_var("scriptrows",''); + #} + + $this->t->pfp("out","header"); + + $this->sieve->close(); + } + +/* function mainScreen() + { + // display the header + $this->display_app_header(); + + // initialize the template + $this->t->set_file(array("filterForm" => "sieveForm.tpl")); + $this->t->set_block('filterForm','header'); + $this->t->set_block('filterForm','scriptrow'); + $this->t->set_block('filterForm','filterrow'); + + // translate most of the parts + $this->translate(); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.addScript' + ); + $this->t->set_var('action_add_script',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + if($this->sieve->listscripts()) + { + foreach($this->sieve->scriptlist as $scriptID => $scriptName) + { + $this->t->set_var("scriptnumber",$scriptID); + $this->t->set_var("scriptname",$scriptName); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.deleteScript', + 'scriptname' => $scriptName + ); + $this->t->set_var('link_deleteScript',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editScript', + 'scriptname' => $scriptName + ); + $this->t->set_var('link_editScript',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + if($this->sieve->activescript == $scriptName) + { + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.deactivateScript', + 'scriptname' => $scriptName + ); + $this->t->set_var('lang_activate',lang('deactivate script')); + } + else + { + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.activateScript', + 'scriptname' => $scriptName + ); + $this->t->set_var('lang_activate',lang('activate script')); + } + $this->t->set_var('link_activateScript',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $this->t->parse('scriptrows','scriptrow',true); + } + } + else + { + $this->t->set_var("scriptrows",''); + } + if(!empty($this->scriptToEdit)) + { + #$this->t->set_var("editScriptName",$this->scriptToEdit); + #$this->t->set_var("scriptContent",$this->scriptContent); + $listOfImages = array( + 'up', + 'down' + ); + foreach ($listOfImages as $image) + { + $this->t->set_var('url_'.$image,$GLOBALS['phpgw']->common->image('felamimail',$image)); + } + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editRule' + ); + $this->t->set_var('url_add_rule',$GLOBALS['phpgw']->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',$this->buildRule($rule)); + $this->t->set_var('ruleID',$ruleID); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.editRule', + 'ruleID' => $ruleID + ); + $this->t->set_var('url_edit_rule',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.increaseFilter', + 'ruleID' => $ruleID + ); + $this->t->set_var('url_increase',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.decreaseFilter', + 'ruleID' => $ruleID + ); + $this->t->set_var('url_decrease',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.updateRules' + ); + $this->t->set_var('action_rulelist',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $this->t->parse('filterrows','filterrow',true); + } + } + else + { + $this->t->set_var("editScriptName",''); + $this->t->set_var("scriptContent",''); + } + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.saveScript' + ); + $this->t->set_var('formAction',$GLOBALS['phpgw']->link('/index.php',$linkData)); + $linkData = array + ( + 'menuaction' => 'felamimail.uisieve.mainScreen' + ); + $this->t->set_var('link_newScript',$GLOBALS['phpgw']->link('/index.php',$linkData)); + + $this->t->pfp("out","header"); + + $this->sieve->close(); + } +*/ + function restoreSessionData() + { + $sessionData = $GLOBALS['phpgw']->session->appsession('sieve_session_data'); + + $this->rules = $sessionData['sieve_rules']; + $this->scriptToEdit = $sessionData['sieve_scriptToEdit']; + } + + 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 saveVacation() + { + + } + + 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['phpgw']->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_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_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_edit_rule",lang('edit rule')); + $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("bg01",$GLOBALS['phpgw_info']["theme"]["bg01"]); + $this->t->set_var("bg02",$GLOBALS['phpgw_info']["theme"]["bg02"]); + $this->t->set_var("bg03",$GLOBALS['phpgw_info']["theme"]["bg03"]); + } + + function updateRules() + { + $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->editScript(); + } + + function updateScript() + { + $scriptName = $this->scriptToEdit; + $script = CreateObject('felamimail.Script',$this->scriptToEdit); + + if(!empty($scriptName)) + { + if($this->sieve->getscript($scriptName)) + { + // fetch the rules to the internal structure inside + // the $script object + if (!$script->retrieveRules($this->sieve)) + { + #print "can't receive script
"; + $this->editScript(); + } + } + else + { + #print "Unable to change active script!
"; + /* we could display the full output here */ + $this->listScripts(); + $GLOBALS['phpgw']->common->phpgw_exit(); + } + } + + $script->rules = $this->rules; + if (!$script->updateScript($this->sieve)) + { + print "update failed
"; + print $script->errstr."
"; + } + } + + function updateVacation() + { + #phpinfo();exit; + + $scriptName = get_var('scriptname',array('GET')); + $script = CreateObject('felamimail.Script',$scriptName); + + if(!empty($scriptName)) + { + if($this->sieve->getscript($scriptName)) + { + // fetch the rules to the internal structure inside + // the $script object + if (!$script->retrieveRules($this->sieve)) + { + #print "can't receive script
"; + $this->editScript(); + } + } + else + { + #print "Unable to change active script!
"; + /* we could display the full output here */ + $this->listScripts(); + $GLOBALS['phpgw']->common->phpgw_exit(); + } + } + + switch(get_var('vacationRule_action',array('POST'))) + { + case 'enable': + case 'save': + $vacation['text'] = get_var('vacation_text',array('POST')); + $vacation['days'] = get_var('days',array('POST')); + $vacation['addresses'] = get_var('vacationAddresses',array('POST')); + $vacation['status'] = 'on'; + if($this->checkRule($vacation)) + { + $script->vacation = $vacation; + if (!$script->updateScript($this->sieve)) + { + print "update failed
"; + print $script->errstr."
"; + } + } + break; + + case 'disable': + $vacation['text'] = get_var('vacation_text',array('POST')); + $vacation['days'] = get_var('days',array('POST')); + $vacation['addresses'] = get_var('vacationAddresses',array('POST')); + $vacation['status'] = 'off'; + $script->vacation = $vacation; + if($this->checkRule($vacation)) + { + if (!$script->updateScript($this->sieve)) + { + print "update failed
"; + print $script->errstr."
"; + } + } + break; + + case 'delete': + $script->vacation = array(); + if (!$script->updateScript($this->sieve)) + { + print "update failed
"; + print $script->errstr."
"; + } + break; + + default: + print "unhandeld vacationRule_action:". get_var('vacationRule_action',array('POST')) ."
"; + break; + } + + $this->editScript(); + } + } +?> diff --git a/felamimail/inc/class.uiwidgets.inc.php b/felamimail/inc/class.uiwidgets.inc.php new file mode 100644 index 0000000000..c68ff2ff98 --- /dev/null +++ b/felamimail/inc/class.uiwidgets.inc.php @@ -0,0 +1,159 @@ +template = $template; + $this->template->set_file(array("body" => 'uiwidgets.tpl')); + } + + /** + * create multiselectbox + * + * this function will create a multiselect box. Hard to describe! :) + * + * @param _selectedValues Array of values for already selected values(the left selectbox) + * @param _predefinedValues Array of values for predefined values(the right selectbox) + * @param _valueName name for the variable containing the selected values + * @param _boxWidth the width of the multiselectbox( example: 100px, 100%) + * + * @returns the html code, to be added into the template + */ + function multiSelectBox($_selectedValues, $_predefinedValues, $_valueName, $_boxWidth="100%") + { + $this->template->set_block('body','multiSelectBox'); + + if(is_array($_selectedValues)) + { + foreach($_selectedValues as $key => $value) + { + $options .= ""; + } + $this->template->set_var('multiSelectBox_selected_options',$options); + } + + $options = ''; + if(is_array($_predefinedValues)) + { + foreach($_predefinedValues as $key => $value) + { + if($key != $_selectedValues["$key"]) + $options .= ""; + } + $this->template->set_var('multiSelectBox_predefinded_options',$options); + } + + $this->template->set_var('multiSelectBox_valueName', $_valueName); + $this->template->set_var('multiSelectBox_boxWidth', $_boxWidth); + + + return $this->template->fp('out','multiSelectBox'); + } + + function tableView($_headValues, $_tableWidth="100%") + { + $this->template->set_block('body','tableView'); + $this->template->set_block('body','tableViewHead'); + + if(is_array($_headValues)) + { + foreach($_headValues as $head) + { + $this->template->set_var('tableHeadContent',$head); + $this->template->parse('tableView_Head','tableViewHead',True); + } + } + + if(is_array($this->tableViewRows)) + { + foreach($this->tableViewRows as $tableRow) + { + $rowData .= ""; + foreach($tableRow as $tableData) + { + switch($tableData['type']) + { + default: + $rowData .= ''.$tableData['text'].''; + break; + } + } + $rowData .= ""; + } + } + + $this->template->set_var('tableView_width', $_tableWidth); + $this->template->set_var('tableView_Rows', $rowData); + + return $this->template->fp('out','tableView'); + } + + function tableViewAddRow() + { + $this->tableViewRows[] = array(); + end($this->tableViewRows); + return key($this->tableViewRows); + } + + function tableViewAddTextCell($_rowID,$_text) + { + $this->tableViewRows[$_rowID][]= array + ( + 'type' => 'text', + 'text' => $_text + ); + } + } +?> \ No newline at end of file