[6146] | 1 | <?php |
---|
| 2 | |
---|
[6149] | 3 | class MailAdapter extends ExpressoAdapter { |
---|
[6146] | 4 | protected $defaultFolders; |
---|
| 5 | protected $imap; |
---|
| 6 | |
---|
| 7 | protected function formatMailObject($str) { |
---|
| 8 | $str = html_entity_decode($str); |
---|
| 9 | $str = preg_replace('/[<>\'"]/', '', $str); |
---|
| 10 | $return = array(); |
---|
| 11 | if(preg_match('/[[:alnum:]\._\-]+@[[:alnum:]_\-\.]+/',$str, $matches1) && |
---|
| 12 | preg_match('/[[:alnum:]\._\-\ ]+/',$str, $matches2)){ |
---|
| 13 | return array( |
---|
| 14 | 'fullName' => mb_convert_encoding(str_replace($matches1[0],'', $str), "UTF8", "ISO_8859-1"), |
---|
| 15 | 'mailAddress' => $matches1[0] |
---|
| 16 | ); |
---|
| 17 | } |
---|
| 18 | else{ |
---|
| 19 | return array('mailAddress' => $str); |
---|
| 20 | } |
---|
| 21 | } |
---|
| 22 | |
---|
[6148] | 23 | protected function loadLang($lang_user){ |
---|
[6146] | 24 | $fn = PHPGW_INCLUDE_ROOT."/expressoMail1_2/setup/phpgw_".$lang_user.'.lang'; |
---|
| 25 | if (file_exists($fn)){ |
---|
| 26 | $fp = fopen($fn,'r'); |
---|
| 27 | while ($data = fgets($fp,16000)){ |
---|
| 28 | list($message_id,$app_name,$null,$content) = explode("\t",substr($data,0,-1)); |
---|
| 29 | $_SESSION['phpgw_info']['expressomail']['lang'][$message_id] = $content; |
---|
| 30 | } |
---|
| 31 | fclose($fp); |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | protected function getImap(){ |
---|
| 37 | if($this->imap == null) { |
---|
| 38 | $boemailadmin = CreateObject('emailadmin.bo'); |
---|
| 39 | $emailadmin_profile = $boemailadmin->getProfileList(); |
---|
| 40 | $_SESSION['phpgw_info']['expressomail']['email_server'] = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']); |
---|
| 41 | |
---|
| 42 | $preferences = $GLOBALS['phpgw']->preferences->read(); |
---|
| 43 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail'] = $preferences['expressoMail']; |
---|
| 44 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['outoffice'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['outoffice']; |
---|
| 45 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'] = $GLOBALS['phpgw_info']['user']['telephonenumber']; |
---|
| 46 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_cache'] = $current_config['expressoMail_enable_cache']; |
---|
| 47 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_x_origin'] = $current_config['expressoMail_use_x_origin']; |
---|
| 48 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['number_of_contacts'] = $current_config['expressoMail_Number_of_dynamic_contacts'] ? $current_config['expressoMail_Number_of_dynamic_contacts'] : "0"; |
---|
| 49 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['notification_domains'] = $current_config['expressoMail_notification_domains']; |
---|
| 50 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'] : "50"; |
---|
| 51 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_characters_number'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['search_characters_number'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['search_characters_number'] : "4"; |
---|
| 52 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size'] = $current_config['expressoMail_Max_attachment_size'] ? $current_config['expressoMail_Max_attachment_size']."M" : ''; |
---|
| 53 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_msg_size'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['max_msg_size'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['max_msg_size'] : "0"; |
---|
| 54 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['imap_max_folders'] = $current_config['expressoMail_imap_max_folders']; |
---|
| 55 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_email_per_page'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['max_email_per_page'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['max_email_per_page'] : "50"; |
---|
| 56 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['extended_info']?$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['extended_info']:'0'; |
---|
| 57 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['from_to_sent'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['from_to_sent'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['from_to_sent'] : "0"; |
---|
| 58 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['return_recipient_deafault'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['return_recipient_deafault'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['return_recipient_deafault'] : "0"; |
---|
| 59 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['quick_search_default'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['quick_search_default'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['quick_search_default'] : 1; |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | $this->loadLang( $GLOBALS['phpgw_info']['user']['preferences']['common']['lang']); |
---|
| 63 | $_SESSION['phpgw_info']['expressomail']['user']['userid'] = $GLOBALS['phpgw_info']['user']['userid']; |
---|
| 64 | $_SESSION['phpgw_info']['expressomail']['user']['passwd'] = $GLOBALS['phpgw_info']['user']['passwd']; |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | $this->imap = CreateObject("expressoMail1_2.imap_functions"); |
---|
| 68 | |
---|
| 69 | if($this->defaultFolders == null) { |
---|
| 70 | $sent = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']) ? |
---|
| 71 | $this->imap->functions->getLang("Sent") : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']; |
---|
| 72 | $spam = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']) ? |
---|
| 73 | $this->imap->functions->getLang("Spam"): $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']; |
---|
| 74 | $drafts = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']) ? |
---|
| 75 | $this->imap->functions->getLang("Drafts") : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']; |
---|
| 76 | $trash = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']) ? |
---|
| 77 | $this->imap->functions->getLang("Trash") : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; |
---|
| 78 | |
---|
| 79 | $this->defaultFolders = array ( |
---|
| 80 | 'INBOX' => 0, |
---|
| 81 | 'INBOX'.$this->imap->imap_delimiter.$spam => 2, |
---|
| 82 | 'INBOX'.$this->imap->imap_delimiter.$sent => 1, |
---|
| 83 | 'INBOX'.$this->imap->imap_delimiter.$drafts => 4, |
---|
| 84 | 'INBOX'.$this->imap->imap_delimiter.$trash => 3 |
---|
| 85 | ); |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | return $this->imap; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | protected function getMessage(){ |
---|
| 95 | $info_msg = $this -> getImap()-> get_info_msg( |
---|
| 96 | array( 'msg_folder' => urlencode($this->getParam('folderID')), |
---|
| 97 | 'msg_number' => $this->getParam('msgID') |
---|
| 98 | )); |
---|
| 99 | |
---|
| 100 | if($info_msg['status_get_msg_info'] == 'false'){ |
---|
| 101 | return false; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | $msg['msgID'] = $info_msg['msg_number']; |
---|
| 105 | $msg['folderID'] = $info_msg['msg_folder']; |
---|
| 106 | //$msg['msgDate'] = $info_msg['fulldate']; |
---|
| 107 | $msg['msgDate'] = $info_msg['msg_day']." ".$info_msg['msg_hour']; |
---|
[6256] | 108 | if($info_msg['from']) { |
---|
| 109 | $msg['msgFrom']['fullName'] = $info_msg['from']['name']; |
---|
| 110 | $msg['msgFrom']['mailAddress'] = $info_msg['from']['email']; |
---|
| 111 | } |
---|
| 112 | if($info_msg['sender'] != null){ |
---|
| 113 | $msg['msgSender']['fullName'] = $info_msg['sender']['name']; |
---|
| 114 | $msg['msgSender']['mailAddress']= $info_msg['sender']['email']; |
---|
| 115 | } |
---|
| 116 | if($info_msg['toaddress2'] != null){ |
---|
| 117 | $toaddresses = explode(",",$info_msg['toaddress2']); |
---|
| 118 | if(count($toaddresses) > 1) { |
---|
| 119 | foreach ($toaddresses as $i => $toaddress){ |
---|
| 120 | $msg['msgTo'][$i] = $this->formatMailObject($toaddress); |
---|
| 121 | } |
---|
[6146] | 122 | } |
---|
[6256] | 123 | else{ |
---|
| 124 | $msg['msgTo'][0] = $this->formatMailObject($info_msg['toaddress2']); |
---|
| 125 | } |
---|
[6146] | 126 | } |
---|
[6256] | 127 | if($info_msg['cc'] != null) { |
---|
| 128 | $ccaddresses = explode(",",$info_msg['cc']); |
---|
| 129 | if(count($ccaddresses) > 1) { |
---|
| 130 | foreach ($ccaddresses as $i => $ccaddress){ |
---|
| 131 | $msg['msgCC'][$i] = $this->formatMailObject($ccaddress); |
---|
| 132 | } |
---|
[6146] | 133 | } |
---|
[6256] | 134 | else{ |
---|
| 135 | $msg['msgCC'][0] = $this->formatMailObject($info_msg['cc']); |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | if($info_msg['reply_toaddress'] != null) { |
---|
| 139 | $msg['msgReplyTo'][0] = $this->formatMailObject($info_msg['reply_toaddress']); |
---|
| 140 | } |
---|
| 141 | $msg['msgSubject'] = ($info_msg['subject'] ? mb_convert_encoding($info_msg['subject'],"UTF8", "ISO_8859-1") : ""); |
---|
[6146] | 142 | $msg['msgHasAttachments'] = $info_msg['attachments'] ? "1" : "0"; |
---|
| 143 | $msg['msgAttachments'] = $info_msg['attachments']; |
---|
| 144 | $msg['msgFlagged'] = $info_msg['Flagged'] == "F" ? "1" : "0"; |
---|
| 145 | $msg['msgForwarded']= $info_msg['Forwarded'] == "F" ? "1" : "0"; |
---|
| 146 | $msg['msgAnswered'] = $info_msg['Answered'] == "A" ? "1" : "0"; |
---|
| 147 | $msg['msgDraft'] = $info_msg['Draft'] == "X" ? "1" : "0"; |
---|
| 148 | $msg['msgSeen'] = $info_msg['Unseen'] == "U" ? "0" : "1"; |
---|
| 149 | $msg['msgSize'] = $info_msg['Size']; |
---|
[6256] | 150 | $msg['msgBody'] = ($info_msg['body'] ? mb_convert_encoding($info_msg['body'],"UTF8", "ISO_8859-1") : ""); |
---|
[6146] | 151 | |
---|
| 152 | return $msg; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | } |
---|