[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) { |
---|
[6666] | 38 | $c = CreateObject('phpgwapi.config','expressoMail1_2'); |
---|
| 39 | $c->read_repository(); |
---|
| 40 | $current_config = $c->config_data; |
---|
[6146] | 41 | $boemailadmin = CreateObject('emailadmin.bo'); |
---|
| 42 | $emailadmin_profile = $boemailadmin->getProfileList(); |
---|
| 43 | $_SESSION['phpgw_info']['expressomail']['email_server'] = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']); |
---|
| 44 | |
---|
| 45 | $preferences = $GLOBALS['phpgw']->preferences->read(); |
---|
| 46 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail'] = $preferences['expressoMail']; |
---|
| 47 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['outoffice'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['outoffice']; |
---|
| 48 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'] = $GLOBALS['phpgw_info']['user']['telephonenumber']; |
---|
| 49 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_cache'] = $current_config['expressoMail_enable_cache']; |
---|
| 50 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_x_origin'] = $current_config['expressoMail_use_x_origin']; |
---|
| 51 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['number_of_contacts'] = $current_config['expressoMail_Number_of_dynamic_contacts'] ? $current_config['expressoMail_Number_of_dynamic_contacts'] : "0"; |
---|
| 52 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['notification_domains'] = $current_config['expressoMail_notification_domains']; |
---|
| 53 | $_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"; |
---|
| 54 | $_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"; |
---|
[6489] | 55 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size'] = $current_config['expressoMail_Max_attachment_size'] ? $current_config['expressoMail_Max_attachment_size']."M" : ini_get('upload_max_filesize'); |
---|
[6146] | 56 | $_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"; |
---|
| 57 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['imap_max_folders'] = $current_config['expressoMail_imap_max_folders']; |
---|
| 58 | $_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"; |
---|
| 59 | $_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'; |
---|
| 60 | $_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"; |
---|
| 61 | $_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"; |
---|
| 62 | $_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; |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | $this->loadLang( $GLOBALS['phpgw_info']['user']['preferences']['common']['lang']); |
---|
| 66 | $_SESSION['phpgw_info']['expressomail']['user']['userid'] = $GLOBALS['phpgw_info']['user']['userid']; |
---|
| 67 | $_SESSION['phpgw_info']['expressomail']['user']['passwd'] = $GLOBALS['phpgw_info']['user']['passwd']; |
---|
[6489] | 68 | $_SESSION['phpgw_info']['expressomail']['user']['email'] = $GLOBALS['phpgw']->preferences->values['email']; |
---|
[6146] | 69 | |
---|
| 70 | |
---|
| 71 | $this->imap = CreateObject("expressoMail1_2.imap_functions"); |
---|
| 72 | |
---|
| 73 | if($this->defaultFolders == null) { |
---|
| 74 | $sent = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']) ? |
---|
| 75 | $this->imap->functions->getLang("Sent") : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']; |
---|
| 76 | $spam = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']) ? |
---|
| 77 | $this->imap->functions->getLang("Spam"): $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']; |
---|
| 78 | $drafts = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']) ? |
---|
| 79 | $this->imap->functions->getLang("Drafts") : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']; |
---|
| 80 | $trash = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']) ? |
---|
| 81 | $this->imap->functions->getLang("Trash") : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; |
---|
| 82 | |
---|
| 83 | $this->defaultFolders = array ( |
---|
| 84 | 'INBOX' => 0, |
---|
| 85 | 'INBOX'.$this->imap->imap_delimiter.$spam => 2, |
---|
| 86 | 'INBOX'.$this->imap->imap_delimiter.$sent => 1, |
---|
| 87 | 'INBOX'.$this->imap->imap_delimiter.$drafts => 4, |
---|
| 88 | 'INBOX'.$this->imap->imap_delimiter.$trash => 3 |
---|
| 89 | ); |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | return $this->imap; |
---|
| 94 | } |
---|
| 95 | |
---|
[6495] | 96 | protected function messageExists($folderID,$msgID) { |
---|
| 97 | $info_msg = $this -> getImap()-> get_info_msg( |
---|
| 98 | array( 'msg_folder' => urlencode($folderID), |
---|
| 99 | 'msg_number' => $msgID |
---|
| 100 | )); |
---|
| 101 | |
---|
| 102 | if($info_msg['status_get_msg_info'] == 'false'){ |
---|
| 103 | return false; |
---|
| 104 | } else { |
---|
| 105 | return true; |
---|
| 106 | } |
---|
| 107 | } |
---|
[6146] | 108 | |
---|
| 109 | protected function getMessage(){ |
---|
| 110 | $info_msg = $this -> getImap()-> get_info_msg( |
---|
| 111 | array( 'msg_folder' => urlencode($this->getParam('folderID')), |
---|
| 112 | 'msg_number' => $this->getParam('msgID') |
---|
| 113 | )); |
---|
| 114 | |
---|
| 115 | if($info_msg['status_get_msg_info'] == 'false'){ |
---|
| 116 | return false; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | $msg['msgID'] = $info_msg['msg_number']; |
---|
| 120 | $msg['folderID'] = $info_msg['msg_folder']; |
---|
| 121 | //$msg['msgDate'] = $info_msg['fulldate']; |
---|
| 122 | $msg['msgDate'] = $info_msg['msg_day']." ".$info_msg['msg_hour']; |
---|
[6256] | 123 | if($info_msg['from']) { |
---|
| 124 | $msg['msgFrom']['fullName'] = $info_msg['from']['name']; |
---|
| 125 | $msg['msgFrom']['mailAddress'] = $info_msg['from']['email']; |
---|
| 126 | } |
---|
| 127 | if($info_msg['sender'] != null){ |
---|
| 128 | $msg['msgSender']['fullName'] = $info_msg['sender']['name']; |
---|
| 129 | $msg['msgSender']['mailAddress']= $info_msg['sender']['email']; |
---|
| 130 | } |
---|
| 131 | if($info_msg['toaddress2'] != null){ |
---|
| 132 | $toaddresses = explode(",",$info_msg['toaddress2']); |
---|
| 133 | if(count($toaddresses) > 1) { |
---|
| 134 | foreach ($toaddresses as $i => $toaddress){ |
---|
| 135 | $msg['msgTo'][$i] = $this->formatMailObject($toaddress); |
---|
| 136 | } |
---|
[6146] | 137 | } |
---|
[6256] | 138 | else{ |
---|
| 139 | $msg['msgTo'][0] = $this->formatMailObject($info_msg['toaddress2']); |
---|
| 140 | } |
---|
[6146] | 141 | } |
---|
[6256] | 142 | if($info_msg['cc'] != null) { |
---|
| 143 | $ccaddresses = explode(",",$info_msg['cc']); |
---|
| 144 | if(count($ccaddresses) > 1) { |
---|
| 145 | foreach ($ccaddresses as $i => $ccaddress){ |
---|
| 146 | $msg['msgCC'][$i] = $this->formatMailObject($ccaddress); |
---|
| 147 | } |
---|
[6146] | 148 | } |
---|
[6256] | 149 | else{ |
---|
| 150 | $msg['msgCC'][0] = $this->formatMailObject($info_msg['cc']); |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | if($info_msg['reply_toaddress'] != null) { |
---|
| 154 | $msg['msgReplyTo'][0] = $this->formatMailObject($info_msg['reply_toaddress']); |
---|
| 155 | } |
---|
| 156 | $msg['msgSubject'] = ($info_msg['subject'] ? mb_convert_encoding($info_msg['subject'],"UTF8", "ISO_8859-1") : ""); |
---|
[6497] | 157 | $msg['msgHasAttachments'] = "0"; |
---|
[7846] | 158 | |
---|
[6497] | 159 | if(count($info_msg['attachments']) > 0) { |
---|
| 160 | $msg['msgAttachments'] = array(); |
---|
| 161 | foreach($info_msg['attachments'] as $i => $attachment){ |
---|
| 162 | $msg['msgAttachments'][] = array ( |
---|
[6499] | 163 | 'attachmentID' => "".$attachment['pid'], |
---|
| 164 | 'attachmentIndex' => "".$i, |
---|
[7846] | 165 | 'attachmentName' => "".mb_convert_encoding($attachment['name'],"UTF8", "ISO_8859-1"), |
---|
[6499] | 166 | 'attachmentSize' => "".$attachment['fsize'], |
---|
[6497] | 167 | 'attachmentEncoding' => $attachment['encoding'] |
---|
| 168 | ); |
---|
| 169 | } |
---|
| 170 | $msg['msgHasAttachments'] = "1"; |
---|
| 171 | } |
---|
[6146] | 172 | $msg['msgFlagged'] = $info_msg['Flagged'] == "F" ? "1" : "0"; |
---|
| 173 | $msg['msgForwarded']= $info_msg['Forwarded'] == "F" ? "1" : "0"; |
---|
| 174 | $msg['msgAnswered'] = $info_msg['Answered'] == "A" ? "1" : "0"; |
---|
| 175 | $msg['msgDraft'] = $info_msg['Draft'] == "X" ? "1" : "0"; |
---|
| 176 | $msg['msgSeen'] = $info_msg['Unseen'] == "U" ? "0" : "1"; |
---|
| 177 | $msg['msgSize'] = $info_msg['Size']; |
---|
[6256] | 178 | $msg['msgBody'] = ($info_msg['body'] ? mb_convert_encoding($info_msg['body'],"UTF8", "ISO_8859-1") : ""); |
---|
[6146] | 179 | |
---|
| 180 | return $msg; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | } |
---|