[2] | 1 | <?php |
---|
[5509] | 2 | /*************************************************************************** |
---|
| 3 | * Expresso Livre * |
---|
| 4 | * http://www.expressolivre.org * |
---|
| 5 | * -------------------------------------------- * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \**************************************************************************/ |
---|
| 11 | |
---|
[2] | 12 | include_once("class.functions.inc.php"); |
---|
| 13 | include_once("class.ldap_functions.inc.php"); |
---|
[91] | 14 | include_once("class.exporteml.inc.php"); |
---|
| 15 | |
---|
[2] | 16 | class imap_functions |
---|
| 17 | { |
---|
| 18 | var $public_functions = array |
---|
[1472] | 19 | ( |
---|
[2] | 20 | 'get_range_msgs' => True, |
---|
| 21 | 'get_info_msg' => True, |
---|
[689] | 22 | 'get_info_msgs' => True, |
---|
[615] | 23 | 'get_folders_list' => True, |
---|
[1518] | 24 | 'import_msgs' => True, |
---|
[4830] | 25 | 'report_mail_error' => True, |
---|
[1518] | 26 | 'msgs_to_archive' => True |
---|
[2] | 27 | ); |
---|
| 28 | |
---|
| 29 | var $ldap; |
---|
| 30 | var $mbox; |
---|
[6171] | 31 | var $mboxFolder; |
---|
[2] | 32 | var $imap_port; |
---|
| 33 | var $has_cid; |
---|
| 34 | var $imap_options = ''; |
---|
| 35 | var $functions; |
---|
[3071] | 36 | var $prefs; |
---|
[650] | 37 | var $foldersLimit; |
---|
[1912] | 38 | var $imap_sentfolder; |
---|
[5134] | 39 | var $rawMessage; |
---|
[5302] | 40 | var $folders; |
---|
[6171] | 41 | var $cache = false; |
---|
| 42 | var $useCache = false; |
---|
| 43 | var $expirationCache = false; |
---|
| 44 | |
---|
[5359] | 45 | |
---|
[2] | 46 | function imap_functions (){ |
---|
[5134] | 47 | $this->init(); |
---|
[5302] | 48 | } |
---|
[5359] | 49 | |
---|
[5134] | 50 | function init(){ |
---|
[5302] | 51 | $this->foldersLimit = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['imap_max_folders'] ? $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['imap_max_folders'] : 20000; //Limit of folders (mailboxes) user can see |
---|
| 52 | $this->username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 53 | $this->password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
| 54 | $this->imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 55 | $this->imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
| 56 | $this->imap_delimiter = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter']; |
---|
| 57 | $this->functions = new functions(); |
---|
[1912] | 58 | $this->imap_sentfolder = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] : str_replace("*","", $this->functions->getLang("Sent")); |
---|
[2] | 59 | $this->has_cid = false; |
---|
[5302] | 60 | $this->prefs = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']; |
---|
| 61 | |
---|
| 62 | //armazena os caminhos das pastas ( sent, spam, drafts, trash ) |
---|
[5306] | 63 | $this->folders['sent'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']) ? 'Sent' : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']; //Variavel folders armazena o caminho /sent |
---|
| 64 | $this->folders['spam'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']) ? 'Spam' : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']; |
---|
| 65 | $this->folders['drafts'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']) ? 'Drafts' : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']; |
---|
| 66 | $this->folders['trash'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']) ? 'Trash' : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; |
---|
| 67 | |
---|
[5359] | 68 | if(isset($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_enable_memcache']) && $_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_enable_memcache'] === 'true') |
---|
| 69 | $this->useCache = true; |
---|
| 70 | |
---|
| 71 | if(isset($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_time_memcache']) && trim($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_time_memcache']) != '') |
---|
| 72 | $this->expirationCache = $_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_time_memcache']; |
---|
| 73 | |
---|
[2] | 74 | if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') |
---|
| 75 | $this->imap_options = '/tls/novalidate-cert'; |
---|
| 76 | else |
---|
| 77 | $this->imap_options = '/notls/novalidate-cert'; |
---|
[5359] | 78 | |
---|
[2] | 79 | } |
---|
[5302] | 80 | |
---|
| 81 | function mount_url_folder($folders){ |
---|
[5306] | 82 | return implode($this->imap_delimiter,$folders); |
---|
[5302] | 83 | } |
---|
| 84 | |
---|
[2] | 85 | // BEGIN of functions. |
---|
[5359] | 86 | function open_mbox( $folder = false, $force_die = true) |
---|
[6171] | 87 | { |
---|
| 88 | $newFolder = mb_convert_encoding($folder, 'UTF7-IMAP','UTF-8, ISO-8859-1, UTF7-IMAP'); |
---|
| 89 | |
---|
| 90 | if($newFolder === $this->mboxFolder && is_resource( $this->mbox )) |
---|
| 91 | return $this->mbox; |
---|
| 92 | |
---|
| 93 | $this->mboxFolder = $newFolder; |
---|
[5359] | 94 | $url = '{'.$this->imap_server.":".$this->imap_port.$this->imap_options.'}'.$this->mboxFolder; |
---|
| 95 | |
---|
| 96 | if (is_resource($this->mbox)) |
---|
| 97 | if ($force_die) |
---|
| 98 | imap_reopen($this->mbox, $url ) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); |
---|
| 99 | else |
---|
| 100 | imap_reopen($this->mbox, $url ); |
---|
| 101 | else |
---|
| 102 | if($force_die) |
---|
| 103 | $this->mbox = imap_open( $url , $this->username, $this->password) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); |
---|
[3394] | 104 | else |
---|
[5359] | 105 | $this->mbox = imap_open( $url , $this->username, $this->password); |
---|
| 106 | |
---|
| 107 | return $this->mbox; |
---|
[2] | 108 | } |
---|
[5516] | 109 | |
---|
| 110 | /** |
---|
| 111 | * Move as pastas que vieram do resultado de um Drag & Drop da arvore de pastas do Expresso Mail |
---|
| 112 | * |
---|
| 113 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 114 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 115 | * @sponsor Caixa Econômica Federal |
---|
| 116 | * @author Gustavo Pereira dos Santos Stabelini |
---|
| 117 | * @param array $params Contem dois indices : um contem o caminho atual da pasta, e o outro contem o caminho futuro da pasta |
---|
| 118 | * @return boolean |
---|
| 119 | * @access public |
---|
| 120 | */ |
---|
[5488] | 121 | |
---|
| 122 | function move_folder($params){ |
---|
| 123 | //preg_match( '/[a-zA-Z0-9]+$/',$params['folder_to_move'], $new_folder); |
---|
| 124 | $old_folder = mb_convert_encoding($params['folder_to_move'], 'UTF7-IMAP','UTF-8, ISO-8859-1, UTF7-IMAP'); |
---|
| 125 | $new_folder = explode($this->imap_delimiter, $old_folder ); |
---|
| 126 | $to_folder = mb_convert_encoding($params['folder_to'], 'UTF7-IMAP','UTF-8, ISO-8859-1, UTF7-IMAP'); |
---|
| 127 | $mbox = imap_open('{'.$this->imap_server.":".$this->imap_port.$this->imap_options.'}'.$new_folder[0], $this->username, $this->password); |
---|
[5520] | 128 | $result = true; |
---|
| 129 | if(!imap_renamemailbox($mbox, '{'.$this->imap_server.":".$this->imap_port.$this->imap_options.'}'.$old_folder, '{'.$this->imap_server.":".$this->imap_port.$this->imap_options.'}'.$to_folder.$this->imap_delimiter.$new_folder[count($new_folder)-1])){ |
---|
| 130 | $result = false; |
---|
| 131 | } |
---|
[5490] | 132 | imap_close($mbox); |
---|
[5520] | 133 | return $result; |
---|
[5488] | 134 | } |
---|
| 135 | |
---|
[5134] | 136 | function parse_error($error, $field = ''){ |
---|
[504] | 137 | // This error is returned from Imap. |
---|
| 138 | if(strstr($error,'Connection refused')) { |
---|
| 139 | return str_replace("%1", $this->functions->getLang("Mail"), $this->functions->getLang("Connection failed with %1 Server. Try later.")); |
---|
| 140 | } |
---|
[5134] | 141 | else if(strstr($error,'virus')) { |
---|
[628] | 142 | return str_replace("%1", $this->functions->getLang("Mail"), $this->functions->getLang("Your message was rejected by antivirus. Perhaps your attachment has been infected.")); |
---|
| 143 | } |
---|
[5134] | 144 | else if(strstr($error,'Failed to add recipient:')) { |
---|
| 145 | preg_match_all('/:\s([\s\.";@!a-z0-9]+)\s\[SMTP:/', $error, $res); |
---|
| 146 | return str_replace("%1", $res['1']['0'], $this->functions->getLang("SMTP Error: The following recipient addresses failed: %1")); |
---|
| 147 | } |
---|
| 148 | else if(strstr($error,'Recipient address rejected')) { |
---|
| 149 | return str_replace("%1", $this->functions->getLang("Mail"), $this->functions->getLang("Invalid recipients in the message").'.'); |
---|
| 150 | } |
---|
| 151 | else if(strstr($error,'Invalid Mail:')) { |
---|
| 152 | return str_replace("%1", $field, $this->functions->getLang("The recipients addresses failed %1")); |
---|
| 153 | } |
---|
| 154 | else if(strstr($error,'Message file too big')) { |
---|
| 155 | return ($this->functions->getLang("Message file too big.")); |
---|
| 156 | } |
---|
[504] | 157 | // This condition verifies if SESSION is expired. |
---|
[6133] | 158 | else if(!count($_SESSION)) |
---|
[504] | 159 | return "nosession"; |
---|
| 160 | |
---|
| 161 | return $error; |
---|
| 162 | } |
---|
[1472] | 163 | |
---|
[6254] | 164 | function get_range_msgs3($params){ |
---|
| 165 | |
---|
| 166 | $return = $this->get_range_msgs2($params); |
---|
| 167 | |
---|
[6576] | 168 | $return['folder'] = mb_convert_encoding( $return['folder'], 'ISO-8859-1', 'UTF-8' ); |
---|
[6254] | 169 | |
---|
| 170 | return $return; |
---|
| 171 | } |
---|
| 172 | |
---|
[2] | 173 | function get_range_msgs2($params) |
---|
[5533] | 174 | { |
---|
[5993] | 175 | include_once dirname(__FILE__).'/../../prototype/api/controller.php'; |
---|
[5359] | 176 | // Free others requests |
---|
| 177 | session_write_close(); |
---|
| 178 | $folder = $params['folder']; |
---|
| 179 | $msg_range_begin = $params['msg_range_begin']; |
---|
| 180 | $msg_range_end = $params['msg_range_end']; |
---|
| 181 | $sort_box_type = isset($params['sort_box_type']) ? $params['sort_box_type'] : ''; |
---|
| 182 | $sort_box_reverse = isset($params['sort_box_reverse']) ? $params['sort_box_reverse'] : ''; |
---|
| 183 | $search_box_type = (isset($params['search_box_type']) && $params['search_box_type'] != 'ALL' && $params['search_box_type'] != '' )? $params['search_box_type'] : false; |
---|
[1472] | 184 | |
---|
[5359] | 185 | if( !$this->mbox || !is_resource( $this->mbox ) ) |
---|
| 186 | $this->mbox = $this->open_mbox($folder); |
---|
[3392] | 187 | |
---|
[5359] | 188 | $return = array(); |
---|
| 189 | $return['folder'] = $folder; |
---|
| 190 | //Para enviar o offset entre o timezone definido pelo usuário e GMT |
---|
| 191 | $return['offsetToGMT'] = $this->functions->CalculateDateOffset(); |
---|
[4050] | 192 | |
---|
[5359] | 193 | if(!$search_box_type || $search_box_type == 'UNSEEN' || $search_box_type == 'SEEN') { |
---|
[6576] | 194 | $msgs_info = imap_status($this->mbox,"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".mb_convert_encoding( $folder, 'UTF7-IMAP', 'UTF-8, ISO-8859-1' ) ,SA_ALL); |
---|
[4169] | 195 | |
---|
[5359] | 196 | $return['tot_unseen'] = ($search_box_type == 'SEEN') ? 0 : $msgs_info->unseen; |
---|
[3392] | 197 | |
---|
[5359] | 198 | $sort_array_msg = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); |
---|
[3392] | 199 | |
---|
[5359] | 200 | $num_msgs = ($search_box_type=="UNSEEN") ? $msgs_info->unseen : (($search_box_type=="SEEN") ? ($msgs_info->messages - $msgs_info->unseen) : $msgs_info->messages); |
---|
[3392] | 201 | |
---|
[5359] | 202 | $i = 0; |
---|
| 203 | if(is_array($sort_array_msg)){ |
---|
| 204 | foreach($sort_array_msg as $msg_number => $value) |
---|
| 205 | { |
---|
| 206 | $sample = false; |
---|
[6240] | 207 | if( (isset($this->prefs['preview_msg_subject']) && ($this->prefs['preview_msg_subject'] === '1')) || |
---|
[6212] | 208 | (isset($this->prefs['preview_msg_tip'] ) && ($this->prefs['preview_msg_tip'] === '1')) ) |
---|
[5359] | 209 | $sample = true; |
---|
| 210 | |
---|
[5787] | 211 | $return[$i] = $this->get_info_head_msg( $msg_number , $sample ); |
---|
| 212 | $i++; |
---|
[5800] | 213 | } |
---|
| 214 | |
---|
[5977] | 215 | $filter = array('AND', array('=', 'folderName', $folder), array('IN','messageNumber', $sort_array_msg)); |
---|
[5814] | 216 | $followupflagged = Controller::find( |
---|
| 217 | array('concept' => 'followupflagged'), |
---|
| 218 | false, |
---|
| 219 | array('filter' => $filter, 'criteria' => array('deepness' => '2')) |
---|
| 220 | ); |
---|
| 221 | $labeleds = Controller::find( |
---|
| 222 | array('concept' => 'labeled'), |
---|
| 223 | false, |
---|
| 224 | array('filter' => $filter, 'criteria' => array('deepness' => '2')) |
---|
| 225 | ); |
---|
| 226 | for($i=0; $i<count($sort_array_msg); $i++){ |
---|
| 227 | if(!isset($return[$i]['msg_number'])) |
---|
[5800] | 228 | continue; |
---|
[5816] | 229 | |
---|
| 230 | $numFlags = count($followupflagged); |
---|
| 231 | for($ii=0; $ii<$numFlags; $ii++){ |
---|
[5814] | 232 | if($return[$i]['msg_number'] == $followupflagged[$ii]['messageNumber']){ |
---|
| 233 | $followupflag = Controller::read( array( 'concept' => 'followupflag', 'id' => $followupflagged[$ii]['followupflagId'] )); |
---|
| 234 | $return[$i]['followupflagged'] = $followupflagged[$ii]; |
---|
| 235 | $return[$i]['followupflagged']['followupflag'] = $followupflag; |
---|
| 236 | break; |
---|
[5748] | 237 | } |
---|
[5814] | 238 | } |
---|
[5816] | 239 | $numLabels = count($labeleds); |
---|
| 240 | for($ii=0; $ii<$numLabels; $ii++){ |
---|
[5814] | 241 | if($return[$i]['msg_number'] == $labeleds[$ii]['messageNumber']){ |
---|
| 242 | $labels = Controller::read( array( 'concept' => 'label', 'id' => $labeleds[$ii]['labelId'])); |
---|
| 243 | $return[$i]['labels'][$labeleds[$ii]['labelId']] = $labels; |
---|
[5748] | 244 | } |
---|
[5814] | 245 | } |
---|
[5787] | 246 | } |
---|
[5359] | 247 | } |
---|
[5800] | 248 | $return['num_msgs'] = $num_msgs; |
---|
[5787] | 249 | } else { |
---|
[4162] | 250 | $num_msgs = imap_num_msg($this->mbox); |
---|
| 251 | $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$num_msgs); |
---|
[828] | 252 | |
---|
[4044] | 253 | |
---|
[4162] | 254 | $return['tot_unseen'] = 0; |
---|
| 255 | $i = 0; |
---|
[4044] | 256 | |
---|
[4162] | 257 | if(is_array($sort_array_msg)){ |
---|
| 258 | |
---|
| 259 | foreach($sort_array_msg as $msg_number => $value) |
---|
| 260 | { |
---|
| 261 | $temp = $this->get_info_head_msg($msg_number); |
---|
| 262 | if(!$temp) |
---|
| 263 | return false; |
---|
| 264 | |
---|
| 265 | if($temp['Unseen'] == 'U' || $temp['Recent'] == 'N'){ |
---|
| 266 | $return['tot_unseen']++; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | if($i <= ($msg_range_end-$msg_range_begin)) |
---|
| 270 | $return[$i] = $temp; |
---|
| 271 | $i++; |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | $return['num_msgs'] = count($sort_array_msg)+($msg_range_begin-1); |
---|
| 275 | } |
---|
[6442] | 276 | |
---|
[4162] | 277 | return $return; |
---|
[4044] | 278 | } |
---|
[5533] | 279 | |
---|
| 280 | |
---|
| 281 | function getMessages($params) { |
---|
| 282 | $result = array(); |
---|
| 283 | |
---|
| 284 | $exporteml = new ExportEml(); |
---|
| 285 | $unseen_msgs = array(); |
---|
| 286 | |
---|
| 287 | foreach($params['messages'] as $folder => $messages) { |
---|
| 288 | foreach($messages as $msg_number) { |
---|
| 289 | |
---|
| 290 | $this->mbox = $this->open_mbox($folder); |
---|
| 291 | |
---|
| 292 | if (isset($params['details']) && $params['details'] == 'all') { |
---|
| 293 | $message = $this->get_info_msg(array('msg_number' => $msg_number, 'msg_folder' =>urlencode($folder))); |
---|
| 294 | } else { |
---|
| 295 | $message['headers'] = $this->get_info_head_msg($msg_number, true); |
---|
| 296 | //$message['attachments'] = $exporteml->get_attachments_in_array(array("num_msg" => $msg_number)); |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | imap_close($this->mbox); |
---|
| 300 | $this->mbox = false; |
---|
| 301 | |
---|
| 302 | if($msg_info['Unseen'] == "U" || $msg_info['Recent'] == "N") { |
---|
| 303 | array_push($unseen_msgs,$msg_number); |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | $result[$folder][] = $message; |
---|
| 307 | } |
---|
| 308 | if($unseen_msgs){ |
---|
| 309 | $msgs_list = implode(",",$unseen_msgs); |
---|
| 310 | $array_msgs = array('folder' => $folder, "msgs_to_set" => $msgs_list, "flag" => "unseen"); |
---|
| 311 | $this->set_messages_flag($array_msgs); |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | return $result; |
---|
| 316 | } |
---|
| 317 | |
---|
[5359] | 318 | /** |
---|
| 319 | * Decodifica uma string no formato mime RFC2047 |
---|
| 320 | * |
---|
| 321 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 322 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 323 | * @sponsor Caixa Econômica Federal |
---|
| 324 | * @author Cristiano Corrêa Schmidt |
---|
| 325 | * @param string $string string no formato mime RFC2047 |
---|
| 326 | * @return string |
---|
| 327 | * @access public |
---|
| 328 | */ |
---|
| 329 | static function decodeMimeString( $string ) |
---|
| 330 | { |
---|
[5373] | 331 | $string = preg_replace('/\?\=(\s)*\=\?/', '?==?', $string); |
---|
[5372] | 332 | return preg_replace_callback( '/\=\?([^\?]*)\?([qb])\?([^\?]*)\?=/i' ,array( 'self' , 'decodeMimeStringCallback'), $string); |
---|
[5359] | 333 | } |
---|
| 334 | |
---|
| 335 | /** |
---|
| 336 | * Decodifica os tokens encontrados na função decodeMimeString |
---|
| 337 | * |
---|
| 338 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 339 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 340 | * @sponsor Caixa Econômica Federal |
---|
| 341 | * @author Cristiano Corrêa Schmidt |
---|
| 342 | * @param array $mathes array retornado pelo preg_replace_callback da função decodeMimeString |
---|
| 343 | * @return string |
---|
| 344 | * @access public |
---|
| 345 | */ |
---|
| 346 | static function decodeMimeStringCallback( $mathes ) |
---|
| 347 | { |
---|
| 348 | $str = (strtolower($mathes[2]) == 'q') ? quoted_printable_decode(str_replace('_','=20',$mathes[3])) : base64_decode( $mathes[3]) ; |
---|
| 349 | return ( strtoupper($mathes[1]) == 'UTF-8' ) ? mb_convert_encoding( $str , 'ISO-8859-1' , 'UTF-8') : $str; |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | /** |
---|
| 353 | * Formata um mailObject para um array com name e email |
---|
| 354 | * |
---|
| 355 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 356 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 357 | * @sponsor Caixa Econômica Federal |
---|
| 358 | * @author Cristiano Corrêa Schmidt |
---|
| 359 | * @return bool |
---|
| 360 | * @access public |
---|
| 361 | */ |
---|
| 362 | static function formatMailObject( $obj ) |
---|
| 363 | { |
---|
| 364 | $return = array(); |
---|
[5853] | 365 | $return['email'] = self::decodeMimeString($obj->mailbox) . ((isset( $obj->host) && ($obj->host != 'unspecified-domain' || $obj->host != '.SYNTAX-ERROR.') )? '@'. $obj->host : ''); |
---|
[5359] | 366 | $return['name'] = ( isset( $obj->personal ) && trim($obj->personal) !== '' ) ? self::decodeMimeString($obj->personal) : $return['email']; |
---|
| 367 | return $return; |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | /** |
---|
| 371 | * Retorna informações do cabeçario da mensagem e um preview caso appendSample = true |
---|
| 372 | * Utiliza memCache caso esta preferencia esteja ativada. |
---|
| 373 | * |
---|
| 374 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 375 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 376 | * @sponsor Caixa Econômica Federal |
---|
| 377 | * @author Cristiano Corrêa Schmidt |
---|
| 378 | * @return bool |
---|
| 379 | * @access public |
---|
| 380 | */ |
---|
| 381 | function get_info_head_msg( $msg_number , $appendSample = false ) |
---|
| 382 | { |
---|
| 383 | $return = false; |
---|
| 384 | $cached = false; |
---|
| 385 | if( $this->useCache === true ) |
---|
| 386 | { |
---|
| 387 | if( $this->cache === false ) |
---|
[3499] | 388 | { |
---|
[5359] | 389 | $this->cache = ServiceLocator::getService( 'memCache' ); //Serviço Cache |
---|
| 390 | $this->cache->connect( $_SESSION['phpgw_info']['expressomail']['server']['server_memcache'] , $_SESSION['phpgw_info']['expressomail']['server']['port_server_memcache'] ); |
---|
[3499] | 391 | } |
---|
[5359] | 392 | |
---|
| 393 | if( $return = $this->cache->get( 'infoHead://'.$this->username.'://'.$this->mboxFolder.'://'.$msg_number )) |
---|
| 394 | $cached = true; |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | $header = imap_headerinfo($this->mbox, imap_msgno( $this->mbox , $msg_number )); //Resgata o objeto Header da mensagem , nescessario mesmo com o cache pois as flags podem ser atualizadas por outro cliente de email |
---|
| 398 | $return['Recent'] = $header->Recent; |
---|
| 399 | $return['Unseen'] = $header->Unseen; |
---|
| 400 | $return['Deleted'] = $header->Deleted; |
---|
| 401 | $return['Flagged'] = $header->Flagged; |
---|
| 402 | if($header->Answered =='A' && $header->Draft == 'X') |
---|
| 403 | $return['Forwarded'] = 'F'; |
---|
| 404 | else |
---|
| 405 | { |
---|
| 406 | $return['Answered'] = $header->Answered; |
---|
| 407 | $return['Draft'] = $header->Draft; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | if( $cached === true ) //Caso a mensagem ja tenha vindo do cache da o return |
---|
| 411 | { |
---|
| 412 | if($appendSample !== false && !isset($return['msg_sample'])) //verifica o msg_sample caso seja alterada a preferencia e não esteja em cache carregar |
---|
[5372] | 413 | { |
---|
| 414 | $return['msg_sample'] = $this->get_msg_sample($msg_number); |
---|
| 415 | $this->cache->set( 'infoHead://'.$this->username.'://'.$this->mboxFolder.'://'.$msg_number , $return , $this->expirationCache); |
---|
| 416 | } |
---|
[5359] | 417 | |
---|
| 418 | return $return; |
---|
| 419 | } |
---|
[5372] | 420 | |
---|
[5359] | 421 | $importance = array(); |
---|
| 422 | $mimeHeader = imap_fetchheader( $this->mbox, $msg_number , FT_UID ); //Resgata o Mime Header da mensagem |
---|
[6442] | 423 | |
---|
[5372] | 424 | $mimeBody = imap_body( $this->mbox, $msg_number , FT_UID|FT_PEEK ); //Resgata o Mime Body da mensagem sem marcar como lida |
---|
[5359] | 425 | $offsetToGMT = $this->functions->CalculateDateOffset(); |
---|
| 426 | $return['ContentType'] = $this->getMessageType( $msg_number , $mimeHeader , $mimeBody ); |
---|
| 427 | $return['Importance'] = ( preg_match('/importance *: *(.*)\r/i', $mimeHeader , $importance) === 0 ) ? 'Normal' : $importance[1]; |
---|
| 428 | $return['msg_number'] = $msg_number; |
---|
| 429 | $return['udate'] = $header->udate; |
---|
| 430 | $return['offsetToGMT'] = $offsetToGMT; |
---|
| 431 | $return['timestamp'] = $header->udate + $return['offsetToGMT']; |
---|
| 432 | $return['smalldate'] = (date('d/m/Y') == gmdate( 'd/m/Y', $return['timestamp'] )) ? gmdate("H:i", $return['timestamp'] ) : gmdate("d/m/Y", $return['timestamp'] ); |
---|
| 433 | $return['Size'] = $header->Size; |
---|
| 434 | $return['from'] = (isset( $header->from[0] )) ? self::formatMailObject( $header->from[0] ) : array( 'name' => '' , 'email' => ''); |
---|
| 435 | $return['subject'] = ( isset($header->subject) && trim($header->subject) !== '' ) ? self::decodeMimeString($header->subject) : $this->functions->getLang('(no subject) '); |
---|
[6178] | 436 | $return['attachment'] = ( preg_match('/((Content-Disposition:(.)*([\r\n\s]*filename))|(Content-Type:(.)*([\r\n\s]*name)))/i', $mimeBody) ) ? '1' : '0'; //Verifica se a anexos na mensagem |
---|
[5372] | 437 | $return['reply_toaddress'] = isset($header->reply_toaddress) ? self::decodeMimeString($header->reply_toaddress) : ''; |
---|
[5359] | 438 | $return['flag'] = $header->Unseen.$header->Recent.$header->Flagged.$header->Draft.$header->Answered.$header->Deleted.( $return['attachment'] === '1' ? 'T': '' ); |
---|
[6185] | 439 | |
---|
| 440 | if (!empty($header->to)){ |
---|
| 441 | foreach ($header->to as $i => $v){ |
---|
| 442 | $return['to'][$i] = self::formatMailObject( $v ); |
---|
| 443 | } |
---|
| 444 | } |
---|
| 445 | else if (!empty($header->cc)){ |
---|
| 446 | foreach ($header->cc as $i => $v){ |
---|
| 447 | $return['to'][$i] = self::formatMailObject( $v ); |
---|
| 448 | } |
---|
| 449 | } |
---|
| 450 | else if (!empty($header->bcc)){ |
---|
| 451 | foreach ($header->bcc as $i => $v){ |
---|
| 452 | $return['to'][$i] = self::formatMailObject( $v ); |
---|
| 453 | } |
---|
| 454 | } |
---|
| 455 | else |
---|
| 456 | $return['to'] = array( 'name' => '' , 'email' => ''); |
---|
| 457 | |
---|
| 458 | if (!empty($return['to'])){ |
---|
| 459 | foreach ($return['to'] as $i => $v){ |
---|
| 460 | if($v['name'] == 'undisclosed-recipients@' || $v['name'] == '@') |
---|
| 461 | $return['to'][$i] = $return['from']; |
---|
| 462 | } |
---|
| 463 | } |
---|
[3499] | 464 | |
---|
[5359] | 465 | if($appendSample !== false) |
---|
| 466 | $return['msg_sample'] = $this->get_msg_sample($msg_number); |
---|
| 467 | |
---|
| 468 | if( $this->useCache === true ) |
---|
| 469 | $this->cache->set( 'infoHead://'.$this->username.'://'.$this->mboxFolder.'://'.$msg_number , $return , $this->expirationCache); |
---|
[5488] | 470 | |
---|
[6442] | 471 | |
---|
| 472 | |
---|
| 473 | |
---|
[5359] | 474 | return $return; |
---|
[2] | 475 | } |
---|
[828] | 476 | |
---|
[4416] | 477 | /** |
---|
[5079] | 478 | * |
---|
[4416] | 479 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
[5134] | 480 | * @param string $string String a ser decodificada |
---|
| 481 | * @return string |
---|
[4416] | 482 | * @todo Verificar a possibilidade de se utilizar a função iconv_mime_decode, que é capaz de identificar a codificação por si só, mas que pode ser interpretada de forma diversa dependendo da implementação do sistema |
---|
| 483 | * @todo Executar testes suficientes para validar a funçao iconv_mime_decode em substituição à este método decode_string |
---|
| 484 | */ |
---|
[2] | 485 | function decode_string($string) |
---|
[4795] | 486 | { |
---|
[5134] | 487 | $return = ''; |
---|
| 488 | $decoded = ''; |
---|
[4795] | 489 | if ((strpos(strtolower($string), '=?iso-8859-1') !== false) || (strpos(strtolower($string), '=?windows-1252') !== false)) |
---|
| 490 | { |
---|
| 491 | $tmp = imap_mime_header_decode($string); |
---|
| 492 | foreach ($tmp as $tmp1) |
---|
[4416] | 493 | { |
---|
[4795] | 494 | $return .= $this->htmlspecialchars_encode($tmp1->text); |
---|
[4416] | 495 | } |
---|
[4795] | 496 | |
---|
[4416] | 497 | return str_replace("\t", "", $return); |
---|
[4795] | 498 | } |
---|
| 499 | else if (strpos(strtolower($string), '=?utf-8') !== false) |
---|
| 500 | { |
---|
| 501 | $elements = imap_mime_header_decode($string); |
---|
[1472] | 502 | |
---|
[4795] | 503 | for($i = 0;$i < count($elements);$i++) |
---|
| 504 | { |
---|
| 505 | $charset = strtolower($elements[$i]->charset); |
---|
| 506 | $text = $elements[$i]->text; |
---|
| 507 | if(!strcasecmp($charset, "utf-8") || !strcasecmp($charset, "utf-7")) |
---|
| 508 | $decoded .= $this->functions->utf8_to_ncr($text); |
---|
| 509 | else |
---|
| 510 | { |
---|
| 511 | if( strcasecmp($charset,"default") ) |
---|
| 512 | $decoded .= $this->htmlspecialchars_encode(iconv($charset, "iso-8859-1", $text)); |
---|
| 513 | else |
---|
| 514 | $decoded .= $this->htmlspecialchars_encode($text); |
---|
| 515 | } |
---|
| 516 | } |
---|
[1401] | 517 | |
---|
[4416] | 518 | return str_replace("\t", "", $decoded); |
---|
[4795] | 519 | } |
---|
[4773] | 520 | else if(strpos(strtolower($string), '=?us-ascii') !== false) |
---|
| 521 | { |
---|
| 522 | $retun = ''; |
---|
| 523 | $tmp = imap_mime_header_decode($string); |
---|
| 524 | foreach ($tmp as $tmp1) |
---|
| 525 | $return .= $this->htmlspecialchars_encode(quoted_printable_decode($tmp1->text)); |
---|
| 526 | |
---|
| 527 | return str_replace("\t", "", $return); |
---|
| 528 | |
---|
| 529 | } |
---|
[5134] | 530 | else if( strpos( $string , '=?' ) !== false ) |
---|
| 531 | return $this->htmlspecialchars_encode(iconv_mime_decode( $string )); |
---|
[4773] | 532 | |
---|
[1401] | 533 | |
---|
[4795] | 534 | return $this->htmlspecialchars_encode($string); |
---|
| 535 | } |
---|
[5079] | 536 | |
---|
| 537 | |
---|
[615] | 538 | /** |
---|
| 539 | * Função que importa arquivos .eml exportados pelo expresso para a caixa do usuário. Testado apenas |
---|
| 540 | * com .emls gerados pelo expresso, e o arquivo pode ser um zip contendo vários emls ou um .eml. |
---|
| 541 | */ |
---|
[5265] | 542 | function import_msgs($params) { |
---|
[1000] | 543 | if(!$this->mbox) |
---|
[660] | 544 | $this->mbox = $this->open_mbox(); |
---|
[1472] | 545 | |
---|
[5264] | 546 | if( preg_match('/local_/',$params["folder"]) ){ |
---|
| 547 | |
---|
[1366] | 548 | // PLEASE, BE CAREFULL!!! YOU SHOULD USE EMAIL CONFIGURATION VALUES (EMAILADMIN MODULE) |
---|
[5302] | 549 | //$tmp_box = mb_convert_encoding('INBOX'.$this->folders['trash'].$this->imap_delimiter.'tmpMoveToLocal', "UTF7-IMAP", "UTF-8"); |
---|
| 550 | $tmp_box = mb_convert_encoding($this->mount_url_folder(array("INBOX",$this->folders['trash'],"tmpMoveToLocal")), "UTF7-IMAP", "UTF-8"); |
---|
| 551 | |
---|
[5264] | 552 | if ( ! imap_createmailbox( $this->mbox,"{".$this -> imap_server."}$tmp_box" ) ) |
---|
[1000] | 553 | return $this->functions->getLang( 'Import to Local : fail...' ); |
---|
| 554 | imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$tmp_box); |
---|
| 555 | $params["folder"] = $tmp_box; |
---|
| 556 | } |
---|
[5264] | 557 | |
---|
[615] | 558 | $errors = array(); |
---|
| 559 | $invalid_format = false; |
---|
[1472] | 560 | $filename = $params['FILES'][0]['name']; |
---|
[5264] | 561 | $params["folder"] = mb_convert_encoding($params["folder"], "UTF7-IMAP","ISO-8859-1, UTF-8"); |
---|
[660] | 562 | $quota = imap_get_quotaroot($this->mbox, $params["folder"]); |
---|
[5264] | 563 | |
---|
[660] | 564 | if((($quota['limit'] - $quota['usage'])*1024) <= $params['FILES'][0]['size']){ |
---|
| 565 | return array( 'error' => $this->functions->getLang("fail in import:"). |
---|
[1000] | 566 | " ".$this->functions->getLang("Over quota")); |
---|
[660] | 567 | } |
---|
[5264] | 568 | |
---|
[615] | 569 | if(substr($filename,strlen($filename)-4)==".zip") { |
---|
[660] | 570 | $zip = zip_open($params['FILES'][0]['tmp_name']); |
---|
[615] | 571 | if ($zip) { |
---|
| 572 | while ($zip_entry = zip_read($zip)) { |
---|
[1000] | 573 | |
---|
[615] | 574 | if (zip_entry_open($zip, $zip_entry, "r")) { |
---|
| 575 | $email = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); |
---|
| 576 | $status = @imap_append($this->mbox, |
---|
[660] | 577 | "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"], |
---|
[615] | 578 | $email |
---|
| 579 | ); |
---|
| 580 | if(!$status) |
---|
| 581 | array_push($errors,zip_entry_name($zip_entry)); |
---|
| 582 | zip_entry_close($zip_entry); |
---|
| 583 | } |
---|
| 584 | } |
---|
[660] | 585 | zip_close($zip); |
---|
[615] | 586 | } |
---|
[5264] | 587 | if (isset( $tmp_box ) && ! sizeof( $errors )){ |
---|
[1000] | 588 | $mc = imap_check($this->mbox); |
---|
| 589 | $result = imap_fetch_overview( $this -> mbox, "1:{$mc -> Nmsgs}", 0 ); |
---|
| 590 | $ids = array( ); |
---|
| 591 | foreach ($result as $overview) |
---|
| 592 | $ids[ ] = $overview -> uid; |
---|
| 593 | return implode( ',', $ids ); |
---|
[830] | 594 | } |
---|
[5264] | 595 | |
---|
| 596 | }else if(substr($filename,strlen($filename)-4)==".eml") { |
---|
[660] | 597 | $email = implode("",file($params['FILES'][0]['tmp_name'])); |
---|
[5264] | 598 | $status = imap_append($this->mbox,"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"],$email); |
---|
[5265] | 599 | |
---|
[5264] | 600 | if(!$status) |
---|
[5266] | 601 | return "Error importing"; |
---|
[5264] | 602 | |
---|
[5134] | 603 | if ( isset( $tmp_box ) && ! sizeof( $errors ) ) { |
---|
| 604 | $mc = imap_check($this->mbox); |
---|
| 605 | |
---|
| 606 | $result = imap_fetch_overview( $this -> mbox, "1:{$mc -> Nmsgs}", 0 ); |
---|
| 607 | |
---|
| 608 | $ids = array( ); |
---|
| 609 | foreach ($result as $overview) |
---|
| 610 | $ids[ ] = $overview -> uid; |
---|
| 611 | |
---|
| 612 | return implode( ',', $ids ); |
---|
| 613 | } |
---|
[615] | 614 | } |
---|
[5264] | 615 | else{ |
---|
[1000] | 616 | if ( isset( $tmp_box ) ) |
---|
| 617 | imap_deletemailbox( $this->mbox,"{".$this -> imap_server."}$tmp_box" ); |
---|
| 618 | |
---|
[660] | 619 | return array("error" => $this->functions->getLang("wrong file format")); |
---|
[615] | 620 | $invalid_format = true; |
---|
| 621 | } |
---|
[1000] | 622 | |
---|
[615] | 623 | if(!$invalid_format) { |
---|
| 624 | if(count($errors)>0) { |
---|
[660] | 625 | $message = $this->functions->getLang("fail in import:")."\n"; |
---|
[615] | 626 | foreach($errors as $arquivo) { |
---|
| 627 | $message.=$arquivo."\n"; |
---|
| 628 | } |
---|
[660] | 629 | return array("error" => $message); |
---|
[615] | 630 | } |
---|
| 631 | else |
---|
[3843] | 632 | return $this->functions->getLang("The import was executed successfully."); |
---|
[615] | 633 | } |
---|
[1000] | 634 | } |
---|
| 635 | /* |
---|
[613] | 636 | Remove os anexos de uma mensagem. A estratégia para isso é criar uma mensagem nova sem os anexos, mantendo apenas |
---|
| 637 | a primeira parte do e-mail, que é o texto, sem anexos. |
---|
| 638 | O método considera que o email é multpart. |
---|
| 639 | */ |
---|
| 640 | function remove_attachments($params) { |
---|
| 641 | include_once("class.message_components.inc.php"); |
---|
| 642 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 643 | $this->mbox = $this->open_mbox($params["folder"]); |
---|
| 644 | $return["status"] = true; |
---|
| 645 | $header = ""; |
---|
[1472] | 646 | |
---|
[613] | 647 | $headertemp = explode("\n",imap_fetchheader($this->mbox, imap_msgno($this->mbox, $params["msg_num"]))); |
---|
| 648 | foreach($headertemp as $head) {//Se eu colocar todo o header do email dá pau no append, então procuro apenas o que interessa. |
---|
| 649 | $head1 = explode(":",$head); |
---|
[1472] | 650 | if ( (strtoupper($head1[0]) == "TO") || |
---|
[3566] | 651 | (strtoupper($head1[0]) == "FROM") || |
---|
| 652 | (strtoupper($head1[0]) == "SUBJECT") || |
---|
| 653 | (strtoupper($head1[0]) == "DATE") ) |
---|
| 654 | $header .= $head."\r\n"; |
---|
[613] | 655 | } |
---|
[1472] | 656 | |
---|
[5134] | 657 | $msg = new message_components($this->mbox); |
---|
[1472] | 658 | $msg->fetch_structure($params["msg_num"]);/* O fetchbody tava trazendo o email com problemas na acentuação. |
---|
| 659 | Então uso essa classe para verificar a codificação e o charset, |
---|
[613] | 660 | para que o método decodeBody do expresso possa trazer tudo certinho*/ |
---|
[1472] | 661 | |
---|
[3566] | 662 | $all_body_type = strtolower($msg->file_type[$params["msg_num"]][0]); |
---|
| 663 | $all_body_encoding = $msg->encoding[$params["msg_num"]][0]; |
---|
| 664 | $all_body_charset = $msg->charset[$params["msg_num"]][0]; |
---|
| 665 | |
---|
| 666 | if($all_body_type=='multipart/alternative') { |
---|
| 667 | if(strtolower($msg->file_type[$params["msg_num"]][2]=='text/html') && |
---|
| 668 | $msg->pid[$params["msg_num"]][2] == '1.2') { |
---|
| 669 | $body_part_to_show = '1.2'; |
---|
| 670 | $all_body_type = strtolower($msg->file_type[$params["msg_num"]][2]); |
---|
| 671 | $all_body_encoding = $msg->encoding[$params["msg_num"]][2]; |
---|
| 672 | $all_body_charset = $msg->charset[$params["msg_num"]][2]; |
---|
| 673 | } |
---|
| 674 | else { |
---|
| 675 | $body_part_to_show = '1.1'; |
---|
| 676 | $all_body_type = strtolower($msg->file_type[$params["msg_num"]][1]); |
---|
| 677 | $all_body_encoding = $msg->encoding[$params["msg_num"]][1]; |
---|
| 678 | $all_body_charset = $msg->charset[$params["msg_num"]][1]; |
---|
| 679 | } |
---|
| 680 | } |
---|
| 681 | else |
---|
| 682 | $body_part_to_show = '1'; |
---|
| 683 | |
---|
[1319] | 684 | $status = imap_append($this->mbox, |
---|
[613] | 685 | "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"], |
---|
| 686 | $header. |
---|
[3566] | 687 | "Content-Type: ".$all_body_type."; charset = \"".$all_body_charset."\"". |
---|
[613] | 688 | "\r\n". |
---|
[3566] | 689 | "Content-Transfer-Encoding: ".$all_body_encoding. |
---|
| 690 | "\r\n". |
---|
| 691 | "\r\n". |
---|
[5134] | 692 | str_replace("\n","\r\n",preg_replace("/<img[^>]+\>/i", " ", $this->decodeBody( |
---|
[3566] | 693 | imap_fetchbody($this->mbox,imap_msgno($this->mbox, $params["msg_num"]),$body_part_to_show), |
---|
| 694 | $all_body_encoding, $all_body_charset |
---|
[5134] | 695 | )) |
---|
| 696 | ), "\\Seen"); //Append do novo email, só com header e conteúdo sem anexos. //Remove imagens do corpo, pois estas estão na lista de anexo e serão removidas. |
---|
[1472] | 697 | |
---|
[1319] | 698 | if(!$status) |
---|
| 699 | { |
---|
[613] | 700 | $return["status"] = false; |
---|
| 701 | $return["msg"] = lang("error appending mail on delete attachments"); |
---|
| 702 | } |
---|
[1319] | 703 | else |
---|
| 704 | { |
---|
| 705 | $status = imap_status($this->mbox, "{".$this->imap_server.":".$this->imap_port."}".$params['folder'], SA_UIDNEXT); |
---|
[1472] | 706 | $return['msg_no'] = $status->uidnext - 1; |
---|
[1319] | 707 | imap_delete($this->mbox, imap_msgno($this->mbox, $params["msg_num"])); |
---|
| 708 | imap_expunge($this->mbox); |
---|
| 709 | } |
---|
[1472] | 710 | |
---|
[613] | 711 | return $return; |
---|
[1472] | 712 | |
---|
[613] | 713 | } |
---|
[1518] | 714 | |
---|
| 715 | function msgs_to_archive($params) { |
---|
| 716 | |
---|
| 717 | $folder = $params['folder']; |
---|
[1931] | 718 | $all_ids = $this-> get_msgs($folder, 'SORTARRIVAL', false, 0,-1,-1); |
---|
[613] | 719 | |
---|
[1518] | 720 | $messages_not_to_copy = explode(",",$params['mails']); |
---|
| 721 | $ids = array(); |
---|
| 722 | |
---|
[1931] | 723 | $cont = 0; |
---|
| 724 | |
---|
[1518] | 725 | foreach($all_ids as $each_id=>$value) { |
---|
[1931] | 726 | if(!in_array($each_id,$messages_not_to_copy)) { |
---|
[1518] | 727 | array_push($ids,$each_id); |
---|
[1931] | 728 | $cont++; |
---|
| 729 | } |
---|
| 730 | if($cont>=100) |
---|
| 731 | break; |
---|
[1518] | 732 | } |
---|
| 733 | |
---|
| 734 | if (empty($ids)) |
---|
| 735 | return array(); |
---|
| 736 | |
---|
| 737 | $params = array("folder"=>$folder,"msgs_number"=>implode(",",$ids)); |
---|
| 738 | |
---|
| 739 | |
---|
| 740 | return $this->get_info_msgs($params); |
---|
| 741 | |
---|
| 742 | |
---|
| 743 | } |
---|
| 744 | |
---|
[689] | 745 | /** |
---|
[1472] | 746 | * |
---|
| 747 | * @return |
---|
[689] | 748 | * @param $params Object |
---|
| 749 | */ |
---|
| 750 | function get_info_msgs($params) { |
---|
| 751 | include_once("class.exporteml.inc.php"); |
---|
[5172] | 752 | |
---|
| 753 | if(array_key_exists('messages', $params)){ |
---|
| 754 | $sel_msgs = explode(",", $params['messages']); |
---|
| 755 | @reset($sel_msgs); |
---|
| 756 | $sorted_msgs = array(); |
---|
| 757 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
| 758 | $sel_msg = explode(";", $sel_msg); |
---|
| 759 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
| 760 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
| 761 | } |
---|
| 762 | else { |
---|
| 763 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
| 764 | } |
---|
| 765 | } |
---|
| 766 | unset($sorted_msgs['']); |
---|
| 767 | |
---|
| 768 | $return = array(); |
---|
| 769 | $array_names_keys = array_keys($sorted_msgs); |
---|
| 770 | |
---|
| 771 | for($i = 0; $i < count($sorted_msgs); $i++){ |
---|
| 772 | |
---|
| 773 | $new_params = array(); |
---|
| 774 | $attach_params = array(); |
---|
| 775 | |
---|
| 776 | $new_params["msg_folder"]= $array_names_keys[$i]; |
---|
| 777 | $attach_params["folder"] = $params["folder"]; |
---|
| 778 | $msgs = explode(",",$sorted_msgs[$array_names_keys[$i]]); |
---|
| 779 | $exporteml = new ExportEml(); |
---|
| 780 | $unseen_msgs = array(); |
---|
| 781 | foreach($msgs as $msg_number) { |
---|
| 782 | $new_params["msg_number"] = $msg_number; |
---|
| 783 | //ini_set("display_errors","1"); |
---|
| 784 | $msg_info = $this->get_info_msg($new_params); |
---|
| 785 | |
---|
| 786 | $this->mbox = $this->open_mbox($array_names_keys[$i]); //Não sei porque, mas se não abrir de novo a caixa dá erro. |
---|
| 787 | $msg_info['header'] = $this->get_info_head_msg($msg_number); |
---|
| 788 | |
---|
| 789 | $attach_params["num_msg"] = $msg_number; |
---|
| 790 | $msg_info['array_attach'] = $exporteml->get_attachments_in_array($attach_params); |
---|
| 791 | imap_close($this->mbox); |
---|
| 792 | $this->mbox=false; |
---|
| 793 | array_push($return,serialize($msg_info)); |
---|
| 794 | |
---|
| 795 | if($msg_info['Unseen'] == "U" || $msg_info['Recent'] == "N"){ |
---|
| 796 | array_push($unseen_msgs,$msg_number); |
---|
| 797 | } |
---|
| 798 | } |
---|
| 799 | } |
---|
| 800 | if($unseen_msgs){ |
---|
| 801 | $msgs_list = implode(",",$unseen_msgs); |
---|
| 802 | $array_msgs = array('folder' => $new_params["msg_folder"], "msgs_to_set" => $msgs_list, "flag" => "unseen"); |
---|
| 803 | $this->set_messages_flag($array_msgs); |
---|
| 804 | } |
---|
| 805 | return $return; |
---|
| 806 | }else{ |
---|
[689] | 807 | $return = array(); |
---|
| 808 | $new_params = array(); |
---|
| 809 | $attach_params = array(); |
---|
| 810 | $new_params["msg_folder"]=$params["folder"]; |
---|
| 811 | $attach_params["folder"] = $params["folder"]; |
---|
| 812 | $msgs = explode(",",$params["msgs_number"]); |
---|
| 813 | $exporteml = new ExportEml(); |
---|
[1382] | 814 | $unseen_msgs = array(); |
---|
[689] | 815 | foreach($msgs as $msg_number) { |
---|
| 816 | $new_params["msg_number"] = $msg_number; |
---|
| 817 | //ini_set("display_errors","1"); |
---|
| 818 | $msg_info = $this->get_info_msg($new_params); |
---|
| 819 | |
---|
| 820 | $this->mbox = $this->open_mbox($params['folder']); //Não sei porque, mas se não abrir de novo a caixa dá erro. |
---|
| 821 | $msg_info['header'] = $this->get_info_head_msg($msg_number); |
---|
| 822 | |
---|
| 823 | $attach_params["num_msg"] = $msg_number; |
---|
| 824 | $msg_info['array_attach'] = $exporteml->get_attachments_in_array($attach_params); |
---|
| 825 | imap_close($this->mbox); |
---|
| 826 | $this->mbox=false; |
---|
| 827 | array_push($return,serialize($msg_info)); |
---|
[1472] | 828 | |
---|
[1388] | 829 | if($msg_info['Unseen'] == "U" || $msg_info['Recent'] == "N"){ |
---|
[1472] | 830 | array_push($unseen_msgs,$msg_number); |
---|
| 831 | } |
---|
| 832 | } |
---|
[1382] | 833 | if($unseen_msgs){ |
---|
| 834 | $msgs_list = implode(",",$unseen_msgs); |
---|
| 835 | $array_msgs = array('folder' => $new_params["msg_folder"], "msgs_to_set" => $msgs_list, "flag" => "unseen"); |
---|
[1472] | 836 | $this->set_messages_flag($array_msgs); |
---|
[5533] | 837 | } |
---|
| 838 | |
---|
[689] | 839 | return $return; |
---|
| 840 | } |
---|
[5533] | 841 | } |
---|
[4795] | 842 | |
---|
[4436] | 843 | /** |
---|
[5079] | 844 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 845 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
[5134] | 846 | * @param $msg_number numero da mensagem |
---|
[4436] | 847 | */ |
---|
[4416] | 848 | function getRawHeader($msg_number) |
---|
| 849 | { |
---|
| 850 | return imap_fetchheader($this->mbox, $msg_number, FT_UID); |
---|
| 851 | } |
---|
| 852 | |
---|
[4436] | 853 | /** |
---|
[5079] | 854 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 855 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
[5134] | 856 | * @param $msg_number numero da mensagem |
---|
[4436] | 857 | */ |
---|
[4416] | 858 | function getRawBody($msg_number) |
---|
| 859 | { |
---|
| 860 | return imap_body($this->mbox, $msg_number, FT_UID); |
---|
| 861 | } |
---|
[689] | 862 | |
---|
[4436] | 863 | |
---|
| 864 | /** |
---|
[5079] | 865 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 866 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
[5134] | 867 | * @param $msg mensagem |
---|
[4436] | 868 | */ |
---|
[4416] | 869 | function builderMsgHeader($msg) |
---|
| 870 | { |
---|
| 871 | |
---|
| 872 | |
---|
| 873 | $fromMail = str_replace('<','', str_replace('>','',$msg->headers['from'])); |
---|
| 874 | $tosMails = str_replace('<','', str_replace('>','',$msg->headers['to'])); |
---|
| 875 | |
---|
| 876 | $tos = explode(',',$tosMails); |
---|
| 877 | $to = ''; |
---|
| 878 | foreach ($tos as $value) |
---|
| 879 | { |
---|
| 880 | $to .= '<a href="mailto:'.str_replace(' ','',$value).'">'.$value.'</a>, '; |
---|
| 881 | } |
---|
| 882 | |
---|
| 883 | $header = ' |
---|
| 884 | <table style="margin: 2px; border: 1px solid black; background: none repeat scroll 0% 0% rgb(234, 234, 234);"> |
---|
| 885 | <tbody> |
---|
| 886 | <tr><td><b>'.$this->functions->getLang('Subject').':</b></td><td>'.$msg->headers['subject'].'</td></tr> |
---|
| 887 | <tr><td><b>'.$this->functions->getLang('From').':</b></td><td><a href="mailto:'.$fromMail.'">'.$fromMail.'</a></td></tr> |
---|
| 888 | <tr><td><b>'.$this->functions->getLang('Date').':</b></td><td>'.$msg->headers['date'].'</td></tr> |
---|
| 889 | <tr><td><b>'.$this->functions->getLang('To').':</b></td><td>'.$to.'</td></tr> |
---|
| 890 | </tbody> |
---|
| 891 | </table> |
---|
| 892 | <br />' |
---|
| 893 | ; |
---|
| 894 | |
---|
| 895 | return $header; |
---|
| 896 | } |
---|
| 897 | |
---|
[5079] | 898 | /** |
---|
[5134] | 899 | * Constroe o corpo da msg direto na variavel de conteudo |
---|
| 900 | * @param Mail_mimeDecode $structure |
---|
| 901 | * @param <type> $content Ponteiro para Variavel de conteudo da msg |
---|
[5079] | 902 | */ |
---|
[4416] | 903 | function builderMsgBody($structure , &$content , $printHeader = false) |
---|
| 904 | { |
---|
| 905 | if(strtolower($structure->ctype_primary) == 'multipart' && strtolower($structure->ctype_secondary) == 'alternative') |
---|
| 906 | { |
---|
| 907 | $numParts = count($structure->parts) - 1; |
---|
| 908 | |
---|
| 909 | for($i = $numParts; $i >= 0; $i--) |
---|
| 910 | { |
---|
| 911 | $part = $structure->parts[$i]; |
---|
| 912 | |
---|
| 913 | switch (strtolower($part->ctype_primary)) |
---|
| 914 | { |
---|
| 915 | case 'text': |
---|
[5134] | 916 | $disposition = isset($part->disposition) ? strtolower($part->disposition) : ''; |
---|
[4416] | 917 | if($disposition != 'attachment') |
---|
| 918 | { |
---|
| 919 | if(strtolower($part->ctype_secondary) == 'html') |
---|
| 920 | { |
---|
| 921 | if($printHeader) |
---|
| 922 | $content .= $this->builderMsgHeader($part); |
---|
| 923 | |
---|
| 924 | $content .= $this->decodeMailPart($part->body,$part->ctype_parameters['charset']); |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | if(strtolower($part->ctype_secondary) == 'plain' ) |
---|
| 928 | { |
---|
| 929 | if($printHeader) |
---|
| 930 | $content .= $this->builderMsgHeader($part); |
---|
| 931 | |
---|
[4781] | 932 | $content .= '<pre>'. htmlentities($this->decodeMailPart($part->body,$part->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 933 | } |
---|
[5134] | 934 | if(strtolower($part->ctype_secondary) == 'calendar') |
---|
| 935 | $content.= $this->builderMsgCalendar($this->decodeMailPart($part->body, $part->ctype_parameters['charset'])); |
---|
[4416] | 936 | |
---|
| 937 | } |
---|
| 938 | |
---|
| 939 | $i = -1; |
---|
| 940 | break; |
---|
| 941 | |
---|
| 942 | case 'multipart': |
---|
| 943 | |
---|
| 944 | if($printHeader) |
---|
| 945 | $content .= $this->builderMsgHeader($part); |
---|
| 946 | |
---|
| 947 | $this->builderMsgBody($part,$content); |
---|
| 948 | |
---|
| 949 | $i = -1; |
---|
| 950 | break; |
---|
| 951 | |
---|
| 952 | case 'message': |
---|
| 953 | |
---|
| 954 | if(!is_array($part->parts)) |
---|
| 955 | { |
---|
| 956 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[4781] | 957 | $content .= '<pre>'. htmlentities($this->decodeMailPart($part->body, $structure->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 958 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
| 959 | } |
---|
| 960 | else |
---|
| 961 | $this->builderMsgBody($part,$content,true); |
---|
| 962 | |
---|
| 963 | $i = -1; |
---|
| 964 | break; |
---|
| 965 | } |
---|
| 966 | } |
---|
| 967 | } |
---|
| 968 | else |
---|
| 969 | { |
---|
| 970 | foreach ($structure->parts as $index => $part) |
---|
| 971 | { |
---|
| 972 | switch (strtolower($part->ctype_primary)) |
---|
| 973 | { |
---|
| 974 | case 'text': |
---|
[5134] | 975 | $disposition = ''; |
---|
| 976 | if(isset($part->disposition)) |
---|
| 977 | $disposition = isset($part->disposition) ? strtolower($part->disposition) : ''; |
---|
[4416] | 978 | if($disposition != 'attachment') |
---|
| 979 | { |
---|
| 980 | if(strtolower($part->ctype_secondary) == 'html') |
---|
| 981 | { |
---|
| 982 | if($printHeader) |
---|
| 983 | $content .= $this->builderMsgHeader($part); |
---|
| 984 | |
---|
| 985 | $content .= $this->decodeMailPart($part->body,$part->ctype_parameters['charset']); |
---|
| 986 | } |
---|
| 987 | |
---|
| 988 | if(strtolower($part->ctype_secondary) == 'plain') |
---|
| 989 | { |
---|
| 990 | if($printHeader) |
---|
| 991 | $content .= $this->builderMsgHeader($part); |
---|
| 992 | |
---|
[4781] | 993 | $content .= '<pre>'. htmlentities($this->decodeMailPart($part->body,$part->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 994 | } |
---|
[5134] | 995 | if(strtolower($part->ctype_secondary) == 'calendar') |
---|
| 996 | $content .= $this->builderMsgCalendar($part->body); |
---|
[4416] | 997 | |
---|
| 998 | } |
---|
| 999 | break; |
---|
| 1000 | case 'multipart': |
---|
| 1001 | |
---|
| 1002 | if($printHeader) |
---|
| 1003 | $content .= $this->builderMsgHeader($part); |
---|
| 1004 | |
---|
| 1005 | $this->builderMsgBody($part,$content); |
---|
| 1006 | |
---|
| 1007 | break; |
---|
| 1008 | case 'message': |
---|
[5134] | 1009 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['nested_messages_are_shown'] != '1') |
---|
| 1010 | { |
---|
[4416] | 1011 | if(!is_array($part->parts)) |
---|
| 1012 | { |
---|
| 1013 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[4781] | 1014 | $content .= '<pre>'. htmlentities($this->decodeMailPart($part->body, $structure->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 1015 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
| 1016 | } |
---|
| 1017 | else |
---|
| 1018 | $this->builderMsgBody($part,$content,true); |
---|
| 1019 | break; |
---|
| 1020 | } |
---|
| 1021 | } |
---|
| 1022 | } |
---|
| 1023 | } |
---|
[5134] | 1024 | } |
---|
[4416] | 1025 | |
---|
| 1026 | |
---|
[4436] | 1027 | /** |
---|
[5079] | 1028 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 1029 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
[5134] | 1030 | * @param $msg_number numero da mensagem |
---|
[4436] | 1031 | */ |
---|
| 1032 | function get_msg_sample($msg_number) |
---|
[4416] | 1033 | { |
---|
[5359] | 1034 | $content = ''; |
---|
| 1035 | $return = array(); |
---|
[4416] | 1036 | |
---|
[5359] | 1037 | include_once('class.message_components.inc.php'); |
---|
[5134] | 1038 | $msg = new message_components($this->mbox); |
---|
[4416] | 1039 | $msg->fetch_structure($msg_number); |
---|
| 1040 | |
---|
[5134] | 1041 | if(!isset($msg->structure[$msg_number]->parts)) |
---|
[4416] | 1042 | { |
---|
[5359] | 1043 | $content = ''; |
---|
| 1044 | if (strtolower($msg->structure[$msg_number]->subtype) == "plain" || strtolower($msg->structure[$msg_number]->subtype) == "html") |
---|
| 1045 | $content = $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID|FT_PEEK), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]); |
---|
[4416] | 1046 | } |
---|
| 1047 | else |
---|
| 1048 | { |
---|
[5359] | 1049 | foreach($msg->pid[$msg_number] as $values => $msg_part) |
---|
| 1050 | { |
---|
| 1051 | $file_type = strtolower($msg->file_type[$msg_number][$values]); |
---|
| 1052 | if($file_type == "text/plain" || $file_type == "text/html") { |
---|
| 1053 | $content = $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID|FT_PEEK), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); |
---|
| 1054 | break; |
---|
| 1055 | } |
---|
| 1056 | } |
---|
[4416] | 1057 | } |
---|
[5359] | 1058 | |
---|
[4416] | 1059 | $tags_replace = array("<br>","<br/>","<br />"); |
---|
[5134] | 1060 | $content = str_replace($tags_replace," ", nl2br($content)); |
---|
| 1061 | $content = $this->html2txt($content); |
---|
[4416] | 1062 | $content != "" ? $return['body'] = " - " . $content: $return['body'] = ""; |
---|
[5359] | 1063 | $return['body'] = base64_encode(mb_convert_encoding(substr($return['body'], 0, 305),'ISO-8859-1' , 'UTF-8,ISO-8859-1')); |
---|
[4416] | 1064 | return $return; |
---|
| 1065 | } |
---|
[5359] | 1066 | |
---|
[5134] | 1067 | function html2txt($document){ |
---|
| 1068 | $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript |
---|
| 1069 | '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags |
---|
| 1070 | '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly |
---|
| 1071 | '@<![\s\S]*?--[ \t\n\r]*>@si' // Strip multi-line comments including CDATA |
---|
| 1072 | ); |
---|
| 1073 | $text = preg_replace($search, '', $document); |
---|
| 1074 | return html_entity_decode($text); |
---|
| 1075 | } |
---|
| 1076 | |
---|
| 1077 | function ope_msg_part($params) |
---|
| 1078 | { |
---|
| 1079 | $return = array(); |
---|
[5316] | 1080 | require_once dirname(__FILE__).'/class.attachment.inc.php'; |
---|
[4416] | 1081 | |
---|
[5134] | 1082 | $atObj = new attachment(); |
---|
| 1083 | $atObj->setStructureFromMail($params['msg_folder'],$params['msg_number']); |
---|
| 1084 | $mbox_stream = $this->open_mbox($params['save_folder']); |
---|
| 1085 | $return['append'] = imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$params['save_folder'], $atObj->getAttachment($params['msg_part']), "\\Seen \\Draft"); |
---|
| 1086 | $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$params['save_folder'], SA_UIDNEXT); |
---|
[4416] | 1087 | |
---|
[5134] | 1088 | $return['msg_folder'] = $params['save_folder']; |
---|
| 1089 | $return['msg_number'] = $status->uidnext - 1; |
---|
| 1090 | |
---|
| 1091 | return $return; |
---|
| 1092 | |
---|
| 1093 | } |
---|
[5079] | 1094 | |
---|
[2] | 1095 | function get_info_msg($params) |
---|
| 1096 | { |
---|
[5689] | 1097 | if(isset($params['alarm'])){ |
---|
| 1098 | $alarm = $params['alarm']; |
---|
| 1099 | }else{ |
---|
| 1100 | $alarm = false; |
---|
| 1101 | } |
---|
| 1102 | |
---|
[51] | 1103 | $return = array(); |
---|
[6442] | 1104 | |
---|
[2] | 1105 | $msg_number = $params['msg_number']; |
---|
[6275] | 1106 | $msg_folder = isset($params['decoded']) ? $params['msg_folder'] : urldecode($params['msg_folder']); |
---|
[4416] | 1107 | |
---|
[5134] | 1108 | if(preg_match('/(.+)(_[a-zA-Z0-9]+)/',$msg_number,$matches)) { //Verifies if it comes from a tab diferent of the main one. |
---|
[4795] | 1109 | $msg_number = $matches[1]; |
---|
| 1110 | $plus_id = $matches[2]; |
---|
| 1111 | } |
---|
| 1112 | else { |
---|
| 1113 | $plus_id = ''; |
---|
| 1114 | } |
---|
| 1115 | |
---|
[6303] | 1116 | $this->mbox = $this->open_mbox($msg_folder); |
---|
[4416] | 1117 | |
---|
[535] | 1118 | $header = $this->get_header($msg_number); |
---|
[205] | 1119 | if (!$header) { |
---|
[4795] | 1120 | $return['status_get_msg_info'] = "false"; |
---|
[205] | 1121 | return $return; |
---|
| 1122 | } |
---|
[4795] | 1123 | |
---|
| 1124 | $header_ = imap_fetchheader($this->mbox, $msg_number, FT_UID); |
---|
[51] | 1125 | $return_get_body = $this->get_body_msg($msg_number, $msg_folder); |
---|
[4416] | 1126 | $body = $return_get_body['body']; |
---|
[1035] | 1127 | if($return_get_body['body']=='isCripted'){ |
---|
| 1128 | $exporteml = new ExportEml(); |
---|
| 1129 | $return['source']=$exporteml->export_msg_data($msg_number,$msg_folder); |
---|
| 1130 | $return['body'] = ""; |
---|
| 1131 | $return['attachments'] = ""; |
---|
| 1132 | $return['thumbs'] = ""; |
---|
| 1133 | $return['signature'] = ""; |
---|
| 1134 | //return $return; |
---|
| 1135 | }else{ |
---|
[4795] | 1136 | $return['body'] = $body; |
---|
| 1137 | $return['attachments'] = $return_get_body['attachments']; |
---|
| 1138 | $return['thumbs'] = $return_get_body['thumbs']; |
---|
[5134] | 1139 | //$return['signature'] = $return_get_body['signature']; |
---|
[4795] | 1140 | } |
---|
[6673] | 1141 | |
---|
| 1142 | $pattern = '/^[ \t]*Disposition-Notification-To:.*/mi'; |
---|
[828] | 1143 | if (preg_match($pattern, $header_, $fields)) |
---|
[6673] | 1144 | $return['DispositionNotificationTo'] = base64_encode(trim(str_ireplace('Disposition-Notification-To:', '', $fields[0]))); |
---|
[828] | 1145 | |
---|
[2] | 1146 | $return['Recent'] = $header->Recent; |
---|
| 1147 | $return['Unseen'] = $header->Unseen; |
---|
[4795] | 1148 | $return['Deleted'] = $header->Deleted; |
---|
[2] | 1149 | $return['Flagged'] = $header->Flagged; |
---|
| 1150 | |
---|
| 1151 | if($header->Answered =='A' && $header->Draft == 'X'){ |
---|
| 1152 | $return['Forwarded'] = 'F'; |
---|
| 1153 | } |
---|
[4795] | 1154 | |
---|
[2] | 1155 | else { |
---|
| 1156 | $return['Answered'] = $header->Answered; |
---|
[4795] | 1157 | $return['Draft'] = $header->Draft; |
---|
[2] | 1158 | } |
---|
| 1159 | |
---|
[4795] | 1160 | $return['msg_number'] = $msg_number.$plus_id; |
---|
[6333] | 1161 | $return['msg_folder'] = isset($params['decoded']) ? mb_convert_encoding( $msg_folder, "ISO-8859-1", "UTF-8" ) : $msg_folder; |
---|
[4795] | 1162 | |
---|
[5134] | 1163 | |
---|
| 1164 | |
---|
| 1165 | $msgTimesTamp = $header->udate + $this->functions->CalculateDateOffset(); //Aplica offset do usuario |
---|
| 1166 | $date_msg = gmdate("d/m/Y",$msgTimesTamp); |
---|
[4795] | 1167 | |
---|
[5134] | 1168 | // Removido codigo pois a o método send_nofication precisa da data completa. |
---|
| 1169 | // if (date("d/m/Y") == $date_msg) |
---|
| 1170 | // $return['udate'] = gmdate("H:i",$header->udate); |
---|
| 1171 | // else |
---|
| 1172 | |
---|
| 1173 | // Passa o a data completa para mensagem. |
---|
| 1174 | $return['udate'] = $header->udate; |
---|
| 1175 | |
---|
[4795] | 1176 | $return['msg_day'] = $date_msg; |
---|
[5134] | 1177 | $return['msg_hour'] = gmdate("H:i",$msgTimesTamp); |
---|
[4795] | 1178 | |
---|
[2] | 1179 | if (date("d/m/Y") == $date_msg) //no dia |
---|
| 1180 | { |
---|
[5134] | 1181 | $return['fulldate'] = gmdate("d/m/Y H:i",$msgTimesTamp); |
---|
| 1182 | $return['smalldate'] = gmdate("H:i",$msgTimesTamp); |
---|
| 1183 | |
---|
[605] | 1184 | |
---|
[5134] | 1185 | $timestamp_now = strtotime("now"); |
---|
| 1186 | // removido offset nao esta sendo parametrizado |
---|
| 1187 | // $timestamp_now = strtotime("now") + $offset; |
---|
| 1188 | |
---|
| 1189 | |
---|
| 1190 | $timestamp_msg_time = $msgTimesTamp; |
---|
[4416] | 1191 | // $timestamp_now is GMT and $timestamp_msg_time is MailDate TZ. |
---|
[535] | 1192 | // The variable $timestamp_diff is calculated without MailDate TZ. |
---|
[4416] | 1193 | $pdate = date_parse($header->MailDate); |
---|
| 1194 | $timestamp_diff = $timestamp_now - $timestamp_msg_time + ($pdate['zone']*(-60)); |
---|
[4795] | 1195 | |
---|
[2] | 1196 | if (gmdate("H",$timestamp_diff) > 0) |
---|
| 1197 | { |
---|
[197] | 1198 | $return['fulldate'] .= " (" . gmdate("H:i", $timestamp_diff) . ' ' . $this->functions->getLang('hours ago') . ')'; |
---|
[2] | 1199 | } |
---|
| 1200 | else |
---|
| 1201 | { |
---|
| 1202 | if (gmdate("i",$timestamp_diff) == 0){ |
---|
[197] | 1203 | $return['fulldate'] .= ' ('. $this->functions->getLang('now').')'; |
---|
[2] | 1204 | } |
---|
| 1205 | elseif (gmdate("i",$timestamp_diff) == 1){ |
---|
[197] | 1206 | $return['fulldate'] .= ' (1 '. $this->functions->getLang('minute ago').')'; |
---|
[2] | 1207 | } |
---|
| 1208 | else{ |
---|
[197] | 1209 | $return['fulldate'] .= " (" . gmdate("i",$timestamp_diff) .' '. $this->functions->getLang('minutes ago') . ')'; |
---|
[2] | 1210 | } |
---|
| 1211 | } |
---|
| 1212 | } |
---|
| 1213 | else{ |
---|
[5134] | 1214 | $return['fulldate'] = gmdate("d/m/Y H:i",$msgTimesTamp); |
---|
| 1215 | $return['smalldate'] = gmdate("d/m/Y",$msgTimesTamp); |
---|
[2] | 1216 | } |
---|
[4795] | 1217 | |
---|
[2] | 1218 | $from = $header->from; |
---|
| 1219 | $return['from'] = array(); |
---|
[5134] | 1220 | $return['from']['name'] = isset($sender[0]->personal) ? $this->decode_string($from[0]->personal) : ''; |
---|
[2] | 1221 | $return['from']['email'] = $this->decode_string($from[0]->mailbox . "@" . $from[0]->host); |
---|
| 1222 | if ($return['from']['name']) |
---|
| 1223 | { |
---|
| 1224 | if (substr($return['from']['name'], 0, 1) == '"') |
---|
| 1225 | $return['from']['full'] = $return['from']['name'] . ' ' . '<' . $return['from']['email'] . '>'; |
---|
| 1226 | else |
---|
| 1227 | $return['from']['full'] = '"' . $return['from']['name'] . '" ' . '<' . $return['from']['email'] . '>'; |
---|
| 1228 | } |
---|
| 1229 | else |
---|
| 1230 | $return['from']['full'] = $return['from']['email']; |
---|
[4795] | 1231 | |
---|
[2] | 1232 | // Sender attribute |
---|
| 1233 | $sender = $header->sender; |
---|
[4795] | 1234 | $return['sender'] = array(); |
---|
[5134] | 1235 | $return['sender']['name'] = isset($sender[0]->personal) ? $this->decode_string($sender[0]->personal): ''; |
---|
[2] | 1236 | $return['sender']['email'] = $this->decode_string($sender[0]->mailbox . "@" . $sender[0]->host); |
---|
[5134] | 1237 | |
---|
[2] | 1238 | if ($return['sender']['name']) |
---|
| 1239 | { |
---|
| 1240 | if (substr($return['sender']['name'], 0, 1) == '"') |
---|
| 1241 | $return['sender']['full'] = $return['sender']['name'] . ' ' . '<' . $return['sender']['email'] . '>'; |
---|
| 1242 | else |
---|
| 1243 | $return['sender']['full'] = '"' . $return['sender']['name'] . '" ' . '<' . $return['sender']['email'] . '>'; |
---|
| 1244 | } |
---|
| 1245 | else |
---|
| 1246 | $return['sender']['full'] = $return['sender']['email']; |
---|
| 1247 | |
---|
| 1248 | if($return['from']['full'] == $return['sender']['full']) |
---|
| 1249 | $return['sender'] = null; |
---|
| 1250 | $to = $header->to; |
---|
| 1251 | $return['toaddress2'] = ""; |
---|
| 1252 | if (!empty($to)) |
---|
| 1253 | { |
---|
| 1254 | foreach ($to as $tmp) |
---|
| 1255 | { |
---|
| 1256 | if (!empty($tmp->personal)) |
---|
| 1257 | { |
---|
| 1258 | $personal_tmp = imap_mime_header_decode($tmp->personal); |
---|
| 1259 | $return['toaddress2'] .= '"' . $personal_tmp[0]->text . '"'; |
---|
| 1260 | $return['toaddress2'] .= " "; |
---|
| 1261 | $return['toaddress2'] .= "<"; |
---|
[320] | 1262 | if ($tmp->host != 'unspecified-domain') |
---|
| 1263 | $return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host; |
---|
| 1264 | else |
---|
| 1265 | $return['toaddress2'] .= $tmp->mailbox; |
---|
[2] | 1266 | $return['toaddress2'] .= ">"; |
---|
| 1267 | $return['toaddress2'] .= ", "; |
---|
| 1268 | } |
---|
| 1269 | else |
---|
| 1270 | { |
---|
[5435] | 1271 | if (isset($tmp->host) && $tmp->host != 'unspecified-domain') |
---|
[320] | 1272 | $return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host; |
---|
| 1273 | else |
---|
| 1274 | $return['toaddress2'] .= $tmp->mailbox; |
---|
[2] | 1275 | $return['toaddress2'] .= ", "; |
---|
| 1276 | } |
---|
| 1277 | } |
---|
| 1278 | $return['toaddress2'] = $this->del_last_two_caracters($return['toaddress2']); |
---|
| 1279 | } |
---|
[4416] | 1280 | else |
---|
| 1281 | { |
---|
[4730] | 1282 | $return['toaddress2'] = ""; |
---|
[4416] | 1283 | } |
---|
[5134] | 1284 | if(isset($header->cc)) |
---|
[2] | 1285 | $cc = $header->cc; |
---|
| 1286 | $return['cc'] = ""; |
---|
| 1287 | if (!empty($cc)) |
---|
| 1288 | { |
---|
| 1289 | foreach ($cc as $tmp_cc) |
---|
| 1290 | { |
---|
| 1291 | if (!empty($tmp_cc->personal)) |
---|
| 1292 | { |
---|
| 1293 | $personal_tmp_cc = imap_mime_header_decode($tmp_cc->personal); |
---|
| 1294 | $return['cc'] .= '"' . $personal_tmp_cc[0]->text . '"'; |
---|
| 1295 | $return['cc'] .= " "; |
---|
| 1296 | $return['cc'] .= "<"; |
---|
[5134] | 1297 | if ($tmp_cc->host != 'unspecified-domain') |
---|
[2] | 1298 | $return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
[5134] | 1299 | else |
---|
| 1300 | $return['cc'] .= $tmp_cc->mailbox; |
---|
| 1301 | //$return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
[2] | 1302 | $return['cc'] .= ">"; |
---|
| 1303 | $return['cc'] .= ", "; |
---|
| 1304 | } |
---|
| 1305 | else |
---|
| 1306 | { |
---|
[5134] | 1307 | if ($tmp_cc->host != 'unspecified-domain') |
---|
[2] | 1308 | $return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
[5134] | 1309 | else |
---|
| 1310 | $return['cc'] .= $tmp_cc->mailbox; |
---|
| 1311 | //$return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
[2] | 1312 | $return['cc'] .= ", "; |
---|
| 1313 | } |
---|
| 1314 | } |
---|
| 1315 | $return['cc'] = $this->del_last_two_caracters($return['cc']); |
---|
| 1316 | } |
---|
| 1317 | else |
---|
| 1318 | { |
---|
| 1319 | $return['cc'] = ""; |
---|
[4795] | 1320 | } |
---|
[449] | 1321 | |
---|
| 1322 | ## |
---|
| 1323 | # @AUTHOR Rodrigo Souza dos Santos |
---|
| 1324 | # @DATE 2008/09/12 |
---|
| 1325 | # @BRIEF Adding the BCC field. |
---|
| 1326 | ## |
---|
[5134] | 1327 | if(isset($header->bcc)){ |
---|
[4795] | 1328 | $bcc = $header->bcc; |
---|
[5134] | 1329 | } |
---|
[449] | 1330 | $return['bcc'] = ""; |
---|
| 1331 | if (!empty($bcc)) |
---|
| 1332 | { |
---|
| 1333 | foreach ($bcc as $tmp_bcc) |
---|
| 1334 | { |
---|
| 1335 | if (!empty($tmp_bcc->personal)) |
---|
| 1336 | { |
---|
| 1337 | $personal_tmp_bcc = imap_mime_header_decode($tmp_bcc->personal); |
---|
| 1338 | $return['bcc'] .= '"' . $personal_tmp_bcc[0]->text . '"'; |
---|
| 1339 | $return['bcc'] .= " "; |
---|
| 1340 | $return['bcc'] .= "<"; |
---|
[5134] | 1341 | if ($tmp_bcc->host != 'unspecified-domain') |
---|
[449] | 1342 | $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
[5134] | 1343 | else |
---|
| 1344 | $return['bcc'] .= $tmp_bcc->mailbox; |
---|
[449] | 1345 | $return['bcc'] .= ">"; |
---|
| 1346 | $return['bcc'] .= ", "; |
---|
| 1347 | } |
---|
| 1348 | else |
---|
| 1349 | { |
---|
[5134] | 1350 | if ($tmp_bcc->host != 'unspecified-domain') |
---|
[449] | 1351 | $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
[5134] | 1352 | else |
---|
| 1353 | $return['bcc'] .= $tmp_bcc->mailbox; |
---|
| 1354 | //$return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
[449] | 1355 | $return['bcc'] .= ", "; |
---|
| 1356 | } |
---|
| 1357 | } |
---|
| 1358 | $return['bcc'] = $this->del_last_two_caracters($return['bcc']); |
---|
[426] | 1359 | } |
---|
[449] | 1360 | else |
---|
| 1361 | { |
---|
| 1362 | $return['bcc'] = ""; |
---|
[4795] | 1363 | } |
---|
[426] | 1364 | |
---|
[2] | 1365 | $reply_to = $header->reply_to; |
---|
| 1366 | $return['reply_to'] = ""; |
---|
| 1367 | if (is_object($reply_to[0])) |
---|
| 1368 | { |
---|
| 1369 | if ($return['from']['email'] != ($reply_to[0]->mailbox."@".$reply_to[0]->host)) |
---|
| 1370 | { |
---|
| 1371 | if (!empty($reply_to[0]->personal)) |
---|
| 1372 | { |
---|
| 1373 | $personal_reply_to = imap_mime_header_decode($tmp_reply_to->personal); |
---|
[41] | 1374 | if(!empty($personal_reply_to[0]->text)) { |
---|
| 1375 | $return['reply_to'] .= '"' . $personal_reply_to[0]->text . '"'; |
---|
| 1376 | $return['reply_to'] .= " "; |
---|
| 1377 | $return['reply_to'] .= "<"; |
---|
| 1378 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 1379 | $return['reply_to'] .= ">"; |
---|
| 1380 | } |
---|
| 1381 | else { |
---|
| 1382 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 1383 | } |
---|
[2] | 1384 | } |
---|
| 1385 | else |
---|
| 1386 | { |
---|
| 1387 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 1388 | } |
---|
| 1389 | } |
---|
| 1390 | } |
---|
| 1391 | $return['reply_to'] = $this->decode_string($return['reply_to']); |
---|
[6007] | 1392 | $return['subject'] = ( isset($header->subject) && trim($header->subject) !== '' ) ? self::decodeMimeString($header->subject) : $this->functions->getLang('(no subject) '); |
---|
[5134] | 1393 | |
---|
[4795] | 1394 | $return['Size'] = $header->Size; |
---|
[828] | 1395 | $return['reply_toaddress'] = $header->reply_toaddress; |
---|
[4795] | 1396 | |
---|
[689] | 1397 | //All this is to help in local messages |
---|
[4795] | 1398 | $return['timestamp'] = $header->udate; |
---|
[689] | 1399 | $return['login'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];//$GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 1400 | $return['reply_toaddress'] = $header->reply_toaddress; |
---|
[6580] | 1401 | |
---|
[5134] | 1402 | if(($return['from']['email'] == '@unspecified-domain' || $return['sender']['email'] == null) && $return['msg_folder'] == 'INBOX/Drafts'){ |
---|
| 1403 | $return['from']['email'] = "Rascunho"; |
---|
| 1404 | } |
---|
[6580] | 1405 | |
---|
| 1406 | if(strpos($return['toaddress2'], 'undisclosed-recipients') !== false){ |
---|
[5134] | 1407 | $return['toaddress2'] = $this->functions->getLang('without destination'); |
---|
[5689] | 1408 | } |
---|
| 1409 | $return['alarm'] = $alarm; |
---|
[6442] | 1410 | |
---|
[2] | 1411 | return $return; |
---|
| 1412 | } |
---|
[1472] | 1413 | |
---|
[5079] | 1414 | |
---|
[5134] | 1415 | /* |
---|
[5079] | 1416 | * Converte textos utf8 para o padrão html. |
---|
[5134] | 1417 | * Modificado por Cristiano Corrêa Schmidt |
---|
| 1418 | * @link http://php.net/manual/en/function.utf8-decode.php |
---|
[5079] | 1419 | * @author luka8088 <luka8088@gmail.com> |
---|
| 1420 | */ |
---|
[5359] | 1421 | static function utf8_to_html ($data) |
---|
[4795] | 1422 | { |
---|
[5359] | 1423 | return preg_replace("/([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)/e", 'self::_utf8_to_html("\\1")', $data); |
---|
[4781] | 1424 | } |
---|
[4795] | 1425 | |
---|
[5359] | 1426 | static function _utf8_to_html ($data) |
---|
| 1427 | { |
---|
[4781] | 1428 | $ret = 0; |
---|
| 1429 | foreach((str_split(strrev(chr((ord($data{0}) % 252 % 248 % 240 % 224 % 192) + 128) . substr($data, 1)))) as $k => $v) |
---|
| 1430 | $ret += (ord($v) % 128) * pow(64, $k); |
---|
[5134] | 1431 | return html_entity_decode("&#$ret;" , ENT_QUOTES); |
---|
[5359] | 1432 | } |
---|
[4781] | 1433 | //------------------------------------------------------------------------------// |
---|
[4795] | 1434 | |
---|
| 1435 | |
---|
[4416] | 1436 | /** |
---|
[5134] | 1437 | * Decodifica uma part da mensagem para iso-8859-1 |
---|
| 1438 | * @param <type> $part parte do email |
---|
| 1439 | * @param <type> $encode codificação da parte |
---|
| 1440 | * @return <type> string decodificada |
---|
[5079] | 1441 | */ |
---|
[4781] | 1442 | function decodeMailPart($part, $encode, $html = true) |
---|
[5359] | 1443 | { |
---|
[4416] | 1444 | switch (strtolower($encode)) |
---|
[5359] | 1445 | { |
---|
[4416] | 1446 | case 'iso-8859-1': |
---|
| 1447 | return $part; |
---|
| 1448 | break; |
---|
| 1449 | case 'utf-8': |
---|
[5359] | 1450 | if ($html) return self::utf8_to_html($part); |
---|
[5134] | 1451 | else return utf8_decode ($part); |
---|
[4416] | 1452 | break; |
---|
| 1453 | default: |
---|
| 1454 | return mb_convert_encoding($part, 'iso-8859-1'); |
---|
[5359] | 1455 | break; |
---|
| 1456 | } |
---|
| 1457 | } |
---|
[4795] | 1458 | |
---|
[4416] | 1459 | |
---|
[2] | 1460 | function get_body_msg($msg_number, $msg_folder) |
---|
| 1461 | { |
---|
[4429] | 1462 | /* |
---|
[4416] | 1463 | * Requires of librarys |
---|
| 1464 | */ |
---|
[5316] | 1465 | require_once dirname(__FILE__).'/../../library/mime/mimePart.php'; |
---|
| 1466 | require_once dirname(__FILE__).'/../../library/mime/mimeDecode.php'; |
---|
| 1467 | require_once dirname(__FILE__).'/class.attachment.inc.php'; |
---|
[5134] | 1468 | //include_once("class.message_components.inc.php"); |
---|
[4416] | 1469 | //--------------------------------------------------------------------// |
---|
[1472] | 1470 | |
---|
[4416] | 1471 | $return = array(); |
---|
[1035] | 1472 | |
---|
[5134] | 1473 | // $msg = new message_components($this->mbox); |
---|
| 1474 | // $msg->fetch_structure($msg_number); |
---|
[1035] | 1475 | |
---|
[4416] | 1476 | $content = ''; |
---|
[1035] | 1477 | |
---|
[5134] | 1478 | /* |
---|
| 1479 | * Chamada original $this->getRawHeader($msg_number)."\r\n".$this->getRawBody($msg_number); |
---|
| 1480 | * Inserido replace para corrigir um bug que acontece raramente em mensagens vindas do outlook com muitos destinatarios |
---|
| 1481 | */ |
---|
| 1482 | $rawMessageData = str_replace("\r\n\t", '', $this->getRawHeader($msg_number))."\r\n".$this->getRawBody($msg_number); |
---|
[3018] | 1483 | |
---|
[4416] | 1484 | $decoder = new Mail_mimeDecode($rawMessageData); |
---|
[3018] | 1485 | |
---|
[4416] | 1486 | $params['include_bodies'] = true; |
---|
| 1487 | $params['decode_bodies'] = true; |
---|
| 1488 | $params['decode_headers'] = true; |
---|
[5134] | 1489 | if(array_key_exists('nested_messages_are_shown', $_SESSION['phpgw_info']['user']['preferences']['expressoMail']) && ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['nested_messages_are_shown'] == '1')) |
---|
| 1490 | $params['rfc_822bodies'] = true; |
---|
[4416] | 1491 | $structure = $decoder->decode($params); |
---|
[3018] | 1492 | |
---|
[4416] | 1493 | /* |
---|
| 1494 | * Inicia Gerenciador de Anexos |
---|
| 1495 | */ |
---|
| 1496 | $attachmentManager = new attachment(); |
---|
| 1497 | $attachmentManager->setStructure($structure); |
---|
| 1498 | //----------------------------------------------// |
---|
[1472] | 1499 | |
---|
[4416] | 1500 | /* |
---|
[4429] | 1501 | * Monta informações dos anexos para o cabecalhos |
---|
[4416] | 1502 | */ |
---|
| 1503 | $attachments = $attachmentManager->getAttachmentsInfo(); |
---|
| 1504 | $return['attachments'] = $attachments; |
---|
| 1505 | //----------------------------------------------// |
---|
[2] | 1506 | |
---|
[4416] | 1507 | /* |
---|
[4429] | 1508 | * Monta informações das imagens |
---|
| 1509 | */ |
---|
[4416] | 1510 | $images = $attachmentManager->getEmbeddedImagesInfo(); |
---|
| 1511 | //----------------------------------------------// |
---|
[1472] | 1512 | |
---|
[4795] | 1513 | if(!$this->has_cid) |
---|
| 1514 | { |
---|
[4416] | 1515 | $return['thumbs'] = $this->get_thumbs($images,$msg_number,$msg_folder); |
---|
[5134] | 1516 | // $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); |
---|
[4795] | 1517 | } |
---|
[1472] | 1518 | |
---|
[4416] | 1519 | switch (strtolower($structure->ctype_primary)) |
---|
[4795] | 1520 | { |
---|
[4908] | 1521 | case 'text': |
---|
| 1522 | if(strtolower($structure->ctype_secondary) == 'x-pkcs7-mime') |
---|
| 1523 | { |
---|
[4795] | 1524 | $return['body']='isCripted'; |
---|
| 1525 | return $return; |
---|
| 1526 | } |
---|
[4416] | 1527 | $attachment = array(); |
---|
[3414] | 1528 | |
---|
[4416] | 1529 | $msg_subtype = strtolower($structure->ctype_secondary); |
---|
[5134] | 1530 | if(isset($structure->disposition)) |
---|
[4416] | 1531 | $disposition = strtolower($structure->disposition); |
---|
[5134] | 1532 | else |
---|
| 1533 | $disposition = ''; |
---|
[1472] | 1534 | |
---|
[4908] | 1535 | if(($msg_subtype == "html" || $msg_subtype == 'plain') && ($disposition != 'attachment')) |
---|
[4795] | 1536 | { |
---|
[4416] | 1537 | if(strtolower($msg_subtype) == 'plain') |
---|
[4795] | 1538 | { |
---|
[5134] | 1539 | if(isset($structure->ctype_parameters['charset'])) |
---|
[4781] | 1540 | $content = $this->decodeMailPart($structure->body, $structure->ctype_parameters['charset'],false); |
---|
[5134] | 1541 | else |
---|
| 1542 | $content = $this->decodeMailPart($structure->body, null,false); |
---|
[4795] | 1543 | $content = str_replace( array( '<', '>' ), array( ' #$<$# ', ' #$>$# ' ), $content ); |
---|
| 1544 | $content = htmlentities( $content ); |
---|
[4784] | 1545 | $this->replace_links($content); |
---|
[4795] | 1546 | $content = str_replace( array( ' #$<$# ', ' #$>$# ' ), array( '<', '>' ), $content ); |
---|
| 1547 | $content = '<pre>' . $content . '</pre>'; |
---|
| 1548 | $return[ 'body' ] = $content; |
---|
| 1549 | return $return; |
---|
| 1550 | } |
---|
[4781] | 1551 | $content = $this->decodeMailPart($structure->body, $structure->ctype_parameters['charset']); |
---|
[4795] | 1552 | } |
---|
[5134] | 1553 | if(strtolower($structure->ctype_secondary) == 'calendar') |
---|
| 1554 | $content .= $this->builderMsgCalendar($structure->body); |
---|
[1897] | 1555 | |
---|
[4416] | 1556 | break; |
---|
[1897] | 1557 | |
---|
[4429] | 1558 | case 'multipart': |
---|
[5134] | 1559 | $this->builderMsgBody($structure , $content); |
---|
[1897] | 1560 | |
---|
[4416] | 1561 | break; |
---|
[1897] | 1562 | |
---|
[4416] | 1563 | case 'message': |
---|
[5134] | 1564 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['nested_messages_are_shown'] != 1) |
---|
| 1565 | { |
---|
[4416] | 1566 | if(!is_array($structure->parts)) |
---|
[4795] | 1567 | { |
---|
[4416] | 1568 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[4781] | 1569 | $content .= '<pre>'.htmlentities($this->decodeMailPart($structure->body, $structure->ctype_parameters['charset'],false)).'</pre>'; |
---|
[4416] | 1570 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[4795] | 1571 | } |
---|
| 1572 | else |
---|
[4416] | 1573 | $this->builderMsgBody($structure , $content,true); |
---|
[5134] | 1574 | } |
---|
[4429] | 1575 | break; |
---|
[3018] | 1576 | |
---|
[5134] | 1577 | case 'application': |
---|
| 1578 | if(strtolower($structure->ctype_secondary) == 'x-pkcs7-mime') |
---|
| 1579 | { |
---|
| 1580 | // $return['body']='isCripted'; |
---|
| 1581 | // return $return; |
---|
| 1582 | |
---|
| 1583 | //TODO: Descartar código após atualização do módulo de segurança da SERPRO |
---|
| 1584 | $rawMessageData2 = $this->extractSignedContents($rawMessageData); |
---|
| 1585 | if($rawMessageData2 === false){ |
---|
| 1586 | $return['body']='isCripted'; |
---|
| 1587 | return $return; |
---|
| 1588 | } |
---|
| 1589 | $decoder2 = new Mail_mimeDecode($rawMessageData2); |
---|
| 1590 | $structure2 = $decoder2->decode($params); |
---|
| 1591 | $this-> builderMsgBody($structure2 , $content); |
---|
| 1592 | |
---|
| 1593 | $attachmentManager->setStructure($structure2); |
---|
| 1594 | /* |
---|
| 1595 | * Monta informações dos anexos para o cabecarios |
---|
| 1596 | */ |
---|
| 1597 | $attachments = $attachmentManager->getAttachmentsInfo(); |
---|
| 1598 | $return['attachments'] = $attachments; |
---|
| 1599 | |
---|
| 1600 | //----------------------------------------------// |
---|
| 1601 | |
---|
| 1602 | /* |
---|
| 1603 | * Monta informações das imagens |
---|
| 1604 | */ |
---|
| 1605 | $images = $attachmentManager->getEmbeddedImagesInfo(); |
---|
| 1606 | //----------------------------------------------// |
---|
| 1607 | |
---|
| 1608 | if(!$this->has_cid){ |
---|
| 1609 | $return['thumbs'] = $this->get_thumbs($images,$msg_number,$msg_folder); |
---|
| 1610 | $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); |
---|
| 1611 | } |
---|
| 1612 | } |
---|
| 1613 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[4429] | 1614 | default: |
---|
| 1615 | if(count($attachments) > 0) |
---|
| 1616 | $content .= ''; |
---|
| 1617 | break; |
---|
[4795] | 1618 | } |
---|
[3018] | 1619 | |
---|
[1472] | 1620 | $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); |
---|
[2] | 1621 | $this->set_messages_flag($params); |
---|
[4416] | 1622 | $content = $this->process_embedded_images($images,$msg_number,$content, $msg_folder); |
---|
[4795] | 1623 | $content = $this->replace_special_characters($content); |
---|
[4416] | 1624 | $this->replace_links($content); |
---|
| 1625 | $return['body'] = &$content; |
---|
| 1626 | |
---|
[4795] | 1627 | return $return; |
---|
[2] | 1628 | } |
---|
[1472] | 1629 | |
---|
[5134] | 1630 | |
---|
| 1631 | //TODO: Descartar código após atualização do módulo de segurança da SERPRO |
---|
| 1632 | function extractSignedContents( $data ) |
---|
| 1633 | { |
---|
| 1634 | $pipes_desc = array( |
---|
| 1635 | 0 => array('pipe', 'r'), |
---|
| 1636 | 1 => array('pipe', 'w') |
---|
| 1637 | ); |
---|
| 1638 | |
---|
| 1639 | $fp = proc_open( 'openssl smime -verify -noverify -nochain', $pipes_desc, $pipes); |
---|
| 1640 | if (!is_resource($fp)) { |
---|
| 1641 | return false; |
---|
| 1642 | } |
---|
| 1643 | |
---|
| 1644 | $output = ''; |
---|
| 1645 | |
---|
| 1646 | /* $pipes[0] => writeable handle connected to child stdin |
---|
| 1647 | $pipes[1] => readable handle connected to child stdout */ |
---|
| 1648 | fwrite($pipes[0], $data); |
---|
| 1649 | fclose($pipes[0]); |
---|
| 1650 | |
---|
| 1651 | while (!feof($pipes[1])) { |
---|
| 1652 | $output .= fgets($pipes[1], 1024); |
---|
| 1653 | } |
---|
| 1654 | fclose($pipes[1]); |
---|
| 1655 | proc_close($fp); |
---|
| 1656 | |
---|
| 1657 | return $output; |
---|
| 1658 | } |
---|
| 1659 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1660 | |
---|
| 1661 | function builderMsgCalendar($calendar) |
---|
| 1662 | { |
---|
| 1663 | $icalService = ServiceLocator::getService('ical'); |
---|
| 1664 | |
---|
| 1665 | $codificao = mb_detect_encoding($calendar.'x', 'UTF-8, ISO-8859-1'); |
---|
| 1666 | if($codificao == 'UTF-8') |
---|
| 1667 | $calendar = utf8_decode($calendar); |
---|
| 1668 | |
---|
| 1669 | if($icalService->setIcal($calendar)) |
---|
| 1670 | { |
---|
| 1671 | $content = ''; |
---|
| 1672 | |
---|
| 1673 | switch ($icalService->getMethod()) { |
---|
| 1674 | |
---|
| 1675 | case 'REPLY': |
---|
| 1676 | break; |
---|
| 1677 | |
---|
[6430] | 1678 | case 'CANCEL': |
---|
[5134] | 1679 | |
---|
| 1680 | $ical = $icalService->getComponent('vevent'); |
---|
| 1681 | $content.= '<b>'.$this->functions->getLang('Event Calendar').'</b><br /><br />'; |
---|
| 1682 | $content.= '<span style="font-size: 12" >'; |
---|
| 1683 | $content.= '<b><span style="color:red">'.$this->functions->getLang('Your event has been canceled').'</span></b>'; |
---|
| 1684 | |
---|
| 1685 | if($ical['description']['value']) |
---|
| 1686 | $content.= ' <br /> <br /> '.str_replace('\n','<br />',nl2br($ical['description']['value'])); |
---|
| 1687 | |
---|
| 1688 | $content.= '<br /><b>* '.$this->functions->getLang('To remove the event from your calendar to import the iCal file attached').'.</b>'; |
---|
| 1689 | $content.= '</span><br /><br />'; |
---|
| 1690 | break; |
---|
| 1691 | |
---|
| 1692 | case 'REQUEST': |
---|
| 1693 | |
---|
| 1694 | $ical = $icalService->getComponent('vevent'); |
---|
| 1695 | if($ical['dtstart']['value']['tz'] == 'Z') |
---|
| 1696 | { |
---|
| 1697 | $tz = $_SESSION['phpgw_info']['user']['preferences']['common']['tz_offset']; |
---|
| 1698 | $ical['dtstart']['value']['hour'] += $tz; |
---|
| 1699 | $ical['dtend']['value']['hour'] += $tz; |
---|
| 1700 | } |
---|
| 1701 | |
---|
| 1702 | $content.= '<b>'.$this->functions->getLang('Event Calendar').'</b><br />'. |
---|
| 1703 | ' <br /> <b>'.$this->functions->getLang('Title').': </b>'.$ical['summary']['value']. |
---|
| 1704 | ' <br /> <b>'.$this->functions->getLang('Location').': </b>'.$ical['location']['value']. |
---|
[5420] | 1705 | ' <br /> <b>'.$this->functions->getLang('Details').': </b>'. str_ireplace('\n','<br />',nl2br($ical['description']['value'])); |
---|
[5134] | 1706 | $content.= ' <br /> <b>'.$this->functions->getLang('Start') . ': </b>' . $ical['dtstart']['value']['day'] . "/" . $ical['dtstart']['value']['month'] . "/" . $ical['dtstart']['value']['year'] . " - " . $ical['dtstart']['value']['hour'] . ":" . $ical['dtstart']['value']['min'] ; |
---|
| 1707 | $content.= ' <br /> <b>'.$this->functions->getLang('End') . ': </b>' . $ical['dtend']['value']['day'] . "/" . $ical['dtend']['value']['month'] . "/" . $ical['dtend']['value']['year'] . " - " . $ical['dtend']['value']['hour'] . ":" . $ical['dtend']['value']['min'] ; |
---|
| 1708 | |
---|
| 1709 | if($ical['organizer']['params']['CN']) |
---|
| 1710 | $content.= ' <br /> <b>'.$this->functions->getLang('Organizer').': </b>'.$ical['organizer']['params']['CN'].' - <a href="MAILTO:'.$ical['organizer']['value'].'">'.$ical['organizer']['value'].'</a></li>' ; |
---|
| 1711 | else |
---|
| 1712 | $content.= ' <br /> <b>'.$this->functions->getLang('Organizer').': </b> <a href="MAILTO:'.$ical['organizer']['value'].'">'.$ical['organizer']['value'].'</a>' ; |
---|
| 1713 | |
---|
| 1714 | if($ical['attendee']) |
---|
| 1715 | { |
---|
| 1716 | $att = ' <br /> <b>'.$this->functions->getLang('Participants').': </b>'; |
---|
| 1717 | $att .= '<ul> '; |
---|
| 1718 | foreach ($ical['attendee'] as $attendee) |
---|
| 1719 | { |
---|
| 1720 | if($attendee['params']['CN']) |
---|
| 1721 | $att .= '<li>'.$attendee['params']['CN'].' - <a href="MAILTO:'.$attendee['value'].'">'.$attendee['value'].'</a></li>' ; |
---|
| 1722 | else |
---|
| 1723 | $att .= '<li><a href="MAILTO:'.$attendee['value'].'">'.$attendee['value'].'</a></li>' ; |
---|
| 1724 | } |
---|
| 1725 | $att .= '</ul> <br />' ; |
---|
| 1726 | } |
---|
| 1727 | $content.= $att; |
---|
| 1728 | |
---|
| 1729 | break; |
---|
| 1730 | default: |
---|
| 1731 | break; |
---|
| 1732 | } |
---|
| 1733 | |
---|
| 1734 | } |
---|
| 1735 | return $content; |
---|
| 1736 | } |
---|
| 1737 | |
---|
[2] | 1738 | function htmlfilter($body) |
---|
| 1739 | { |
---|
| 1740 | require_once('htmlfilter.inc'); |
---|
[1472] | 1741 | |
---|
[2] | 1742 | $tag_list = Array( |
---|
| 1743 | false, |
---|
| 1744 | 'blink', |
---|
| 1745 | 'object', |
---|
| 1746 | 'meta', |
---|
| 1747 | 'html', |
---|
| 1748 | 'link', |
---|
| 1749 | 'frame', |
---|
| 1750 | 'iframe', |
---|
| 1751 | 'layer', |
---|
| 1752 | 'ilayer', |
---|
| 1753 | 'plaintext' |
---|
| 1754 | ); |
---|
| 1755 | |
---|
| 1756 | /** |
---|
| 1757 | * A very exclusive set: |
---|
| 1758 | */ |
---|
| 1759 | // $tag_list = Array(true, "b", "a", "i", "img", "strong", "em", "p"); |
---|
[5814] | 1760 | |
---|
| 1761 | |
---|
[2] | 1762 | $rm_tags_with_content = Array( |
---|
| 1763 | 'script', |
---|
| 1764 | 'style', |
---|
| 1765 | 'applet', |
---|
| 1766 | 'embed', |
---|
| 1767 | 'head', |
---|
| 1768 | 'frameset', |
---|
| 1769 | 'xml', |
---|
| 1770 | 'xmp' |
---|
| 1771 | ); |
---|
| 1772 | |
---|
| 1773 | $self_closing_tags = Array( |
---|
| 1774 | 'img', |
---|
| 1775 | 'br', |
---|
| 1776 | 'hr', |
---|
| 1777 | 'input' |
---|
| 1778 | ); |
---|
| 1779 | |
---|
| 1780 | $force_tag_closing = true; |
---|
| 1781 | |
---|
| 1782 | $rm_attnames = Array( |
---|
| 1783 | '/.*/' => |
---|
| 1784 | Array( |
---|
| 1785 | '/target/i', |
---|
| 1786 | //'/^on.*/i', -> onClick, dos compromissos da agenda. |
---|
| 1787 | '/^dynsrc/i', |
---|
| 1788 | '/^datasrc/i', |
---|
| 1789 | '/^data.*/i', |
---|
| 1790 | '/^lowsrc/i' |
---|
| 1791 | ) |
---|
| 1792 | ); |
---|
| 1793 | |
---|
| 1794 | /** |
---|
| 1795 | * Yeah-yeah, so this looks horrible. Check out htmlfilter.inc for |
---|
| 1796 | * some idea of what's going on here. :) |
---|
| 1797 | */ |
---|
| 1798 | |
---|
| 1799 | $bad_attvals = Array( |
---|
| 1800 | '/.*/' => |
---|
| 1801 | Array( |
---|
| 1802 | '/.*/' => |
---|
| 1803 | Array( |
---|
| 1804 | Array( |
---|
| 1805 | '/^([\'\"])\s*\S+\s*script\s*:*(.*)([\'\"])/si', |
---|
| 1806 | //'/^([\'\"])\s*https*\s*:(.*)([\'\"])/si', -> doclinks notes |
---|
| 1807 | '/^([\'\"])\s*mocha\s*:*(.*)([\'\"])/si', |
---|
| 1808 | '/^([\'\"])\s*about\s*:(.*)([\'\"])/si' |
---|
| 1809 | ), |
---|
| 1810 | Array( |
---|
| 1811 | '\\1oddjob:\\2\\1', |
---|
| 1812 | //'\\1uucp:\\2\\1', -> doclinks notes |
---|
| 1813 | '\\1amaretto:\\2\\1', |
---|
| 1814 | '\\1round:\\2\\1' |
---|
| 1815 | ) |
---|
[1472] | 1816 | ), |
---|
| 1817 | |
---|
[2] | 1818 | '/^style/i' => |
---|
| 1819 | Array( |
---|
| 1820 | Array( |
---|
| 1821 | '/expression/i', |
---|
| 1822 | '/behaviou*r/i', |
---|
| 1823 | '/binding/i', |
---|
| 1824 | '/include-source/i', |
---|
| 1825 | '/url\s*\(\s*([\'\"]*)\s*https*:.*([\'\"]*)\s*\)/si', |
---|
| 1826 | '/url\s*\(\s*([\'\"]*)\s*\S+\s*script:.*([\'\"]*)\s*\)/si' |
---|
| 1827 | ), |
---|
| 1828 | Array( |
---|
| 1829 | 'idiocy', |
---|
| 1830 | 'idiocy', |
---|
| 1831 | 'idiocy', |
---|
| 1832 | 'idiocy', |
---|
| 1833 | 'url(\\1http://securityfocus.com/\\1)', |
---|
| 1834 | 'url(\\1http://securityfocus.com/\\1)' |
---|
| 1835 | ) |
---|
| 1836 | ) |
---|
| 1837 | ) |
---|
| 1838 | ); |
---|
| 1839 | |
---|
| 1840 | $add_attr_to_tag = Array( |
---|
| 1841 | '/^a$/i' => Array('target' => '"_new"') |
---|
| 1842 | ); |
---|
[1472] | 1843 | |
---|
| 1844 | |
---|
[2] | 1845 | $trusted_body = sanitize($body, |
---|
| 1846 | $tag_list, |
---|
| 1847 | $rm_tags_with_content, |
---|
| 1848 | $self_closing_tags, |
---|
| 1849 | $force_tag_closing, |
---|
| 1850 | $rm_attnames, |
---|
| 1851 | $bad_attvals, |
---|
| 1852 | $add_attr_to_tag |
---|
| 1853 | ); |
---|
[1472] | 1854 | |
---|
[2] | 1855 | return $trusted_body; |
---|
| 1856 | } |
---|
[1472] | 1857 | |
---|
[2] | 1858 | function decodeBody($body, $encoding, $charset=null) |
---|
| 1859 | { |
---|
[4416] | 1860 | |
---|
[2] | 1861 | if ($encoding == 'quoted-printable') |
---|
[828] | 1862 | { |
---|
[2] | 1863 | $body = quoted_printable_decode($body); |
---|
[1792] | 1864 | |
---|
[4795] | 1865 | } |
---|
| 1866 | else if ($encoding == 'base64') |
---|
| 1867 | { |
---|
| 1868 | $body = base64_decode($body); |
---|
| 1869 | } |
---|
| 1870 | // All other encodings are returned raw. |
---|
| 1871 | if (strtolower($charset) == "utf-8") |
---|
| 1872 | return utf8_decode($body); |
---|
| 1873 | else |
---|
| 1874 | return $body; |
---|
| 1875 | } |
---|
| 1876 | |
---|
[4436] | 1877 | |
---|
| 1878 | /** |
---|
| 1879 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 1880 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 1881 | * @param $images |
---|
| 1882 | * @param $msgno |
---|
| 1883 | * @param $body |
---|
| 1884 | * @param $msg_folder |
---|
| 1885 | */ |
---|
[4416] | 1886 | function process_embedded_images($images, $msgno, $body, $msg_folder) |
---|
[2] | 1887 | { |
---|
[1472] | 1888 | |
---|
[4416] | 1889 | foreach ($images as $image) |
---|
[4795] | 1890 | { |
---|
[5783] | 1891 | $image['cid'] = preg_replace('/</i', '', $image['cid']); |
---|
| 1892 | $image['cid'] = preg_replace('/>/i', '', $image['cid']); |
---|
[5134] | 1893 | |
---|
| 1894 | $body = str_replace("src=\"cid:".$image['cid']."\"", " src=\"./inc/get_archive.php?msgFolder=$msg_folder&msgNumber=$msgno&indexPart=".$image['pid']."\" ", $body); |
---|
| 1895 | $body = str_replace("src='cid:".$image['cid']."'", " src=\"./inc/get_archive.php?msgFolder=$msg_folder&msgNumber=$msgno&indexPart=".$image['pid']."\"", $body); |
---|
| 1896 | $body = str_replace("src=cid:".$image['cid'], " src=\"./inc/get_archive.php?msgFolder=$msg_folder&msgNumber=$msgno&indexPart=".$image['pid']."\"", $body); |
---|
[4795] | 1897 | } |
---|
| 1898 | return $body; |
---|
[2] | 1899 | } |
---|
[1472] | 1900 | |
---|
[5309] | 1901 | function replace_special_characters($body) |
---|
[5476] | 1902 | { |
---|
| 1903 | if(trim($body) === '') return; |
---|
| 1904 | |
---|
[5375] | 1905 | $body = str_ireplace('POSITION: ABSOLUTE;','', $body); |
---|
[5476] | 1906 | $body = str_ireplace('<o:p> </o:p>','<br />', $body);//Qubra de linha do MSO |
---|
| 1907 | $body = preg_replace('/<(meta|base|link|html|\/html)[^>]*>/i', '', $body); |
---|
| 1908 | |
---|
[5993] | 1909 | require_once(dirname(__FILE__).'/../../library/CssToInlineStyles/css_to_inline_styles.php'); |
---|
[5476] | 1910 | $cssToInlineStyles = new CSSToInlineStyles($body); |
---|
| 1911 | $cssToInlineStyles->setUseInlineStylesBlock(true); |
---|
| 1912 | $cssToInlineStyles->setCleanup(TRUE); |
---|
| 1913 | $body = $cssToInlineStyles->convert(); //Converte as tag style em inline styles |
---|
[4795] | 1914 | |
---|
[5309] | 1915 | ///--------------------------------// |
---|
| 1916 | // tags to be removed doe to security reasons |
---|
| 1917 | $tag_list = Array( |
---|
| 1918 | 'blink', 'object', 'frame', 'iframe', |
---|
| 1919 | 'layer', 'ilayer', 'plaintext', 'script', |
---|
[5476] | 1920 | 'applet', 'embed', 'frameset', 'xml', 'xmp','style','head' |
---|
[5309] | 1921 | ); |
---|
[2] | 1922 | |
---|
[5309] | 1923 | foreach ($tag_list as $index => $tag) |
---|
| 1924 | $body = @mb_eregi_replace("<$tag\\b[^>]*>(.*?)</$tag>", '', $body); |
---|
[5134] | 1925 | |
---|
[5476] | 1926 | // Malicious Code Remove |
---|
| 1927 | $dirtyCodePattern = "/(<([\w]+[\w0-9]*)(.*)on(mouse(move|over|down|up)|load|blur|change|error|click|dblclick|focus|key(down|up|press)|select)([\n\ ]*)=([\n\ ]*)[\"'][^>\"']*[\"']([^>]*)>)(.*)(<\/\\2>)?/misU"; |
---|
| 1928 | preg_match_all($dirtyCodePattern, $body, $rest, PREG_PATTERN_ORDER); |
---|
| 1929 | foreach ($rest[0] as $i => $val) { |
---|
| 1930 | if (!(preg_match("/javascript:window\.open\(\"([^'\"]*)\/index\.php\?menuaction=calendar\.uicalendar\.set_action\&cal_id=([^;'\"]+);?['\"]/i", $rest[1][$i]) && strtoupper($rest[4][$i]) == "CLICK" )) //Calendar events |
---|
| 1931 | $body = str_replace($rest[1][$i], "<" . $rest[2][$i] . $rest[3][$i] . $rest[7][$i] . ">", $body); |
---|
[5435] | 1932 | } |
---|
[5309] | 1933 | |
---|
[5476] | 1934 | /* |
---|
| 1935 | * Remove deslocamento a esquerda colocado pelo Outlook. |
---|
| 1936 | * Este delocamento faz com que algumas palavras fiquem escondidas atras da barra lateral do expresso. |
---|
| 1937 | */ |
---|
| 1938 | $body = mb_ereg_replace("(<p[^>]*)(text-indent:[^>;]*-[^>;]*;)([^>]*>)", "\\1\\3", $body); |
---|
| 1939 | $body = mb_ereg_replace("(<p[^>]*)(margin-right:[^>;]*-[^>;]*;)([^>]*>)", "\\1\\3", $body); |
---|
| 1940 | $body = mb_ereg_replace("(<p[^>]*)(margin-left:[^>;]*-[^>;]*;)([^>]*>)", "\\1\\3", $body); |
---|
| 1941 | //--------------------------------------------------------------------------------------------// |
---|
| 1942 | //Remoção de tags <span></span> para correção de erro no firefox |
---|
| 1943 | //Comentado pois estes replaces geram erros no html da msg, não se pode garantir que o os </span></span> sejam realmente os fechamentos dos <span><span>. |
---|
| 1944 | //Caso realmente haja a nescessidade de remover estes spans deve ser repensado a forma de como faze-lo. |
---|
| 1945 | // $body = mb_eregi_replace("<span><span>","",$body); |
---|
| 1946 | // $body = mb_eregi_replace("</span></span>","",$body); |
---|
| 1947 | //Correção para compatibilização com Outlook, ao visualizar a mensagem |
---|
| 1948 | $body = mb_ereg_replace('<!--\[', '<!-- [', $body); |
---|
| 1949 | $body = mb_ereg_replace('<!\[endif\]-->', '<![endif]-->', $body); |
---|
| 1950 | $body = preg_replace("/<p[^\/>]*>([\s]?)*<\/p[^>]*>/", '', $body); //Remove paragrafos vazios (evita duplo espaçamento em emails do MSO) |
---|
| 1951 | |
---|
| 1952 | return $body ; |
---|
[5309] | 1953 | } |
---|
[5079] | 1954 | |
---|
[4784] | 1955 | function replace_links_callback($matches) |
---|
[4800] | 1956 | { |
---|
[5247] | 1957 | if($matches[3]) |
---|
| 1958 | $pref = $matches[3]; |
---|
| 1959 | else |
---|
| 1960 | $pref = $matches[3] = 'http'; |
---|
[4795] | 1961 | |
---|
[5247] | 1962 | return '<a href="'.$pref.'://'.$matches[4].$matches[5].'" target="_blank">'.$matches[0].'</a>'; |
---|
[4784] | 1963 | } |
---|
[4795] | 1964 | |
---|
| 1965 | |
---|
[4436] | 1966 | /** |
---|
| 1967 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 1968 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 1969 | * @param $body corpo da mensagem |
---|
| 1970 | */ |
---|
| 1971 | function replace_links(&$body) |
---|
[5247] | 1972 | { |
---|
[4784] | 1973 | // Trata urls do tipo aaaa.bbb.empresa |
---|
| 1974 | // Usadas na intranet. |
---|
[5247] | 1975 | $pattern = '/(?<=[\s|(<br>)|\n|\r|;])(((http|https|ftp|ftps)?:\/\/((?:[\w]\.?)+(?::[\d]+)?[:\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\:\/\w.\-~&=?%;@+]*))/i'; |
---|
| 1976 | $body = preg_replace_callback($pattern,array( &$this, 'replace_links_callback'), $body); |
---|
[1897] | 1977 | |
---|
[4795] | 1978 | } |
---|
| 1979 | |
---|
[91] | 1980 | function get_signature($msg, $msg_number, $msg_folder) |
---|
[1035] | 1981 | { |
---|
[3352] | 1982 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
| 1983 | include_once("class.db_functions.inc.php"); |
---|
| 1984 | foreach ($msg->file_type[$msg_number] as $index => $file_type) |
---|
| 1985 | { |
---|
| 1986 | $sign = array(); |
---|
| 1987 | $temp = $this->get_info_head_msg($msg_number); |
---|
| 1988 | if($temp['ContentType'] =='normal') return $sign; |
---|
| 1989 | $file_type = strtolower($file_type); |
---|
| 1990 | if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') |
---|
[91] | 1991 | { |
---|
[3394] | 1992 | if ($temp['ContentType'] == 'signature') |
---|
[3352] | 1993 | { |
---|
[3394] | 1994 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 1995 | $this->mbox = $this->open_mbox($msg_folder); |
---|
[1035] | 1996 | |
---|
[3352] | 1997 | $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); |
---|
[1035] | 1998 | |
---|
[3352] | 1999 | $imap_msg = @imap_fetchheader($this->mbox, $msg_number, FT_UID); |
---|
| 2000 | $imap_msg .= @imap_body($this->mbox, $msg_number, FT_UID); |
---|
[1035] | 2001 | |
---|
[3352] | 2002 | $certificado = new certificadoB(); |
---|
| 2003 | $validade = $certificado->verificar($imap_msg); |
---|
[3394] | 2004 | $sign[] = $certificado->msg_sem_assinatura; |
---|
[3352] | 2005 | if ($certificado->apresentado) |
---|
| 2006 | { |
---|
| 2007 | $from = $header->from; |
---|
| 2008 | foreach ($from as $id => $object) |
---|
| 2009 | { |
---|
| 2010 | $fromname = $object->personal; |
---|
| 2011 | $fromaddress = $object->mailbox . "@" . $object->host; |
---|
| 2012 | } |
---|
| 2013 | foreach ($certificado->erros_ssl as $item) |
---|
| 2014 | { |
---|
| 2015 | $sign[] = $item . "#@#"; |
---|
| 2016 | } |
---|
[1035] | 2017 | |
---|
[3352] | 2018 | if (count($certificado->erros_ssl) < 1) |
---|
| 2019 | { |
---|
| 2020 | $check_msg = 'Message untouched'; |
---|
| 2021 | if(strtoupper($fromaddress) == strtoupper($certificado->dados['EMAIL'])) |
---|
| 2022 | { |
---|
| 2023 | $check_msg .= ' and authentic###'; |
---|
| 2024 | } |
---|
| 2025 | else |
---|
| 2026 | { |
---|
| 2027 | $check_msg .= ' with signer different from sender#@#'; |
---|
| 2028 | } |
---|
| 2029 | $sign[] = $check_msg; |
---|
| 2030 | } |
---|
| 2031 | |
---|
| 2032 | $sign[] = 'Message signed by: ###' . $certificado->dados['NOME']; |
---|
| 2033 | $sign[] = 'Certificate email: ###' . $certificado->dados['EMAIL']; |
---|
| 2034 | $sign[] = 'Mail from: ###' . $fromaddress; |
---|
| 2035 | $sign[] = 'Certificate Authority: ###' . $certificado->dados['EMISSOR']; |
---|
| 2036 | $sign[] = 'Validity of certificate: ###' . gmdate('r',openssl_to_timestamp($certificado->dados['FIM_VALIDADE'])); |
---|
| 2037 | $sign[] = 'Message date: ###' . $header->Date; |
---|
[1035] | 2038 | |
---|
[3352] | 2039 | $cert = openssl_x509_parse($certificado->cert_assinante); |
---|
[1035] | 2040 | |
---|
[3352] | 2041 | $sign_alert = array(); |
---|
| 2042 | $sign_alert[] = 'Certificate Owner###:\n'; |
---|
| 2043 | $sign_alert[] = 'Common Name (CN)### ' . $cert[subject]['CN'] . '\n'; |
---|
| 2044 | $X = substr($certificado->dados['NASCIMENTO'] ,0,2) . '-' . substr($certificado->dados['NASCIMENTO'] ,2,2) . '-' . substr($certificado->dados['NASCIMENTO'] ,4,4); |
---|
| 2045 | $sign_alert[]= 'Organization (O)### ' . $cert[subject]['O'] . '\n'; |
---|
| 2046 | $sign_alert[]= 'Organizational Unit (OU)### ' . $cert[subject]['OU'][0] . '\n'; |
---|
| 2047 | //$sign_alert[] = 'Serial Number### ' . $cert['serialNumber'] . '\n'; |
---|
| 2048 | $sign_alert[] = 'Personal Data###:' . '\n'; |
---|
| 2049 | $sign_alert[] = 'Birthday### ' . $X . '\n'; |
---|
| 2050 | $sign_alert[]= 'Fiscal Id### ' . $certificado->dados['CPF'] . '\n'; |
---|
| 2051 | $sign_alert[]= 'Identification### ' . $certificado->dados['RG'] . '\n\n'; |
---|
| 2052 | $sign_alert[]= 'Certificate Issuer###:\n'; |
---|
| 2053 | $sign_alert[]= 'Common Name (CN)### ' . $cert[issuer]['CN'] . '\n'; |
---|
| 2054 | $sign_alert[]= 'Organization (O)### ' . $cert[issuer]['O'] . '\n'; |
---|
| 2055 | $sign_alert[]= 'Organizational Unit (OU)### ' . $cert[issuer]['OU'][0] . '\n\n'; |
---|
| 2056 | $sign_alert[]= 'Validity###:\n'; |
---|
| 2057 | $H = data_hora($cert[validFrom]); |
---|
| 2058 | $X = substr($H,6,2) . '-' . substr($H,4,2) . '-' . substr($H,0,4); |
---|
| 2059 | $sign_alert[]= 'Valid From### ' . $X . '\n'; |
---|
| 2060 | $H = data_hora($cert[validTo]); |
---|
| 2061 | $X = substr($H,6,2) . '-' . substr($H,4,2) . '-' . substr($H,0,4); |
---|
| 2062 | $sign_alert[]= 'Valid Until### ' . $X; |
---|
| 2063 | $sign[] = $sign_alert; |
---|
| 2064 | |
---|
| 2065 | $this->db = new db_functions(); |
---|
| 2066 | |
---|
| 2067 | // TODO: testar se existe um certificado no banco e verificar qual ᅵ o mais atual. |
---|
| 2068 | if(!$certificado->dados['EXPIRADO'] && !$certificado->dados['REVOGADO'] && count($certificado->erros_ssl) < 1) |
---|
| 2069 | $this->db->insert_certificate(strtolower($certificado->dados['EMAIL']), $certificado->cert_assinante, $certificado->dados['SERIALNUMBER'], $certificado->dados['AUTHORITYKEYIDENTIFIER']); |
---|
[91] | 2070 | } |
---|
[3352] | 2071 | else |
---|
| 2072 | { |
---|
| 2073 | $sign[] = "<span style=color:red>" . $this->functions->getLang('Invalid signature') . "</span>"; |
---|
| 2074 | foreach($certificado->erros_ssl as $item) |
---|
| 2075 | $sign[] = "<span style=color:red>" . $this->functions->getLang($item) . "</span>"; |
---|
| 2076 | } |
---|
| 2077 | } |
---|
[91] | 2078 | } |
---|
[3352] | 2079 | } |
---|
| 2080 | return $sign; |
---|
[91] | 2081 | } |
---|
| 2082 | |
---|
[4436] | 2083 | |
---|
| 2084 | /** |
---|
| 2085 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 2086 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 2087 | * @param $images |
---|
| 2088 | * @param $msg_number |
---|
| 2089 | * @param $msg_folder |
---|
| 2090 | */ |
---|
[4416] | 2091 | function get_thumbs($images, $msg_number, $msg_folder) |
---|
[2] | 2092 | { |
---|
[4416] | 2093 | |
---|
[5134] | 2094 | if (!count($images)) return ''; |
---|
[4416] | 2095 | |
---|
[5316] | 2096 | foreach ($images as $key => $value) { |
---|
[5134] | 2097 | $images[$key]['width'] = 160; |
---|
| 2098 | $images[$key]['height'] = 120; |
---|
[5316] | 2099 | $images[$key]['url'] = "inc/get_archive.php?msgFolder=".$msg_folder."&msgNumber=".$msg_number."&indexPart=".$value['pid']."&image=true"; |
---|
[4795] | 2100 | } |
---|
[5134] | 2101 | |
---|
| 2102 | return json_encode($images); |
---|
[2] | 2103 | } |
---|
[1472] | 2104 | |
---|
[2] | 2105 | /*function delete_msg($params) |
---|
| 2106 | { |
---|
| 2107 | $folder = $params['folder']; |
---|
| 2108 | $msgs_to_delete = explode(",",$params['msgs_to_delete']); |
---|
[1472] | 2109 | |
---|
[2] | 2110 | $mbox_stream = $this->open_mbox($folder); |
---|
[1472] | 2111 | |
---|
[2] | 2112 | foreach ($msgs_to_delete as $msg_number){ |
---|
| 2113 | imap_delete($mbox_stream, $msg_number, FT_UID); |
---|
| 2114 | } |
---|
| 2115 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
| 2116 | return $params['msgs_to_delete']; |
---|
| 2117 | }*/ |
---|
| 2118 | |
---|
| 2119 | // Novo |
---|
| 2120 | function delete_msgs($params) |
---|
| 2121 | { |
---|
[4795] | 2122 | |
---|
[2] | 2123 | $folder = $params['folder']; |
---|
[51] | 2124 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); |
---|
[2] | 2125 | $msgs_number = explode(",",$params['msgs_number']); |
---|
[5134] | 2126 | if(array_key_exists('border_ID' ,$params)) |
---|
[2] | 2127 | $border_ID = $params['border_ID']; |
---|
[5134] | 2128 | else |
---|
| 2129 | $border_ID = ''; |
---|
[2] | 2130 | $return = array(); |
---|
[4795] | 2131 | |
---|
[5134] | 2132 | if (array_key_exists('get_previous_msg' , $params) && $params['get_previous_msg']){ |
---|
[2] | 2133 | $return['previous_msg'] = $this->get_info_previous_msg($params); |
---|
[449] | 2134 | // Fix problem in unserialize function JS. |
---|
| 2135 | $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); |
---|
| 2136 | } |
---|
[2] | 2137 | |
---|
[4795] | 2138 | //$mbox_stream = $this->open_mbox($folder); |
---|
[504] | 2139 | $mbox_stream = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); |
---|
[4795] | 2140 | |
---|
[2] | 2141 | foreach ($msgs_number as $msg_number) |
---|
| 2142 | { |
---|
| 2143 | if (imap_delete($mbox_stream, $msg_number, FT_UID)); |
---|
| 2144 | $return['msgs_number'][] = $msg_number; |
---|
| 2145 | } |
---|
[4795] | 2146 | |
---|
[2] | 2147 | $return['folder'] = $folder; |
---|
| 2148 | $return['border_ID'] = $border_ID; |
---|
[4795] | 2149 | |
---|
[51] | 2150 | if($mbox_stream) |
---|
| 2151 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[6212] | 2152 | |
---|
[5172] | 2153 | $return['status'] = true; |
---|
[2] | 2154 | return $return; |
---|
| 2155 | } |
---|
| 2156 | |
---|
[1472] | 2157 | |
---|
[2] | 2158 | function refresh($params) |
---|
| 2159 | { |
---|
[3265] | 2160 | |
---|
[5134] | 2161 | $return = array(); |
---|
| 2162 | $return['new_msgs'] = 0; |
---|
[2] | 2163 | $folder = $params['folder']; |
---|
| 2164 | $msg_range_begin = $params['msg_range_begin']; |
---|
| 2165 | $msg_range_end = $params['msg_range_end']; |
---|
| 2166 | $msgs_existent = $params['msgs_existent']; |
---|
[1472] | 2167 | $sort_box_type = $params['sort_box_type']; |
---|
[2] | 2168 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 2169 | $msgs_in_the_server = array(); |
---|
[53] | 2170 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
[828] | 2171 | $msgs_in_the_server = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); |
---|
| 2172 | $msgs_in_the_server = array_keys($msgs_in_the_server); |
---|
| 2173 | $num_msgs = (count($msgs_in_the_server) - imap_num_recent($this->mbox)); |
---|
[5158] | 2174 | $dif = ($params['msg_range_end'] - $params['msg_range_begin']) +1; |
---|
| 2175 | if(!count($msgs_in_the_server)){ |
---|
| 2176 | $msg_range_begin -= $dif; |
---|
| 2177 | $msg_range_end -= $dif; |
---|
| 2178 | $msgs_in_the_server = $this->get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$msg_range_begin,$msg_range_end); |
---|
| 2179 | $msgs_in_the_server = array_keys($msgs_in_the_server); |
---|
| 2180 | $num_msgs = NULL; |
---|
| 2181 | $return['msg_range_begin'] = $msg_range_begin; |
---|
| 2182 | $return['msg_range_end'] = $msg_range_end; |
---|
| 2183 | } |
---|
| 2184 | $return['new_msgs'] = imap_num_recent($this->mbox); |
---|
| 2185 | |
---|
[1472] | 2186 | $msgs_in_the_client = explode(",", $msgs_existent); |
---|
[51] | 2187 | |
---|
[2] | 2188 | $msg_to_insert = array_diff($msgs_in_the_server, $msgs_in_the_client); |
---|
[5134] | 2189 | |
---|
| 2190 | if(count($msg_to_insert) > 0 && $return['new_msgs'] == 0 && $msgs_in_the_client[0] != ""){ |
---|
| 2191 | $aux = 0; |
---|
| 2192 | while(array_key_exists($aux, $msg_to_insert)){ |
---|
| 2193 | if($msg_to_insert[$aux] > $msgs_in_the_client[0]){ |
---|
| 2194 | $return['new_msgs'] += 1; |
---|
| 2195 | } |
---|
| 2196 | $aux++; |
---|
| 2197 | } |
---|
| 2198 | }else if(count($msg_to_insert) > 0 && $msgs_in_the_server && $msgs_in_the_client[0] != "" && $return['new_msgs'] == 0){ |
---|
| 2199 | $aux = 0; |
---|
| 2200 | while(array_key_exists($aux, $msg_to_insert)){ |
---|
| 2201 | if($msg_to_insert[$aux] == $msgs_in_the_server[$aux]){ |
---|
| 2202 | $return['new_msgs'] += 1; |
---|
| 2203 | } |
---|
| 2204 | $aux++; |
---|
| 2205 | } |
---|
[5158] | 2206 | }else if($num_msgs < $msg_range_end && $return['new_msgs'] == 0 && count($msg_to_insert) > 0 && $msg_range_end == $dif){ |
---|
[5134] | 2207 | $return['tot_msgs'] = $num_msgs; |
---|
| 2208 | } |
---|
| 2209 | |
---|
[5158] | 2210 | if(!count($msgs_in_the_server)){ |
---|
| 2211 | return Array(); |
---|
| 2212 | } |
---|
| 2213 | |
---|
[271] | 2214 | $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); |
---|
[2] | 2215 | $msgs_to_exec = array(); |
---|
[3265] | 2216 | foreach($msg_to_insert as $msg_number) |
---|
| 2217 | $msgs_to_exec[] = $msg_number; |
---|
[4764] | 2218 | //sort($msgs_to_exec); |
---|
[2] | 2219 | $i = 0; |
---|
[3265] | 2220 | foreach($msgs_to_exec as $msg_number) |
---|
[2] | 2221 | { |
---|
[5359] | 2222 | $sample = false; |
---|
| 2223 | if( (isset($this->prefs['preview_msg_subject']) || ($this->prefs['preview_msg_subject'] === '1')) && (isset($this->prefs['preview_msg_tip'] ) || ($this->prefs['preview_msg_tip'] === '1')) ) |
---|
| 2224 | $sample = true; |
---|
| 2225 | |
---|
| 2226 | $return[$i] = $this->get_info_head_msg($msg_number , $sample ); |
---|
| 2227 | |
---|
| 2228 | //get the next msg number to append this msg in the view in a correct place |
---|
| 2229 | $msg_key_position = array_search($msg_number, $msgs_in_the_server); |
---|
[3955] | 2230 | |
---|
[5359] | 2231 | $return[$i]['msg_key_position'] = $msg_key_position; |
---|
| 2232 | if($msg_key_position !== false && array_key_exists($msg_key_position + 1,$msgs_in_the_server) !== false) |
---|
| 2233 | $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position + 1]; |
---|
| 2234 | else |
---|
| 2235 | $return[$i]['next_msg_number'] = $msgs_in_the_server[$msg_key_position]; |
---|
[1472] | 2236 | |
---|
[5359] | 2237 | $return[$i]['msg_folder'] = $folder; |
---|
| 2238 | $i++; |
---|
[2] | 2239 | } |
---|
[3265] | 2240 | $return['quota'] = $this->get_quota(array('folder_id' => $folder)); |
---|
| 2241 | $return['sort_box_type'] = $params['sort_box_type']; |
---|
[3427] | 2242 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 2243 | $this->open_mbox($folder); |
---|
[5359] | 2244 | |
---|
[271] | 2245 | $return['msgs_to_delete'] = $msg_to_delete; |
---|
[3493] | 2246 | $return['offsetToGMT'] = $this->functions->CalculateDateOffset(); |
---|
[411] | 2247 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 2248 | imap_close($this->mbox); |
---|
[828] | 2249 | |
---|
[2] | 2250 | return $return; |
---|
| 2251 | } |
---|
| 2252 | |
---|
[1035] | 2253 | /** |
---|
| 2254 | * Método que faz a verificação do Content-Type do e-mail e verifica se é um e-mail normal, |
---|
| 2255 | * assinado ou cifrado. |
---|
| 2256 | * @author Mário César Kolling <mario.kolling@serpro.gov.br> |
---|
| 2257 | * @param $headers Uma String contendo os Headers do e-mail retornados pela função imap_imap_fetchheader |
---|
| 2258 | * @param $msg_number O número da mesagem |
---|
| 2259 | * @return Retorna o tipo da mensagem (normal, signature, cipher). |
---|
| 2260 | */ |
---|
[5359] | 2261 | function getMessageType($msg_number, $headers = false , &$body = false){ |
---|
[3394] | 2262 | include_once(dirname( __FILE__ ) ."/../../security/classes/CertificadoB.php"); |
---|
[1035] | 2263 | $contentType = "normal"; |
---|
[5359] | 2264 | |
---|
| 2265 | if (!$headers) |
---|
| 2266 | $headers = imap_fetchheader($this->mbox, $msg_number, FT_UID); |
---|
[1035] | 2267 | |
---|
[5359] | 2268 | if (preg_match("/pkcs7-signature/i", $headers) == 1) |
---|
| 2269 | $contentType = "signature"; |
---|
| 2270 | else if (preg_match("/pkcs7-mime/i", $headers) == 1) |
---|
| 2271 | $contentType = testa_p7m( $body ? $body : imap_body($this->mbox, $msg_number , FT_UID )) ; |
---|
| 2272 | |
---|
[1035] | 2273 | return $contentType; |
---|
| 2274 | } |
---|
[5216] | 2275 | |
---|
[5218] | 2276 | /** |
---|
| 2277 | * Retorna a posição que a pasta esta dentro do array de pastas |
---|
| 2278 | * |
---|
| 2279 | * @license www.gnu.org/copyleft/gpl.html GPL |
---|
| 2280 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 2281 | * @sponsor Caixa Econômica Federal |
---|
| 2282 | * @author Cristiano Corrêa Schmidt |
---|
| 2283 | * @access public |
---|
| 2284 | */ |
---|
| 2285 | |
---|
[5216] | 2286 | function getFolderPos(&$array , $find) |
---|
| 2287 | { |
---|
| 2288 | foreach($array as $i => $v) |
---|
| 2289 | if($v['id'] === $find) |
---|
| 2290 | return $i; |
---|
| 2291 | return false; |
---|
| 2292 | } |
---|
| 2293 | |
---|
| 2294 | /** |
---|
| 2295 | * Ordenas as pastas padrões do usuario na ordem INBOX > SENT > DRAFTS > SPAM > TRASH > OTHERS |
---|
| 2296 | * |
---|
| 2297 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 2298 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 2299 | * @sponsor Caixa Econômica Federal |
---|
| 2300 | * @author Cristiano Corrêa Schmidt |
---|
| 2301 | * @access public |
---|
| 2302 | */ |
---|
| 2303 | function orderDefaultFolders( &$folders , $user) |
---|
[2] | 2304 | { |
---|
[5216] | 2305 | $principals = array(); |
---|
| 2306 | for($x = 0; $x < 5 ; $x++) |
---|
| 2307 | { |
---|
| 2308 | switch ($x) { |
---|
| 2309 | case 0: |
---|
| 2310 | if( ($p = $this->getFolderPos($folders , $user )) || $p === 0 ) |
---|
| 2311 | $principals[] = $folders[$p]; |
---|
| 2312 | break; |
---|
| 2313 | case 1: |
---|
[5306] | 2314 | if( ($p = $this->getFolderPos($folders , $this->mount_url_folder(array($user , $this->folders['drafts'])) )) || $p === 0 ) |
---|
[5216] | 2315 | $principals[] = $folders[$p]; |
---|
| 2316 | break; |
---|
| 2317 | case 2: |
---|
[5306] | 2318 | if( ($p = $this->getFolderPos($folders , $this->mount_url_folder(array($user , $this->folders['sent'])) )) || $p === 0 ) |
---|
[5216] | 2319 | $principals[] = $folders[$p]; |
---|
| 2320 | break; |
---|
| 2321 | case 3: |
---|
[5306] | 2322 | if( ($p = $this->getFolderPos($folders , $this->mount_url_folder(array($user , $this->folders['spam'])) )) || $p === 0 ) |
---|
[5216] | 2323 | $principals[] = $folders[$p]; |
---|
| 2324 | break; |
---|
| 2325 | case 4: |
---|
[5306] | 2326 | if( ($p = $this->getFolderPos($folders , $this->mount_url_folder(array($user , $this->folders['trash'])) )) || $p === 0 ) |
---|
[5216] | 2327 | $principals[] = $folders[$p]; |
---|
| 2328 | break; |
---|
| 2329 | } |
---|
| 2330 | if($p !== false) |
---|
| 2331 | unset($folders[$p]); |
---|
[1953] | 2332 | } |
---|
[5216] | 2333 | $folders = array_merge($principals, $folders); |
---|
| 2334 | } |
---|
| 2335 | |
---|
| 2336 | /** |
---|
| 2337 | * Retorna lista de pastas do usuario no padrão que a lib javascript espera. |
---|
| 2338 | * |
---|
| 2339 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 2340 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 2341 | * @sponsor Caixa Econômica Federal |
---|
| 2342 | * @author Cristiano Corrêa Schmidt |
---|
| 2343 | * @access public |
---|
| 2344 | */ |
---|
| 2345 | function get_folders_list($params = null) |
---|
| 2346 | { |
---|
[6243] | 2347 | $return = $this->getFolders( $params ); |
---|
| 2348 | |
---|
| 2349 | foreach ($return as $i => &$vv) |
---|
| 2350 | { |
---|
| 2351 | $vv['folder_id'] = mb_convert_encoding($vv['folder_id'],'ISO-8859-1','UTF7-IMAP');//DECODIFICA ID DAS PASTAS COM ACENTOS |
---|
| 2352 | $vv['folder_name'] = mb_convert_encoding($vv['folder_name'],'ISO-8859-1','UTF7-IMAP');//DECODIFICA NOME DAS PASTAS COM ACENTOS |
---|
| 2353 | $vv['folder_parent'] = mb_convert_encoding($vv['folder_parent'],'ISO-8859-1','UTF7-IMAP');//DECODIFICA NOME DAS PASTAS COM ACENTOS |
---|
| 2354 | } |
---|
[5844] | 2355 | |
---|
[6243] | 2356 | return ( $return ); |
---|
| 2357 | } |
---|
| 2358 | |
---|
| 2359 | function getFolders($params = null) |
---|
| 2360 | { |
---|
[5216] | 2361 | ///Define Variaveis |
---|
| 2362 | $prefixShared = 'user'; //Prefixo das pastas compartilhadas |
---|
| 2363 | $uid2cn = (isset($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'])) ? $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] : false; |
---|
| 2364 | $mboxStream = $this->open_mbox(); //abre conexão imap |
---|
| 2365 | $currentFolder = isset($params['folder']) ? $params['folder'] : 'INBOX'; |
---|
| 2366 | $folders = array(); |
---|
| 2367 | $return = array(); |
---|
| 2368 | /////////////////////////////////////////////////////////////// |
---|
| 2369 | |
---|
| 2370 | if( isset($params['onload']) && $_SESSION['phpgw_info']['expressomail']['server']['certificado']) |
---|
| 2371 | $this->delete_mailbox(array('del_past' => 'INBOX'.$this->imap_delimiter.'decifradas')); //Deleta Pasta decifradas |
---|
| 2372 | |
---|
| 2373 | session_write_close(); // Free others requests |
---|
[3018] | 2374 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
[3790] | 2375 | |
---|
[5216] | 2376 | if ( isset($params['noSharedFolders']) ) |
---|
| 2377 | $folders_list = array_merge(imap_getmailboxes($mboxStream, $serverString, 'INBOX' ), imap_getmailboxes($mboxStream, $serverString, 'INBOX/*' ) ); |
---|
[3790] | 2378 | else |
---|
[5216] | 2379 | $folders_list = imap_getmailboxes($mboxStream, $serverString, '*' ); |
---|
[3761] | 2380 | |
---|
[3018] | 2381 | $folders_list = array_slice($folders_list,0,$this->foldersLimit); |
---|
| 2382 | |
---|
[5216] | 2383 | if (!is_array($folders_list)) return false; |
---|
| 2384 | if($uid2cn) |
---|
| 2385 | $this->ldap = new ldap_functions(); |
---|
| 2386 | |
---|
| 2387 | foreach ($folders_list as $i => $v ) //Separando Pastas e informações |
---|
[1816] | 2388 | { |
---|
[5216] | 2389 | $folderId = substr($v->name,(strpos($v->name , '}') + 1)); |
---|
| 2390 | $nameArray = explode($this->imap_delimiter, $folderId); |
---|
| 2391 | $nameCount = count($nameArray); |
---|
| 2392 | $decifrada = mb_convert_encoding('INBOX'.$this->imap_delimiter.'decifradas','UTF7-IMAP','ISO-8859-1'); //Ignorar esta pasta decifrada |
---|
| 2393 | $parent = ($nameCount > 1 && $nameArray[($nameCount - 2)] !== 'INBOX') ? implode($this->imap_delimiter, array_slice($nameArray, 0, ($nameCount - 1))): ''; //Pega folder pai |
---|
| 2394 | if($nameArray[0] === 'user') |
---|
| 2395 | $folders[$prefixShared.$this->imap_delimiter.$nameArray[1]][] = array('id' => $folderId , 'stream' => $v->name , 'attributes' => $v->attributes , 'name' => $nameArray[($nameCount-1)] , 'user' => $nameArray[1] ,'parent' => $parent); |
---|
| 2396 | else if( $folderId !== $decifrada) //Escapa pasta decifrada |
---|
[6005] | 2397 | $folders['INBOX'][strtolower($folderId)] = array('id' => $folderId , 'stream' => $v->name , 'attributes' => $v->attributes ,'name' => $nameArray[($nameCount-1)] , 'parent' => $parent); |
---|
[1816] | 2398 | } |
---|
[5216] | 2399 | unset($folders_list); //destroy array de objetos desnecessarios |
---|
[6002] | 2400 | |
---|
[6005] | 2401 | ksort($folders['INBOX']); |
---|
| 2402 | |
---|
[5216] | 2403 | foreach($folders as $i => $v) //Ordenando e resgatando novas informações |
---|
| 2404 | { |
---|
| 2405 | $this->orderDefaultFolders($folders[$i] , $i); //Ordenando Pastas Padrões |
---|
| 2406 | |
---|
| 2407 | foreach ($folders[$i] as $ii => $vv) |
---|
[5134] | 2408 | { |
---|
[5216] | 2409 | $append = array(); |
---|
[6243] | 2410 | $append['folder_id'] = $vv['id']; |
---|
[5216] | 2411 | $append['folder_name'] = (($uid2cn && isset($vv['user'])) && ($cn = $this->ldap->uid2cn($vv['user']))) ? $cn : $vv['name']; |
---|
| 2412 | $status = imap_status($mboxStream, $vv['stream'], SA_UNSEEN); //Resgata Numero de mensagens não lidas |
---|
| 2413 | $append['folder_unseen'] = isset($status->unseen) ? $status->unseen : 0 ; |
---|
| 2414 | $append['folder_hasChildren'] = (($vv['attributes'] == 32) && ($vv['name'] != 'INBOX')) ? 1 : 0; |
---|
[6243] | 2415 | $append['folder_parent'] = $vv['parent']; |
---|
[5216] | 2416 | $return[] = $append; |
---|
[5134] | 2417 | } |
---|
| 2418 | } |
---|
[5216] | 2419 | |
---|
| 2420 | $quotaInfo = (!isset($params['noQuotaInfo'])) ? $this->get_quota( array('folder_id' => $currentFolder)) : false; //VERIFICA SE O USUARIO TEM COTA |
---|
[5243] | 2421 | |
---|
[5216] | 2422 | return ( ( is_array($quotaInfo) ) ? array_merge($return, $quotaInfo) : $return ); |
---|
[2] | 2423 | } |
---|
[5216] | 2424 | |
---|
[1472] | 2425 | |
---|
[2] | 2426 | function create_mailbox($arr) |
---|
| 2427 | { |
---|
| 2428 | $namebox = $arr['newp']; |
---|
[5488] | 2429 | $base_path = $arr['base_path']; |
---|
[2] | 2430 | $mbox_stream = $this->open_mbox(); |
---|
| 2431 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[5488] | 2432 | $test = explode("/", $namebox); |
---|
| 2433 | if(count($test) < 1 || $base_path == null || $base_path == "" || $base_path == 'undefined'){ |
---|
| 2434 | if($base_path != null || $base_path != "" || $base_path != 'undefined'){ |
---|
| 2435 | $namebox = $base_path.$namebox; |
---|
| 2436 | } |
---|
| 2437 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP", "UTF-8"); |
---|
| 2438 | $result = "Ok"; |
---|
[6243] | 2439 | |
---|
[5488] | 2440 | if(!imap_createmailbox($mbox_stream,"{".$imap_server."}".$namebox)) |
---|
| 2441 | { |
---|
| 2442 | $result = implode("<br />\n", imap_errors()); |
---|
| 2443 | } |
---|
| 2444 | }else{ |
---|
| 2445 | $child = $base_path.$this->imap_delimiter; |
---|
| 2446 | for($i =0; $i < count($test); $i++){ |
---|
| 2447 | $child .= ($test[$i] ? $test[$i] : $this->functions->getLang("New Folder")); |
---|
| 2448 | $namebox = mb_convert_encoding($child, "UTF7-IMAP", "UTF-8"); |
---|
| 2449 | $result = "Ok"; |
---|
[6243] | 2450 | |
---|
[5488] | 2451 | if(!imap_createmailbox($mbox_stream,"{".$imap_server."}$namebox")) |
---|
| 2452 | { |
---|
| 2453 | $result = implode("<br />\n", imap_errors()); |
---|
| 2454 | } |
---|
| 2455 | $child .=$this->imap_delimiter; |
---|
| 2456 | } |
---|
| 2457 | } |
---|
[51] | 2458 | if($mbox_stream) |
---|
| 2459 | imap_close($mbox_stream); |
---|
[2] | 2460 | return $result; |
---|
| 2461 | } |
---|
[1472] | 2462 | |
---|
[2] | 2463 | function create_extra_mailbox($arr) |
---|
| 2464 | { |
---|
| 2465 | $nameboxs = explode(";",$arr['nw_folders']); |
---|
| 2466 | $result = ""; |
---|
| 2467 | $mbox_stream = $this->open_mbox(); |
---|
| 2468 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[1472] | 2469 | foreach($nameboxs as $key=>$tmp){ |
---|
[2] | 2470 | if($tmp != ""){ |
---|
| 2471 | if(!imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}$tmp"))){ |
---|
| 2472 | $result = implode("<br />\n", imap_errors()); |
---|
[51] | 2473 | if($mbox_stream) |
---|
[1472] | 2474 | imap_close($mbox_stream); |
---|
[2] | 2475 | return $result; |
---|
| 2476 | } |
---|
| 2477 | } |
---|
| 2478 | } |
---|
[51] | 2479 | if($mbox_stream) |
---|
| 2480 | imap_close($mbox_stream); |
---|
[2] | 2481 | return true; |
---|
| 2482 | } |
---|
[1472] | 2483 | |
---|
[2] | 2484 | function delete_mailbox($arr) |
---|
| 2485 | { |
---|
| 2486 | $namebox = $arr['del_past']; |
---|
| 2487 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[1953] | 2488 | $mbox_stream = $this->mbox ? $this->mbox : $this->open_mbox(); |
---|
[2] | 2489 | //$del_folder = imap_deletemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox"); |
---|
[1472] | 2490 | |
---|
[2] | 2491 | $result = "Ok"; |
---|
| 2492 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); |
---|
| 2493 | if(!imap_deletemailbox($mbox_stream,"{".$imap_server."}$namebox")) |
---|
| 2494 | { |
---|
| 2495 | $result = implode("<br />\n", imap_errors()); |
---|
| 2496 | } |
---|
[1953] | 2497 | /* |
---|
[51] | 2498 | if($mbox_stream) |
---|
| 2499 | imap_close($mbox_stream); |
---|
[1953] | 2500 | */ |
---|
[2] | 2501 | return $result; |
---|
| 2502 | } |
---|
[1472] | 2503 | |
---|
[2] | 2504 | function ren_mailbox($arr) |
---|
| 2505 | { |
---|
| 2506 | $namebox = $arr['current']; |
---|
| 2507 | $new_box = $arr['rename']; |
---|
| 2508 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 2509 | $mbox_stream = $this->open_mbox(); |
---|
| 2510 | //$ren_folder = imap_renamemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox","{".$imap_server."}INBOX.$new_box"); |
---|
[1472] | 2511 | |
---|
[2] | 2512 | $result = "Ok"; |
---|
| 2513 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); |
---|
[51] | 2514 | $new_box = mb_convert_encoding($new_box, "UTF7-IMAP","UTF-8"); |
---|
[1472] | 2515 | |
---|
[2] | 2516 | if(!imap_renamemailbox($mbox_stream,"{".$imap_server."}$namebox","{".$imap_server."}$new_box")) |
---|
| 2517 | { |
---|
[1472] | 2518 | $result = imap_errors(); |
---|
[2] | 2519 | } |
---|
[51] | 2520 | if($mbox_stream) |
---|
| 2521 | imap_close($mbox_stream); |
---|
[2] | 2522 | return $result; |
---|
[1472] | 2523 | |
---|
[2] | 2524 | } |
---|
[1472] | 2525 | |
---|
[2] | 2526 | function get_num_msgs($params) |
---|
| 2527 | { |
---|
| 2528 | $folder = $params['folder']; |
---|
[411] | 2529 | if(!$this->mbox || !is_resource($this->mbox)) { |
---|
[2] | 2530 | $this->mbox = $this->open_mbox($folder); |
---|
[411] | 2531 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[2] | 2532 | return imap_last_error(); |
---|
[1472] | 2533 | } |
---|
[2] | 2534 | $num_msgs = imap_num_msg($this->mbox); |
---|
[432] | 2535 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 2536 | imap_close($this->mbox); |
---|
[1472] | 2537 | |
---|
[2] | 2538 | return $num_msgs; |
---|
| 2539 | } |
---|
[1472] | 2540 | |
---|
[1912] | 2541 | function folder_exists($folder){ |
---|
| 2542 | $mbox = $this->open_mbox(); |
---|
| 2543 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 2544 | $list = imap_getmailboxes($mbox,$serverString, $folder); |
---|
| 2545 | $return = is_array($list); |
---|
| 2546 | imap_close($mbox); |
---|
| 2547 | return $return; |
---|
| 2548 | } |
---|
| 2549 | |
---|
[6212] | 2550 | function send_mail($params) { |
---|
[5604] | 2551 | require_once dirname(__FILE__) . '/../../services/class.servicelocator.php'; |
---|
| 2552 | require_once dirname(__FILE__) . '/../../prototype/api/controller.php'; |
---|
| 2553 | $mailService = ServiceLocator::getService('mail'); |
---|
[449] | 2554 | |
---|
[5604] | 2555 | include_once("class.db_functions.inc.php"); |
---|
| 2556 | $db = new db_functions(); |
---|
| 2557 | $fromaddress = $params['input_from'] ? explode(';', $params['input_from']) : ""; |
---|
| 2558 | $message_attachments_contents = (isset($params['message_attachments_content'])) ? $params['message_attachments_content'] : false; |
---|
[5346] | 2559 | |
---|
[5604] | 2560 | ## |
---|
| 2561 | # @AUTHOR Rodrigo Souza dos Santos |
---|
| 2562 | # @DATE 2008/09/17$fileName |
---|
| 2563 | # @BRIEF Checks if the user has permission to send an email with the email address used. |
---|
| 2564 | ## |
---|
| 2565 | if (is_array($fromaddress) && ($fromaddress[1] != $_SESSION['phpgw_info']['expressomail']['user']['email'])) { |
---|
| 2566 | $deny = true; |
---|
| 2567 | foreach ($_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] as $key => $val) |
---|
| 2568 | if (array_key_exists('mail', $val) && $val['mail'][0] == $fromaddress[1]) |
---|
| 2569 | $deny = false and end($_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes']); |
---|
[5346] | 2570 | |
---|
[5604] | 2571 | if ($deny) |
---|
| 2572 | return "The server denied your request to send a mail, you cannot use this mail address."; |
---|
| 2573 | } |
---|
[5134] | 2574 | |
---|
[5604] | 2575 | $toaddress = $db->getAddrs(explode(',', $params['input_to'])); //implode(',',); |
---|
| 2576 | $ccaddress = $db->getAddrs(explode(',', $params['input_cc'])); //implode(',',); |
---|
| 2577 | $ccoaddress = $db->getAddrs(explode(',', $params['input_cco'])); //implode(',',); |
---|
[1035] | 2578 | |
---|
[5604] | 2579 | if ($toaddress["False"] || $ccaddress["False"] || $ccoaddress["False"]) { |
---|
| 2580 | return $this->parse_error("Invalid Mail:", ($toaddress["False"] ? $toaddress["False"] : ($ccaddress["False"] ? $ccaddress["False"] : $ccoaddress["False"]))); |
---|
| 2581 | } |
---|
[5134] | 2582 | |
---|
[5604] | 2583 | $toaddress = implode(',', $toaddress); |
---|
| 2584 | $ccaddress = implode(',', $ccaddress); |
---|
| 2585 | $ccoaddress = implode(',', $ccoaddress); |
---|
[5134] | 2586 | |
---|
[5604] | 2587 | if ($toaddress == "" && $ccaddress == "" && $ccoaddress == "") { |
---|
| 2588 | return $this->parse_error("Invalid Mail:", ($params['input_to'] ? $params['input_to'] : ($params['input_cc'] ? $params['input_cc'] : $params['input_cco']))); |
---|
| 2589 | } |
---|
[5134] | 2590 | |
---|
[5604] | 2591 | $toaddress = preg_replace('/<\s+/', '<', $toaddress); |
---|
| 2592 | $toaddress = preg_replace('/\s+>/', '>', $toaddress); |
---|
[5134] | 2593 | |
---|
[5604] | 2594 | $ccaddress = preg_replace('/<\s+/', '<', $ccaddress); |
---|
| 2595 | $ccaddress = preg_replace('/\s+>/', '>', $ccaddress); |
---|
[5134] | 2596 | |
---|
[5604] | 2597 | $ccoaddress = preg_replace('/<\s+/', '<', $ccoaddress); |
---|
| 2598 | $ccoaddress = preg_replace('/\s+>/', '>', $ccoaddress); |
---|
[5134] | 2599 | |
---|
[5604] | 2600 | $replytoaddress = $params['input_replyto']; |
---|
| 2601 | $subject = $params['input_subject']; |
---|
| 2602 | $return_receipt = $params['input_return_receipt']; |
---|
| 2603 | $is_important = $params['input_important_message']; |
---|
| 2604 | $encrypt = $params['input_return_cripto']; |
---|
| 2605 | $signed = $params['input_return_digital']; |
---|
[5906] | 2606 | |
---|
| 2607 | $params['attachments'] = mb_convert_encoding($params['attachments'], "UTF7-IMAP","UTF-8, ISO-8859-1, UTF7-IMAP"); |
---|
[5604] | 2608 | $message_attachments = $params['message_attachments']; |
---|
[5134] | 2609 | |
---|
[5604] | 2610 | if (substr($params['input_to'], -1) == ',') |
---|
| 2611 | $params['input_to'] = substr($params['input_to'], 0, -1); |
---|
| 2612 | |
---|
| 2613 | if (substr($params['input_cc'], -1) == ',') |
---|
| 2614 | $params['input_cc'] = substr($params['input_cc'], 0, -1); |
---|
| 2615 | |
---|
| 2616 | if (substr($params['input_cco'], -1) == ',') |
---|
| 2617 | $params['input_cco'] = substr($params['input_cco'], 0, -1); |
---|
| 2618 | |
---|
| 2619 | // Valida numero Maximo de Destinatarios |
---|
| 2620 | if ($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoAdmin_maximum_recipients'] > 0) { |
---|
| 2621 | $sendersNumber = count(explode(',', $params['input_to'])); |
---|
| 2622 | |
---|
| 2623 | if ($params['input_cc']) |
---|
| 2624 | $sendersNumber += count(explode(',', $params['input_cc'])); |
---|
| 2625 | if ($params['input_cco']) |
---|
| 2626 | $sendersNumber += count(explode(',', $params['input_cco'])); |
---|
| 2627 | |
---|
| 2628 | $userMaxmimumSenders = $db->getMaximumRecipientsUser($this->username); |
---|
| 2629 | if ($userMaxmimumSenders) { |
---|
| 2630 | if ($sendersNumber > $userMaxmimumSenders) |
---|
| 2631 | return $this->functions->getLang('Number of recipients greater than allowed'); |
---|
| 2632 | } |
---|
| 2633 | else { |
---|
[5134] | 2634 | $ldap = new ldap_functions(); |
---|
[5604] | 2635 | $groupsToUser = $ldap->get_user_groups($this->username); |
---|
[5134] | 2636 | |
---|
[5604] | 2637 | $groupMaxmimumSenders = $db->getMaximumRecipientsGroup($groupsToUser); |
---|
[5134] | 2638 | |
---|
[5604] | 2639 | if ($groupMaxmimumSenders > 0) { |
---|
| 2640 | if ($sendersNumber > $groupMaxmimumSenders) |
---|
| 2641 | return $this->functions->getLang('Number of recipients greater than allowed'); |
---|
| 2642 | } |
---|
| 2643 | else { |
---|
| 2644 | if ($sendersNumber > $_SESSION['phpgw_info']['expresso']['expressoMail']['expressoAdmin_maximum_recipients']) |
---|
| 2645 | return $this->functions->getLang('Number of recipients greater than allowed'); |
---|
| 2646 | } |
---|
| 2647 | } |
---|
| 2648 | } |
---|
| 2649 | //Fim Valida numero maximo de destinatarios |
---|
| 2650 | //Valida envio de email para shared accounts |
---|
| 2651 | if ($_SESSION['phpgw_info']['expresso']['expressoMail']['expressoMail_block_institutional_comunication'] == 'true') { |
---|
| 2652 | $ldap = new ldap_functions(); |
---|
| 2653 | $arrayF = explode(';', $params['input_from']); |
---|
[5134] | 2654 | |
---|
[5604] | 2655 | /* |
---|
| 2656 | * Verifica se o remetente n?o ? uma conta compartilhada |
---|
| 2657 | */ |
---|
| 2658 | if (!$ldap->isSharedAccountByMail($arrayF[1])) { |
---|
| 2659 | $groupsToUser = $ldap->get_user_groups($this->username); |
---|
| 2660 | $sharedAccounts = $ldap->returnSharedsAccounts($toaddress, $ccaddress, $ccoaddress); |
---|
[5134] | 2661 | |
---|
[5604] | 2662 | /* |
---|
| 2663 | * Pega o UID do remetente |
---|
| 2664 | */ |
---|
| 2665 | $uidFrom = $ldap->mail2uid($arrayF[1]); |
---|
[5134] | 2666 | |
---|
[5604] | 2667 | /* |
---|
| 2668 | * Remove a conta compartilhada caso o uid do remetente exista na conta compartilhada |
---|
| 2669 | */ |
---|
| 2670 | foreach ($sharedAccounts as $key => $value) { |
---|
| 2671 | if ($value) |
---|
| 2672 | $acl = $this->getaclfrombox($value); |
---|
[5134] | 2673 | |
---|
[5604] | 2674 | if (array_key_exists($uidFrom, $acl)) |
---|
| 2675 | unset($sharedAccounts[$key]); |
---|
| 2676 | } |
---|
[5134] | 2677 | |
---|
[5604] | 2678 | /* |
---|
| 2679 | * Caso ainda exista contas compartilhadas, verifica se existe alguma exce??o para estas contas |
---|
| 2680 | */ |
---|
| 2681 | if (count($sharedAccounts) > 0) |
---|
| 2682 | $accountsBlockeds = $db->validadeSharedAccounts($this->username, $groupsToUser, $sharedAccounts); |
---|
[5134] | 2683 | |
---|
[5604] | 2684 | /* |
---|
| 2685 | * Retorna as contas compartilhadas bloqueadas |
---|
| 2686 | */ |
---|
| 2687 | if (count($accountsBlockeds) > 0) { |
---|
| 2688 | $return = ''; |
---|
[5134] | 2689 | |
---|
[5604] | 2690 | foreach ($accountsBlockeds as $accountBlocked) |
---|
| 2691 | $return.= $accountBlocked . ', '; |
---|
[5134] | 2692 | |
---|
[5604] | 2693 | $return = substr($return, 0, -2); |
---|
| 2694 | |
---|
| 2695 | return $this->functions->getLang('you are blocked from sending mail to the following addresses') . ': ' . $return; |
---|
[5134] | 2696 | } |
---|
| 2697 | } |
---|
[1035] | 2698 | } |
---|
[5604] | 2699 | // Fim Valida envio de email para shared accounts |
---|
| 2700 | // TODO - implementar tratamento SMIME no novo serviço de envio de emails e retirar o AND false abaixo |
---|
| 2701 | if ($params['smime'] AND false) { |
---|
| 2702 | $body = $params['smime']; |
---|
| 2703 | $mail->SMIME = true; |
---|
| 2704 | // A MSG assinada deve ser testada neste ponto. |
---|
| 2705 | // Testar o certificado e a integridade da msg.... |
---|
| 2706 | include_once(dirname(__FILE__) . "/../../security/classes/CertificadoB.php"); |
---|
| 2707 | $erros_acumulados = ''; |
---|
| 2708 | $certificado = new certificadoB(); |
---|
| 2709 | $validade = $certificado->verificar($body); |
---|
| 2710 | if (!$validade) { |
---|
| 2711 | foreach ($certificado->erros_ssl as $linha_erro) { |
---|
| 2712 | $erros_acumulados .= $linha_erro; |
---|
| 2713 | } |
---|
| 2714 | } else { |
---|
| 2715 | // Testa o CERTIFICADO: se o CPF he o do usuario logado, se pode assinar msgs e se nao esta expirado... |
---|
| 2716 | if ($certificado->apresentado) { |
---|
| 2717 | if ($certificado->dados['EXPIRADO']) |
---|
| 2718 | $erros_acumulados .='Certificado expirado.'; |
---|
| 2719 | $this->cpf = isset($GLOBALS['phpgw_info']['server']['certificado_atributo_cpf']) && $GLOBALS['phpgw_info']['server']['certificado_atributo_cpf'] != '' ? $_SESSION['phpgw_info']['expressomail']['user'][$GLOBALS['phpgw_info']['server']['certificado_atributo_cpf']] : $this->username; |
---|
| 2720 | if ($certificado->dados['CPF'] != $this->cpf) |
---|
| 2721 | $erros_acumulados .=' CPF no certificado diferente do logado no expresso.'; |
---|
| 2722 | if (!($certificado->dados['KEYUSAGE']['digitalSignature'] && $certificado->dados['EXTKEYUSAGE']['emailProtection'])) |
---|
| 2723 | $erros_acumulados .=' Certificado nao permite assinar mensagens.'; |
---|
| 2724 | } |
---|
| 2725 | else { |
---|
| 2726 | $$erros_acumulados .= 'Nao foi possivel usar o certificado para assinar a msg'; |
---|
| 2727 | } |
---|
[1035] | 2728 | } |
---|
[5604] | 2729 | if (!$erros_acumulados == '') { |
---|
| 2730 | return $erros_acumulados; |
---|
[1035] | 2731 | } |
---|
[5604] | 2732 | } else { |
---|
| 2733 | //Compatibilização com Outlook, ao encaminhar a mensagem |
---|
| 2734 | $body = mb_ereg_replace('<!--\[', '<!-- [', $params['body']); |
---|
[5620] | 2735 | $body = str_replace("%nbsp;"," ",$body); |
---|
[5745] | 2736 | //$body = preg_replace("/\n/"," ",$body); |
---|
| 2737 | //$body = preg_replace("/\r/","" ,$body); |
---|
[5620] | 2738 | $body = html_entity_decode ( $body, ENT_QUOTES , 'ISO-8859-1' ); |
---|
[1035] | 2739 | } |
---|
[5134] | 2740 | |
---|
[5604] | 2741 | $attachments = $_FILES; |
---|
| 2742 | $forwarding_attachments = $params['forwarding_attachments']; |
---|
| 2743 | $local_attachments = $params['local_attachments']; |
---|
[5906] | 2744 | |
---|
[3369] | 2745 | |
---|
[5604] | 2746 | //Test if must be saved in shared folder and change if necessary |
---|
| 2747 | if ($fromaddress[2] == 'y') { |
---|
| 2748 | //build shared folder path |
---|
| 2749 | $newfolder = "user" . $this->imap_delimiter . $fromaddress[3] . $this->imap_delimiter . $this->imap_sentfolder; |
---|
[5844] | 2750 | |
---|
| 2751 | if ($this->folder_exists($newfolder)){ |
---|
| 2752 | $has_new_folder = false; |
---|
[5604] | 2753 | $folder = $newfolder; |
---|
[5844] | 2754 | } |
---|
| 2755 | else{ |
---|
| 2756 | $name_folder = $this->imap_sentfolder; |
---|
| 2757 | $base_path = "user" . $this->imap_delimiter . $fromaddress[3]; |
---|
| 2758 | $arr_new_folder['newp'] = $name_folder; |
---|
| 2759 | $arr_new_folder['base_path'] = $base_path; |
---|
| 2760 | |
---|
| 2761 | $this->create_mailbox($arr_new_folder); |
---|
| 2762 | $has_new_folder = true; |
---|
| 2763 | $folder = $newfolder; |
---|
| 2764 | } |
---|
[5604] | 2765 | } else { |
---|
[5844] | 2766 | $has_new_folder = false; |
---|
[5604] | 2767 | $folder = $params['folder']; |
---|
| 2768 | } |
---|
[1035] | 2769 | |
---|
[6576] | 2770 | $folder = mb_convert_encoding($folder, 'UTF7-IMAP', 'ISO-8859-1'); |
---|
[5604] | 2771 | $folder = preg_replace('/INBOX[\/.]/i', 'INBOX' . $this->imap_delimiter, $folder); |
---|
| 2772 | $folder_name = $params['folder_name']; |
---|
[1472] | 2773 | |
---|
[5604] | 2774 | // TODO - tratar assinatura e remover o AND false |
---|
| 2775 | if ($signed && !$params['smime'] AND false) { |
---|
| 2776 | $mail->Mailer = "smime"; |
---|
| 2777 | $mail->SignedBody = true; |
---|
| 2778 | } |
---|
[5134] | 2779 | |
---|
| 2780 | |
---|
[5604] | 2781 | if ($fromaddress) |
---|
| 2782 | $mailService->setFrom('"' . $fromaddress[0] . '" <' . $fromaddress[1] . '>'); |
---|
| 2783 | else |
---|
| 2784 | $mailService->setFrom('"' . $_SESSION['phpgw_info']['expressomail']['user']['firstname'] . ' ' . $_SESSION['phpgw_info']['expressomail']['user']['lastname'] . '" <' . $_SESSION['phpgw_info']['expressomail']['user']['email'] . '>'); |
---|
[271] | 2785 | |
---|
[5604] | 2786 | $bol = $this->add_recipients('to', $toaddress, $mailService); |
---|
| 2787 | if (!$bol) { |
---|
| 2788 | return $this->parse_error("Invalid Mail:", $toaddress); |
---|
| 2789 | } |
---|
| 2790 | $bol = $this->add_recipients('cc', $ccaddress, $mailService); |
---|
| 2791 | if (!$bol) { |
---|
| 2792 | return $this->parse_error("Invalid Mail:", $ccaddress); |
---|
| 2793 | } |
---|
| 2794 | $allow = $_SESSION['phpgw_info']['server']['expressomail']['allow_hidden_copy']; |
---|
[5453] | 2795 | |
---|
[5604] | 2796 | if ($allow) { |
---|
| 2797 | //$mailService->addBcc($ccoaddress); |
---|
| 2798 | $bol = $this->add_recipients('cco', $ccoaddress, $mailService); |
---|
[5453] | 2799 | |
---|
[5604] | 2800 | if (!$bol) { |
---|
| 2801 | return $this->parse_error("Invalid Mail:", $ccoaddress); |
---|
| 2802 | } |
---|
| 2803 | } |
---|
[5453] | 2804 | |
---|
[5604] | 2805 | //Implementação para o In-Reply-To e References |
---|
| 2806 | $msg_numb = $params['messageNum']; |
---|
| 2807 | $msg_folder = $params['messageFolder']; |
---|
| 2808 | $this->mbox = $this->open_mbox($msg_folder); |
---|
[5134] | 2809 | |
---|
[5604] | 2810 | $header = $this->get_header($msg_numb); |
---|
| 2811 | $header_ = imap_fetchheader($this->mbox, $msg_numb, FT_UID); |
---|
[6673] | 2812 | $pattern = '/^[ \t]*Disposition-Notification-To:.*/mi'; |
---|
| 2813 | if (preg_match($pattern, $header_, $fields)) |
---|
| 2814 | $return['DispositionNotificationTo'] = base64_encode(trim(str_ireplace('Disposition-Notification-To:', '', $fields[0]))); |
---|
[5604] | 2815 | |
---|
| 2816 | $message_id = $header->message_id; |
---|
| 2817 | $references = array(); |
---|
| 2818 | if ($message_id != "") { |
---|
| 2819 | $mailService->addHeaderField('In-Reply-To', $message_id); |
---|
| 2820 | |
---|
| 2821 | if (isset($header->references)) { |
---|
| 2822 | array_push($references, $header->references); |
---|
[1035] | 2823 | } |
---|
[5604] | 2824 | array_push($references, $message_id); |
---|
| 2825 | $mailService->addHeaderField('References', $references); |
---|
| 2826 | } |
---|
[1035] | 2827 | |
---|
| 2828 | |
---|
[5604] | 2829 | $mailService->setSubject($subject); |
---|
[5745] | 2830 | $isHTML = ( isset($params['type']) && $params['type'] == 'html' )? true : false; |
---|
[5604] | 2831 | |
---|
| 2832 | |
---|
| 2833 | // TODO - tratar mensagem criptografada e remover o AND false abaixo |
---|
| 2834 | if (($encrypt && $signed && $params['smime']) || ($encrypt && !$signed) AND false) { // a msg deve ser enviada cifrada... |
---|
| 2835 | $email = $this->add_recipients_cert($toaddress . ',' . $ccaddress . ',' . $ccoaddress); |
---|
| 2836 | $email = explode(",", $email); |
---|
| 2837 | // Deve ser testado se foram obtidos os certificados de todos os destinatarios. |
---|
| 2838 | // Deve ser verificado um numero limite de destinatarios. |
---|
| 2839 | // Deve ser verificado se os certificados sao validos. |
---|
| 2840 | // Se uma das verificacoes falhar, nao enviar o e-mail e avisar o usuario. |
---|
| 2841 | // O array $mail->Certs_crypt soh deve ser preenchido se os certificados passarem nas verificacoes. |
---|
| 2842 | $numero_maximo = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['num_max_certs_to_cipher']; // Este valor dever ser configurado pelo administrador do site .... |
---|
| 2843 | $erros_acumulados = ""; |
---|
| 2844 | $aux_mails = array(); |
---|
| 2845 | $mail_list = array(); |
---|
| 2846 | if (count($email) > $numero_maximo) { |
---|
| 2847 | $erros_acumulados .= "Excedido o numero maximo (" . $numero_maximo . ") de destinatarios para uma msg cifrada...." . chr(0x0A); |
---|
[1035] | 2848 | return $erros_acumulados; |
---|
| 2849 | } |
---|
[5604] | 2850 | // adiciona o email do remetente. eh para cifrar a msg para ele tambem. Assim vai poder visualizar a msg na pasta enviados.. |
---|
| 2851 | $email[] = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 2852 | foreach ($email as $item) { |
---|
| 2853 | $certificate = $db->get_certificate(strtolower($item)); |
---|
| 2854 | if (!$certificate) { |
---|
| 2855 | $erros_acumulados .= "Chamada com parametro invalido. e-Mail nao pode ser vazio." . chr(0x0A); |
---|
| 2856 | return $erros_acumulados; |
---|
| 2857 | } |
---|
[1035] | 2858 | |
---|
[5604] | 2859 | if (array_key_exists("dberr1", $certificate)) { |
---|
[1035] | 2860 | |
---|
[5604] | 2861 | $erros_acumulados .= "Ocorreu um erro quando pesquisava certificados dos destinatarios para cifrar a msg." . chr(0x0A); |
---|
| 2862 | return $erros_acumulados; |
---|
| 2863 | } |
---|
| 2864 | if (array_key_exists("dberr2", $certificate)) { |
---|
| 2865 | $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado nao localizado.' . chr(0x0A); |
---|
| 2866 | //continue; |
---|
| 2867 | } |
---|
| 2868 | /* Retirado este teste para evitar mensagem de erro duplicada. |
---|
| 2869 | if (!array_key_exists("certs", $certificate)) |
---|
| 2870 | { |
---|
| 2871 | $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado nao localizado.' . chr(0x0A); |
---|
| 2872 | continue; |
---|
| 2873 | } |
---|
| 2874 | */ |
---|
| 2875 | include_once(dirname(__FILE__) . "/../../security/classes/CertificadoB.php"); |
---|
| 2876 | |
---|
| 2877 | foreach ($certificate['certs'] as $registro) { |
---|
| 2878 | $c1 = new certificadoB(); |
---|
| 2879 | $c1->certificado($registro['chave_publica']); |
---|
| 2880 | if ($c1->apresentado) { |
---|
| 2881 | $c2 = new Verifica_Certificado($c1->dados, $registro['chave_publica']); |
---|
| 2882 | if (!$c1->dados['EXPIRADO'] && !$c2->revogado && $c2->status) { |
---|
| 2883 | $aux_mails[] = $registro['chave_publica']; |
---|
| 2884 | $mail_list[] = strtolower($item); |
---|
| 2885 | } else { |
---|
| 2886 | if ($c1->dados['EXPIRADO'] || $c2->revogado) { |
---|
| 2887 | $db->update_certificate($c1->dados['SERIALNUMBER'], $c1->dados['EMAIL'], $c1->dados['AUTHORITYKEYIDENTIFIER'], $c1->dados['EXPIRADO'], $c2->revogado); |
---|
| 2888 | } |
---|
| 2889 | |
---|
| 2890 | $erros_acumulados .= $item . ': ' . $c2->msgerro . chr(0x0A); |
---|
| 2891 | foreach ($c2->erros_ssl as $linha) { |
---|
| 2892 | $erros_acumulados .= $linha . chr(0x0A); |
---|
| 2893 | } |
---|
| 2894 | $erros_acumulados .= 'Emissor: ' . $c1->dados['EMISSOR'] . chr(0x0A); |
---|
| 2895 | $erros_acumulados .= $c1->dados['CRLDISTRIBUTIONPOINTS'] . chr(0x0A); |
---|
[1035] | 2896 | } |
---|
[5604] | 2897 | } else { |
---|
| 2898 | $erros_acumulados .= $item . ' : Nao pode cifrar a msg. Certificado invalido.' . chr(0x0A); |
---|
[1035] | 2899 | } |
---|
| 2900 | } |
---|
[5604] | 2901 | if (!(in_array(strtolower($item), $mail_list)) && !empty($erros_acumulados)) { |
---|
| 2902 | return $erros_acumulados; |
---|
[1035] | 2903 | } |
---|
| 2904 | } |
---|
[5604] | 2905 | |
---|
| 2906 | $mail->Certs_crypt = $aux_mails; |
---|
[1035] | 2907 | } |
---|
| 2908 | |
---|
[5604] | 2909 | $attachment = json_decode($params['attachments'],TRUE); |
---|
[1035] | 2910 | |
---|
[5604] | 2911 | foreach ($attachment as &$value) |
---|
| 2912 | { |
---|
| 2913 | if((int)$value > 0) //BD attachment |
---|
| 2914 | { |
---|
| 2915 | $att = Controller::read(array('id'=> $value , 'concept' => 'mailAttachment')); |
---|
[828] | 2916 | |
---|
[5604] | 2917 | if($att['disposition'] == 'embedded') |
---|
| 2918 | { |
---|
[6576] | 2919 | $body = str_replace('"../prototype/getArchive.php?mailAttachment='.$att['id'].'"', '"'.mb_convert_encoding($att['name'], 'ISO-8859-1' , 'UTF-8,ISO-8859-1').'"', $body); |
---|
[6536] | 2920 | $mailService->addStringImage(base64_decode($att['source']), $att['type'], mb_convert_encoding($att['name'], 'ISO-8859-1' , 'UTF-8,ISO-8859-1')); |
---|
[5604] | 2921 | } |
---|
| 2922 | else |
---|
[6536] | 2923 | $mailService->addStringAttachment(base64_decode($att['source']), mb_convert_encoding($att['name'], 'ISO-8859-1' , 'UTF-8,ISO-8859-1'), $att['type'], 'base64', isset($att['disposition']) ? $att['disposition'] :'attachment' ); |
---|
[5620] | 2924 | |
---|
| 2925 | $message_size_total += $att['size']; |
---|
[5604] | 2926 | unset($att); |
---|
| 2927 | } |
---|
| 2928 | else //message attachment |
---|
| 2929 | { |
---|
| 2930 | $value = json_decode($value, true); |
---|
[6265] | 2931 | |
---|
[5620] | 2932 | switch ($value['type']) { |
---|
| 2933 | case 'imapPart': |
---|
| 2934 | $att = $this->getForwardingAttachment($value['folder'],$value['uid'], $value['part']); |
---|
| 2935 | if(strstr($body,'<img src="./inc/get_archive.php?msgFolder='.$value['folder'].'&msgNumber='.$value['uid'].'&indexPart='.$value['part'].'" />') !== false)//Embeded IMG |
---|
| 2936 | { |
---|
| 2937 | $body = str_ireplace('<img src="./inc/get_archive.php?msgFolder='.$value['folder'].'&msgNumber='.$value['uid'].'&indexPart='.$value['part'].'" />' , '<img src="'.$att['name'].'" />', $body); |
---|
[6576] | 2938 | $mailService->addStringImage($att['source'], $att['type'],mb_convert_encoding($att['name'], 'ISO-8859-1' , 'UTF-8,ISO-8859-1') ); |
---|
[5620] | 2939 | } |
---|
| 2940 | else |
---|
[6536] | 2941 | $mailService->addStringAttachment($att['source'], mb_convert_encoding($att['name'], 'ISO-8859-1' , 'UTF-8,ISO-8859-1'), $att['type'], 'base64', isset($att['disposition']) ? $att['disposition'] :'attachment' ); |
---|
[5620] | 2942 | |
---|
| 2943 | $message_size_total += $att['size']; //Adiciona o tamanho do anexo a variavel que controlao tamanho da msg. |
---|
| 2944 | unset($att); |
---|
| 2945 | break; |
---|
| 2946 | case 'imapMSG': |
---|
| 2947 | $mbox_stream = $this->open_mbox($value['folder']); |
---|
| 2948 | $rawmsg = $this->getRawHeader($value['uid']) . "\r\n\r\n" . $this->getRawBody($value['uid']); |
---|
[6536] | 2949 | |
---|
| 2950 | $mailService->addStringAttachment($rawmsg, mb_convert_encoding(base64_decode($value['name']), 'ISO-8859-1' , 'UTF-8,ISO-8859-1'), 'message/rfc822', '7bit', 'attachment' ); |
---|
[5620] | 2951 | $message_size_total += mb_strlen($rawmsg); //Adiciona o tamanho do anexo a variavel que controlao tamanho da msg. |
---|
| 2952 | unset($rawmsg); |
---|
| 2953 | break; |
---|
| 2954 | |
---|
| 2955 | default: |
---|
| 2956 | break; |
---|
| 2957 | } |
---|
[5604] | 2958 | } |
---|
| 2959 | } |
---|
[6265] | 2960 | |
---|
[5604] | 2961 | $message_size_total += strlen($params['body']); /* Tamanho do corpo da mensagem. */ |
---|
[37] | 2962 | |
---|
[5604] | 2963 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2964 | /** |
---|
| 2965 | * Faz a validação pelo tamanho máximo de mensagem permitido para o usuário. Se o usuário não estiver em nenhuma regra, usa o tamanho padrão. |
---|
| 2966 | */ |
---|
| 2967 | $default_max_size_rule = $db->get_default_max_size_rule(); |
---|
| 2968 | if (!$default_max_size_rule) { |
---|
| 2969 | $default_max_size_rule = str_replace("M", "", ini_get('upload_max_filesize')) * 1024 * 1024; /* hack para não bloquear o envio de email quando não for configurado um tamanho padrão */ |
---|
| 2970 | } else { |
---|
| 2971 | foreach ($default_max_size_rule as $i => $value) { |
---|
| 2972 | $default_max_size_rule = $value['config_value']; |
---|
| 2973 | } |
---|
| 2974 | } |
---|
[5134] | 2975 | |
---|
[5604] | 2976 | $default_max_size_rule = $default_max_size_rule * 1024 * 1024; /* Tamanho da regra padrão, em bytes */ |
---|
| 2977 | $id_user = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
[5134] | 2978 | |
---|
| 2979 | |
---|
[5604] | 2980 | $ldap = new ldap_functions(); |
---|
| 2981 | $groups_user = $ldap->get_user_groups($id_user); |
---|
[614] | 2982 | |
---|
[5604] | 2983 | $size_rule_by_group = array(); |
---|
| 2984 | foreach ($groups_user as $k => $value_) { |
---|
| 2985 | $rule_in_group = $db->get_rule_by_user_in_groups($k); |
---|
| 2986 | if ($rule_in_group != "") |
---|
| 2987 | array_push($size_rule_by_group, $rule_in_group); |
---|
| 2988 | } |
---|
[504] | 2989 | |
---|
[5604] | 2990 | $n_rule_groups = 0; |
---|
| 2991 | $maior_valor_regra_grupo = 0; |
---|
| 2992 | foreach ($size_rule_by_group as $i => $value) { |
---|
| 2993 | if (is_array($value[0])) { |
---|
| 2994 | $n_rule_groups++; |
---|
| 2995 | if ($value[0]['email_max_recipient'] > $maior_valor_regra_grupo) |
---|
| 2996 | $maior_valor_regra_grupo = $value[0]['email_max_recipient']; |
---|
| 2997 | } |
---|
| 2998 | } |
---|
[1472] | 2999 | |
---|
[5604] | 3000 | if ($default_max_size_rule) { |
---|
| 3001 | $size_rule = $db->get_rule_by_user($_SESSION['phpgw_info']['expressomail']['user']['userid']); |
---|
[5134] | 3002 | |
---|
[5604] | 3003 | if (!$size_rule && $n_rule_groups == 0) /* O usuário não está em nenhuma regra por usuário nem por grupo. Vai usar a regra padrão. */ { |
---|
| 3004 | if ($message_size_total > $default_max_size_rule) |
---|
[6133] | 3005 | return $this->functions->getLang("Message size greateruler than allowed (Default rule)")." (".$default_max_size_rule / 1024 / 1024 ." Mb)"; |
---|
[5604] | 3006 | } |
---|
[5134] | 3007 | |
---|
[5604] | 3008 | else { |
---|
| 3009 | if (count($size_rule) > 0) /* Verifica se existe regra por usuário. Se houver, ela vai se sobresair das regras por grupo. */ { |
---|
| 3010 | $regra_mais_permissiva = 0; |
---|
| 3011 | foreach ($size_rule as $i => $value) { |
---|
| 3012 | if ($regra_mais_permissiva < $value['email_max_recipient']) |
---|
| 3013 | $regra_mais_permissiva = $value['email_max_recipient']; |
---|
| 3014 | } |
---|
| 3015 | $regra_mais_permissiva = $regra_mais_permissiva * 1024 * 1024; |
---|
| 3016 | if ($message_size_total > $regra_mais_permissiva) |
---|
| 3017 | return $this->functions->getLang("Message size greater than allowed (Rule By User)"); |
---|
| 3018 | } |
---|
| 3019 | else /* Regra por grupo */ { |
---|
| 3020 | $maior_valor_regra_grupo = $maior_valor_regra_grupo * 1024 * 1024; |
---|
| 3021 | if ($message_size_total > $maior_valor_regra_grupo) |
---|
| 3022 | return $this->functions->getLang("Message size greater than allowed (Rule By Group)"); |
---|
| 3023 | } |
---|
| 3024 | } |
---|
| 3025 | } |
---|
| 3026 | /** |
---|
| 3027 | * Fim da validação do tamanho da regra do tamanho de mensagem. |
---|
| 3028 | */ |
---|
| 3029 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[6483] | 3030 | if ($isHTML) |
---|
| 3031 | { |
---|
| 3032 | $this->rfc2397ToEmbeddedAttachment($mailService , $body); |
---|
[5134] | 3033 | |
---|
[6576] | 3034 | $defaultStyle = ''; |
---|
[6483] | 3035 | if(isset($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['font_family_editor']) && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['font_family_editor']) |
---|
| 3036 | $defaultStyle .= ' font-family:'.$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['font_family_editor'] .';'; |
---|
| 3037 | |
---|
| 3038 | if(isset($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['font_size_editor']) && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['font_size_editor']) |
---|
| 3039 | $defaultStyle .= ' font-size:'.$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['font_size_editor'].';'; |
---|
[6576] | 3040 | |
---|
| 3041 | $body = '<span class="'.$defaultStyle.'">'.$body.'</span>'; |
---|
[5604] | 3042 | $mailService->setBodyHtml($body); |
---|
[6483] | 3043 | } |
---|
[5604] | 3044 | else |
---|
| 3045 | $mailService->setBodyText($body); |
---|
[2] | 3046 | |
---|
[5604] | 3047 | if ($is_important) |
---|
| 3048 | $mailService->addHeaderField('Importance', 'High'); |
---|
[3018] | 3049 | |
---|
[5604] | 3050 | if ($return_receipt) |
---|
| 3051 | $mailService->addHeaderField('Disposition-Notification-To', $_SESSION['phpgw_info']['expressomail']['user']['email']); |
---|
[3018] | 3052 | |
---|
[4416] | 3053 | |
---|
[5604] | 3054 | if ($folder != 'null') { |
---|
| 3055 | $mbox_stream = $this->open_mbox($folder); |
---|
| 3056 | @imap_append($mbox_stream, "{" . $this->imap_server . ":" . $this->imap_port . "}" . $folder, $mailService->getMessage(), "\\Seen"); |
---|
| 3057 | } |
---|
[4416] | 3058 | |
---|
[5604] | 3059 | $sent = $mailService->send(); |
---|
[4416] | 3060 | |
---|
[5604] | 3061 | if ($sent !== true) { |
---|
| 3062 | return $this->parse_error($sent); |
---|
| 3063 | } else { |
---|
| 3064 | if ($signed && !$params['smime']) { |
---|
| 3065 | return $sent; |
---|
| 3066 | } |
---|
| 3067 | if ($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") { |
---|
| 3068 | $userid = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 3069 | $userip = $_SESSION['phpgw_info']['expressomail']['user']['session_ip']; |
---|
| 3070 | $now = date("d/m/y H:i:s"); |
---|
| 3071 | $addrs = $toaddress . $ccaddress . $ccoaddress; |
---|
| 3072 | $sent = trim($sent); |
---|
| 3073 | error_log("$now - $userip - $sent [$subject] - $userid => $addrs\r\n", 3, "/home/expressolivre/mail_senders.log"); |
---|
| 3074 | } |
---|
[6528] | 3075 | if($params['uids_save'] ) |
---|
| 3076 | $this->delete_msgs(array('folder'=> $params['save_folder'] , 'msgs_number' => $params['uids_save'])); |
---|
[5604] | 3077 | |
---|
[5844] | 3078 | //return array("success" => true, "folder" => $folder_list); |
---|
| 3079 | return array("success" => true, "load" => $has_new_folder); |
---|
[5604] | 3080 | |
---|
| 3081 | } |
---|
| 3082 | } |
---|
| 3083 | |
---|
| 3084 | |
---|
[3018] | 3085 | function add_recipients_cert($full_address) |
---|
[1035] | 3086 | { |
---|
| 3087 | $result = ""; |
---|
| 3088 | $parse_address = imap_rfc822_parse_adrlist($full_address, ""); |
---|
| 3089 | foreach ($parse_address as $val) |
---|
| 3090 | { |
---|
| 3091 | //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; |
---|
| 3092 | if ($val->mailbox == "INVALID_ADDRESS") |
---|
| 3093 | continue; |
---|
| 3094 | if ($val->mailbox == "UNEXPECTED_DATA_AFTER_ADDRESS") |
---|
| 3095 | continue; |
---|
| 3096 | if (empty($val->personal)) |
---|
| 3097 | $result .= $val->mailbox."@".$val->host . ","; |
---|
| 3098 | else |
---|
| 3099 | $result .= $val->mailbox."@".$val->host . ","; |
---|
| 3100 | } |
---|
| 3101 | |
---|
| 3102 | return substr($result,0,-1); |
---|
| 3103 | } |
---|
| 3104 | |
---|
[5243] | 3105 | function add_recipients($recipient_type, $full_address, $mail, $mobile = false) |
---|
[2] | 3106 | { |
---|
[3932] | 3107 | //remove a comma if is given two unexpected commas |
---|
| 3108 | $full_address = preg_replace("/, ?,/",",",$full_address); |
---|
[1472] | 3109 | $parse_address = imap_rfc822_parse_adrlist($full_address, ""); |
---|
[5254] | 3110 | |
---|
[5255] | 3111 | $bolean = true; |
---|
| 3112 | foreach ($parse_address as $val) |
---|
| 3113 | { |
---|
| 3114 | //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; |
---|
| 3115 | if ($val->mailbox == "INVALID_ADDRESS") |
---|
| 3116 | continue; |
---|
| 3117 | switch($recipient_type) |
---|
[5243] | 3118 | { |
---|
[5255] | 3119 | case "to": |
---|
| 3120 | if($mobile){ |
---|
| 3121 | $mail->AddAddress($val->mailbox."@".$val->host, $val->personal); |
---|
| 3122 | }else{ |
---|
| 3123 | $mail->AddTo( ($val->personal ? "\"$val->personal\" <$val->mailbox@$val->host>" : "$val->mailbox@$val->host")); |
---|
| 3124 | } |
---|
| 3125 | break; |
---|
| 3126 | case "cc": |
---|
| 3127 | if($mobile){ |
---|
| 3128 | $mail->AddCC($val->mailbox."@".$val->host, $val->personal); |
---|
| 3129 | }else{ |
---|
| 3130 | $mail->AddCC( ($val->personal ? "\"$val->personal\" <$val->mailbox@$val->host>" : "$val->mailbox@$val->host")); |
---|
[5243] | 3131 | } |
---|
[5255] | 3132 | break; |
---|
| 3133 | case "cco": |
---|
| 3134 | $mail->AddBcc(($val->personal ? "\"$val->personal\" <$val->mailbox@$val->host>" : "$val->mailbox@$val->host")); |
---|
| 3135 | break; |
---|
[2] | 3136 | } |
---|
[5255] | 3137 | if($val->mailbox == "UNEXPECTED_DATA_AFTER_ADDRESS"){ |
---|
| 3138 | $bolean = false; |
---|
[2] | 3139 | } |
---|
| 3140 | } |
---|
[5134] | 3141 | return $bolean; |
---|
[2] | 3142 | } |
---|
[5620] | 3143 | |
---|
| 3144 | function getForwardingAttachment($folder, $uid, $part, $rfc_822bodies = true , $info = true ) |
---|
| 3145 | { |
---|
[5316] | 3146 | include_once dirname(__FILE__).'/class.attachment.inc.php'; |
---|
[4416] | 3147 | $attachment = new attachment(); |
---|
[5620] | 3148 | $attachment->decodeConf['rfc_822bodies'] = $rfc_822bodies; //Forçar a não decodificação de mensagens em anexo. |
---|
| 3149 | $attachment->setStructureFromMail($folder, $uid); |
---|
| 3150 | |
---|
| 3151 | if($info === true) |
---|
| 3152 | { |
---|
| 3153 | $return = $attachment->getAttachmentInfo($part); |
---|
| 3154 | $return['source'] = $attachment->getAttachment($part); |
---|
| 3155 | return $return; |
---|
| 3156 | } |
---|
| 3157 | return $attachment->getAttachment($part); |
---|
| 3158 | } |
---|
| 3159 | |
---|
[2] | 3160 | function del_last_caracter($string) |
---|
| 3161 | { |
---|
| 3162 | $string = substr($string,0,(strlen($string) - 1)); |
---|
[1472] | 3163 | return $string; |
---|
[2] | 3164 | } |
---|
[1472] | 3165 | |
---|
[2] | 3166 | function del_last_two_caracters($string) |
---|
| 3167 | { |
---|
| 3168 | $string = substr($string,0,(strlen($string) - 2)); |
---|
[1472] | 3169 | return $string; |
---|
[2] | 3170 | } |
---|
[1472] | 3171 | |
---|
[5766] | 3172 | function messages_sort($sort_box_type,$sort_box_reverse, $search_box_type,$offsetBegin,$offsetEnd,$folder) |
---|
[659] | 3173 | { |
---|
[5900] | 3174 | $sort = array(); |
---|
[1625] | 3175 | if ($sort_box_type != "SORTFROM" && $search_box_type!= "FLAGGED"){ |
---|
[970] | 3176 | $imapsort = imap_sort($this->mbox,constant($sort_box_type),$sort_box_reverse,SE_UID,$search_box_type); |
---|
[5900] | 3177 | foreach($imapsort as $iuid){ |
---|
| 3178 | $sort[$iuid] = $iuid; |
---|
| 3179 | } |
---|
[1518] | 3180 | if ($offsetBegin == -1 && $offsetEnd ==-1 ) |
---|
| 3181 | $slice_array = false; |
---|
| 3182 | else |
---|
| 3183 | $slice_array = true; |
---|
[970] | 3184 | } |
---|
| 3185 | else |
---|
[659] | 3186 | { |
---|
[970] | 3187 | if ($offsetBegin > $offsetEnd) {$temp=$offsetEnd; $offsetEnd=$offsetBegin; $offsetBegin=$temp;} |
---|
| 3188 | $num_msgs = imap_num_msg($this->mbox); |
---|
| 3189 | if ($offsetEnd > $num_msgs) {$offsetEnd = $num_msgs;} |
---|
[975] | 3190 | $slice_array = true; |
---|
[5900] | 3191 | $from_to_sent = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['from_to_sent']; |
---|
| 3192 | $dates = array(); |
---|
[983] | 3193 | for ($i=$num_msgs; $i>0; $i--) |
---|
[828] | 3194 | { |
---|
[983] | 3195 | if ($sort_box_type == "SORTARRIVAL" && $sort_box_reverse && count($sort) >= $offsetEnd) |
---|
| 3196 | break; |
---|
[970] | 3197 | $iuid = @imap_uid($this->mbox,$i); |
---|
| 3198 | $header = $this->get_header($iuid); |
---|
[5900] | 3199 | |
---|
[970] | 3200 | // List UNSEEN messages. |
---|
| 3201 | if($search_box_type == "UNSEEN" && (!trim($header->Recent) && !trim($header->Unseen))){ |
---|
| 3202 | continue; |
---|
| 3203 | } |
---|
| 3204 | // List SEEN messages. |
---|
| 3205 | elseif($search_box_type == "SEEN" && (trim($header->Recent) || trim($header->Unseen))){ |
---|
| 3206 | continue; |
---|
| 3207 | } |
---|
| 3208 | // List ANSWERED messages. |
---|
| 3209 | elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){ |
---|
| 3210 | continue; |
---|
| 3211 | } |
---|
| 3212 | // List FLAGGED messages. |
---|
| 3213 | elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){ |
---|
| 3214 | continue; |
---|
| 3215 | } |
---|
| 3216 | |
---|
[5766] | 3217 | if($sort_box_type=='SORTFROM') { |
---|
| 3218 | if (strrpos($folder,'Sent') && $from_to_sent) |
---|
| 3219 | $tmp = self::formatMailObject($header->to[0]); |
---|
[970] | 3220 | else |
---|
[5766] | 3221 | $tmp = self::formatMailObject($header->from[0]); |
---|
| 3222 | $sort[$iuid] = ($tmp['name']) ? $tmp['name'] : $tmp['email']; |
---|
[970] | 3223 | } |
---|
| 3224 | else if($sort_box_type=='SORTSUBJECT') { |
---|
| 3225 | $sort[$iuid] = $header->subject; |
---|
| 3226 | } |
---|
| 3227 | else if($sort_box_type=='SORTSIZE') { |
---|
| 3228 | $sort[$iuid] = $header->Size; |
---|
| 3229 | } |
---|
| 3230 | else { |
---|
| 3231 | $sort[$iuid] = $header->udate; |
---|
| 3232 | } |
---|
[5900] | 3233 | $dates[$iuid] = $header->udate; |
---|
[659] | 3234 | } |
---|
[5900] | 3235 | $keys = array_keys($sort); |
---|
| 3236 | array_multisort($sort, SORT_ASC, $keys, SORT_DESC, $dates, SORT_DESC); |
---|
| 3237 | $sort = array_combine($keys, $sort); |
---|
[970] | 3238 | if ($sort_box_reverse) |
---|
| 3239 | $sort = array_reverse($sort,true); |
---|
[659] | 3240 | } |
---|
[5134] | 3241 | if(empty($sort) or !is_array($sort)){ |
---|
[972] | 3242 | $sort = array(); |
---|
[5134] | 3243 | } |
---|
[972] | 3244 | if ($slice_array) |
---|
[828] | 3245 | $sort = array_slice($sort,$offsetBegin-1,$offsetEnd-($offsetBegin-1),true); |
---|
| 3246 | return $sort; |
---|
| 3247 | |
---|
[659] | 3248 | } |
---|
[970] | 3249 | |
---|
[5172] | 3250 | function move_delete_search_messages($params){ |
---|
| 3251 | $move = false; |
---|
| 3252 | $msg_no_move = ""; |
---|
| 3253 | |
---|
| 3254 | $params['selected_messages'] = urldecode($params['selected_messages_move']); |
---|
| 3255 | $params['new_folder'] = urldecode($params['new_folder_move']); |
---|
| 3256 | $params['new_folder_name'] = urldecode($params['new_folder_name_move']); |
---|
| 3257 | $sel_msgs = explode(",", $params['selected_messages']); |
---|
| 3258 | @reset($sel_msgs); |
---|
| 3259 | $sorted_msgs = array(); |
---|
| 3260 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
| 3261 | $sel_msg = explode(";", $sel_msg); |
---|
| 3262 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
| 3263 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
| 3264 | } |
---|
| 3265 | else { |
---|
| 3266 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
| 3267 | } |
---|
| 3268 | } |
---|
| 3269 | @ksort($sorted_msgs); |
---|
| 3270 | $last_return = false; |
---|
| 3271 | foreach($sorted_msgs as $folder => $msgs_number) { |
---|
| 3272 | $params['msgs_number'] = $msgs_number; |
---|
| 3273 | $params['folder'] = $folder; |
---|
| 3274 | |
---|
| 3275 | $last_return = $this->move_messages($params); |
---|
| 3276 | |
---|
| 3277 | if($last_return['status']){ |
---|
| 3278 | $move = true; |
---|
| 3279 | }else{ |
---|
| 3280 | $msg_no_move = $params['msgs_number']; |
---|
| 3281 | } |
---|
| 3282 | } |
---|
| 3283 | $sel_msgs = null; |
---|
| 3284 | $params['selected_messages'] = urldecode($params['selected_messages_delete']); |
---|
| 3285 | $params['new_folder'] = urldecode($params['new_folder_delete']); |
---|
| 3286 | $params['new_folder_name'] = urldecode($params['new_folder_name_delete']); |
---|
| 3287 | $sel_msgs = explode(",", $params['selected_messages']); |
---|
| 3288 | @reset($sel_msgs); |
---|
| 3289 | $sorted_msgs = array(); |
---|
| 3290 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
| 3291 | $sel_msg = explode(";", $sel_msg); |
---|
| 3292 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
| 3293 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
| 3294 | } |
---|
| 3295 | else { |
---|
| 3296 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
| 3297 | } |
---|
| 3298 | } |
---|
| 3299 | @ksort($sorted_msgs); |
---|
| 3300 | $last_return = false; |
---|
| 3301 | foreach($sorted_msgs as $folder => $msgs_number) { |
---|
| 3302 | $params['msgs_number'] = $msgs_number; |
---|
| 3303 | $params['folder'] = $folder; |
---|
| 3304 | |
---|
| 3305 | $params['folder'] = $params['new_folder_delete']; |
---|
| 3306 | $last_return = $this->delete_msgs($params); |
---|
| 3307 | $last_return['deleted'] = true; |
---|
| 3308 | if($last_return['status']){ |
---|
| 3309 | $move = true; |
---|
| 3310 | }else{ |
---|
| 3311 | $msg_no_move = $params['msgs_number']; |
---|
| 3312 | } |
---|
| 3313 | |
---|
| 3314 | } |
---|
| 3315 | |
---|
| 3316 | if($move) |
---|
| 3317 | $last_return['move'] = true; |
---|
| 3318 | |
---|
| 3319 | if($msg_no_move != "") |
---|
| 3320 | $last_return['no_move'] = $msg_no_move; |
---|
| 3321 | |
---|
| 3322 | return $last_return; |
---|
| 3323 | } |
---|
[970] | 3324 | |
---|
[1472] | 3325 | function move_search_messages($params){ |
---|
[5256] | 3326 | $params['selected_messages'] = str_replace('/',$this->imap_delimiter,urldecode($params['selected_messages'])); |
---|
| 3327 | $params['new_folder'] = str_replace('/',$this->imap_delimiter,urldecode($params['new_folder'])); |
---|
[163] | 3328 | $params['new_folder_name'] = urldecode($params['new_folder_name']); |
---|
| 3329 | $sel_msgs = explode(",", $params['selected_messages']); |
---|
[5172] | 3330 | $move = false; |
---|
| 3331 | $msg_no_move = ""; |
---|
| 3332 | |
---|
[1472] | 3333 | @reset($sel_msgs); |
---|
[163] | 3334 | $sorted_msgs = array(); |
---|
| 3335 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
| 3336 | $sel_msg = explode(";", $sel_msg); |
---|
| 3337 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
| 3338 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
[1472] | 3339 | } |
---|
[163] | 3340 | else { |
---|
| 3341 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
| 3342 | } |
---|
| 3343 | } |
---|
| 3344 | @ksort($sorted_msgs); |
---|
[1472] | 3345 | $last_return = false; |
---|
| 3346 | foreach($sorted_msgs as $folder => $msgs_number) { |
---|
[163] | 3347 | $params['msgs_number'] = $msgs_number; |
---|
[1472] | 3348 | $params['folder'] = $folder; |
---|
[5172] | 3349 | |
---|
| 3350 | if($params['delete'] === 'true'){ |
---|
| 3351 | $params['folder'] = $params['new_folder']; |
---|
| 3352 | $last_return = $this->delete_msgs($params); |
---|
[163] | 3353 | $last_return['deleted'] = true; |
---|
[5172] | 3354 | |
---|
| 3355 | if($last_return['status']){ |
---|
| 3356 | $move = true; |
---|
| 3357 | }else{ |
---|
| 3358 | $msg_no_move = $params['msgs_number']; |
---|
[163] | 3359 | } |
---|
[5172] | 3360 | |
---|
| 3361 | }else{ |
---|
| 3362 | $last_return = $this->move_messages($params); |
---|
| 3363 | |
---|
| 3364 | if($last_return['status']){ |
---|
| 3365 | $move = true; |
---|
| 3366 | }else{ |
---|
| 3367 | $msg_no_move = $params['msgs_number']; |
---|
| 3368 | } |
---|
[163] | 3369 | } |
---|
[5172] | 3370 | } |
---|
| 3371 | |
---|
| 3372 | if($move) |
---|
| 3373 | $last_return['move'] = true; |
---|
| 3374 | |
---|
| 3375 | if($msg_no_move != "") |
---|
| 3376 | $last_return['no_move'] = $msg_no_move; |
---|
| 3377 | |
---|
[163] | 3378 | return $last_return; |
---|
| 3379 | } |
---|
[1472] | 3380 | |
---|
[2] | 3381 | function move_messages($params) |
---|
| 3382 | { |
---|
[1472] | 3383 | $folder = $params['folder']; |
---|
[6304] | 3384 | $newmailbox = mb_convert_encoding($params['new_folder'], "UTF7-IMAP", ( isset($params['decoded']) ? "" : "ISO-8859-1, " )."UTF-8, UTF7-IMAP" ); |
---|
[6305] | 3385 | $new_folder_name = isset($params['decoded']) ? mb_convert_encoding($params['new_folder_name'], "ISO-8859-1", "UTF-8" ) : $params['new_folder_name']; |
---|
[4997] | 3386 | $msgs_number = $params['msgs_number']; |
---|
[2] | 3387 | $return = array('msgs_number' => $msgs_number, |
---|
| 3388 | 'folder' => $folder, |
---|
| 3389 | 'new_folder_name' => $new_folder_name, |
---|
[325] | 3390 | 'border_ID' => $params['border_ID'], |
---|
| 3391 | 'status' => true); //Status foi adicionado para validar as permissoes ACL |
---|
[1472] | 3392 | |
---|
[325] | 3393 | //Este bloco tem a finalidade de averiguar as permissoes para pastas compartilhadas |
---|
| 3394 | if (substr($folder,0,4) == 'user'){ |
---|
[6305] | 3395 | $acl = $this->getacltouser($folder, isset($params['decoded'])); |
---|
[325] | 3396 | /* |
---|
| 3397 | * l - lookup (mailbox is visible to LIST/LSUB commands) |
---|
| 3398 | * r - read (SELECT the mailbox, perform CHECK, FETCH, PARTIAL, SEARCH, COPY from mailbox) |
---|
| 3399 | * s - keep seen/unseen information across sessions (STORE SEEN flag) |
---|
| 3400 | * w - write (STORE flags other than SEEN and DELETED) |
---|
| 3401 | * i - insert (perform APPEND, COPY into mailbox) |
---|
| 3402 | * p - post (send mail to submission address for mailbox, not enforced by IMAP4 itself) |
---|
| 3403 | * c - create (CREATE new sub-mailboxes in any implementation-defined hierarchy) |
---|
| 3404 | * d - delete (STORE DELETED flag, perform EXPUNGE) |
---|
| 3405 | * a - administer (perform SETACL) |
---|
| 3406 | */ |
---|
| 3407 | if (strpos($acl, "d") === false){ |
---|
| 3408 | $return['status'] = false; |
---|
| 3409 | return $return; |
---|
| 3410 | } |
---|
| 3411 | } |
---|
[432] | 3412 | //Este bloco tem a finalidade de transformar o CPF das pastas compartilhadas em common name |
---|
[5134] | 3413 | if(array_key_exists('uid2cn', $_SESSION['phpgw_info']['user']['preferences']['expressoMail'])){ |
---|
[1747] | 3414 | if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn']){ |
---|
| 3415 | if (substr($new_folder_name,0,4) == 'user'){ |
---|
| 3416 | $this->ldap = new ldap_functions(); |
---|
| 3417 | $tmp_folder_name = explode($this->imap_delimiter, $new_folder_name); |
---|
| 3418 | $return['new_folder_name'] = array_pop($tmp_folder_name); |
---|
| 3419 | if( $cn = $this->ldap->uid2cn($return['new_folder_name'])) |
---|
| 3420 | { |
---|
| 3421 | $return['new_folder_name'] = $cn; |
---|
| 3422 | } |
---|
| 3423 | } |
---|
[432] | 3424 | } |
---|
[5134] | 3425 | } |
---|
[1472] | 3426 | |
---|
| 3427 | // Caso estejamos no box principal, nao eh necessario pegar a informacao da mensagem anterior. |
---|
[51] | 3428 | if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) |
---|
[449] | 3429 | { |
---|
[2] | 3430 | $return['previous_msg'] = $this->get_info_previous_msg($params); |
---|
[449] | 3431 | // Fix problem in unserialize function JS. |
---|
[5134] | 3432 | if(array_key_exists('body', $return['previous_msg'])) |
---|
[449] | 3433 | $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); |
---|
| 3434 | } |
---|
[1472] | 3435 | |
---|
| 3436 | $mbox_stream = $this->open_mbox($folder); |
---|
[2] | 3437 | if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { |
---|
| 3438 | imap_expunge($mbox_stream); |
---|
[51] | 3439 | if($mbox_stream) |
---|
| 3440 | imap_close($mbox_stream); |
---|
[2] | 3441 | return $return; |
---|
| 3442 | }else { |
---|
[1472] | 3443 | if(strstr(imap_last_error(),'Over quota')) { |
---|
[2] | 3444 | $accountID = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminUsername']; |
---|
[1472] | 3445 | $pass = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; |
---|
| 3446 | $userID = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
[2] | 3447 | $server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[504] | 3448 | $mbox = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}INBOX", $accountID, $pass) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); |
---|
[2] | 3449 | if(!$mbox) |
---|
| 3450 | return imap_last_error(); |
---|
[1472] | 3451 | $quota = imap_get_quotaroot($mbox_stream, "INBOX"); |
---|
[2] | 3452 | if(! imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, 2.1 * $quota['usage'])) { |
---|
[51] | 3453 | if($mbox_stream) |
---|
| 3454 | imap_close($mbox_stream); |
---|
[1472] | 3455 | if($mbox) |
---|
[51] | 3456 | imap_close($mbox); |
---|
[1472] | 3457 | return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; |
---|
[2] | 3458 | } |
---|
| 3459 | if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { |
---|
| 3460 | imap_expunge($mbox_stream); |
---|
[51] | 3461 | if($mbox_stream) |
---|
| 3462 | imap_close($mbox_stream); |
---|
[2] | 3463 | // return to original quota limit. |
---|
| 3464 | if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { |
---|
[51] | 3465 | if($mbox) |
---|
| 3466 | imap_close($mbox); |
---|
[1472] | 3467 | return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; |
---|
[2] | 3468 | } |
---|
[1472] | 3469 | return $return; |
---|
[2] | 3470 | } |
---|
| 3471 | else { |
---|
[51] | 3472 | if($mbox_stream) |
---|
| 3473 | imap_close($mbox_stream); |
---|
[2] | 3474 | if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { |
---|
[51] | 3475 | if($mbox) |
---|
| 3476 | imap_close($mbox); |
---|
[1472] | 3477 | return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; |
---|
[2] | 3478 | } |
---|
[1472] | 3479 | return imap_last_error(); |
---|
[2] | 3480 | } |
---|
[1472] | 3481 | |
---|
[2] | 3482 | } |
---|
| 3483 | else { |
---|
[51] | 3484 | if($mbox_stream) |
---|
| 3485 | imap_close($mbox_stream); |
---|
| 3486 | return "move_messages() line ".__LINE__.": ". imap_last_error()." folder:".$newmailbox; |
---|
[2] | 3487 | } |
---|
[1472] | 3488 | } |
---|
[2] | 3489 | } |
---|
[5206] | 3490 | |
---|
[5264] | 3491 | function set_messages_flag_from_search($params){ |
---|
| 3492 | $error = False; |
---|
| 3493 | $fileNames = ""; |
---|
| 3494 | |
---|
| 3495 | $sel_msgs = explode(",", $params['msg_to_flag']); |
---|
| 3496 | @reset($sel_msgs); |
---|
| 3497 | $sorted_msgs = array(); |
---|
| 3498 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
| 3499 | $sel_msg = explode(";", $sel_msg); |
---|
| 3500 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
| 3501 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
| 3502 | } |
---|
| 3503 | else { |
---|
| 3504 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
| 3505 | } |
---|
| 3506 | } |
---|
| 3507 | unset($sorted_msgs['']); |
---|
| 3508 | $array_names_keys = array_keys($sorted_msgs); |
---|
| 3509 | // Verifica se as n mensagens selecionadas |
---|
| 3510 | // se encontram em um mesmo folder |
---|
| 3511 | if (count($sorted_msgs)==1){ |
---|
| 3512 | $param['folder'] = $array_names_keys[0]; |
---|
| 3513 | $param['msgs_to_set'] = $sorted_msgs[$array_names_keys[0]]; |
---|
| 3514 | $param['flag'] = $params['flag']; |
---|
| 3515 | $returns[0] = $this->set_messages_flag($param); |
---|
| 3516 | return $returns; |
---|
| 3517 | }else{ |
---|
| 3518 | for($i = 0; $i < count($array_names_keys); $i++){ |
---|
| 3519 | $param['folder'] = $array_names_keys[$i]; |
---|
| 3520 | $param['msgs_to_set'] = $sorted_msgs[$array_names_keys[$i]]; |
---|
| 3521 | $param['flag'] = $params['flag']; |
---|
| 3522 | $returns[$i] = $this->set_messages_flag($param); |
---|
| 3523 | } |
---|
| 3524 | } |
---|
| 3525 | return $returns; |
---|
| 3526 | } |
---|
[2] | 3527 | function set_messages_flag($params) |
---|
[5264] | 3528 | { |
---|
[6304] | 3529 | $folder = ( isset($params['decoded']) ) ? $params['folder'] : mb_convert_encoding($params['folder'], "UTF7-IMAP", "ISO-8859-1, UTF-8, UTF7-IMAP"); |
---|
[5134] | 3530 | $msgs_to_set = $params['msgs_to_set']; |
---|
[2] | 3531 | $flag = $params['flag']; |
---|
| 3532 | $return = array(); |
---|
[5134] | 3533 | $return["msgs_to_set"] = $msgs_to_set; |
---|
[2] | 3534 | $return["flag"] = $flag; |
---|
[5182] | 3535 | $return["msgs_not_to_set"] = ""; |
---|
| 3536 | |
---|
[5264] | 3537 | $this->mbox = $this->open_mbox($folder); |
---|
[5223] | 3538 | |
---|
[5182] | 3539 | if ($flag == "unseen"){ |
---|
| 3540 | $return["msgs_to_set"] = ""; |
---|
| 3541 | $msgs = explode(",",$msgs_to_set); |
---|
| 3542 | foreach($msgs as $men){ |
---|
| 3543 | if (imap_clearflag_full($this->mbox, $men, "\\Seen", ST_UID)) |
---|
| 3544 | $return["msgs_to_set"] .= $men.","; |
---|
| 3545 | else |
---|
| 3546 | $return["msgs_not_to_set"] .= $men.","; |
---|
| 3547 | } |
---|
| 3548 | $return["status"] = true; |
---|
| 3549 | }elseif ($flag == "seen"){ |
---|
| 3550 | $return["msgs_to_set"] = ""; |
---|
| 3551 | $msgs = explode(",",$msgs_to_set); |
---|
| 3552 | foreach($msgs as $men){ |
---|
| 3553 | if (imap_setflag_full($this->mbox, $men, "\\Seen", ST_UID)) |
---|
| 3554 | $return["msgs_to_set"] .= $men.","; |
---|
| 3555 | else |
---|
| 3556 | $return["msgs_not_to_set"] .= $men.","; |
---|
| 3557 | } |
---|
| 3558 | $return["status"] = true; |
---|
| 3559 | }elseif ($flag == "answered"){ |
---|
[51] | 3560 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered", ST_UID); |
---|
| 3561 | imap_clearflag_full($this->mbox, $msgs_to_set, "\\Draft", ST_UID); |
---|
[2] | 3562 | } |
---|
| 3563 | elseif ($flag == "forwarded") |
---|
[51] | 3564 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered \\Draft", ST_UID); |
---|
[2] | 3565 | elseif ($flag == "flagged") |
---|
[51] | 3566 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); |
---|
[614] | 3567 | elseif ($flag == "unflagged") { |
---|
| 3568 | $flag_importance = false; |
---|
| 3569 | $msgs_number = explode(",",$msgs_to_set); |
---|
[659] | 3570 | $unflagged_msgs = ""; |
---|
[614] | 3571 | foreach($msgs_number as $msg_number) { |
---|
| 3572 | preg_match('/importance *: *(.*)\r/i', |
---|
| 3573 | imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) |
---|
[1472] | 3574 | ,$importance); |
---|
[673] | 3575 | if(strtolower($importance[1])=="high" && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { |
---|
[614] | 3576 | $flag_importance=true; |
---|
| 3577 | } |
---|
[659] | 3578 | else { |
---|
| 3579 | $unflagged_msgs.=$msg_number.","; |
---|
[1472] | 3580 | } |
---|
[614] | 3581 | } |
---|
| 3582 | |
---|
[659] | 3583 | if($unflagged_msgs!="") { |
---|
| 3584 | imap_clearflag_full($this->mbox,substr($unflagged_msgs,0,strlen($unflagged_msgs)-1), "\\Flagged", ST_UID); |
---|
| 3585 | $return["msgs_unflageds"] = substr($unflagged_msgs,0,strlen($unflagged_msgs)-1); |
---|
| 3586 | } |
---|
| 3587 | else { |
---|
| 3588 | $return["msgs_unflageds"] = false; |
---|
| 3589 | } |
---|
| 3590 | |
---|
[673] | 3591 | if($flag_importance && $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) { |
---|
[614] | 3592 | $return["status"] = false; |
---|
| 3593 | $return["msg"] = $this->functions->getLang("At least one of selected message cant be marked as normal"); |
---|
| 3594 | } |
---|
[659] | 3595 | else { |
---|
| 3596 | $return["status"] = true; |
---|
| 3597 | } |
---|
[614] | 3598 | } |
---|
[5182] | 3599 | |
---|
| 3600 | if(($flag == "seen") || ($flag == "unseen")){ |
---|
| 3601 | if ($return["msgs_not_to_set"] != ""){ |
---|
| 3602 | $return["msgs_not_to_set"] = substr($return["msgs_not_to_set"], 0, -1); |
---|
[5223] | 3603 | $return["status"] = false; |
---|
[5182] | 3604 | } |
---|
| 3605 | if($return["msgs_to_set"] != ""){ |
---|
| 3606 | $return["msgs_to_set"] = substr($return["msgs_to_set"], 0, -1); |
---|
| 3607 | } |
---|
| 3608 | } |
---|
[411] | 3609 | if($this->mbox && is_resource($this->mbox)) |
---|
[5223] | 3610 | imap_close($this->mbox); |
---|
[2] | 3611 | return $return; |
---|
| 3612 | } |
---|
[1472] | 3613 | |
---|
[2] | 3614 | function get_file_type($file_name) |
---|
| 3615 | { |
---|
| 3616 | $file_name = strtolower($file_name); |
---|
| 3617 | $strFileType = strrev(substr(strrev($file_name),0,4)); |
---|
[5134] | 3618 | if ($strFileType == ".eml") |
---|
| 3619 | return "message/rfc822"; |
---|
[1472] | 3620 | if ($strFileType == ".asf") |
---|
[2] | 3621 | return "video/x-ms-asf"; |
---|
| 3622 | if ($strFileType == ".avi") |
---|
| 3623 | return "video/avi"; |
---|
| 3624 | if ($strFileType == ".doc") |
---|
| 3625 | return "application/msword"; |
---|
| 3626 | if ($strFileType == ".zip") |
---|
| 3627 | return "application/zip"; |
---|
| 3628 | if ($strFileType == ".xls") |
---|
| 3629 | return "application/vnd.ms-excel"; |
---|
| 3630 | if ($strFileType == ".gif") |
---|
| 3631 | return "image/gif"; |
---|
| 3632 | if ($strFileType == ".jpg" || $strFileType == "jpeg") |
---|
| 3633 | return "image/jpeg"; |
---|
| 3634 | if ($strFileType == ".png") |
---|
| 3635 | return "image/png"; |
---|
| 3636 | if ($strFileType == ".wav") |
---|
| 3637 | return "audio/wav"; |
---|
| 3638 | if ($strFileType == ".mp3") |
---|
| 3639 | return "audio/mpeg3"; |
---|
| 3640 | if ($strFileType == ".mpg" || $strFileType == "mpeg") |
---|
| 3641 | return "video/mpeg"; |
---|
| 3642 | if ($strFileType == ".rtf") |
---|
| 3643 | return "application/rtf"; |
---|
| 3644 | if ($strFileType == ".htm" || $strFileType == "html") |
---|
| 3645 | return "text/html"; |
---|
[1472] | 3646 | if ($strFileType == ".xml") |
---|
[2] | 3647 | return "text/xml"; |
---|
[1472] | 3648 | if ($strFileType == ".xsl") |
---|
[2] | 3649 | return "text/xsl"; |
---|
[1472] | 3650 | if ($strFileType == ".css") |
---|
[2] | 3651 | return "text/css"; |
---|
[1472] | 3652 | if ($strFileType == ".php") |
---|
[2] | 3653 | return "text/php"; |
---|
[1472] | 3654 | if ($strFileType == ".asp") |
---|
[2] | 3655 | return "text/asp"; |
---|
| 3656 | if ($strFileType == ".pdf") |
---|
| 3657 | return "application/pdf"; |
---|
| 3658 | if ($strFileType == ".txt") |
---|
| 3659 | return "text/plain"; |
---|
| 3660 | if ($strFileType == ".wmv") |
---|
| 3661 | return "video/x-ms-wmv"; |
---|
| 3662 | if ($strFileType == ".sxc") |
---|
| 3663 | return "application/vnd.sun.xml.calc"; |
---|
| 3664 | if ($strFileType == ".stc") |
---|
| 3665 | return "application/vnd.sun.xml.calc.template"; |
---|
| 3666 | if ($strFileType == ".sxd") |
---|
| 3667 | return "application/vnd.sun.xml.draw"; |
---|
| 3668 | if ($strFileType == ".std") |
---|
| 3669 | return "application/vnd.sun.xml.draw.template"; |
---|
| 3670 | if ($strFileType == ".sxi") |
---|
| 3671 | return "application/vnd.sun.xml.impress"; |
---|
| 3672 | if ($strFileType == ".sti") |
---|
| 3673 | return "application/vnd.sun.xml.impress.template"; |
---|
| 3674 | if ($strFileType == ".sxm") |
---|
| 3675 | return "application/vnd.sun.xml.math"; |
---|
| 3676 | if ($strFileType == ".sxw") |
---|
| 3677 | return "application/vnd.sun.xml.writer"; |
---|
| 3678 | if ($strFileType == ".sxq") |
---|
| 3679 | return "application/vnd.sun.xml.writer.global"; |
---|
| 3680 | if ($strFileType == ".stw") |
---|
| 3681 | return "application/vnd.sun.xml.writer.template"; |
---|
[1472] | 3682 | |
---|
| 3683 | |
---|
| 3684 | return "application/octet-stream"; |
---|
[2] | 3685 | } |
---|
[6242] | 3686 | |
---|
[2] | 3687 | function htmlspecialchars_encode($str) |
---|
| 3688 | { |
---|
[449] | 3689 | return str_replace( array('&', '"','\'','<','>','{','}'), array('&','"',''','<','>','{','}'), $str); |
---|
[2] | 3690 | } |
---|
| 3691 | function htmlspecialchars_decode($str) |
---|
| 3692 | { |
---|
[449] | 3693 | return str_replace( array('&','"',''','<','>','{','}'), array('&', '"','\'','<','>','{','}'), $str); |
---|
[2] | 3694 | } |
---|
[1472] | 3695 | |
---|
[828] | 3696 | function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse,$offsetBegin = 0,$offsetEnd = 0) |
---|
| 3697 | { |
---|
| 3698 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[51] | 3699 | $this->mbox = $this->open_mbox($folder); |
---|
[432] | 3700 | |
---|
[5766] | 3701 | return $this->messages_sort($sort_box_type,$sort_box_reverse, $search_box_type,$offsetBegin,$offsetEnd,$folder); |
---|
[828] | 3702 | } |
---|
[1472] | 3703 | |
---|
[53] | 3704 | function get_info_next_msg($params) |
---|
| 3705 | { |
---|
| 3706 | $msg_number = $params['msg_number']; |
---|
| 3707 | $folder = $params['msg_folder']; |
---|
| 3708 | $sort_box_type = $params['sort_box_type']; |
---|
| 3709 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 3710 | $reuse_border = $params['reuse_border']; |
---|
| 3711 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
[1472] | 3712 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
| 3713 | |
---|
[320] | 3714 | $success = false; |
---|
| 3715 | if (is_array($sort_array_msg)) |
---|
[2] | 3716 | { |
---|
[320] | 3717 | foreach ($sort_array_msg as $i => $value){ |
---|
| 3718 | if ($value == $msg_number) |
---|
| 3719 | { |
---|
| 3720 | $success = true; |
---|
| 3721 | break; |
---|
| 3722 | } |
---|
| 3723 | } |
---|
[2] | 3724 | } |
---|
| 3725 | |
---|
[320] | 3726 | if (! $success || $i >= sizeof($sort_array_msg)-1) |
---|
[2] | 3727 | { |
---|
| 3728 | $params['status'] = 'false'; |
---|
| 3729 | $params['command_to_exec'] = "delete_border('". $reuse_border ."');"; |
---|
| 3730 | return $params; |
---|
| 3731 | } |
---|
[1472] | 3732 | |
---|
[2] | 3733 | $params = array(); |
---|
| 3734 | $params['msg_number'] = $sort_array_msg[($i+1)]; |
---|
| 3735 | $params['msg_folder'] = $folder; |
---|
[1472] | 3736 | |
---|
| 3737 | $return = $this->get_info_msg($params); |
---|
[2] | 3738 | $return["reuse_border"] = $reuse_border; |
---|
| 3739 | return $return; |
---|
| 3740 | } |
---|
| 3741 | |
---|
| 3742 | function get_info_previous_msg($params) |
---|
| 3743 | { |
---|
| 3744 | $msg_number = $params['msgs_number']; |
---|
| 3745 | $folder = $params['folder']; |
---|
| 3746 | $sort_box_type = $params['sort_box_type']; |
---|
| 3747 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 3748 | $reuse_border = $params['reuse_border']; |
---|
[53] | 3749 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
| 3750 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
[1472] | 3751 | |
---|
[320] | 3752 | $success = false; |
---|
| 3753 | if (is_array($sort_array_msg)) |
---|
[2] | 3754 | { |
---|
[320] | 3755 | foreach ($sort_array_msg as $i => $value){ |
---|
| 3756 | if ($value == $msg_number) |
---|
| 3757 | { |
---|
| 3758 | $success = true; |
---|
| 3759 | break; |
---|
| 3760 | } |
---|
| 3761 | } |
---|
[2] | 3762 | } |
---|
[320] | 3763 | if (! $success || $i == 0) |
---|
| 3764 | { |
---|
[2] | 3765 | $params['status'] = 'false'; |
---|
| 3766 | $params['command_to_exec'] = "delete_border('". $reuse_border ."');"; |
---|
| 3767 | return $params; |
---|
| 3768 | } |
---|
[1472] | 3769 | |
---|
[2] | 3770 | $params = array(); |
---|
| 3771 | $params['msg_number'] = $sort_array_msg[($i-1)]; |
---|
| 3772 | $params['msg_folder'] = $folder; |
---|
[1472] | 3773 | |
---|
[2] | 3774 | $return = $this->get_info_msg($params); |
---|
| 3775 | $return["reuse_border"] = $reuse_border; |
---|
| 3776 | return $return; |
---|
| 3777 | } |
---|
[1472] | 3778 | |
---|
[2] | 3779 | // This function updates the values: quota, paging and new messages menu. |
---|
| 3780 | function get_menu_values($params){ |
---|
| 3781 | $return_array = array(); |
---|
| 3782 | $return_array = $this->get_quota($params); |
---|
[1472] | 3783 | |
---|
[2] | 3784 | $mbox_stream = $this->open_mbox($params['folder']); |
---|
[1472] | 3785 | $return_array['num_msgs'] = imap_num_msg($mbox_stream); |
---|
[51] | 3786 | if($mbox_stream) |
---|
| 3787 | imap_close($mbox_stream); |
---|
[1472] | 3788 | |
---|
| 3789 | return $return_array; |
---|
[2] | 3790 | } |
---|
[1472] | 3791 | |
---|
[325] | 3792 | function get_quota($params){ |
---|
[1472] | 3793 | |
---|
[5362] | 3794 | $folder_id = str_replace('/',$this->imap_delimiter,$params['folder_id']); |
---|
[5463] | 3795 | $folder_id = mb_convert_encoding($folder_id, "UTF7-IMAP","UTF-8, ISO-8859-1, UTF7-IMAP"); |
---|
[1035] | 3796 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[51] | 3797 | $this->mbox = $this->open_mbox(); |
---|
[345] | 3798 | |
---|
[325] | 3799 | $quota = imap_get_quotaroot($this->mbox, $folder_id); |
---|
[411] | 3800 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 3801 | imap_close($this->mbox); |
---|
[1472] | 3802 | |
---|
[2] | 3803 | if (!$quota){ |
---|
| 3804 | return array( |
---|
| 3805 | 'quota_percent' => 0, |
---|
| 3806 | 'quota_used' => 0, |
---|
| 3807 | 'quota_limit' => 0 |
---|
| 3808 | ); |
---|
| 3809 | } |
---|
[1472] | 3810 | |
---|
[2] | 3811 | if(count($quota) && $quota['limit']) { |
---|
[3064] | 3812 | $quota_limit = $quota['limit']; |
---|
| 3813 | $quota_used = $quota['usage']; |
---|
[2] | 3814 | if($quota_used >= $quota_limit) |
---|
[650] | 3815 | { |
---|
| 3816 | $quotaPercent = 100; |
---|
| 3817 | } |
---|
| 3818 | else |
---|
| 3819 | { |
---|
[2] | 3820 | $quotaPercent = ($quota_used / $quota_limit)*100; |
---|
| 3821 | $quotaPercent = (($quotaPercent)* 100 + .5 )* .01; |
---|
[650] | 3822 | } |
---|
[2] | 3823 | return array( |
---|
| 3824 | 'quota_percent' => floor($quotaPercent), |
---|
[3064] | 3825 | 'quota_used' => $quota_used, |
---|
| 3826 | 'quota_limit' => $quota_limit |
---|
[2] | 3827 | ); |
---|
| 3828 | } |
---|
[1472] | 3829 | else |
---|
[2] | 3830 | return array(); |
---|
| 3831 | } |
---|
[1472] | 3832 | |
---|
[6673] | 3833 | function send_notification($params) |
---|
| 3834 | { |
---|
| 3835 | $mailService = ServiceLocator::getService('mail'); |
---|
[3231] | 3836 | $body = lang("Your message: %1",$params['subject']) . '<br>'; |
---|
[4739] | 3837 | $body .= lang("Received in: %1",date("d/m/Y H:i",$params['date'])) . '<br>'; |
---|
[3231] | 3838 | $body .= lang("Has been read by: %1 < %2 > at %3", $_SESSION['phpgw_info']['expressomail']['user']['fullname'], $_SESSION['phpgw_info']['expressomail']['user']['email'], date("d/m/Y H:i")); |
---|
[6673] | 3839 | return $mailService->sendMail(base64_decode($params['notificationto']), |
---|
| 3840 | $_SESSION['phpgw_info']['expressomail']['user']['email'], |
---|
| 3841 | $this->htmlspecialchars_decode(lang("Read receipt: %1",$params['subject'])), |
---|
| 3842 | $body); |
---|
[2] | 3843 | |
---|
| 3844 | } |
---|
[1472] | 3845 | |
---|
[1965] | 3846 | function empty_folder($params) |
---|
[2] | 3847 | { |
---|
[1965] | 3848 | $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server'][$params['clean_folder']]; |
---|
[2] | 3849 | $mbox_stream = $this->open_mbox($folder); |
---|
| 3850 | $return = imap_delete($mbox_stream,'1:*'); |
---|
[51] | 3851 | if($mbox_stream) |
---|
| 3852 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 3853 | return $return; |
---|
| 3854 | } |
---|
[1472] | 3855 | |
---|
[2] | 3856 | function search($params) |
---|
| 3857 | { |
---|
[673] | 3858 | include("class.imap_attachment.inc.php"); |
---|
[1472] | 3859 | $imap_attachment = new imap_attachment(); |
---|
[2] | 3860 | $criteria = $params['criteria']; |
---|
| 3861 | $return = array(); |
---|
| 3862 | $folders = $this->get_folders_list(); |
---|
[1472] | 3863 | |
---|
[2] | 3864 | $j = 0; |
---|
| 3865 | foreach($folders as $folder) |
---|
| 3866 | { |
---|
| 3867 | $mbox_stream = $this->open_mbox($folder); |
---|
| 3868 | $messages = imap_search($mbox_stream, $criteria, SE_UID); |
---|
[1472] | 3869 | |
---|
[2] | 3870 | if ($messages == '') |
---|
| 3871 | continue; |
---|
[1472] | 3872 | |
---|
[2] | 3873 | $i = 0; |
---|
| 3874 | $return[$j] = array(); |
---|
| 3875 | $return[$j]['folder_name'] = $folder['name']; |
---|
[1472] | 3876 | |
---|
[2] | 3877 | foreach($messages as $msg_number) |
---|
| 3878 | { |
---|
[535] | 3879 | $header = $this->get_header($msg_number); |
---|
[2] | 3880 | if (!is_object($header)) |
---|
| 3881 | return false; |
---|
[1472] | 3882 | |
---|
[2] | 3883 | $return[$j][$i]['msg_folder'] = $folder['name']; |
---|
| 3884 | $return[$j][$i]['msg_number'] = $msg_number; |
---|
| 3885 | $return[$j][$i]['Recent'] = $header->Recent; |
---|
| 3886 | $return[$j][$i]['Unseen'] = $header->Unseen; |
---|
| 3887 | $return[$j][$i]['Answered'] = $header->Answered; |
---|
| 3888 | $return[$j][$i]['Deleted'] = $header->Deleted; |
---|
| 3889 | $return[$j][$i]['Draft'] = $header->Draft; |
---|
| 3890 | $return[$j][$i]['Flagged'] = $header->Flagged; |
---|
[1472] | 3891 | |
---|
[535] | 3892 | $date_msg = gmdate("d/m/Y",$header->udate); |
---|
| 3893 | if (gmdate("d/m/Y") == $date_msg) |
---|
| 3894 | $return[$j][$i]['udate'] = gmdate("H:i",$header->udate); |
---|
[2] | 3895 | else |
---|
| 3896 | $return[$j][$i]['udate'] = $date_msg; |
---|
[1472] | 3897 | |
---|
[2] | 3898 | $fromaddress = imap_mime_header_decode($header->fromaddress); |
---|
| 3899 | $return[$j][$i]['fromaddress'] = ''; |
---|
| 3900 | foreach ($fromaddress as $tmp) |
---|
| 3901 | $return[$j][$i]['fromaddress'] .= $this->replace_maior_menor($tmp->text); |
---|
[1472] | 3902 | |
---|
[2] | 3903 | $from = $header->from; |
---|
| 3904 | $return[$j][$i]['from'] = array(); |
---|
| 3905 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
| 3906 | $return[$j][$i]['from']['name'] = $tmp[0]->text; |
---|
| 3907 | $return[$j][$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
[1472] | 3908 | $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; |
---|
[2] | 3909 | |
---|
| 3910 | $to = $header->to; |
---|
| 3911 | $return[$j][$i]['to'] = array(); |
---|
| 3912 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
| 3913 | $return[$j][$i]['to']['name'] = $tmp[0]->text; |
---|
| 3914 | $return[$j][$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
[1472] | 3915 | $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; |
---|
[2] | 3916 | |
---|
| 3917 | $subject = imap_mime_header_decode($header->fetchsubject); |
---|
| 3918 | $return[$j][$i]['subject'] = ''; |
---|
| 3919 | foreach ($subject as $tmp) |
---|
| 3920 | $return[$j][$i]['subject'] .= $tmp->text; |
---|
| 3921 | |
---|
| 3922 | $return[$j][$i]['Size'] = $header->Size; |
---|
| 3923 | $return[$j][$i]['reply_toaddress'] = $header->reply_toaddress; |
---|
[1472] | 3924 | |
---|
[2] | 3925 | $return[$j][$i]['attachment'] = array(); |
---|
| 3926 | $return[$j][$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($mbox_stream, $msg_number); |
---|
[1472] | 3927 | |
---|
[2] | 3928 | $i++; |
---|
| 3929 | } |
---|
| 3930 | $j++; |
---|
[51] | 3931 | if($mbox_stream) |
---|
| 3932 | imap_close($mbox_stream); |
---|
[2] | 3933 | } |
---|
[1472] | 3934 | |
---|
[2] | 3935 | return $return; |
---|
| 3936 | } |
---|
[3923] | 3937 | |
---|
| 3938 | |
---|
[1709] | 3939 | function mobile_search($params) |
---|
| 3940 | { |
---|
| 3941 | include("class.imap_attachment.inc.php"); |
---|
| 3942 | $imap_attachment = new imap_attachment(); |
---|
| 3943 | $criterias = array ("TO","SUBJECT","FROM","CC"); |
---|
| 3944 | $return = array(); |
---|
[3589] | 3945 | if(!isset($params['folder'])) { |
---|
| 3946 | $folder_params = array("noSharedFolders"=>1); |
---|
| 3947 | if(isset($params['folderType'])) |
---|
| 3948 | $folder_params['folderType'] = $params['folderType']; |
---|
| 3949 | $folders = $this->get_folders_list($folder_params); |
---|
| 3950 | } |
---|
| 3951 | else |
---|
| 3952 | $folders = array(0=>array('folder_id'=>$params['folder'])); |
---|
[1709] | 3953 | $num_msgs = 0; |
---|
[3923] | 3954 | $max_msgs = $params['max_msgs'] + 1; //get one more because mobile paginate |
---|
| 3955 | $return["msgs"] = array(); |
---|
| 3956 | |
---|
| 3957 | //get max_msgs of each folder order by date and later order all messages together and retur only max_msgs msgs |
---|
[1709] | 3958 | foreach($folders as $id =>$folder) |
---|
| 3959 | { |
---|
| 3960 | if(strpos($folder['folder_id'],'user')===false && is_array($folder)) { |
---|
| 3961 | foreach($criterias as $criteria_fixed) |
---|
[3923] | 3962 | { |
---|
| 3963 | $_filter = $criteria_fixed . ' "'.$params['filter'].'"'; |
---|
| 3964 | |
---|
[3573] | 3965 | $mbox_stream = $this->open_mbox($folder['folder_id']); |
---|
[3923] | 3966 | |
---|
| 3967 | $messages = imap_sort($mbox_stream,SORTARRIVAL,1,SE_UID,$_filter); |
---|
[1709] | 3968 | |
---|
| 3969 | if ($messages == ''){ |
---|
| 3970 | if($mbox_stream) |
---|
| 3971 | imap_close($mbox_stream); |
---|
| 3972 | continue; |
---|
| 3973 | } |
---|
[3923] | 3974 | |
---|
[1709] | 3975 | foreach($messages as $msg_number) |
---|
[3923] | 3976 | { |
---|
[1709] | 3977 | $temp = $this->get_info_head_msg($msg_number); |
---|
| 3978 | if(!$temp) |
---|
| 3979 | return false; |
---|
[3573] | 3980 | $temp['msg_folder'] = $folder['folder_id']; |
---|
[3923] | 3981 | $return["msgs"][$num_msgs] = $temp; |
---|
[1709] | 3982 | $num_msgs++; |
---|
| 3983 | } |
---|
[3923] | 3984 | |
---|
[1709] | 3985 | if($mbox_stream) |
---|
| 3986 | imap_close($mbox_stream); |
---|
| 3987 | } |
---|
[3923] | 3988 | } |
---|
[1709] | 3989 | } |
---|
[3923] | 3990 | |
---|
| 3991 | if(!function_exists("cmp_date")) { |
---|
| 3992 | function cmp_date($obj1, $obj2){ |
---|
| 3993 | if($obj1['timestamp'] == $obj2['timestamp']) return 0; |
---|
| 3994 | return ($obj1['timestamp'] < $obj2['timestamp']) ? 1 : -1; |
---|
| 3995 | } |
---|
| 3996 | } |
---|
| 3997 | usort($return["msgs"], "cmp_date"); |
---|
| 3998 | $return["has_more_msg"] = (sizeof($return["msgs"]) > $max_msgs); |
---|
| 3999 | $return["msgs"] = array_slice($return["msgs"], 0, $max_msgs); |
---|
[4560] | 4000 | $return["msgs"]['num_msgs'] = $num_msgs; |
---|
[3923] | 4001 | |
---|
[1709] | 4002 | return $return; |
---|
| 4003 | } |
---|
[1472] | 4004 | |
---|
[2] | 4005 | function delete_and_show_previous_message($params) |
---|
| 4006 | { |
---|
| 4007 | $return = $this->get_info_previous_msg($params); |
---|
[1472] | 4008 | |
---|
[2] | 4009 | $params_tmp1 = array(); |
---|
| 4010 | $params_tmp1['msgs_to_delete'] = $params['msg_number']; |
---|
| 4011 | $params_tmp1['folder'] = $params['msg_folder']; |
---|
| 4012 | $return_tmp1 = $this->delete_msg($params_tmp1); |
---|
[1472] | 4013 | |
---|
[2] | 4014 | $return['msg_number_deleted'] = $return_tmp1; |
---|
[1472] | 4015 | |
---|
[2] | 4016 | return $return; |
---|
| 4017 | } |
---|
[1472] | 4018 | |
---|
| 4019 | |
---|
[2] | 4020 | function automatic_trash_cleanness($params) |
---|
| 4021 | { |
---|
| 4022 | $before_date = date("m/d/Y", strtotime("-".$params['before_date']." day")); |
---|
| 4023 | $criteria = 'BEFORE "'.$before_date.'"'; |
---|
[5302] | 4024 | //$mbox_stream = $this->open_mbox('INBOX'.$this->folders['trash']); |
---|
| 4025 | $mbox_stream = $this->open_mbox($this->mount_url_folder(array("INBOX",$this->folders['trash']))); |
---|
| 4026 | |
---|
[3018] | 4027 | // Free others requests |
---|
| 4028 | session_write_close(); |
---|
[2] | 4029 | $messages = imap_search($mbox_stream, $criteria, SE_UID); |
---|
| 4030 | if (is_array($messages)){ |
---|
| 4031 | foreach ($messages as $msg_number){ |
---|
| 4032 | imap_delete($mbox_stream, $msg_number, FT_UID); |
---|
| 4033 | } |
---|
| 4034 | } |
---|
[51] | 4035 | if($mbox_stream) |
---|
| 4036 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 4037 | return $messages; |
---|
| 4038 | } |
---|
| 4039 | // Fix the search problem with special characters!!!! |
---|
| 4040 | function remove_accents($string) { |
---|
[1472] | 4041 | return strtr($string, |
---|
| 4042 | "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ", |
---|
[2] | 4043 | "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); |
---|
| 4044 | } |
---|
| 4045 | |
---|
[4795] | 4046 | function make_search_date($date,$before = false){ |
---|
| 4047 | |
---|
[1622] | 4048 | //TODO: Adaptar a data de acordo com o locale do sistema. |
---|
| 4049 | list($day,$month,$year) = explode("/", $date); |
---|
[4795] | 4050 | $before?$day=(int)$day+1:$day=(int)$day; |
---|
| 4051 | $timestamp = mktime(0,0,0,(int)$month,$day,(int)$year); |
---|
| 4052 | $search_date = date('d-M-Y',$timestamp); |
---|
[1622] | 4053 | return $search_date; |
---|
| 4054 | |
---|
[4795] | 4055 | } |
---|
[1622] | 4056 | |
---|
[3843] | 4057 | function search_msg( $params = false ) |
---|
| 4058 | { |
---|
[5359] | 4059 | |
---|
[6058] | 4060 | include '../prototype/api/controller.php'; |
---|
[3843] | 4061 | if(strpos($params['condition'],"#")===false) |
---|
| 4062 | { //local messages |
---|
| 4063 | $search=false; |
---|
| 4064 | } |
---|
| 4065 | else |
---|
| 4066 | { |
---|
| 4067 | $search = explode(",",$params['condition']); |
---|
| 4068 | } |
---|
| 4069 | |
---|
| 4070 | $params['page'] = $params['page'] * 1; |
---|
[689] | 4071 | |
---|
[3843] | 4072 | if( is_array($search) ) |
---|
| 4073 | { |
---|
| 4074 | $search = array_unique($search); // Remove duplicated folders |
---|
| 4075 | $search_criteria = ''; |
---|
| 4076 | $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number']; |
---|
| 4077 | foreach($search as $tmp) |
---|
| 4078 | { |
---|
| 4079 | $tmp1 = explode("##",$tmp); |
---|
| 4080 | $sum = 0; |
---|
| 4081 | $name_box = $tmp1[0]; |
---|
| 4082 | unset($filter); |
---|
| 4083 | foreach($tmp1 as $index => $criteria) |
---|
| 4084 | { |
---|
| 4085 | if ($index != 0 && strlen($criteria) != 0) |
---|
| 4086 | { |
---|
| 4087 | $filter_array = explode("<=>",html_entity_decode(rawurldecode($criteria))); |
---|
| 4088 | $filter .= " ".$filter_array[0]; |
---|
| 4089 | if (strlen($filter_array[1]) != 0) |
---|
| 4090 | { |
---|
| 4091 | if ( trim($filter_array[0]) != 'BEFORE' && |
---|
| 4092 | trim($filter_array[0]) != 'SINCE' && |
---|
| 4093 | trim($filter_array[0]) != 'ON') |
---|
| 4094 | { |
---|
| 4095 | $filter .= '"'.$filter_array[1].'"'; |
---|
[5134] | 4096 | }else if(trim($filter_array[0]) == 'BEFORE' ){ |
---|
[4795] | 4097 | $filter .= '"'.$this->make_search_date($filter_array[1],true).'"'; |
---|
| 4098 | }else{ |
---|
| 4099 | $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; |
---|
| 4100 | } |
---|
[3843] | 4101 | } |
---|
| 4102 | } |
---|
| 4103 | } |
---|
| 4104 | |
---|
[5134] | 4105 | $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO-8859-1" ); |
---|
[3843] | 4106 | $filter = $this->remove_accents($filter); |
---|
[1472] | 4107 | |
---|
[3843] | 4108 | //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name |
---|
| 4109 | if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user') |
---|
| 4110 | { |
---|
| 4111 | $folder_name = explode($this->imap_delimiter,$name_box); |
---|
| 4112 | $this->ldap = new ldap_functions(); |
---|
| 4113 | |
---|
| 4114 | if ($cn = $this->ldap->uid2cn($folder_name[1])) |
---|
| 4115 | { |
---|
| 4116 | $folder_name[1] = $cn; |
---|
| 4117 | } |
---|
| 4118 | $folder_name = implode($this->imap_delimiter,$folder_name); |
---|
[3391] | 4119 | } |
---|
[3843] | 4120 | else |
---|
[5134] | 4121 | $folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO-8859-1" ); |
---|
[3843] | 4122 | |
---|
[5359] | 4123 | |
---|
| 4124 | $this->open_mbox($name_box); |
---|
| 4125 | |
---|
[3843] | 4126 | if (preg_match("/^.?\bALL\b/", $filter)) |
---|
| 4127 | { |
---|
| 4128 | // Quick Search, note: this ALL isn't the same ALL from imap_search |
---|
| 4129 | $all_criterias = array ("TO","SUBJECT","FROM","CC"); |
---|
| 4130 | |
---|
| 4131 | foreach($all_criterias as $criteria_fixed) |
---|
| 4132 | { |
---|
| 4133 | $_filter = $criteria_fixed . substr($filter,4); |
---|
| 4134 | |
---|
[5359] | 4135 | $search_criteria = imap_search($this->mbox, $_filter, SE_UID); |
---|
[3843] | 4136 | |
---|
| 4137 | if(is_array($search_criteria)) |
---|
| 4138 | { |
---|
| 4139 | foreach($search_criteria as $new_search) |
---|
| 4140 | { |
---|
[5488] | 4141 | $elem = $this->get_info_head_msg($new_search); |
---|
| 4142 | $elem['udate'] = gmdate('d/m/Y', $elem['udate'] + $this->functions->CalculateDateOffset()); |
---|
[5134] | 4143 | $elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); |
---|
[4795] | 4144 | $elem['uid'] = $new_search; |
---|
| 4145 | /* compare dates in ordering */ |
---|
| 4146 | $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); |
---|
[3843] | 4147 | $retorno[] = $elem; |
---|
| 4148 | } |
---|
| 4149 | } |
---|
| 4150 | } |
---|
| 4151 | } |
---|
[4068] | 4152 | else{ |
---|
[5359] | 4153 | $search_criteria = imap_search($this->mbox, $filter, SE_UID); |
---|
[4941] | 4154 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_important_flag']) |
---|
| 4155 | { |
---|
| 4156 | if((!strpos($filter,"FLAGGED") === false) || (!strpos($filter,"UNFLAGGED") === false)) |
---|
| 4157 | { |
---|
[5359] | 4158 | $num_msgs = imap_num_msg($this->mbox); |
---|
[4941] | 4159 | $flagged_msgs = array(); |
---|
| 4160 | for ($i=$num_msgs; $i>0; $i--) |
---|
[4068] | 4161 | { |
---|
[4941] | 4162 | $iuid = @imap_uid($this->mbox,$i); |
---|
| 4163 | $header = $this->get_header($iuid); |
---|
| 4164 | if(trim($header->Flagged)) |
---|
| 4165 | { |
---|
| 4166 | $flagged_msgs[$i] = $iuid; |
---|
| 4167 | } |
---|
[4068] | 4168 | } |
---|
[5134] | 4169 | if((count($flagged_msgs) >0) && (strpos($filter,"UNFLAGGED") === false)) |
---|
[4941] | 4170 | { |
---|
[5134] | 4171 | $arry_diff = is_array($search_criteria) ? array_diff($flagged_msgs,$search_criteria):$flagged_msgs; |
---|
| 4172 | foreach($arry_diff as $msg) |
---|
[4941] | 4173 | { |
---|
[5134] | 4174 | $search_criteria[] = $msg; |
---|
[4941] | 4175 | } |
---|
| 4176 | } |
---|
[5134] | 4177 | else if((count($flagged_msgs) >0) && (is_array($search_criteria)) && (!strpos($filter,"UNFLAGGED") === false)) |
---|
[4941] | 4178 | { |
---|
[5134] | 4179 | $search_criteria = array_diff($search_criteria,$flagged_msgs); |
---|
[4941] | 4180 | } |
---|
| 4181 | } |
---|
| 4182 | } |
---|
| 4183 | |
---|
| 4184 | if( is_array( $search_criteria) ) |
---|
| 4185 | { |
---|
| 4186 | foreach($search_criteria as $new_search) |
---|
[6058] | 4187 | { |
---|
| 4188 | |
---|
[5359] | 4189 | $elem = $this->get_info_head_msg( $new_search ); |
---|
[5372] | 4190 | $elem['udate'] = gmdate('d/m/Y', $elem['udate'] + $this->functions->CalculateDateOffset()); |
---|
[5488] | 4191 | $elem['boxname'] = mb_convert_encoding( $name_box, "ISO-8859-1", "UTF7-IMAP" ); |
---|
[4941] | 4192 | $elem['uid'] = $new_search; |
---|
| 4193 | /* compare dates in ordering */ |
---|
[6058] | 4194 | $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); |
---|
| 4195 | |
---|
| 4196 | $filter = array('AND', array('=', 'folderName', $name_box), array('=','messageNumber', $new_search)); |
---|
| 4197 | $followupflagged = Controller::find( |
---|
| 4198 | array('concept' => 'followupflagged'), |
---|
| 4199 | false, |
---|
| 4200 | array('filter' => $filter, 'criteria' => array('deepness' => '2')) |
---|
| 4201 | ); |
---|
| 4202 | |
---|
| 4203 | if(isset($followupflagged[0]['followupflagId'])) |
---|
| 4204 | { |
---|
| 4205 | $followupflag = Controller::read( array( 'concept' => 'followupflag', 'id' => $followupflagged[0]['followupflagId'] )); |
---|
| 4206 | $followupflagged[0]['followupflag'] = $followupflag; |
---|
| 4207 | $elem['followupflagged'] = $followupflagged[0]; |
---|
| 4208 | |
---|
| 4209 | } |
---|
| 4210 | $labeleds = Controller::find( |
---|
| 4211 | array('concept' => 'labeled'), |
---|
| 4212 | false, |
---|
| 4213 | array('filter' => $filter, 'criteria' => array('deepness' => '2')) |
---|
| 4214 | ); |
---|
| 4215 | foreach ($labeleds as $e){ |
---|
| 4216 | $labels = Controller::read( array( 'concept' => 'label', 'id' => $e['labelId'])); |
---|
| 4217 | $elem['labels'][$e['labelId']] = $labels; |
---|
| 4218 | } |
---|
[4941] | 4219 | $retorno[] = $elem; |
---|
| 4220 | } |
---|
| 4221 | } |
---|
[3843] | 4222 | } |
---|
| 4223 | } |
---|
| 4224 | } |
---|
| 4225 | |
---|
[5359] | 4226 | imap_close($this->mbox); |
---|
[3803] | 4227 | $num_msgs = count($retorno); |
---|
| 4228 | /* Comparison functions, descendent is ascendent with parms inverted */ |
---|
[4515] | 4229 | function SORTDATE($a, $b){ return ($a['udatecomp'] < $b['udatecomp']); } |
---|
[3803] | 4230 | function SORTDATE_REVERSE($b, $a) { return SORTDATE($a,$b); } |
---|
[3391] | 4231 | |
---|
[3803] | 4232 | function SORTWHO($a, $b) { return (strtoupper($a['from']) > strtoupper($b['from'])); } |
---|
| 4233 | function SORTWHO_REVERSE($b, $a) { return SORTWHO($a,$b); } |
---|
| 4234 | |
---|
| 4235 | function SORTSUBJECT($a, $b) { return (strtoupper($a['subject']) > strtoupper($b['subject'])); } |
---|
| 4236 | function SORTSUBJECT_REVERSE($b, $a) { return SORTSUBJECT($a,$b); } |
---|
| 4237 | |
---|
| 4238 | function SORTBOX($a, $b) { return ($a['boxname'] > $b['boxname']); } |
---|
| 4239 | function SORTBOX_REVERSE($b, $a) { return SORTBOX($a,$b); } |
---|
| 4240 | |
---|
| 4241 | function SORTSIZE($a, $b) { return ($a['size'] > $b['size']); } |
---|
| 4242 | function SORTSIZE_REVERSE($b, $a) { return SORTSIZE($a,$b); } |
---|
| 4243 | |
---|
[3843] | 4244 | usort( $retorno, $params['sort_type']); |
---|
| 4245 | $pageret = array_slice( $retorno, $params['page'] * $this->prefs['max_email_per_page'], $this->prefs['max_email_per_page']); |
---|
| 4246 | |
---|
| 4247 | $arrayRetorno['num_msgs'] = $num_msgs; |
---|
| 4248 | $arrayRetorno['data'] = $pageret; |
---|
[4158] | 4249 | $arrayRetorno['currentTab'] = $params['current_tab']; |
---|
[5359] | 4250 | return ($pageret) ? $arrayRetorno : 'none'; |
---|
[2] | 4251 | } |
---|
[1472] | 4252 | |
---|
[3391] | 4253 | function size_msg($size){ |
---|
| 4254 | $var = floor($size/1024); |
---|
| 4255 | if($var >= 1){ |
---|
| 4256 | return $var." kb"; |
---|
| 4257 | }else{ |
---|
| 4258 | return $size ." b"; |
---|
| 4259 | } |
---|
| 4260 | } |
---|
| 4261 | |
---|
[2] | 4262 | function ob_array($the_object) |
---|
| 4263 | { |
---|
| 4264 | $the_array=array(); |
---|
| 4265 | if(!is_scalar($the_object)) |
---|
| 4266 | { |
---|
| 4267 | foreach($the_object as $id => $object) |
---|
| 4268 | { |
---|
| 4269 | if(is_scalar($object)) |
---|
| 4270 | { |
---|
| 4271 | $the_array[$id]=$object; |
---|
| 4272 | } |
---|
| 4273 | else |
---|
| 4274 | { |
---|
| 4275 | $the_array[$id]=$this->ob_array($object); |
---|
| 4276 | } |
---|
| 4277 | } |
---|
| 4278 | return $the_array; |
---|
| 4279 | } |
---|
| 4280 | else |
---|
| 4281 | { |
---|
| 4282 | return $the_object; |
---|
| 4283 | } |
---|
| 4284 | } |
---|
[1472] | 4285 | |
---|
[2] | 4286 | function getacl() |
---|
| 4287 | { |
---|
| 4288 | $this->ldap = new ldap_functions(); |
---|
[1472] | 4289 | |
---|
[2] | 4290 | $return = array(); |
---|
[1472] | 4291 | $mbox_stream = $this->open_mbox(); |
---|
[2] | 4292 | $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); |
---|
[1472] | 4293 | |
---|
[2] | 4294 | $i = 0; |
---|
| 4295 | foreach ($mbox_acl as $user => $acl) |
---|
| 4296 | { |
---|
| 4297 | if ($user != $this->username) |
---|
| 4298 | { |
---|
| 4299 | $return[$i]['uid'] = $user; |
---|
| 4300 | $return[$i]['cn'] = $this->ldap->uid2cn($user); |
---|
| 4301 | } |
---|
| 4302 | $i++; |
---|
| 4303 | } |
---|
| 4304 | return $return; |
---|
| 4305 | } |
---|
[1472] | 4306 | |
---|
[2] | 4307 | function setacl($params) |
---|
| 4308 | { |
---|
| 4309 | $old_users = $this->getacl(); |
---|
| 4310 | if (!count($old_users)) |
---|
| 4311 | $old_users = array(); |
---|
[1472] | 4312 | |
---|
[2] | 4313 | $tmp_array = array(); |
---|
| 4314 | foreach ($old_users as $index => $user_info) |
---|
| 4315 | { |
---|
| 4316 | $tmp_array[$index] = $user_info['uid']; |
---|
| 4317 | } |
---|
| 4318 | $old_users = $tmp_array; |
---|
[1472] | 4319 | |
---|
[2] | 4320 | $users = unserialize($params['users']); |
---|
| 4321 | if (!count($users)) |
---|
| 4322 | $users = array(); |
---|
[1472] | 4323 | |
---|
[2] | 4324 | //$add_share = array_diff($users, $old_users); |
---|
| 4325 | $remove_share = array_diff($old_users, $users); |
---|
| 4326 | |
---|
| 4327 | $mbox_stream = $this->open_mbox(); |
---|
| 4328 | |
---|
| 4329 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 4330 | $mailboxes_list = imap_getmailboxes($mbox_stream, $serverString, "user".$this->imap_delimiter.$this->username."*"); |
---|
| 4331 | |
---|
| 4332 | /*if (count($add_share)) |
---|
| 4333 | { |
---|
| 4334 | foreach ($add_share as $index=>$uid) |
---|
| 4335 | { |
---|
| 4336 | if (is_array($mailboxes_list)) |
---|
| 4337 | { |
---|
| 4338 | foreach ($mailboxes_list as $key => $val) |
---|
| 4339 | { |
---|
| 4340 | $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); |
---|
| 4341 | imap_setacl ($mbox_stream, $folder, "$uid", "lrswipcda"); |
---|
| 4342 | } |
---|
| 4343 | } |
---|
| 4344 | } |
---|
| 4345 | }*/ |
---|
[1472] | 4346 | |
---|
[2] | 4347 | if (count($remove_share)) |
---|
| 4348 | { |
---|
| 4349 | foreach ($remove_share as $index=>$uid) |
---|
| 4350 | { |
---|
[4741] | 4351 | if (is_array($mailboxes_list)) |
---|
| 4352 | { |
---|
| 4353 | foreach ($mailboxes_list as $key => $val) |
---|
| 4354 | { |
---|
| 4355 | $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); |
---|
| 4356 | $folder = str_replace("&-", "&", $folder); |
---|
| 4357 | imap_setacl ($mbox_stream, $folder, "$uid", ""); |
---|
| 4358 | } |
---|
| 4359 | } |
---|
[1472] | 4360 | } |
---|
[2] | 4361 | } |
---|
[1472] | 4362 | |
---|
[2] | 4363 | return true; |
---|
| 4364 | } |
---|
[1472] | 4365 | |
---|
[2] | 4366 | function getaclfromuser($params) |
---|
| 4367 | { |
---|
| 4368 | $useracl = $params['user']; |
---|
| 4369 | $return = array(); |
---|
[1472] | 4370 | $mbox_stream = $this->open_mbox(); |
---|
[5864] | 4371 | if($params['getShared']){ |
---|
| 4372 | $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$useracl); |
---|
| 4373 | foreach ($mbox_acl as $user => $acl) |
---|
[2] | 4374 | { |
---|
[5864] | 4375 | if (($user == $this->username) && ($user != $useracl)) |
---|
| 4376 | { |
---|
| 4377 | $return[$useracl] = $acl; |
---|
| 4378 | } |
---|
| 4379 | } |
---|
| 4380 | }else { |
---|
| 4381 | $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); |
---|
| 4382 | foreach ($mbox_acl as $user => $acl) |
---|
| 4383 | { |
---|
| 4384 | if (($user != $this->username) && ($user == $useracl)) |
---|
| 4385 | { |
---|
| 4386 | $return[$user] = $acl; |
---|
| 4387 | } |
---|
[2] | 4388 | } |
---|
| 4389 | } |
---|
[5864] | 4390 | if(count($return) == 0) |
---|
| 4391 | $return[$useracl] = 'false'; |
---|
| 4392 | |
---|
[2] | 4393 | return $return; |
---|
| 4394 | } |
---|
| 4395 | |
---|
[6305] | 4396 | function getacltouser($user, $decode = false) |
---|
[2] | 4397 | { |
---|
| 4398 | $return = array(); |
---|
[6305] | 4399 | $mbox_stream = $this->open_mbox(); |
---|
[5864] | 4400 | |
---|
[6305] | 4401 | if( $decode ) |
---|
| 4402 | $user = mb_convert_encoding($user, 'UTF7-IMAP','UTF-8, ISO-8859-1, UTF7-IMAP'); |
---|
| 4403 | |
---|
[325] | 4404 | //Alterado, antes era 'imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); |
---|
| 4405 | //Afim de tratar as pastas compartilhadas, verificandos as permissoes de operacao sobre as mesmas |
---|
| 4406 | //No caso de se tratar da caixa do proprio usuario logado, utiliza a sintaxe abaixo |
---|
| 4407 | if(substr($user,0,4) != 'user') |
---|
[449] | 4408 | $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); |
---|
[325] | 4409 | else |
---|
[5134] | 4410 | $mbox_acl = @imap_getacl($mbox_stream, $user); |
---|
[5864] | 4411 | |
---|
[5134] | 4412 | if(isset($mbox_acl[$this->username])) |
---|
[2] | 4413 | return $mbox_acl[$this->username]; |
---|
[5134] | 4414 | else |
---|
| 4415 | return ''; |
---|
[2] | 4416 | } |
---|
| 4417 | |
---|
[1472] | 4418 | |
---|
[2] | 4419 | function setaclfromuser($params) |
---|
| 4420 | { |
---|
| 4421 | $user = $params['user']; |
---|
| 4422 | $acl = $params['acl']; |
---|
[1472] | 4423 | |
---|
[2] | 4424 | $mbox_stream = $this->open_mbox(); |
---|
| 4425 | |
---|
| 4426 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 4427 | $mailboxes_list = imap_getmailboxes($mbox_stream, $serverString, "user".$this->imap_delimiter.$this->username."*"); |
---|
| 4428 | |
---|
| 4429 | if (is_array($mailboxes_list)) |
---|
| 4430 | { |
---|
| 4431 | foreach ($mailboxes_list as $key => $val) |
---|
| 4432 | { |
---|
[449] | 4433 | $folder = str_replace($serverString, "", imap_utf7_encode($val->name)); |
---|
| 4434 | $folder = str_replace("&-", "&", $folder); |
---|
[2] | 4435 | if (!imap_setacl ($mbox_stream, $folder, $user, $acl)) |
---|
| 4436 | { |
---|
[449] | 4437 | $return = imap_last_error(); |
---|
[2] | 4438 | } |
---|
| 4439 | } |
---|
| 4440 | } |
---|
[449] | 4441 | if (isset($return)) |
---|
| 4442 | return $return; |
---|
| 4443 | else |
---|
| 4444 | return true; |
---|
[2] | 4445 | } |
---|
[1472] | 4446 | |
---|
[51] | 4447 | function download_attachment($msg,$msgno) |
---|
| 4448 | { |
---|
[1472] | 4449 | $array_parts_attachments = array(); |
---|
[3289] | 4450 | //$array_parts_attachments['names'] = ''; |
---|
[689] | 4451 | include_once("class.imap_attachment.inc.php"); |
---|
[1472] | 4452 | $imap_attachment = new imap_attachment(); |
---|
| 4453 | |
---|
[51] | 4454 | if (count($msg->fname[$msgno]) > 0) |
---|
| 4455 | { |
---|
| 4456 | $i = 0; |
---|
| 4457 | foreach ($msg->fname[$msgno] as $index=>$fname) |
---|
| 4458 | { |
---|
| 4459 | $array_parts_attachments[$i]['pid'] = $msg->pid[$msgno][$index]; |
---|
[1397] | 4460 | $array_parts_attachments[$i]['name'] = $imap_attachment->flat_mime_decode($this->decode_string($fname)); |
---|
[51] | 4461 | $array_parts_attachments[$i]['name'] = $array_parts_attachments[$i]['name'] ? $array_parts_attachments[$i]['name'] : "attachment.bin"; |
---|
| 4462 | $array_parts_attachments[$i]['encoding'] = $msg->encoding[$msgno][$index]; |
---|
[3289] | 4463 | //$array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', '; |
---|
[51] | 4464 | $array_parts_attachments[$i]['fsize'] = $msg->fsize[$msgno][$index]; |
---|
| 4465 | $i++; |
---|
| 4466 | } |
---|
| 4467 | } |
---|
[3289] | 4468 | //$array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); |
---|
[51] | 4469 | return $array_parts_attachments; |
---|
[1472] | 4470 | } |
---|
[69] | 4471 | |
---|
[4436] | 4472 | |
---|
| 4473 | /** |
---|
| 4474 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 4475 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 4476 | * @param $params |
---|
| 4477 | */ |
---|
| 4478 | function spam($params) |
---|
[69] | 4479 | { |
---|
[4416] | 4480 | |
---|
| 4481 | $mbox_stream = $this->open_mbox($params['folder']); |
---|
[69] | 4482 | $msgs_number = explode(',',$params['msgs_number']); |
---|
| 4483 | |
---|
[4416] | 4484 | $user = Array(); |
---|
| 4485 | |
---|
| 4486 | if(substr($params['folder'], 0, 4) == 'user') |
---|
| 4487 | { |
---|
| 4488 | $ldapObject = new ldap_functions(); |
---|
| 4489 | |
---|
| 4490 | $folderArray = Array(); |
---|
| 4491 | $folderArray = explode($this->imap_delimiter, $params['folder']); |
---|
| 4492 | |
---|
| 4493 | $user['name'] = $folderArray[1]; |
---|
| 4494 | $user['email'] = $ldapObject->getMailByUid($user['name']); |
---|
| 4495 | |
---|
| 4496 | } |
---|
| 4497 | else |
---|
| 4498 | { |
---|
| 4499 | $user['name'] = $this->username; |
---|
| 4500 | $user['email'] = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 4501 | } |
---|
| 4502 | |
---|
| 4503 | foreach($msgs_number as $msg_number) |
---|
| 4504 | { |
---|
[877] | 4505 | $imap_msg_number = imap_msgno($mbox_stream, $msg_number); |
---|
| 4506 | $header = imap_fetchheader($mbox_stream, $imap_msg_number); |
---|
| 4507 | $body = imap_body($mbox_stream, $imap_msg_number); |
---|
[69] | 4508 | $msg = $header . $body; |
---|
[4416] | 4509 | strtok($user['email'], '@'); |
---|
[69] | 4510 | $domain = strtok('@'); |
---|
| 4511 | |
---|
[4416] | 4512 | |
---|
| 4513 | |
---|
[449] | 4514 | //Encontrar a assinatura do dspam no cabecalho |
---|
| 4515 | $v = explode("\r\n", $header); |
---|
| 4516 | foreach ($v as $linha){ |
---|
[5783] | 4517 | if (preg_match('/^Message-ID/i', $linha)) { |
---|
[877] | 4518 | $args = explode(" ", $linha); |
---|
| 4519 | $msg_id = "'$args[1]'"; |
---|
[5783] | 4520 | } elseif (preg_match('/^X-DSPAM-Signature/i', $linha)) { |
---|
[449] | 4521 | $args = explode(" ",$linha); |
---|
| 4522 | $signature = $args[1]; |
---|
| 4523 | } |
---|
| 4524 | } |
---|
| 4525 | |
---|
[877] | 4526 | // Seleciona qual comando a ser executado |
---|
[4416] | 4527 | switch($params['spam']){ |
---|
[449] | 4528 | case 'true': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam']; break; |
---|
| 4529 | case 'false': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham']; break; |
---|
| 4530 | } |
---|
[877] | 4531 | |
---|
[4416] | 4532 | |
---|
[877] | 4533 | $tags = array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##', '##MSGID##'); |
---|
[4416] | 4534 | $cmd = str_replace($tags, array($user['email'], $user['name'], $domain, $signature, $msg_id), $cmd); |
---|
| 4535 | |
---|
[78] | 4536 | system($cmd); |
---|
[69] | 4537 | } |
---|
[4416] | 4538 | |
---|
[69] | 4539 | imap_close($mbox_stream); |
---|
| 4540 | return false; |
---|
| 4541 | } |
---|
[4436] | 4542 | |
---|
| 4543 | |
---|
[5134] | 4544 | /** |
---|
| 4545 | * Descrição do método |
---|
| 4546 | * |
---|
| 4547 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 4548 | * @author |
---|
| 4549 | * @sponsor Caixa Econômica Federal |
---|
| 4550 | * @author |
---|
| 4551 | * @param <tipo> <$msg_number> <Número da mensagem> |
---|
| 4552 | * @return <cabeçalho da mensagem> |
---|
| 4553 | * @access <public> |
---|
| 4554 | */ |
---|
[4436] | 4555 | function get_header($msg_number) |
---|
| 4556 | { |
---|
[4795] | 4557 | $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); |
---|
[535] | 4558 | if (!is_object($header)) |
---|
| 4559 | return false; |
---|
[1472] | 4560 | |
---|
[5134] | 4561 | if($header->Flagged != "F" ) { |
---|
[659] | 4562 | $flag = preg_match('/importance *: *(.*)\r/i', |
---|
| 4563 | imap_fetchheader($this->mbox, imap_msgno($this->mbox, $msg_number)) |
---|
[1472] | 4564 | ,$importance); |
---|
[659] | 4565 | $header->Flagged = $flag==0?false:strtolower($importance[1])=="high"?"F":false; |
---|
| 4566 | } |
---|
[1472] | 4567 | |
---|
[535] | 4568 | return $header; |
---|
| 4569 | } |
---|
[1000] | 4570 | |
---|
| 4571 | //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Insere emails no imap a partir do fonte do mesmo. Se o argumento timestamp for passado ele utiliza do script python |
---|
| 4572 | ///expressoMail1_2/imap.py para inserir uma msg com o horário correto pois isso não é porssível com a função imap_append do php. |
---|
| 4573 | |
---|
[5191] | 4574 | |
---|
[3911] | 4575 | function insert_email($source,$folder,$timestamp,$flags){ |
---|
[5191] | 4576 | |
---|
[1000] | 4577 | $username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 4578 | $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
| 4579 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 4580 | $imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
| 4581 | $imap_options = '/notls/novalidate-cert'; |
---|
[5134] | 4582 | |
---|
| 4583 | |
---|
| 4584 | $folder = mb_convert_encoding( $folder, "UTF7-IMAP","ISO-8859-1"); |
---|
| 4585 | |
---|
[1000] | 4586 | $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$folder, $username, $password); |
---|
[5134] | 4587 | |
---|
| 4588 | if(imap_last_error() === 'Mailbox already exists') |
---|
[1000] | 4589 | imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}".$folder)); |
---|
| 4590 | if($timestamp){ |
---|
[4436] | 4591 | $pdate = date_parse(date('r')); // pega a data atual do servidor (TODO: pegar a data da mensagem local) |
---|
| 4592 | $timestamp += $pdate['zone']*(60); //converte a data da mensagem para o fuso horário GMT 0. Isto é feito devido ao Expresso Mail armazenar a data no fuso horário GMT 0 e para exibi-la converte ela para o fuso horário local. |
---|
[4457] | 4593 | /* TODO: o diretorio /tmp deve ser substituido pelo diretorio temporario configurado no setup */ |
---|
| 4594 | $file = "/tmp/sess_".$_SESSION[ 'phpgw_session' ][ 'session_id' ]; |
---|
| 4595 | |
---|
[1000] | 4596 | $f = fopen($file,"w"); |
---|
| 4597 | fputs($f,base64_encode($source)); |
---|
[4795] | 4598 | fclose($f); |
---|
[5316] | 4599 | $command = "python ".dirname(__FILE__)."/../imap.py \"$imap_server\" \"$imap_port\" \"$username\" \"$password\" \"$timestamp\" \"$folder\" \"$file\""; |
---|
[5134] | 4600 | $return['command']= exec($command); |
---|
[1000] | 4601 | }else{ |
---|
| 4602 | $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $source, "\\Seen"); |
---|
| 4603 | } |
---|
| 4604 | $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); |
---|
[3872] | 4605 | |
---|
[1000] | 4606 | $return['msg_no'] = $status->uidnext - 1; |
---|
[3911] | 4607 | $return['error'] = imap_last_error(); |
---|
| 4608 | if(!$return['error'] && $flags != '' ){ |
---|
[3872] | 4609 | |
---|
[3911] | 4610 | $flags_array=explode(':',$flags); |
---|
| 4611 | //"Answered","Draft","Flagged","Unseen" |
---|
| 4612 | $flags_fixed = ""; |
---|
| 4613 | if($flags_array[0] == 'A') |
---|
| 4614 | $flags_fixed.="\\Answered "; |
---|
| 4615 | if($flags_array[1] == 'X') |
---|
| 4616 | $flags_fixed.="\\Draft "; |
---|
| 4617 | if($flags_array[2] == 'F') |
---|
| 4618 | $flags_fixed.="\\Flagged "; |
---|
| 4619 | if($flags_array[3] != 'U') |
---|
| 4620 | $flags_fixed.="\\Seen "; |
---|
[5184] | 4621 | if($flags_array[4] == 'F') |
---|
| 4622 | $flags_fixed.="\\Answered \\Draft "; |
---|
[3911] | 4623 | imap_setflag_full($mbox_stream, $return['msg_no'], $flags_fixed, ST_UID); |
---|
| 4624 | } |
---|
[5134] | 4625 | |
---|
| 4626 | //Ignorando erro de AUTH=Plain |
---|
| 4627 | if($return['error'] === 'SECURITY PROBLEM: insecure server advertised AUTH=PLAIN') |
---|
| 4628 | $return['error'] = false; |
---|
| 4629 | |
---|
[1000] | 4630 | if($mbox_stream) |
---|
[3911] | 4631 | imap_close($mbox_stream); |
---|
[1000] | 4632 | return $return; |
---|
| 4633 | } |
---|
| 4634 | |
---|
[5134] | 4635 | function show_decript($params,$dec=0){ |
---|
[1035] | 4636 | $source = $params['source']; |
---|
[5083] | 4637 | |
---|
[5134] | 4638 | //error_log("source: $source\nversao: " . PHP_VERSION); |
---|
| 4639 | if ($dec == 0) |
---|
| 4640 | { |
---|
| 4641 | $source = str_replace(" ", "+", $source,$i); |
---|
[5083] | 4642 | if (version_compare(PHP_VERSION, '5.2.0', '>=')){ |
---|
| 4643 | if(!$source = base64_decode($source,true)) |
---|
[5134] | 4644 | return "error ".$source."Espaï¿?os ".$i; |
---|
[5083] | 4645 | |
---|
| 4646 | } |
---|
| 4647 | else { |
---|
| 4648 | if(!$source = base64_decode($source)) |
---|
[5134] | 4649 | return "error ".$source."Espaï¿?os ".$i; |
---|
| 4650 | } |
---|
[1035] | 4651 | } |
---|
[3803] | 4652 | |
---|
[1035] | 4653 | $insert = $this->insert_email($source,'INBOX'.$this->imap_delimiter.'decifradas'); |
---|
| 4654 | |
---|
| 4655 | $get['msg_number'] = $insert['msg_no']; |
---|
| 4656 | $get['msg_folder'] = 'INBOX'.$this->imap_delimiter.'decifradas'; |
---|
| 4657 | $return = $this->get_info_msg($get); |
---|
| 4658 | $get['msg_number'] = $params['ID']; |
---|
| 4659 | $get['msg_folder'] = $params['folder']; |
---|
| 4660 | $tmp = $this->get_info_msg($get); |
---|
| 4661 | if(!$tmp['status_get_msg_info']) |
---|
| 4662 | { |
---|
| 4663 | $return['msg_day']=$tmp['msg_day']; |
---|
| 4664 | $return['msg_hour']=$tmp['msg_hour']; |
---|
| 4665 | $return['fulldate']=$tmp['fulldate']; |
---|
| 4666 | $return['smalldate']=$tmp['smalldate']; |
---|
| 4667 | } |
---|
| 4668 | else |
---|
| 4669 | { |
---|
| 4670 | $return['msg_day']=''; |
---|
| 4671 | $return['msg_hour']=''; |
---|
| 4672 | $return['fulldate']=''; |
---|
| 4673 | $return['smalldate']=''; |
---|
| 4674 | } |
---|
| 4675 | $return['msg_no'] =$insert['msg_no']; |
---|
| 4676 | $return['error'] = $insert['error']; |
---|
| 4677 | $return['folder'] = $params['folder']; |
---|
| 4678 | //$return['acls'] = $insert['acls']; |
---|
| 4679 | $return['original_ID'] = $params['ID']; |
---|
| 4680 | |
---|
| 4681 | return $return; |
---|
| 4682 | |
---|
| 4683 | } |
---|
[1472] | 4684 | |
---|
[1000] | 4685 | //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Trata fontes de emails enviados via POST para o servidor por um xmlhttprequest, as partes codificados com |
---|
| 4686 | //Base64 os "+" são substituidos por " " no envio e essa função arruma esse efeito. |
---|
| 4687 | |
---|
| 4688 | function treat_base64_from_post($source){ |
---|
| 4689 | $offset = 0; |
---|
| 4690 | do |
---|
| 4691 | { |
---|
| 4692 | if($inicio = strpos($source, 'Content-Transfer-Encoding: base64', $offset)) |
---|
| 4693 | { |
---|
| 4694 | $inicio = strpos($source, "\n\r", $inicio); |
---|
| 4695 | $fim = strpos($source, '--', $inicio); |
---|
| 4696 | if(!$fim) |
---|
| 4697 | $fim = strpos($source,"\n\r", $inicio); |
---|
| 4698 | $length = $fim-$inicio; |
---|
| 4699 | $parte = substr( $source,$inicio,$length-1); |
---|
| 4700 | $parte = str_replace(" ", "+", $parte); |
---|
| 4701 | $source = substr_replace($source, $parte, $inicio, $length-1); |
---|
| 4702 | } |
---|
| 4703 | if($offset > $inicio) |
---|
| 4704 | $offset=FALSE; |
---|
| 4705 | else |
---|
| 4706 | $offset = $inicio; |
---|
| 4707 | } |
---|
| 4708 | while($offset); |
---|
| 4709 | return $source; |
---|
| 4710 | } |
---|
| 4711 | |
---|
| 4712 | //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Recebe os fontes dos emails a serem desarquivados, separa e envia cada um para função insert_mail. |
---|
| 4713 | |
---|
| 4714 | function unarchive_mail($params) |
---|
[5191] | 4715 | { |
---|
[1000] | 4716 | $dest_folder = $params['folder']; |
---|
| 4717 | $sources = explode("#@#@#@",$params['source']); |
---|
[5134] | 4718 | //Add user timeszone |
---|
[5191] | 4719 | $timestamps = explode("#@#@#@",$params['timestamp']); |
---|
| 4720 | |
---|
| 4721 | |
---|
[3911] | 4722 | $flags = explode("#@#@#@",$params['flags']); |
---|
[5191] | 4723 | |
---|
[5134] | 4724 | foreach($sources as $index=>$src) { |
---|
| 4725 | if($src!=""){ |
---|
[3911] | 4726 | $source = $this->treat_base64_from_post($src); |
---|
[5191] | 4727 | $timestampsactual = $timestamps[$index] + $this->functions->CalculateDateOffset(); |
---|
| 4728 | $insert = $this->insert_email($source, mb_convert_encoding( $dest_folder,"ISO-8859-1","UTF-8"), $timestampsactual,$flags[$index]); |
---|
[3911] | 4729 | } |
---|
| 4730 | } |
---|
[1000] | 4731 | return $insert; |
---|
| 4732 | } |
---|
| 4733 | |
---|
| 4734 | function download_all_local_attachments($params) |
---|
| 4735 | { |
---|
| 4736 | $source = $params['source']; |
---|
| 4737 | $source = $this->treat_base64_from_post($source); |
---|
| 4738 | $insert = $this->insert_email($source,'INBOX'.$this->imap_delimiter.'decifradas'); |
---|
| 4739 | $exporteml = new ExportEml(); |
---|
| 4740 | $params['num_msg']=$insert['msg_no']; |
---|
| 4741 | $params['folder']='INBOX'.$this->imap_delimiter.'decifradas'; |
---|
| 4742 | return $exporteml->download_all_attachments($params); |
---|
| 4743 | } |
---|
[4830] | 4744 | |
---|
| 4745 | /** |
---|
| 4746 | * Método que envia um email reportando um erro no email do usuário |
---|
| 4747 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 4748 | * @author Prognus Software Livre (http://www.prognus.com.br) |
---|
| 4749 | */ |
---|
| 4750 | function report_mail_error($params) |
---|
| 4751 | { |
---|
| 4752 | $params = $params['params']; |
---|
| 4753 | $array_params = explode(";;", $params); |
---|
| 4754 | $id_msg = $array_params[0]; |
---|
| 4755 | $msg_user = $array_params[1]; |
---|
| 4756 | |
---|
| 4757 | if($msg_user == '') |
---|
| 4758 | $msg_user = "Sem mensagem!"; |
---|
| 4759 | |
---|
[6120] | 4760 | $toname = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
[4830] | 4761 | |
---|
[6120] | 4762 | $exporteml = new ExportEml(); |
---|
[4830] | 4763 | $mail_content = $exporteml->export_msg_data($id_msg, $msg_folder); |
---|
| 4764 | $this->open_mbox($msg_folder); |
---|
| 4765 | $title = "Erro de email reportado"; |
---|
| 4766 | $body = "<body>O usuário <strong>$toname</strong> reportou um erro na tentativa de acesso ao conteúdo do email.<br><br>Segue em anexo o fonte da mensagem" . " reportada.<br><br><hr><strong><u>Mensagem do usuário:</strong></u><br><br><br>" . |
---|
| 4767 | "$msg_user</body><br><br><hr>"; |
---|
[6120] | 4768 | |
---|
[5399] | 4769 | require_once dirname(__FILE__) . '/../../services/class.servicelocator.php'; |
---|
[4830] | 4770 | $mailService = ServiceLocator::getService('mail'); |
---|
[5134] | 4771 | $mailService->addStringAttachment($mail_content, 'report.eml', 'application/text'); |
---|
| 4772 | $mailService->sendMail($_SESSION['phpgw_info']['expressomail']['server']['sugestoes_email_to'], $GLOBALS['phpgw_info']['user']['email'], $title, $body); |
---|
[4830] | 4773 | } |
---|
| 4774 | |
---|
[5134] | 4775 | function array_msort($array, $cols) |
---|
| 4776 | { |
---|
| 4777 | $colarr = array(); |
---|
| 4778 | foreach ($cols as $col => $order) { |
---|
| 4779 | $colarr[$col] = array(); |
---|
| 4780 | foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); } |
---|
| 4781 | } |
---|
| 4782 | $params = array(); |
---|
| 4783 | foreach ($cols as $col => $order) { |
---|
| 4784 | $params[] =& $colarr[$col]; |
---|
| 4785 | $params = array_merge($params, (array)$order); |
---|
| 4786 | } |
---|
| 4787 | call_user_func_array('array_multisort', $params); |
---|
| 4788 | $ret = array(); |
---|
| 4789 | $keys = array(); |
---|
| 4790 | $first = true; |
---|
| 4791 | foreach ($colarr as $col => $arr) { |
---|
| 4792 | foreach ($arr as $k => $v) { |
---|
| 4793 | if ($first) { $keys[$k] = substr($k,1); } |
---|
| 4794 | $k = $keys[$k]; |
---|
| 4795 | if (!isset($ret[$k])) $ret[$k] = $array[$k]; |
---|
| 4796 | $ret[$k][$col] = $array[$k][$col]; |
---|
| 4797 | } |
---|
| 4798 | $first = false; |
---|
| 4799 | } |
---|
| 4800 | |
---|
| 4801 | return $ret; |
---|
| 4802 | |
---|
| 4803 | } |
---|
| 4804 | |
---|
[5533] | 4805 | function parseCriteriaSearchMail($search) |
---|
| 4806 | { |
---|
| 4807 | $criteria = ''; |
---|
| 4808 | $searchArray = explode(' ', $search); |
---|
[5134] | 4809 | |
---|
[5533] | 4810 | foreach ($searchArray as $v) |
---|
| 4811 | if(trim($v) !== '' ) |
---|
| 4812 | $criteria .= 'TEXT "'.$v.'" ' ; |
---|
| 4813 | |
---|
| 4814 | return $criteria; |
---|
| 4815 | } |
---|
[5134] | 4816 | |
---|
| 4817 | function quickSearchMail( $params ) |
---|
| 4818 | { |
---|
[6310] | 4819 | include '../prototype/api/controller.php'; |
---|
| 4820 | set_time_limit(270); //Aumenta o tempo limit da requisição, em algumas buscas o imap demora para retornar o resultado. |
---|
[5134] | 4821 | $return = array(); |
---|
| 4822 | $return['folder'] = $params['folder']; |
---|
| 4823 | if(!is_array($params['folder'])) |
---|
| 4824 | $params['folder'] = array( $params['folder'] ); |
---|
| 4825 | |
---|
| 4826 | if(!isset($params['sort'])) |
---|
[5172] | 4827 | $params['sort'] = 'SORTDATE_REVERSE'; |
---|
[5134] | 4828 | |
---|
| 4829 | $params['search'] = mb_convert_encoding($params['search'], 'UTF-8',mb_detect_encoding($params['search'].'x', 'UTF-8, ISO-8859-1')); |
---|
[5861] | 4830 | |
---|
[5134] | 4831 | $i = 0; |
---|
| 4832 | if(!isset($params['page'])) $params['page'] = 0; |
---|
| 4833 | $end = ($this->prefs['max_email_per_page'] * ((int)$params['page'] + 1)); |
---|
| 4834 | $ini = $end - $this->prefs['max_email_per_page'] ; |
---|
| 4835 | $count = 0; |
---|
| 4836 | |
---|
[5533] | 4837 | if (!preg_match('/KEYWORD/i', $params['search'])){ |
---|
| 4838 | $search = $this->parseCriteriaSearchMail($params['search']); |
---|
| 4839 | } else { |
---|
| 4840 | $search = $params['search']; |
---|
| 4841 | } |
---|
| 4842 | |
---|
[5134] | 4843 | foreach ($params['folder'] as $folder) |
---|
| 4844 | { |
---|
| 4845 | $imap = $this->open_mbox( $folder ) ; |
---|
[5172] | 4846 | $msgIds = imap_sort( $imap , SORTDATE , 1 , SE_UID , $search ,'UTF-8'); |
---|
[5134] | 4847 | |
---|
| 4848 | $count += count($msgIds); |
---|
| 4849 | |
---|
| 4850 | foreach ($msgIds as $ii => $v) |
---|
[6442] | 4851 | { |
---|
[5134] | 4852 | $msg = imap_headerinfo ( $imap, imap_msgno($imap, $v) ); |
---|
[6442] | 4853 | |
---|
[5134] | 4854 | $return['msgs'][$i]['from'] = ''; |
---|
| 4855 | |
---|
[6171] | 4856 | if(isset($msg->from[0])) |
---|
| 4857 | { |
---|
| 4858 | $from = self::formatMailObject( $msg->from[0] ); |
---|
| 4859 | $return['msgs'][$i]['from'] = mb_convert_encoding($from['name'] ? $from['name'] : $from['email'], 'UTF-8'); |
---|
| 4860 | } |
---|
| 4861 | else |
---|
| 4862 | $return['msgs'][$i]['from'] = ''; |
---|
[5134] | 4863 | |
---|
| 4864 | $return['msgs'][$i]['subject'] = ' '; |
---|
| 4865 | |
---|
| 4866 | $subject = imap_mime_header_decode($msg->subject); |
---|
| 4867 | foreach ($subject as $tmp) |
---|
[5189] | 4868 | $return['msgs'][$i]['subject'] .= mb_convert_encoding($tmp->text, 'UTF-8', 'UTF-8 , ISO-8859-1'); |
---|
[5134] | 4869 | |
---|
[5533] | 4870 | $filter = array('AND', array('=', 'folderName', $folder), array('=','messageNumber', $v)); |
---|
| 4871 | $followupflagged = Controller::find( |
---|
[6171] | 4872 | array('concept' => 'followupflagged' , 'folder' => $folder ), |
---|
[5533] | 4873 | false, |
---|
| 4874 | array('filter' => $filter, 'criteria' => array('deepness' => '2')) |
---|
| 4875 | ); |
---|
| 4876 | |
---|
[5541] | 4877 | if(isset($followupflagged[0]['followupflagId'])) |
---|
| 4878 | { |
---|
| 4879 | $followupflag = Controller::read( array( 'concept' => 'followupflag', 'id' => $followupflagged[0]['followupflagId'] )); |
---|
| 4880 | $followupflagged[0]['followupflag'] = $followupflag; |
---|
| 4881 | $return['msgs'][$i]['followupflagged'] = $followupflagged[0]; |
---|
| 4882 | |
---|
[5740] | 4883 | } |
---|
[5533] | 4884 | $labeleds = Controller::find( |
---|
| 4885 | array('concept' => 'labeled'), |
---|
| 4886 | false, |
---|
| 4887 | array('filter' => $filter, 'criteria' => array('deepness' => '2')) |
---|
| 4888 | ); |
---|
[6171] | 4889 | if(is_array($labeleds)) |
---|
[5541] | 4890 | foreach ($labeleds as $e){ |
---|
| 4891 | $labels = Controller::read( array( 'concept' => 'label', 'id' => $e['labelId'])); |
---|
| 4892 | $return['msgs'][$i]['labels'][$e['labelId']] = $labels; |
---|
[5605] | 4893 | } |
---|
[5134] | 4894 | $return['msgs'][$i]['flag'] = ' '; |
---|
| 4895 | $return['msgs'][$i]['flag'] .= $msg->Unseen ? $msg->Unseen : ''; |
---|
| 4896 | $return['msgs'][$i]['flag'] .= $msg->Recent ? $msg->Recent : ''; |
---|
| 4897 | $return['msgs'][$i]['flag'] .= $msg->Draft ? $msg->Draft : ''; |
---|
| 4898 | $return['msgs'][$i]['flag'] .= $msg->Answered ? $msg->Answered : ''; |
---|
| 4899 | $return['msgs'][$i]['flag'] .= $msg->Deleted ? $msg->Deleted : ''; |
---|
| 4900 | |
---|
[6442] | 4901 | $header = imap_fetchheader( $imap, $v , FT_UID ); // Necessario para recuperar se a mensagem é importante ou não. |
---|
| 4902 | $importante = array(); |
---|
| 4903 | |
---|
| 4904 | if($msg->Flagged != 'F') |
---|
| 4905 | $return['msgs'][$i]['flag'] .= ( preg_match('/importance *: *(.*)\r/i', $header , $importante) === 0 ) ? '' : 'F'; |
---|
| 4906 | else |
---|
| 4907 | $return['msgs'][$i]['flag'] .= $msg->Flagged ? $msg->Flagged : ''; |
---|
| 4908 | |
---|
[5134] | 4909 | $return['msgs'][$i]['udate'] = gmdate("d/m/Y",$msg->udate + $this->functions->CalculateDateOffset()); |
---|
| 4910 | $return['msgs'][$i]['udatecomp'] = substr ($return['msgs'][$i]['udate'], -4) ."-". substr ($return['msgs'][$i]['udate'], 3, 2) ."-". substr ($return['msgs'][$i]['udate'], 0, 2); |
---|
| 4911 | $return['msgs'][$i]['date'] = $msg->udate; |
---|
| 4912 | $return['msgs'][$i]['size'] = $msg->Size; |
---|
| 4913 | $return['msgs'][$i]['boxname'] = $folder; |
---|
| 4914 | $return['msgs'][$i]['uid'] = $v; |
---|
| 4915 | $i++; |
---|
| 4916 | } |
---|
| 4917 | } |
---|
| 4918 | |
---|
| 4919 | $return['num_msgs'] = $count; |
---|
| 4920 | |
---|
| 4921 | if(!isset($return['msgs'])) |
---|
| 4922 | $return['msgs'] = array(); |
---|
| 4923 | |
---|
| 4924 | define('SORTBOX', 69); |
---|
| 4925 | define('SORTWHO', 2); |
---|
| 4926 | define('SORTBOX_REVERSE', 69); |
---|
| 4927 | define('SORTWHO_REVERSE', 2); |
---|
| 4928 | define('SORTDATE_REVERSE', 0); |
---|
| 4929 | define('SORTSUBJECT_REVERSE', 3); |
---|
| 4930 | define('SORTSIZE_REVERSE', 6); |
---|
| 4931 | |
---|
| 4932 | switch (constant( $params['sort'] )){ |
---|
| 4933 | case 0 : $sA = 'date'; break; |
---|
| 4934 | case 2 : $sA = 'from'; break; |
---|
| 4935 | case 69 : $sA = 'boxname'; break; |
---|
| 4936 | case 3 : $sA = 'subject'; break; |
---|
| 4937 | case 6 : $sA = 'size'; break; |
---|
| 4938 | } |
---|
[4830] | 4939 | |
---|
[5134] | 4940 | |
---|
[5172] | 4941 | if($params['sort'] !== 'SORTDATE_REVERSE') |
---|
[5134] | 4942 | if(strpos($params['sort'],'REVERSE') !== false) |
---|
[5172] | 4943 | $return['msgs'] = $this->array_msort($return['msgs'] , array( $sA => SORT_DESC)); |
---|
| 4944 | else |
---|
| 4945 | $return['msgs'] = $this->array_msort($return['msgs'] , array( $sA => SORT_ASC)); |
---|
[5134] | 4946 | |
---|
| 4947 | $k = -1; |
---|
| 4948 | $nMsgs = array(); |
---|
| 4949 | |
---|
| 4950 | foreach ($return['msgs'] as $v) |
---|
| 4951 | { |
---|
| 4952 | $k++; |
---|
| 4953 | if($k < $ini || $k >= $end ) continue; |
---|
| 4954 | $nMsgs[] = $v; |
---|
| 4955 | } |
---|
[6442] | 4956 | $return['msgs'] = $nMsgs; |
---|
[5189] | 4957 | |
---|
[5134] | 4958 | $return = json_encode($return); |
---|
| 4959 | $return = base64_encode($return); |
---|
[4830] | 4960 | |
---|
[5134] | 4961 | return $return; |
---|
| 4962 | } |
---|
| 4963 | |
---|
[3157] | 4964 | function get_quota_folders(){ |
---|
| 4965 | |
---|
| 4966 | // Additional Imap Class for not-implemented functions into PHP-IMAP extension. |
---|
| 4967 | include_once("class.imapfp.inc.php"); |
---|
| 4968 | $imapfp = new imapfp(); |
---|
| 4969 | |
---|
| 4970 | if(!$imapfp->open($this->imap_server,$this->imap_port)) |
---|
| 4971 | return $imapfp->get_error(); |
---|
| 4972 | if (!$imapfp->login( $this->username,$this->password )) |
---|
| 4973 | return $imapfp->get_error(); |
---|
| 4974 | |
---|
| 4975 | $response_array = $imapfp->get_mailboxes_size(); |
---|
| 4976 | if ($imapfp->error) |
---|
| 4977 | return $imapfp->get_error(); |
---|
| 4978 | |
---|
| 4979 | $data = array(); |
---|
| 4980 | $quota_root = $this->get_quota(array('folder_id' => "INBOX")); |
---|
| 4981 | $data["quota_root"] = $quota_root; |
---|
| 4982 | |
---|
| 4983 | foreach ($response_array as $idx=>$line) { |
---|
| 4984 | $line2 = str_replace('"', "", $line); |
---|
| 4985 | $line2 = str_replace(" /vendor/cmu/cyrus-imapd/size (value.shared ",";",str_replace("* ANNOTATION ","",$line2)); |
---|
| 4986 | list($folder,$size) = explode(";",$line2); |
---|
[3854] | 4987 | $quota_used = str_replace(")","",$size); |
---|
| 4988 | $quotaPercent = (($quota_used / 1024) / $data["quota_root"]["quota_limit"])*100; |
---|
[6576] | 4989 | $folder = mb_convert_encoding($folder, "ISO-8859-1", "UTF7-IMAP"); |
---|
[3157] | 4990 | if(!preg_match('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i',$folder)){ |
---|
| 4991 | $folder = $this->functions->getLang("Inbox"); |
---|
| 4992 | } |
---|
| 4993 | else |
---|
| 4994 | $folder = preg_replace('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i','', $folder); |
---|
| 4995 | |
---|
| 4996 | $data[$folder] = array("quota_percent" => sprintf("%.1f",round($quotaPercent,1)), "quota_used" => $quota_used); |
---|
| 4997 | } |
---|
| 4998 | $imapfp->close(); |
---|
| 4999 | return $data; |
---|
| 5000 | } |
---|
[5134] | 5001 | |
---|
| 5002 | function getaclfrombox($mail) |
---|
[6120] | 5003 | { |
---|
| 5004 | $mailArray = explode('@', $mail); |
---|
| 5005 | $boxacl = $mailArray[0]; |
---|
| 5006 | $return = array(); |
---|
[5134] | 5007 | |
---|
[6120] | 5008 | if(!$this->mbox) |
---|
| 5009 | $this->open_mbox(); |
---|
[5134] | 5010 | |
---|
[6120] | 5011 | $mbox_acl = imap_getacl($this->mbox, 'user' . $this->imap_delimiter . $boxacl); |
---|
[5134] | 5012 | |
---|
[6120] | 5013 | foreach ($mbox_acl as $user => $acl) |
---|
| 5014 | { |
---|
| 5015 | if ($user != $boxacl ) |
---|
| 5016 | $return[$user] = $acl; |
---|
| 5017 | } |
---|
| 5018 | return $return; |
---|
| 5019 | } |
---|
[5539] | 5020 | |
---|
| 5021 | |
---|
| 5022 | function searchSieveRule( $params ) |
---|
| 5023 | { |
---|
| 5024 | |
---|
| 5025 | $imap = $this->open_mbox( 'INBOX' ); |
---|
| 5026 | $msgs = imap_sort( $imap , SORTDATE , 0 , SE_UID); |
---|
| 5027 | |
---|
| 5028 | $rr = array(); |
---|
| 5029 | |
---|
| 5030 | |
---|
| 5031 | foreach ($msgs as $i => $v) |
---|
| 5032 | { |
---|
| 5033 | |
---|
| 5034 | $msg = imap_headerinfo ( $imap, imap_msgno($imap, $v) ); |
---|
| 5035 | |
---|
| 5036 | if(isset($params['from'])) |
---|
| 5037 | { |
---|
| 5038 | $from['from'] = array(); |
---|
| 5039 | $from['from']['name'] = $this->decode_string($msg->from[0]->personal); |
---|
| 5040 | $from['from']['email'] = $this->decode_string($msg->from[0]->mailbox . "@" . $msg->from[0]->host); |
---|
| 5041 | if ($from['from']['name']) |
---|
| 5042 | { |
---|
| 5043 | if (substr($from['from']['name'], 0, 1) == '"') |
---|
| 5044 | $from['from']['full'] = $from['from']['name'] . ' ' . '<' . $from['from']['email'] . '>'; |
---|
| 5045 | else |
---|
| 5046 | $from['from']['full'] = '"' . $from['from']['name'] . '" ' . '<' . $from['from']['email'] . '>'; |
---|
| 5047 | } |
---|
| 5048 | else |
---|
| 5049 | $from['from']['full'] = $from['from']['email']; |
---|
| 5050 | |
---|
| 5051 | if($this->filterCheck( $from['from']['full'] , $params['from']['criteria'] , $params['from']['filter'] )) |
---|
| 5052 | $rr['from'][] = $v; |
---|
| 5053 | } |
---|
| 5054 | |
---|
| 5055 | if(isset($params['to'])) |
---|
| 5056 | { |
---|
| 5057 | $tos = $msg->to; |
---|
| 5058 | $val = ''; |
---|
| 5059 | foreach( $tos as $to) |
---|
| 5060 | { |
---|
| 5061 | $tmp = imap_mime_header_decode($to->personal); |
---|
| 5062 | $val .= '"' . $tmp[0]->text . '" ' . '<' . $to->mailbox . "@" . $to->host . '>'; |
---|
| 5063 | |
---|
| 5064 | } |
---|
| 5065 | if($this->filterCheck( $val , $params['to']['criteria'] , $params['to']['filter'] )) |
---|
| 5066 | $rr['to'][] = $v; |
---|
| 5067 | |
---|
| 5068 | $tos = $msg->cc; |
---|
| 5069 | $val = ''; |
---|
| 5070 | foreach( $tos as $to) |
---|
| 5071 | { |
---|
| 5072 | $tmp = imap_mime_header_decode($to->personal); |
---|
| 5073 | $val .= '"' . $tmp[0]->text . '" ' . '<' . $to->mailbox . "@" . $to->host . '>'; |
---|
| 5074 | |
---|
| 5075 | } |
---|
| 5076 | |
---|
| 5077 | if($this->filterCheck( $val , $params['to']['criteria'] , $params['to']['filter'] )) |
---|
| 5078 | $rr['to'][] = $v; |
---|
| 5079 | } |
---|
| 5080 | |
---|
| 5081 | if(isset($params['subject'])) |
---|
| 5082 | { |
---|
| 5083 | $ss = ''; |
---|
| 5084 | $subject = imap_mime_header_decode($msg->subject); |
---|
| 5085 | foreach ($subject as $tmp) |
---|
| 5086 | $ss .= $tmp->text; |
---|
| 5087 | |
---|
| 5088 | if($this->filterCheck($ss , $params['subject']['criteria'] , $params['subject']['filter'] )) |
---|
| 5089 | $rr['subject'][] = $v; |
---|
| 5090 | } |
---|
| 5091 | |
---|
| 5092 | if(isset($params['body'])) |
---|
| 5093 | { |
---|
| 5094 | $this->mbox = $this->open_mbox( 'INBOX' ); |
---|
| 5095 | $b = $this->get_body_msg( $v , 'INBOX' ); |
---|
| 5096 | |
---|
| 5097 | if( $this->filterCheck( $b['body'] , $params['body']['criteria'] , $params['body']['filter'] )) |
---|
| 5098 | $rr['body'][] = $v; |
---|
| 5099 | |
---|
| 5100 | unset($b); |
---|
| 5101 | } |
---|
| 5102 | |
---|
| 5103 | if(isset($params['size'])) |
---|
| 5104 | { |
---|
| 5105 | if( $this->filterCheck( $msg->Size , $params['size']['criteria'] , $params['size']['filter'] )) |
---|
| 5106 | $rr['size'][] = $v; |
---|
| 5107 | } |
---|
| 5108 | } |
---|
| 5109 | |
---|
| 5110 | $rrr = array(); |
---|
| 5111 | $init = true; |
---|
| 5112 | |
---|
| 5113 | |
---|
| 5114 | foreach ($rr as $i => $v) |
---|
| 5115 | { |
---|
| 5116 | if(count($rrr) == 0 && $init === true) |
---|
| 5117 | $rrr = $v; |
---|
| 5118 | else if($params['isExact'] === true) |
---|
| 5119 | $rrr = array_diff($rrr , $v); |
---|
| 5120 | else |
---|
| 5121 | $rrr = array_unique(array_merge($rrr , $v)); |
---|
| 5122 | |
---|
| 5123 | } |
---|
| 5124 | |
---|
| 5125 | |
---|
| 5126 | // if($params['page'] && $params['rows']) |
---|
| 5127 | // { |
---|
| 5128 | // |
---|
| 5129 | // $end = ( $params['rows'] * $params['page'] ); |
---|
| 5130 | // $ini = $end - $params['rows'] ; |
---|
| 5131 | // |
---|
| 5132 | // //Pegando os do range da paginação |
---|
| 5133 | // $k = -1; |
---|
| 5134 | // $r = array(); |
---|
| 5135 | // foreach ($rrr as $v) |
---|
| 5136 | // { |
---|
| 5137 | // $k++; |
---|
| 5138 | // if( $k < $ini || $k >= $end ) continue; |
---|
| 5139 | // $r[] = $v; |
---|
| 5140 | // } |
---|
| 5141 | // ////////////////////////////////////// |
---|
| 5142 | // } |
---|
| 5143 | // else |
---|
| 5144 | $r = $rrr; |
---|
| 5145 | |
---|
| 5146 | return $r ; |
---|
| 5147 | } |
---|
| 5148 | |
---|
| 5149 | function filterCheck( $val , $crit ,$fil ) |
---|
| 5150 | { |
---|
| 5151 | switch ( $fil ) { |
---|
| 5152 | case '=' : //Igual |
---|
| 5153 | if( $val == $crit ) return true; else return false; break; |
---|
| 5154 | case '*' : //Existe |
---|
| 5155 | if( strpos( $val , $crit ) !== false ) return true; else return false; break; |
---|
| 5156 | case '!*' : //Não existe |
---|
| 5157 | if( strpos( $val , $crit ) === false ) return true; else return false; break; |
---|
| 5158 | case '^' : //Começa com |
---|
| 5159 | if( substr ($val , 0 , strlen($crit) ) == $crit ) return true; else return false; break; |
---|
| 5160 | case '$' : //Termina com |
---|
| 5161 | if( substr ($val , 0 , -(strlen($crit)) ) == $crit ) return true; else return false; break; |
---|
| 5162 | case '>' : //Maior que |
---|
| 5163 | if( $val > (int)($crit * 1024) ) return true; else return false; break; |
---|
| 5164 | case '<' : //Menor que |
---|
| 5165 | if( $val < (int)($crit * 1024) ) return true; else return false; break; |
---|
| 5166 | } |
---|
| 5167 | } |
---|
| 5168 | |
---|
[6120] | 5169 | |
---|
| 5170 | |
---|
| 5171 | /** |
---|
| 5172 | * Método que aplica a ação do filtro nas mensagens da caixa de entrada |
---|
| 5173 | * |
---|
| 5174 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 5175 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 5176 | * @sponsor Caixa Econômica Federal |
---|
| 5177 | * @author Airton Bordin Junior <airton@prognus.com.br> |
---|
| 5178 | * @author Gustavo Pereira dos Santos <gustavo@prognus.com.br> |
---|
| 5179 | * @param <Array> <$msgs> <Mensagens da caixa de entrada> |
---|
| 5180 | * @param <Array> <$proc> <ações do filtro> |
---|
| 5181 | * @return <Regras do usuário em Array> |
---|
[6457] | 5182 | * @access public |
---|
[6120] | 5183 | */ |
---|
[5862] | 5184 | function apliSieveFilter($msgs , $proc) |
---|
[5539] | 5185 | { |
---|
| 5186 | $ret = array(); |
---|
[5862] | 5187 | foreach ($msgs as $i => $msg) |
---|
| 5188 | { |
---|
| 5189 | switch($proc['type']){ |
---|
| 5190 | case 'fileinto': |
---|
| 5191 | $imap = $this->open_mbox( 'INBOX' ); |
---|
[5539] | 5192 | if($proc['keep'] === true) |
---|
[5862] | 5193 | $ret[$msg][] = imap_mail_copy($imap,$msg,$proc['value'], CP_UID); |
---|
[5539] | 5194 | else |
---|
[5862] | 5195 | /* Está sempre copiando a mensagem para a pasta destino */ |
---|
| 5196 | //$ret[$msg][] = imap_mail_move($imap,$msg,$proc['parameter'], CP_UID); |
---|
[6120] | 5197 | $ret[$msg][] = imap_mail_move($imap,$msg,$proc['parameter'], CP_UID); |
---|
[5862] | 5198 | break; |
---|
[6120] | 5199 | case 'redirect': |
---|
| 5200 | foreach($msgs as $msg) |
---|
| 5201 | { |
---|
[5539] | 5202 | $info = $this->get_info_msg(array('msg_folder' => 'INBOX','msg_number' => $msg)); |
---|
[6120] | 5203 | Controller::create( array( 'service' => 'SMTP' ), array( 'body' => $info['body'], |
---|
| 5204 | 'isHtml' => true, |
---|
| 5205 | 'subject' => $info['subject'], |
---|
| 5206 | 'from' => $info['from']['full'], |
---|
| 5207 | 'to' => $proc['parameter']) |
---|
| 5208 | ); |
---|
[5539] | 5209 | |
---|
[5862] | 5210 | if($proc['keep'] !== true) |
---|
| 5211 | $this->delete_msgs(array('msgs_number' => $msg , 'folder' => 'INBOX')); |
---|
[6120] | 5212 | } |
---|
[5862] | 5213 | break; |
---|
| 5214 | |
---|
| 5215 | case 'setflag': |
---|
| 5216 | foreach($msgs as $msg) |
---|
| 5217 | $ret[$msg][] = $this->set_messages_flag( array( 'folder' => 'INBOX' , 'msgs_to_set' => $msg , 'flag' => $proc['parameter']) ); |
---|
| 5218 | break; |
---|
| 5219 | } |
---|
[5539] | 5220 | } |
---|
| 5221 | return $ret; |
---|
| 5222 | } |
---|
[6457] | 5223 | |
---|
| 5224 | /** |
---|
| 5225 | * Método que convert imagens no formato rfc2397 para Embedded Attachment |
---|
| 5226 | * |
---|
| 5227 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 5228 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 5229 | * @sponsor Caixa Econômica Federal |
---|
| 5230 | * @author Cristiano Corrêa Schmidt |
---|
| 5231 | * @param <MailService> <$mailService> <Referencia objeto MailService> |
---|
| 5232 | * @param <String> <$body> <Referencia Corpo do email> |
---|
| 5233 | * @return <void> |
---|
| 5234 | * @access public |
---|
| 5235 | */ |
---|
| 5236 | function rfc2397ToEmbeddedAttachment( &$mailService , &$body ) |
---|
| 5237 | { |
---|
| 5238 | $matches = array(); |
---|
| 5239 | preg_match_all("/src=[\'|\"]+data:([^,]*);base64,([a-zA-Z0-9\+\/\=]+)[\'|\"]+/i", $body, $matches, PREG_SET_ORDER); //Resgata imagens em rfc2397 |
---|
| 5240 | |
---|
| 5241 | foreach ($matches as $i => &$v) |
---|
| 5242 | { |
---|
| 5243 | $ext = explode(';', $v[1]); //quebra todos os parametros em um array. |
---|
| 5244 | $mailService->addStringImage(base64_decode($v[2]), $ext[0] , 'EmbeddedImage'.$i.'.'.$this->mimeToExtension($v[1])); |
---|
| 5245 | $body = str_replace($v[0], 'src="EmbeddedImage'.$i.'.'.$this->mimeToExtension($ext[0]).'"' , $body); |
---|
| 5246 | } |
---|
| 5247 | } |
---|
| 5248 | |
---|
| 5249 | /** |
---|
| 5250 | * Método que retorna a extensão do arquivo atraves do mime type |
---|
| 5251 | * |
---|
| 5252 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 5253 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 5254 | * @sponsor Caixa Econômica Federal |
---|
| 5255 | * @author Cristiano Corrêa Schmidt |
---|
| 5256 | * @param <String> <$mimeType> <Mime Type do arquivo> |
---|
| 5257 | * @return <String> <extensão> |
---|
| 5258 | * @access public |
---|
| 5259 | */ |
---|
| 5260 | function mimeToExtension($mimeType) |
---|
| 5261 | { |
---|
| 5262 | switch ( $mimeType ) |
---|
| 5263 | { |
---|
| 5264 | case 'image/bmp' : |
---|
| 5265 | return 'bmp'; |
---|
| 5266 | case 'image/cgm' : |
---|
| 5267 | return 'cgm'; |
---|
| 5268 | case 'image/vnd.djvu' : |
---|
| 5269 | return 'djv'; |
---|
| 5270 | case 'image/gif' : |
---|
| 5271 | return 'gif'; |
---|
| 5272 | case 'image/x-icon' : |
---|
| 5273 | return 'ico'; |
---|
| 5274 | case 'image/ief' : |
---|
| 5275 | return 'ief'; |
---|
| 5276 | case 'image/jpeg' : |
---|
| 5277 | return 'jpg'; |
---|
| 5278 | case 'image/x-macpaint' : |
---|
| 5279 | return 'mac'; |
---|
| 5280 | case 'image/pict' : |
---|
| 5281 | return 'pct'; |
---|
| 5282 | case 'image/png' : |
---|
| 5283 | return 'png'; |
---|
| 5284 | case 'image/x-quicktime' : |
---|
| 5285 | return 'qti'; |
---|
| 5286 | case 'image/x-rgb' : |
---|
| 5287 | return 'rgb'; |
---|
| 5288 | case 'image/tiff' : |
---|
| 5289 | return 'tif'; |
---|
| 5290 | default: |
---|
| 5291 | return ''; |
---|
| 5292 | } |
---|
| 5293 | |
---|
| 5294 | } |
---|
[6487] | 5295 | |
---|
| 5296 | |
---|
| 5297 | /** |
---|
| 5298 | * Método que retorna as mensagens com a flag $FilteredMessage que representa as mensagens filtradas que devem ser alertadas para o usuário |
---|
| 5299 | * |
---|
| 5300 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 5301 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 5302 | * @sponsor Caixa Econômica Federal |
---|
| 5303 | * @author Airton Bordin Junior <airton@prognus.com.br> |
---|
| 5304 | * @author Marcieli <marcieli@prognus.com.br> |
---|
| 5305 | * @author Marcos <marcosw@prognus.com.br> |
---|
| 5306 | * @param <Array> <$paramFolders> <Pastas onde devem ser buscadas as mensagens> |
---|
| 5307 | * @return <Mensagens encontradas com a flag $FilteredMessage> |
---|
| 5308 | * @access <public> |
---|
| 5309 | */ |
---|
| 5310 | function getFlaggedAlertMessages($paramFolders) { |
---|
| 5311 | |
---|
| 5312 | $folders = explode(",", $paramFolders['folders']); |
---|
| 5313 | |
---|
| 5314 | $messages = array(); |
---|
| 5315 | $result = array(); |
---|
| 5316 | $label = '$FilteredMessage'; |
---|
| 5317 | |
---|
| 5318 | foreach ($folders as $folder) { |
---|
| 5319 | $this->mbox = $this->open_mbox($folder); |
---|
| 5320 | /* Não deletadas, não lidas e com a flag */ |
---|
| 5321 | $messages = imap_search($this->mbox, 'UNDELETED UNSEEN KEYWORD "$FilteredMessage"', SE_UID); |
---|
| 5322 | if(is_array($messages)) |
---|
| 5323 | foreach ($messages as $k => $m) { |
---|
| 5324 | $headers = imap_fetch_overview($this->mbox, $m, FT_UID); |
---|
| 5325 | $date = explode(" ", $headers[0]->date); |
---|
| 5326 | $result[$m."_".$folder] = array ( |
---|
| 5327 | 'udate' => $headers[0]->udate, |
---|
| 5328 | 'smalldate' => $date[4], |
---|
| 5329 | 'from' => $headers[0]->from, |
---|
| 5330 | 'subject' => self::decodeMimeString($headers[0]->subject), |
---|
| 5331 | 'msg_number' => $m, |
---|
| 5332 | 'msg_folder' => $folder |
---|
| 5333 | ); |
---|
| 5334 | } |
---|
| 5335 | } |
---|
| 5336 | $result_final = array(); |
---|
| 5337 | foreach ($result as $r){ |
---|
| 5338 | $result_final[] = $r; |
---|
| 5339 | } |
---|
| 5340 | |
---|
| 5341 | return $result_final; |
---|
| 5342 | } |
---|
| 5343 | |
---|
| 5344 | /** |
---|
| 5345 | * Esta função é chamada ao clicar sobre uma mensagem listada nos alertas de Filtro por Remetente |
---|
| 5346 | * remove a flag e chama a função que recupera os dados da mensagem, para serem utilizados na abertura da aba de leitura da msg |
---|
| 5347 | */ |
---|
| 5348 | function open_flagged_msg($params){ |
---|
| 5349 | $message_number = $params['msg_number']; |
---|
| 5350 | $message_folder = $params['msg_folder']; |
---|
| 5351 | $alarm = $params['alarm']; |
---|
| 5352 | if ($message_folder && $message_number) { |
---|
| 5353 | $this->mbox = $this->open_mbox($message_folder); |
---|
| 5354 | imap_clearflag_full($this->mbox, $message_number, '$FilteredMessage', ST_UID); |
---|
| 5355 | } |
---|
| 5356 | $r = $this->get_info_msg(array('msg_number' => $message_number, 'msg_folder' =>urlencode($message_folder), 'alarm' => ($alarm))); |
---|
| 5357 | return $r; |
---|
| 5358 | } |
---|
| 5359 | |
---|
| 5360 | /** |
---|
| 5361 | * Remove a flag que caracteriza uma mensagem como alertada por Filtro por Remetente. |
---|
| 5362 | * se houver o parametro msg_number, então remove a flag de uma msg especifica |
---|
| 5363 | * se não houver o parametro msg_number, mas sim o from, então remove a flag de todas as msgs da pasta (parametro from), |
---|
| 5364 | * e que o remetente for o from. |
---|
| 5365 | */ |
---|
| 5366 | function removeFlagMessagesFilter($params){ |
---|
| 5367 | $message_number = $params['msg_number']; |
---|
| 5368 | $folder = $params['folder']; |
---|
| 5369 | |
---|
| 5370 | if(isset($message_number)){ |
---|
| 5371 | if(isset($folder)){ |
---|
| 5372 | $message_number = explode(',', $message_number); |
---|
| 5373 | $this->mbox = $this->open_mbox($folder); |
---|
| 5374 | foreach ($message_number as $k => $m) { |
---|
| 5375 | imap_clearflag_full($this->mbox, $m, '$FilteredMessage', ST_UID); |
---|
| 5376 | } |
---|
| 5377 | } |
---|
| 5378 | } |
---|
| 5379 | else{ |
---|
| 5380 | $from = $params['from']; |
---|
| 5381 | if(isset($folder) && isset($from)){ |
---|
| 5382 | $this->mbox = $this->open_mbox($folder); |
---|
| 5383 | $messages = imap_search($this->mbox, 'UNDELETED UNSEEN KEYWORD "$FilteredMessage"', SE_UID); |
---|
| 5384 | } |
---|
| 5385 | if(is_array($messages)){ |
---|
| 5386 | foreach ($messages as $k => $m) { |
---|
| 5387 | $headers = imap_fetch_overview($this->mbox, $m, FT_UID); |
---|
| 5388 | if(strpos($headers[0]->from, $from) > 0){ |
---|
| 5389 | imap_clearflag_full($this->mbox, $m, '$FilteredMessage', ST_UID); |
---|
| 5390 | } |
---|
| 5391 | } |
---|
| 5392 | } |
---|
| 5393 | } |
---|
| 5394 | |
---|
| 5395 | return array('status' => "success"); |
---|
| 5396 | } |
---|
| 5397 | |
---|
[2] | 5398 | } |
---|
[278] | 5399 | ?> |
---|