[2] | 1 | <?php |
---|
| 2 | include_once("class.functions.inc.php"); |
---|
| 3 | include_once("class.ldap_functions.inc.php"); |
---|
[91] | 4 | include_once("class.exporteml.inc.php"); |
---|
| 5 | |
---|
[2] | 6 | class imap_functions |
---|
| 7 | { |
---|
| 8 | var $public_functions = array |
---|
[449] | 9 | ( |
---|
[2] | 10 | 'get_range_msgs' => True, |
---|
| 11 | 'get_info_msg' => True, |
---|
| 12 | 'get_folders_list' => True |
---|
| 13 | ); |
---|
| 14 | |
---|
| 15 | var $ldap; |
---|
| 16 | var $mbox; |
---|
| 17 | var $imap_port; |
---|
| 18 | var $has_cid; |
---|
| 19 | var $imap_options = ''; |
---|
| 20 | var $functions; |
---|
| 21 | |
---|
| 22 | function imap_functions (){ |
---|
| 23 | $this->username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 24 | $this->password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
| 25 | $this->imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 26 | $this->imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
| 27 | $this->imap_delimiter = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter']; |
---|
[449] | 28 | $this->functions = new functions(); |
---|
[2] | 29 | $this->has_cid = false; |
---|
[449] | 30 | |
---|
[2] | 31 | if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') |
---|
| 32 | { |
---|
| 33 | $this->imap_options = '/tls/novalidate-cert'; |
---|
| 34 | } |
---|
| 35 | else |
---|
| 36 | { |
---|
| 37 | $this->imap_options = '/notls/novalidate-cert'; |
---|
| 38 | } |
---|
| 39 | } |
---|
| 40 | // BEGIN of functions. |
---|
| 41 | function open_mbox($folder = False) |
---|
| 42 | { |
---|
[51] | 43 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); |
---|
[504] | 44 | $this->mbox = @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())))); |
---|
[2] | 45 | return $this->mbox; |
---|
| 46 | } |
---|
| 47 | |
---|
[504] | 48 | function parse_error($error){ |
---|
| 49 | // This error is returned from Imap. |
---|
| 50 | if(strstr($error,'Connection refused')) { |
---|
| 51 | return str_replace("%1", $this->functions->getLang("Mail"), $this->functions->getLang("Connection failed with %1 Server. Try later.")); |
---|
| 52 | } |
---|
| 53 | // This error is returned from Postfix. |
---|
| 54 | elseif(strstr($error,'message file too big')) { |
---|
| 55 | return str_replace("%1", ini_get('upload_max_filesize'),$this->functions->getLang('The size of this message has exceeded the limit (%1B).')); |
---|
| 56 | } |
---|
| 57 | // This condition verifies if SESSION is expired. |
---|
| 58 | elseif(!count($_SESSION)) |
---|
| 59 | return "nosession"; |
---|
| 60 | |
---|
| 61 | return $error; |
---|
| 62 | } |
---|
| 63 | |
---|
[2] | 64 | function get_range_msgs2($params) |
---|
| 65 | { |
---|
| 66 | include("class.imap_attachment.inc.php"); |
---|
| 67 | $imap_attachment = new imap_attachment(); |
---|
[53] | 68 | $folder = $params['folder']; |
---|
[2] | 69 | $msg_range_begin = $params['msg_range_begin']; |
---|
| 70 | $msg_range_end = $params['msg_range_end']; |
---|
[449] | 71 | $sort_box_type = $params['sort_box_type']; |
---|
[53] | 72 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
[51] | 73 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
[449] | 74 | $sort_array_msg = $this-> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
| 75 | |
---|
[2] | 76 | $return = array(); |
---|
| 77 | $i = 0; |
---|
[46] | 78 | $num_msgs = (is_array($sort_array_msg) ? count($sort_array_msg) : 0); |
---|
[449] | 79 | if($num_msgs) { |
---|
[46] | 80 | for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= $num_msgs)); $msg_range_begin++) |
---|
[2] | 81 | { |
---|
| 82 | $msg_number = $sort_array_msg[$msg_range_begin-1]; |
---|
| 83 | |
---|
[535] | 84 | $header = $this->get_header($msg_number); |
---|
[2] | 85 | if (!is_object($header)) |
---|
[449] | 86 | return false; |
---|
| 87 | |
---|
[2] | 88 | $return[$i]['Recent'] = $header->Recent; |
---|
| 89 | $return[$i]['Unseen'] = $header->Unseen; |
---|
| 90 | if($header->Answered =='A' && $header->Draft == 'X'){ |
---|
| 91 | $return[$i]['Forwarded'] = 'F'; |
---|
| 92 | } |
---|
| 93 | else { |
---|
| 94 | $return[$i]['Answered'] = $header->Answered; |
---|
[449] | 95 | $return[$i]['Draft'] = $header->Draft; |
---|
[2] | 96 | } |
---|
| 97 | $return[$i]['Deleted'] = $header->Deleted; |
---|
| 98 | $return[$i]['Flagged'] = $header->Flagged; |
---|
[449] | 99 | |
---|
[2] | 100 | $return[$i]['msg_number'] = $msg_number; |
---|
| 101 | //$return[$i]['msg_folder'] = $folder; |
---|
[449] | 102 | |
---|
[535] | 103 | $date_msg = gmdate("d/m/Y",$header->udate); |
---|
| 104 | if (gmdate("d/m/Y") == $date_msg) |
---|
| 105 | $return[$i]['udate'] = gmdate("H:i",$header->udate); |
---|
[2] | 106 | else |
---|
| 107 | $return[$i]['udate'] = $date_msg; |
---|
[449] | 108 | |
---|
[2] | 109 | $from = $header->from; |
---|
| 110 | $return[$i]['from'] = array(); |
---|
| 111 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
[37] | 112 | $return[$i]['from']['name'] = $this->decode_string($tmp[0]->text); |
---|
[2] | 113 | $return[$i]['from']['email'] = $this->decode_string($from[0]->mailbox) . "@" . $from[0]->host; |
---|
| 114 | if(!$return[$i]['from']['name']) |
---|
| 115 | $return[$i]['from']['name'] = $return[$i]['from']['email']; |
---|
| 116 | $to = $header->to; |
---|
| 117 | $return[$i]['to'] = array(); |
---|
| 118 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
[37] | 119 | $return[$i]['to']['name'] = $this->decode_string($this->decode_string($tmp[0]->text)); |
---|
| 120 | $return[$i]['to']['email'] = $this->decode_string($to[0]->mailbox) . "@" . $to[0]->host; |
---|
| 121 | if(!$return[$i]['to']['name']) |
---|
| 122 | $return[$i]['to']['name'] = $return[$i]['to']['email']; |
---|
[2] | 123 | $return[$i]['subject'] = $this->decode_string($header->fetchsubject); |
---|
| 124 | |
---|
| 125 | $return[$i]['Size'] = $header->Size; |
---|
[449] | 126 | |
---|
[2] | 127 | $return[$i]['attachment'] = array(); |
---|
[449] | 128 | $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); |
---|
[2] | 129 | $i++; |
---|
| 130 | } |
---|
[46] | 131 | } |
---|
[449] | 132 | $return['num_msgs'] = $num_msgs; |
---|
| 133 | |
---|
[2] | 134 | return $return; |
---|
| 135 | } |
---|
[449] | 136 | |
---|
[2] | 137 | function decode_string($string) |
---|
[449] | 138 | { |
---|
[2] | 139 | if ((strpos(strtolower($string), '=?iso-8859-1') !== false) || (strpos(strtolower($string), '=?windows-1252') !== false)) |
---|
| 140 | { |
---|
| 141 | $tmp = imap_mime_header_decode($string); |
---|
| 142 | foreach ($tmp as $tmp1) |
---|
| 143 | $return .= $this->htmlspecialchars_encode($tmp1->text); |
---|
| 144 | return $return; |
---|
| 145 | } |
---|
| 146 | else if (strpos(strtolower($string), '=?utf-8') !== false) |
---|
| 147 | { |
---|
| 148 | $elements = imap_mime_header_decode($string); |
---|
| 149 | for($i = 0;$i < count($elements);$i++) { |
---|
| 150 | $charset = $elements[$i]->charset; |
---|
| 151 | $text =$elements[$i]->text; |
---|
| 152 | if(!strcasecmp($charset, "utf-8") || |
---|
| 153 | !strcasecmp($charset, "utf-7")) { |
---|
| 154 | $text = iconv($charset, "ISO-8859-1", $text); |
---|
| 155 | } |
---|
| 156 | $decoded .= $this->htmlspecialchars_encode($text); |
---|
| 157 | } |
---|
| 158 | return $decoded; |
---|
| 159 | } |
---|
| 160 | else |
---|
| 161 | return $this->htmlspecialchars_encode($string); |
---|
| 162 | } |
---|
[449] | 163 | |
---|
[613] | 164 | /* |
---|
| 165 | Remove os anexos de uma mensagem. A estratégia para isso é criar uma mensagem nova sem os anexos, mantendo apenas |
---|
| 166 | a primeira parte do e-mail, que é o texto, sem anexos. |
---|
| 167 | O método considera que o email é multpart. |
---|
| 168 | */ |
---|
| 169 | function remove_attachments($params) { |
---|
| 170 | include_once("class.message_components.inc.php"); |
---|
| 171 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
| 172 | $this->mbox = $this->open_mbox($params["folder"]); |
---|
| 173 | $return["status"] = true; |
---|
| 174 | $return["msg_num"] = $params["msg_num"]; |
---|
| 175 | $header = ""; |
---|
| 176 | |
---|
| 177 | $headertemp = explode("\n",imap_fetchheader($this->mbox, imap_msgno($this->mbox, $params["msg_num"]))); |
---|
| 178 | foreach($headertemp as $head) {//Se eu colocar todo o header do email dá pau no append, então procuro apenas o que interessa. |
---|
| 179 | $head1 = explode(":",$head); |
---|
| 180 | if ( (strtoupper($head1[0]) == strtoupper("to")) || |
---|
| 181 | (strtoupper($head1[0]) == strtoupper("from")) || |
---|
| 182 | (strtoupper($head1[0]) == strtoupper("subject")) || |
---|
| 183 | (strtoupper($head1[0]) == strtoupper("date")) ) |
---|
| 184 | $header .= $head."\r\n"; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | $msg = &new message_components($this->mbox); |
---|
| 188 | $msg->fetch_structure($params["msg_num"]);/* O fetchbody tava trazendo o email com problemas na acentuação. |
---|
| 189 | Então uso essa classe para verificar a codificação e o charset, |
---|
| 190 | para que o método decodeBody do expresso possa trazer tudo certinho*/ |
---|
| 191 | |
---|
| 192 | $status = @imap_append($this->mbox, |
---|
| 193 | "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"], |
---|
| 194 | $header. |
---|
| 195 | "\r\n". |
---|
| 196 | str_replace("\n","\r\n",$this->decodeBody( |
---|
| 197 | imap_fetchbody($this->mbox,imap_msgno($this->mbox, $params["msg_num"]),"1"), |
---|
| 198 | $msg->encoding[$params["msg_num"]][0], $msg->charset[$params["msg_num"]][0] |
---|
| 199 | ) |
---|
| 200 | )); //Append do novo email, só com header e conteúdo sem anexos. |
---|
| 201 | |
---|
| 202 | if(!$status) { |
---|
| 203 | $return["status"] = false; |
---|
| 204 | $return["msg"] = lang("error appending mail on delete attachments"); |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | @imap_delete($this->mbox, imap_msgno($this->mbox, $params["msg_num"])); //Insere o novo e-mail sem anexos. |
---|
| 208 | @imap_expunge($this->mbox); //Deleta o e-mail com anexos |
---|
| 209 | |
---|
| 210 | return $return; |
---|
| 211 | |
---|
| 212 | } |
---|
| 213 | |
---|
[2] | 214 | function get_info_msg($params) |
---|
| 215 | { |
---|
[51] | 216 | $return = array(); |
---|
[2] | 217 | $msg_number = $params['msg_number']; |
---|
[205] | 218 | $msg_folder = $params['msg_folder']; |
---|
[449] | 219 | |
---|
[411] | 220 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[449] | 221 | $this->mbox = $this->open_mbox($msg_folder); |
---|
| 222 | |
---|
[535] | 223 | $header = $this->get_header($msg_number); |
---|
[205] | 224 | if (!$header) { |
---|
[535] | 225 | $return['status_get_msg_info'] = "false"; |
---|
[205] | 226 | return $return; |
---|
| 227 | } |
---|
[535] | 228 | |
---|
[51] | 229 | $all_header = explode("\n", imap_fetchheader($this->mbox, $msg_number, FT_UID)); |
---|
| 230 | $return_get_body = $this->get_body_msg($msg_number, $msg_folder); |
---|
[449] | 231 | |
---|
[603] | 232 | //Substituição de links em email para abrir no próprio expresso |
---|
| 233 | $body = ereg_replace("<a[^>]*href=[\'\"]mailto:([^\"\']+)[\'\"]>([^<]+)</a>","<a href=\"javascript:new_message_to('\\1')\">\\2</a>",$return_get_body['body']); |
---|
| 234 | |
---|
[591] | 235 | $return['body'] = $body; |
---|
[51] | 236 | $return['attachments'] = $return_get_body['attachments']; |
---|
[91] | 237 | $return['thumbs'] = $return_get_body['thumbs']; |
---|
| 238 | $return['signature'] = $return_get_body['signature']; |
---|
[449] | 239 | |
---|
[2] | 240 | foreach($all_header as $line) { |
---|
| 241 | if (eregi("^Disposition-Notification-To", $line)) { |
---|
| 242 | eregi("^([^:]*): (.*)", $line, &$arg); |
---|
| 243 | $return['DispositionNotificationTo'] = $arg[2]; |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | $return['Recent'] = $header->Recent; |
---|
| 247 | $return['Unseen'] = $header->Unseen; |
---|
[449] | 248 | $return['Deleted'] = $header->Deleted; |
---|
[2] | 249 | $return['Flagged'] = $header->Flagged; |
---|
| 250 | |
---|
| 251 | if($header->Answered =='A' && $header->Draft == 'X'){ |
---|
| 252 | $return['Forwarded'] = 'F'; |
---|
| 253 | } |
---|
[535] | 254 | |
---|
[2] | 255 | else { |
---|
| 256 | $return['Answered'] = $header->Answered; |
---|
[449] | 257 | $return['Draft'] = $header->Draft; |
---|
[2] | 258 | } |
---|
| 259 | |
---|
| 260 | $return['msg_number'] = $msg_number; |
---|
| 261 | $return['msg_folder'] = $msg_folder; |
---|
[449] | 262 | |
---|
[535] | 263 | $date_msg = gmdate("d/m/Y",$header->udate); |
---|
[2] | 264 | if (date("d/m/Y") == $date_msg) |
---|
[535] | 265 | $return['udate'] = gmdate("H:i",$header->udate); |
---|
[2] | 266 | else |
---|
| 267 | $return['udate'] = $date_msg; |
---|
[449] | 268 | |
---|
| 269 | $return['msg_day'] = $date_msg; |
---|
[535] | 270 | $return['msg_hour'] = gmdate("H:i",$header->udate); |
---|
[449] | 271 | |
---|
[2] | 272 | if (date("d/m/Y") == $date_msg) //no dia |
---|
| 273 | { |
---|
[535] | 274 | $return['fulldate'] = gmdate("d/m/Y H:i",$header->udate); |
---|
| 275 | $return['smalldate'] = gmdate("H:i",$header->udate); |
---|
[605] | 276 | |
---|
[535] | 277 | $timestamp_now = strtotime("now"); |
---|
[605] | 278 | $timestamp_msg_time = $header->udate; |
---|
[535] | 279 | // $timestamp_now is GMT and $timestamp_msg_time is MailDate TZ. |
---|
| 280 | // The variable $timestamp_diff is calculated without MailDate TZ. |
---|
| 281 | $pdate = date_parse($header->MailDate); |
---|
| 282 | $timestamp_diff = $timestamp_now - $timestamp_msg_time + ($pdate['zone']*(-60)); |
---|
[449] | 283 | |
---|
[2] | 284 | if (gmdate("H",$timestamp_diff) > 0) |
---|
| 285 | { |
---|
[197] | 286 | $return['fulldate'] .= " (" . gmdate("H:i", $timestamp_diff) . ' ' . $this->functions->getLang('hours ago') . ')'; |
---|
[2] | 287 | } |
---|
| 288 | else |
---|
| 289 | { |
---|
| 290 | if (gmdate("i",$timestamp_diff) == 0){ |
---|
[197] | 291 | $return['fulldate'] .= ' ('. $this->functions->getLang('now').')'; |
---|
[2] | 292 | } |
---|
| 293 | elseif (gmdate("i",$timestamp_diff) == 1){ |
---|
[197] | 294 | $return['fulldate'] .= ' (1 '. $this->functions->getLang('minute ago').')'; |
---|
[2] | 295 | } |
---|
| 296 | else{ |
---|
[197] | 297 | $return['fulldate'] .= " (" . gmdate("i",$timestamp_diff) .' '. $this->functions->getLang('minutes ago') . ')'; |
---|
[2] | 298 | } |
---|
| 299 | } |
---|
| 300 | } |
---|
| 301 | else{ |
---|
[535] | 302 | $return['fulldate'] = gmdate("d/m/Y H:i",$header->udate); |
---|
| 303 | $return['smalldate'] = gmdate("d/m/Y",$header->udate); |
---|
[2] | 304 | } |
---|
[449] | 305 | |
---|
[2] | 306 | $from = $header->from; |
---|
| 307 | $return['from'] = array(); |
---|
| 308 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
| 309 | $return['from']['name'] = $this->decode_string($tmp[0]->text); |
---|
| 310 | $return['from']['email'] = $this->decode_string($from[0]->mailbox . "@" . $from[0]->host); |
---|
| 311 | if ($return['from']['name']) |
---|
| 312 | { |
---|
| 313 | if (substr($return['from']['name'], 0, 1) == '"') |
---|
| 314 | $return['from']['full'] = $return['from']['name'] . ' ' . '<' . $return['from']['email'] . '>'; |
---|
| 315 | else |
---|
| 316 | $return['from']['full'] = '"' . $return['from']['name'] . '" ' . '<' . $return['from']['email'] . '>'; |
---|
| 317 | } |
---|
| 318 | else |
---|
| 319 | $return['from']['full'] = $return['from']['email']; |
---|
[449] | 320 | |
---|
[2] | 321 | // Sender attribute |
---|
| 322 | $sender = $header->sender; |
---|
| 323 | $return['sender'] = array(); |
---|
| 324 | $tmp = imap_mime_header_decode($sender[0]->personal); |
---|
| 325 | $return['sender']['name'] = $this->decode_string($tmp[0]->text); |
---|
| 326 | $return['sender']['email'] = $this->decode_string($sender[0]->mailbox . "@" . $sender[0]->host); |
---|
| 327 | if ($return['sender']['name']) |
---|
| 328 | { |
---|
| 329 | if (substr($return['sender']['name'], 0, 1) == '"') |
---|
| 330 | $return['sender']['full'] = $return['sender']['name'] . ' ' . '<' . $return['sender']['email'] . '>'; |
---|
| 331 | else |
---|
| 332 | $return['sender']['full'] = '"' . $return['sender']['name'] . '" ' . '<' . $return['sender']['email'] . '>'; |
---|
| 333 | } |
---|
| 334 | else |
---|
| 335 | $return['sender']['full'] = $return['sender']['email']; |
---|
| 336 | |
---|
| 337 | if($return['from']['full'] == $return['sender']['full']) |
---|
| 338 | $return['sender'] = null; |
---|
| 339 | $to = $header->to; |
---|
| 340 | $return['toaddress2'] = ""; |
---|
| 341 | if (!empty($to)) |
---|
| 342 | { |
---|
| 343 | foreach ($to as $tmp) |
---|
| 344 | { |
---|
| 345 | if (!empty($tmp->personal)) |
---|
| 346 | { |
---|
| 347 | $personal_tmp = imap_mime_header_decode($tmp->personal); |
---|
| 348 | $return['toaddress2'] .= '"' . $personal_tmp[0]->text . '"'; |
---|
| 349 | $return['toaddress2'] .= " "; |
---|
| 350 | $return['toaddress2'] .= "<"; |
---|
[320] | 351 | if ($tmp->host != 'unspecified-domain') |
---|
| 352 | $return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host; |
---|
| 353 | else |
---|
| 354 | $return['toaddress2'] .= $tmp->mailbox; |
---|
[2] | 355 | $return['toaddress2'] .= ">"; |
---|
| 356 | $return['toaddress2'] .= ", "; |
---|
| 357 | } |
---|
| 358 | else |
---|
| 359 | { |
---|
[320] | 360 | if ($tmp->host != 'unspecified-domain') |
---|
| 361 | $return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host; |
---|
| 362 | else |
---|
| 363 | $return['toaddress2'] .= $tmp->mailbox; |
---|
[2] | 364 | $return['toaddress2'] .= ", "; |
---|
| 365 | } |
---|
| 366 | } |
---|
| 367 | $return['toaddress2'] = $this->del_last_two_caracters($return['toaddress2']); |
---|
| 368 | } |
---|
| 369 | else |
---|
| 370 | { |
---|
| 371 | $return['toaddress2'] = "<Empty>"; |
---|
[449] | 372 | } |
---|
| 373 | |
---|
[2] | 374 | $cc = $header->cc; |
---|
| 375 | $return['cc'] = ""; |
---|
| 376 | if (!empty($cc)) |
---|
| 377 | { |
---|
| 378 | foreach ($cc as $tmp_cc) |
---|
| 379 | { |
---|
| 380 | if (!empty($tmp_cc->personal)) |
---|
| 381 | { |
---|
| 382 | $personal_tmp_cc = imap_mime_header_decode($tmp_cc->personal); |
---|
| 383 | $return['cc'] .= '"' . $personal_tmp_cc[0]->text . '"'; |
---|
| 384 | $return['cc'] .= " "; |
---|
| 385 | $return['cc'] .= "<"; |
---|
| 386 | $return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
| 387 | $return['cc'] .= ">"; |
---|
| 388 | $return['cc'] .= ", "; |
---|
| 389 | } |
---|
| 390 | else |
---|
| 391 | { |
---|
| 392 | $return['cc'] .= $tmp_cc->mailbox . "@" . $tmp_cc->host; |
---|
| 393 | $return['cc'] .= ", "; |
---|
| 394 | } |
---|
| 395 | } |
---|
| 396 | $return['cc'] = $this->del_last_two_caracters($return['cc']); |
---|
| 397 | } |
---|
| 398 | else |
---|
| 399 | { |
---|
| 400 | $return['cc'] = ""; |
---|
[449] | 401 | } |
---|
| 402 | |
---|
| 403 | ## |
---|
| 404 | # @AUTHOR Rodrigo Souza dos Santos |
---|
| 405 | # @DATE 2008/09/12 |
---|
| 406 | # @BRIEF Adding the BCC field. |
---|
| 407 | ## |
---|
| 408 | $bcc = $header->bcc; |
---|
| 409 | $return['bcc'] = ""; |
---|
| 410 | if (!empty($bcc)) |
---|
| 411 | { |
---|
| 412 | foreach ($bcc as $tmp_bcc) |
---|
| 413 | { |
---|
| 414 | if (!empty($tmp_bcc->personal)) |
---|
| 415 | { |
---|
| 416 | $personal_tmp_bcc = imap_mime_header_decode($tmp_bcc->personal); |
---|
| 417 | $return['bcc'] .= '"' . $personal_tmp_bcc[0]->text . '"'; |
---|
| 418 | $return['bcc'] .= " "; |
---|
| 419 | $return['bcc'] .= "<"; |
---|
| 420 | $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
| 421 | $return['bcc'] .= ">"; |
---|
| 422 | $return['bcc'] .= ", "; |
---|
| 423 | } |
---|
| 424 | else |
---|
| 425 | { |
---|
| 426 | $return['bcc'] .= $tmp_bcc->mailbox . "@" . $tmp_bcc->host; |
---|
| 427 | $return['bcc'] .= ", "; |
---|
| 428 | } |
---|
| 429 | } |
---|
| 430 | $return['bcc'] = $this->del_last_two_caracters($return['bcc']); |
---|
[426] | 431 | } |
---|
[449] | 432 | else |
---|
| 433 | { |
---|
| 434 | $return['bcc'] = ""; |
---|
| 435 | } |
---|
[426] | 436 | |
---|
[2] | 437 | $reply_to = $header->reply_to; |
---|
| 438 | $return['reply_to'] = ""; |
---|
| 439 | if (is_object($reply_to[0])) |
---|
| 440 | { |
---|
| 441 | if ($return['from']['email'] != ($reply_to[0]->mailbox."@".$reply_to[0]->host)) |
---|
| 442 | { |
---|
| 443 | if (!empty($reply_to[0]->personal)) |
---|
| 444 | { |
---|
| 445 | $personal_reply_to = imap_mime_header_decode($tmp_reply_to->personal); |
---|
[41] | 446 | if(!empty($personal_reply_to[0]->text)) { |
---|
| 447 | $return['reply_to'] .= '"' . $personal_reply_to[0]->text . '"'; |
---|
| 448 | $return['reply_to'] .= " "; |
---|
| 449 | $return['reply_to'] .= "<"; |
---|
| 450 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 451 | $return['reply_to'] .= ">"; |
---|
| 452 | } |
---|
| 453 | else { |
---|
| 454 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 455 | } |
---|
[2] | 456 | } |
---|
| 457 | else |
---|
| 458 | { |
---|
| 459 | $return['reply_to'] .= $reply_to[0]->mailbox . "@" . $reply_to[0]->host; |
---|
| 460 | } |
---|
| 461 | } |
---|
| 462 | } |
---|
| 463 | $return['reply_to'] = $this->decode_string($return['reply_to']); |
---|
| 464 | $return['subject'] = $this->decode_string($header->fetchsubject); |
---|
| 465 | $return['Size'] = $header->Size; |
---|
[605] | 466 | $return['reply_toaddress'] = $header->reply_toaddress; |
---|
[2] | 467 | return $return; |
---|
| 468 | } |
---|
[449] | 469 | |
---|
[2] | 470 | function get_body_msg($msg_number, $msg_folder) |
---|
| 471 | { |
---|
| 472 | include_once("class.message_components.inc.php"); |
---|
[51] | 473 | $msg = &new message_components($this->mbox); |
---|
[2] | 474 | $msg->fetch_structure($msg_number); |
---|
[51] | 475 | $return = array(); |
---|
[449] | 476 | $return['attachments'] = $this-> download_attachment($msg,$msg_number); |
---|
[51] | 477 | if(!$this->has_cid) |
---|
[91] | 478 | { |
---|
[178] | 479 | $return['thumbs'] = $this->get_thumbs($msg,$msg_number,urlencode($msg_folder)); |
---|
[91] | 480 | $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); |
---|
[449] | 481 | } |
---|
| 482 | |
---|
[2] | 483 | if(!$msg->structure[$msg_number]->parts) //Simple message, only 1 piece |
---|
| 484 | { |
---|
| 485 | $attachment = array(); //No attachments |
---|
[449] | 486 | |
---|
[2] | 487 | $content = ''; |
---|
| 488 | if (strtolower($msg->structure[$msg_number]->subtype) == "plain") |
---|
| 489 | { |
---|
[51] | 490 | $content .= nl2br($this->decodeBody((imap_body($this->mbox, $msg_number, FT_UID)), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0])); |
---|
[2] | 491 | } |
---|
| 492 | else if (strtolower($msg->structure[$msg_number]->subtype) == "html") |
---|
| 493 | { |
---|
[51] | 494 | $content .= $this->decodeBody(imap_body($this->mbox, $msg_number, FT_UID), $msg->encoding[$msg_number][0], $msg->charset[$msg_number][0]); |
---|
[2] | 495 | } |
---|
| 496 | } |
---|
[449] | 497 | else |
---|
[2] | 498 | { //Complicated message, multiple parts |
---|
| 499 | $html_body = ''; |
---|
| 500 | $content = ''; |
---|
| 501 | $has_multipart = true; |
---|
| 502 | $this->has_cid = false; |
---|
[449] | 503 | |
---|
[2] | 504 | if (strtolower($msg->structure[$msg_number]->subtype) == "related") |
---|
| 505 | $this->has_cid = true; |
---|
[449] | 506 | |
---|
[469] | 507 | if (strtolower($msg->structure[$msg_number]->subtype) == "alternative") { |
---|
| 508 | $show_only_html = false; |
---|
| 509 | foreach($msg->pid[$msg_number] as $values => $msg_part) { |
---|
[432] | 510 | $file_type = strtolower($msg->file_type[$msg_number][$values]); |
---|
| 511 | if($file_type == "text/html") |
---|
[469] | 512 | $show_only_html = true; |
---|
[432] | 513 | } |
---|
[469] | 514 | } |
---|
[2] | 515 | else |
---|
| 516 | $show_only_html = false; |
---|
| 517 | |
---|
| 518 | foreach($msg->pid[$msg_number] as $values => $msg_part) |
---|
| 519 | { |
---|
[449] | 520 | |
---|
[2] | 521 | $file_type = strtolower($msg->file_type[$msg_number][$values]); |
---|
| 522 | if($file_type == "message/rfc822") |
---|
| 523 | $has_multipart = false; |
---|
[449] | 524 | |
---|
[2] | 525 | if($file_type == "multipart/alternative") |
---|
| 526 | $has_multipart = false; |
---|
[449] | 527 | |
---|
| 528 | if(($file_type == "text/plain" |
---|
[2] | 529 | || $file_type == "text/html") |
---|
| 530 | && $file_type != 'attachment') |
---|
| 531 | { |
---|
| 532 | if($file_type == "text/plain" && !$show_only_html && $has_multipart) |
---|
| 533 | { |
---|
| 534 | // if TXT file size > 100kb, then it will not expand. |
---|
| 535 | if(!($file_type == "text/plain" && $msg->fsize[$msg_number][$values] > 102400)) { |
---|
[449] | 536 | $content .= nl2br(htmlentities($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]))); |
---|
[2] | 537 | } |
---|
| 538 | } |
---|
| 539 | // if HTML attachment file size > 300kb, then it will not expand. |
---|
[449] | 540 | else if($file_type == "text/html" && $msg->fsize[$msg_number][$values] < 307200) |
---|
[2] | 541 | { |
---|
[51] | 542 | $content .= $this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values]); |
---|
[2] | 543 | $show_only_html = true; |
---|
| 544 | } |
---|
| 545 | } |
---|
| 546 | else if($file_type == "message/delivery-status"){ |
---|
| 547 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[449] | 548 | $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); |
---|
[2] | 549 | |
---|
| 550 | } |
---|
[65] | 551 | else if($file_type == "message/rfc822" || $file_type == "text/rfc822-headers"){ |
---|
[449] | 552 | |
---|
[2] | 553 | include_once("class.imap_attachment.inc.php"); |
---|
| 554 | $att = new imap_attachment(); |
---|
[51] | 555 | $attachments = $att -> get_attachment_info($this->mbox,$msg_number); |
---|
[449] | 556 | if($attachments['number_attachments'] > 0) { |
---|
[2] | 557 | foreach($attachments ['attachment'] as $index => $attachment){ |
---|
| 558 | if(strtolower($attachment['type']) == "delivery-status" || |
---|
[449] | 559 | strtolower($attachment['type']) == "rfc822" || |
---|
[65] | 560 | strtolower($attachment['type']) == "rfc822-headers" || |
---|
[2] | 561 | strtolower($attachment['type']) == "plain" |
---|
| 562 | ){ |
---|
[449] | 563 | $obj = imap_rfc822_parse_headers(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID), $msg->encoding[$msg_number][$values]); |
---|
| 564 | $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; |
---|
[2] | 565 | $content .= "<br><table style='margin:2px;border:1px solid black;background:#EAEAEA'>"; |
---|
| 566 | $content .= "<tr><td><b>".$this->functions->getLang("Subject").":</b></td><td>".$this->decode_string($obj->subject)."</td></tr>"; |
---|
| 567 | $content .= "<tr><td><b>".$this->functions->getLang("From").":</b></td><td>".$this->decode_string($obj->from[0]->mailbox."@".$obj->from[0]->host)."</td></tr>"; |
---|
| 568 | $content .= "<tr><td><b>".$this->functions->getLang("Date").":</b></td><td>".$obj->date."</td></tr>"; |
---|
| 569 | $content .= "<tr><td><b>".$this->functions->getLang("TO").":</b></td><td>".$this->decode_string($obj->to[0]->mailbox."@".$obj->to[0]->host)."</td></tr>"; |
---|
[449] | 570 | $content .= !$obj->cc ? "</table><br>" :"<tr><td><b>".$this->functions->getLang("CC").":</b></td><td>".$this->decode_string($obj->cc[0]->mailbox."@".$obj->cc[0]->host)."</td></tr></table><br>"; |
---|
[2] | 571 | $ix_part = strtolower($attachment['type']) == "delivery-status" ? 1 : 0; |
---|
[449] | 572 | $content .= nl2br($this->decodeBody(imap_fetchbody($this->mbox, $msg_number, ($attachment['part_in_msg']+$ix_part).".1", FT_UID), $msg->encoding[$msg_number][$values], $msg->charset[$msg_number][$values])); |
---|
| 573 | break; |
---|
[2] | 574 | } |
---|
| 575 | } |
---|
| 576 | } |
---|
| 577 | } |
---|
| 578 | } |
---|
| 579 | if($file_type == "text/plain" && ($show_only_html && $msg_part == 1) || (!$show_only_html && $msg_part == 3)){ |
---|
| 580 | if(strtolower($msg->structure[$msg_number]->subtype) == "mixed" && $msg_part == 1) |
---|
[51] | 581 | $content .= nl2br(imap_base64(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID))); |
---|
[25] | 582 | else if(!strtolower($msg->structure[$msg_number]->subtype) == "mixed") |
---|
[449] | 583 | $content .= nl2br(imap_fetchbody($this->mbox, $msg_number, $msg_part, FT_UID)); |
---|
[2] | 584 | } |
---|
[449] | 585 | } |
---|
[2] | 586 | // Force message with flag Seen (imap_fetchbody not works correctly) |
---|
[449] | 587 | $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); |
---|
[2] | 588 | $this->set_messages_flag($params); |
---|
[205] | 589 | $content = $this->process_embedded_images($msg,$msg_number,$content, $msg_folder); |
---|
[2] | 590 | $content = $this->replace_special_characters($content); |
---|
[51] | 591 | $return['body'] = $content; |
---|
| 592 | return $return; |
---|
[2] | 593 | } |
---|
[449] | 594 | |
---|
[2] | 595 | function htmlfilter($body) |
---|
| 596 | { |
---|
| 597 | require_once('htmlfilter.inc'); |
---|
[449] | 598 | |
---|
[2] | 599 | $tag_list = Array( |
---|
| 600 | false, |
---|
| 601 | 'blink', |
---|
| 602 | 'object', |
---|
| 603 | 'meta', |
---|
| 604 | 'html', |
---|
| 605 | 'link', |
---|
| 606 | 'frame', |
---|
| 607 | 'iframe', |
---|
| 608 | 'layer', |
---|
| 609 | 'ilayer', |
---|
| 610 | 'plaintext' |
---|
| 611 | ); |
---|
| 612 | |
---|
| 613 | /** |
---|
| 614 | * A very exclusive set: |
---|
| 615 | */ |
---|
| 616 | // $tag_list = Array(true, "b", "a", "i", "img", "strong", "em", "p"); |
---|
| 617 | $rm_tags_with_content = Array( |
---|
| 618 | 'script', |
---|
| 619 | 'style', |
---|
| 620 | 'applet', |
---|
| 621 | 'embed', |
---|
| 622 | 'head', |
---|
| 623 | 'frameset', |
---|
| 624 | 'xml', |
---|
| 625 | 'xmp' |
---|
| 626 | ); |
---|
| 627 | |
---|
| 628 | $self_closing_tags = Array( |
---|
| 629 | 'img', |
---|
| 630 | 'br', |
---|
| 631 | 'hr', |
---|
| 632 | 'input' |
---|
| 633 | ); |
---|
| 634 | |
---|
| 635 | $force_tag_closing = true; |
---|
| 636 | |
---|
| 637 | $rm_attnames = Array( |
---|
| 638 | '/.*/' => |
---|
| 639 | Array( |
---|
| 640 | '/target/i', |
---|
| 641 | //'/^on.*/i', -> onClick, dos compromissos da agenda. |
---|
| 642 | '/^dynsrc/i', |
---|
| 643 | '/^datasrc/i', |
---|
| 644 | '/^data.*/i', |
---|
| 645 | '/^lowsrc/i' |
---|
| 646 | ) |
---|
| 647 | ); |
---|
| 648 | |
---|
| 649 | /** |
---|
| 650 | * Yeah-yeah, so this looks horrible. Check out htmlfilter.inc for |
---|
| 651 | * some idea of what's going on here. :) |
---|
| 652 | */ |
---|
| 653 | |
---|
| 654 | $bad_attvals = Array( |
---|
| 655 | '/.*/' => |
---|
| 656 | Array( |
---|
| 657 | '/.*/' => |
---|
| 658 | Array( |
---|
| 659 | Array( |
---|
| 660 | '/^([\'\"])\s*\S+\s*script\s*:*(.*)([\'\"])/si', |
---|
| 661 | //'/^([\'\"])\s*https*\s*:(.*)([\'\"])/si', -> doclinks notes |
---|
| 662 | '/^([\'\"])\s*mocha\s*:*(.*)([\'\"])/si', |
---|
| 663 | '/^([\'\"])\s*about\s*:(.*)([\'\"])/si' |
---|
| 664 | ), |
---|
| 665 | Array( |
---|
| 666 | '\\1oddjob:\\2\\1', |
---|
| 667 | //'\\1uucp:\\2\\1', -> doclinks notes |
---|
| 668 | '\\1amaretto:\\2\\1', |
---|
| 669 | '\\1round:\\2\\1' |
---|
| 670 | ) |
---|
[449] | 671 | ), |
---|
| 672 | |
---|
[2] | 673 | '/^style/i' => |
---|
| 674 | Array( |
---|
| 675 | Array( |
---|
| 676 | '/expression/i', |
---|
| 677 | '/behaviou*r/i', |
---|
| 678 | '/binding/i', |
---|
| 679 | '/include-source/i', |
---|
| 680 | '/url\s*\(\s*([\'\"]*)\s*https*:.*([\'\"]*)\s*\)/si', |
---|
| 681 | '/url\s*\(\s*([\'\"]*)\s*\S+\s*script:.*([\'\"]*)\s*\)/si' |
---|
| 682 | ), |
---|
| 683 | Array( |
---|
| 684 | 'idiocy', |
---|
| 685 | 'idiocy', |
---|
| 686 | 'idiocy', |
---|
| 687 | 'idiocy', |
---|
| 688 | 'url(\\1http://securityfocus.com/\\1)', |
---|
| 689 | 'url(\\1http://securityfocus.com/\\1)' |
---|
| 690 | ) |
---|
| 691 | ) |
---|
| 692 | ) |
---|
| 693 | ); |
---|
| 694 | |
---|
| 695 | $add_attr_to_tag = Array( |
---|
| 696 | '/^a$/i' => Array('target' => '"_new"') |
---|
| 697 | ); |
---|
[449] | 698 | |
---|
| 699 | |
---|
[2] | 700 | $trusted_body = sanitize($body, |
---|
| 701 | $tag_list, |
---|
| 702 | $rm_tags_with_content, |
---|
| 703 | $self_closing_tags, |
---|
| 704 | $force_tag_closing, |
---|
| 705 | $rm_attnames, |
---|
| 706 | $bad_attvals, |
---|
| 707 | $add_attr_to_tag |
---|
| 708 | ); |
---|
[449] | 709 | |
---|
[2] | 710 | return $trusted_body; |
---|
| 711 | } |
---|
[449] | 712 | |
---|
[2] | 713 | function decodeBody($body, $encoding, $charset=null) |
---|
| 714 | { |
---|
| 715 | /** |
---|
| 716 | * replace e-mail by anchor. |
---|
| 717 | */ |
---|
| 718 | // HTML Filter |
---|
[13] | 719 | //$body = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=# onclick=\"javascript:new_message('new_by_message', '\\2@\\3')\">\\2@\\3</a>", $body); |
---|
[2] | 720 | $body = str_replace("\r\n", "\n", $body); |
---|
| 721 | if ($encoding == 'quoted-printable') |
---|
| 722 | { |
---|
[449] | 723 | |
---|
[2] | 724 | for($i=0;$i<256;$i++) { |
---|
| 725 | $c1=dechex($i); |
---|
| 726 | if(strlen($c1)==1){$c1="0".$c1;} |
---|
| 727 | $c1="=".$c1; |
---|
| 728 | $myqprinta[]=$c1; |
---|
| 729 | $myqprintb[]=chr($i); |
---|
[449] | 730 | } |
---|
[2] | 731 | $body = str_replace($myqprinta,$myqprintb,($body)); |
---|
| 732 | $body = quoted_printable_decode($body); |
---|
[449] | 733 | while (ereg("=\n", $body)) |
---|
[2] | 734 | { |
---|
| 735 | $body = ereg_replace ("=\n", '', $body); |
---|
| 736 | } |
---|
| 737 | } |
---|
[449] | 738 | else if ($encoding == 'base64') |
---|
[2] | 739 | { |
---|
| 740 | $body = base64_decode($body); |
---|
| 741 | } |
---|
[449] | 742 | /*else if ($encoding == '7bit') |
---|
[12] | 743 | { |
---|
[449] | 744 | $body = quoted_printable_decode($body); |
---|
[13] | 745 | }*/ |
---|
[2] | 746 | // All other encodings are returned raw. |
---|
| 747 | if (strtolower($charset) == "utf-8") |
---|
| 748 | return utf8_decode($body); |
---|
| 749 | else |
---|
| 750 | return $body; |
---|
| 751 | } |
---|
[449] | 752 | |
---|
[205] | 753 | function process_embedded_images($msg, $msgno, $body, $msg_folder) |
---|
[2] | 754 | { |
---|
| 755 | if (count($msg->inline_id[$msgno]) > 0) |
---|
| 756 | { |
---|
| 757 | foreach ($msg->inline_id[$msgno] as $index => $cid) |
---|
| 758 | { |
---|
| 759 | $cid = eregi_replace("<", "", $cid); |
---|
| 760 | $cid = eregi_replace(">", "", $cid); |
---|
| 761 | $msg_part = $msg->pid[$msgno][$index]; |
---|
| 762 | //$body = eregi_replace("alt=\"\"", "", $body); |
---|
| 763 | $body = eregi_replace("<br/>", "", $body); |
---|
| 764 | $body = str_replace("src=\"cid:".$cid."\"", " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=$msg_part\" ", $body); |
---|
| 765 | $body = str_replace("src='cid:".$cid."'", " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=$msg_part\" ", $body); |
---|
| 766 | $body = str_replace("src=cid:".$cid, " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=$msg_part\" ", $body); |
---|
| 767 | } |
---|
| 768 | } |
---|
[449] | 769 | |
---|
[2] | 770 | return $body; |
---|
| 771 | } |
---|
[449] | 772 | |
---|
[2] | 773 | function replace_special_characters($body) |
---|
| 774 | { |
---|
| 775 | // Suspected TAGS! |
---|
[449] | 776 | /*$tag_list = Array( |
---|
[2] | 777 | 'blink','object','meta', |
---|
| 778 | 'html','link','frame', |
---|
| 779 | 'iframe','layer','ilayer', |
---|
| 780 | 'plaintext','script','style','img', |
---|
| 781 | 'applet','embed','head', |
---|
| 782 | 'frameset','xml','xmp'); |
---|
| 783 | */ |
---|
| 784 | |
---|
[449] | 785 | // Layout problem: Change html elements |
---|
| 786 | // with absolute position to relate position, CASE INSENSITIVE. |
---|
[6] | 787 | $body = @eregi_replace("POSITION: ABSOLUTE;","",$body); |
---|
| 788 | |
---|
[2] | 789 | $tag_list = Array('head','blink','object','frame', |
---|
| 790 | 'iframe','layer','ilayer','plaintext','script', |
---|
[63] | 791 | 'applet','embed','frameset','xml','xmp','style'); |
---|
[2] | 792 | |
---|
| 793 | $body = $this-> replace_links($body); |
---|
[449] | 794 | $blocked_tags = array(); |
---|
[2] | 795 | foreach($tag_list as $index => $tag) { |
---|
| 796 | $new_body = eregi_replace("<$tag", "<!--$tag", $body); |
---|
| 797 | if($body != $new_body) { |
---|
| 798 | $blocked_tags[] = $tag; |
---|
| 799 | } |
---|
| 800 | $body = eregi_replace("</$tag>", "</$tag-->", $new_body); |
---|
| 801 | } |
---|
| 802 | |
---|
| 803 | return "<span>".$body; |
---|
| 804 | } |
---|
| 805 | |
---|
[449] | 806 | function replace_links($body) { |
---|
| 807 | $matches = array(); |
---|
[2] | 808 | // Verify exception. |
---|
[449] | 809 | @preg_match("/<a href=\"notes:\/\/\//",$body,$matches); |
---|
[2] | 810 | // It no has exception,then open the link in new window. |
---|
[449] | 811 | if(count($matches)) |
---|
| 812 | return $body; |
---|
| 813 | |
---|
| 814 | $pattern = '/(?<=[\s|(<br>)|\n|\r|;])((http(s?):\/\/((?:[\w]\.?)+(?::[\d]+)?[:\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\:\/\w.\-~&=?%;@+]*))/i'; |
---|
| 815 | $replacement = '<a href="http$3://$4$5" target="_blank">$1</a>'; |
---|
| 816 | return preg_replace($pattern, $replacement, $body); |
---|
| 817 | |
---|
| 818 | // Original |
---|
| 819 | //return preg_replace('/(?<=[\s|(<br>)|\n|\r|;])((http(s?):\/\/((?:[\w]\.?)+(?::[\d]+)?[\/.\-~&=?%;@#,+\w]*))|((?:www?\.)(?:\w\.?)*(?::\d+)?[\/\w.\-~&=?%;@+]*))/i', '<a href="http$3://$4$5" target="_blank">http$3://$4$5</a>', $body); |
---|
[2] | 820 | } |
---|
| 821 | |
---|
[91] | 822 | function get_signature($msg, $msg_number, $msg_folder) |
---|
[449] | 823 | { |
---|
[91] | 824 | foreach ($msg->file_type[$msg_number] as $index => $file_type) |
---|
| 825 | { |
---|
| 826 | $file_type = strtolower($file_type); |
---|
[449] | 827 | if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') |
---|
[91] | 828 | { |
---|
[449] | 829 | if ($file_type == 'application/x-pkcs7-signature') |
---|
[91] | 830 | { |
---|
| 831 | $export_mail = new ExportEml(); |
---|
| 832 | $params['folder'] = $msg_folder; |
---|
| 833 | $params['msgs_to_export'] = $msg_number; |
---|
[109] | 834 | $tempDir = ini_get("session.save_path"); |
---|
[449] | 835 | $cert_file = $tempDir."/certificate_".base_convert(microtime(), 10, 36).".crt"; |
---|
[109] | 836 | $result = openssl_pkcs7_verify($export_mail->export_msg($params),PKCS7_NOVERIFY,$cert_file); |
---|
| 837 | if (file_exists($cert_file)) |
---|
| 838 | { |
---|
| 839 | $handle = fopen ($cert_file,"r"); |
---|
| 840 | $pemout = fread($handle,filesize($cert_file)); |
---|
| 841 | fclose($handle); |
---|
| 842 | $cert=openssl_x509_parse($pemout); |
---|
| 843 | $temp = "\\nSigned by: ".$cert[subject][CN]; |
---|
| 844 | $temp .= "\\nEmail Address: ".$cert[subject][emailAddress]; |
---|
| 845 | $temp .= "\\nCertificate issued by: ".$cert[issuer][CN]."\\n"; |
---|
| 846 | } |
---|
[91] | 847 | /* Message verified */ |
---|
| 848 | if ($result === true) |
---|
[109] | 849 | $sign = $temp; |
---|
[91] | 850 | else |
---|
| 851 | $sign = "void"; |
---|
| 852 | } |
---|
| 853 | } |
---|
| 854 | } |
---|
[449] | 855 | return $sign; |
---|
[91] | 856 | } |
---|
| 857 | |
---|
[51] | 858 | function get_thumbs($msg, $msg_number, $msg_folder) |
---|
[2] | 859 | { |
---|
| 860 | $thumbs_array = array(); |
---|
| 861 | $i = 0; |
---|
| 862 | foreach ($msg->file_type[$msg_number] as $index => $file_type) |
---|
| 863 | { |
---|
| 864 | $file_type = strtolower($file_type); |
---|
| 865 | if(strtolower($msg->encoding[$msg_number][$index]) == 'base64') { |
---|
| 866 | if (($file_type == 'image/jpeg') || ($file_type == 'image/pjpeg') || ($file_type == 'image/gif') || ($file_type == 'image/png')) { |
---|
| 867 | $img = "<IMG id='".$msg_folder.";;".$msg_number.";;".$i.";;".$msg->pid[$msg_number][$index].";;".$msg->encoding[$msg_number][$index]."' style='border:2px solid #fde7bc;padding:5px' title='".$this->functions->getLang("Click here do view (+)")."'src=./inc/show_thumbs.php?file_type=".$file_type."&msg_num=".$msg_number."&msg_folder=".$msg_folder."&msg_part=".$msg->pid[$msg_number][$index].">"; |
---|
| 868 | $href = "<a onMouseDown='save_image(event,this)' href='#".$msg_folder.";;".$msg_number.";;".$i.";;".$msg->pid[$msg_number][$index].";;".$msg->encoding[$msg_number][$index]."' onClick=\"window.open('./inc/show_img.php?msg_num=".$msg_number."&msg_folder=".$msg_folder."&msg_part=".$msg->pid[$msg_number][$index]."','mywindow','width=700,height=600,scrollbars=yes');\">". $img ."</a>"; |
---|
| 869 | $thumbs_array[] = $href; |
---|
| 870 | } |
---|
| 871 | $i++; |
---|
| 872 | } |
---|
| 873 | } |
---|
| 874 | return $thumbs_array; |
---|
| 875 | } |
---|
[449] | 876 | |
---|
[2] | 877 | /*function delete_msg($params) |
---|
| 878 | { |
---|
| 879 | $folder = $params['folder']; |
---|
| 880 | $msgs_to_delete = explode(",",$params['msgs_to_delete']); |
---|
[449] | 881 | |
---|
[2] | 882 | $mbox_stream = $this->open_mbox($folder); |
---|
[449] | 883 | |
---|
[2] | 884 | foreach ($msgs_to_delete as $msg_number){ |
---|
| 885 | imap_delete($mbox_stream, $msg_number, FT_UID); |
---|
| 886 | } |
---|
| 887 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
| 888 | return $params['msgs_to_delete']; |
---|
| 889 | }*/ |
---|
| 890 | |
---|
| 891 | // Novo |
---|
| 892 | function delete_msgs($params) |
---|
| 893 | { |
---|
[449] | 894 | |
---|
[2] | 895 | $folder = $params['folder']; |
---|
[51] | 896 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); |
---|
[2] | 897 | $msgs_number = explode(",",$params['msgs_number']); |
---|
| 898 | $border_ID = $params['border_ID']; |
---|
[449] | 899 | |
---|
[2] | 900 | $return = array(); |
---|
[449] | 901 | |
---|
| 902 | if ($params['get_previous_msg']){ |
---|
[2] | 903 | $return['previous_msg'] = $this->get_info_previous_msg($params); |
---|
[449] | 904 | // Fix problem in unserialize function JS. |
---|
| 905 | $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); |
---|
| 906 | } |
---|
[2] | 907 | |
---|
[504] | 908 | //$mbox_stream = $this->open_mbox($folder); |
---|
| 909 | $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())))); |
---|
[449] | 910 | |
---|
[2] | 911 | foreach ($msgs_number as $msg_number) |
---|
| 912 | { |
---|
| 913 | if (imap_delete($mbox_stream, $msg_number, FT_UID)); |
---|
| 914 | $return['msgs_number'][] = $msg_number; |
---|
| 915 | } |
---|
[449] | 916 | |
---|
[2] | 917 | $return['folder'] = $folder; |
---|
| 918 | $return['border_ID'] = $border_ID; |
---|
[449] | 919 | |
---|
[51] | 920 | if($mbox_stream) |
---|
| 921 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 922 | return $return; |
---|
| 923 | } |
---|
| 924 | |
---|
[449] | 925 | |
---|
[2] | 926 | function refresh($params) |
---|
| 927 | { |
---|
| 928 | include("class.imap_attachment.inc.php"); |
---|
[449] | 929 | $imap_attachment = new imap_attachment(); |
---|
[2] | 930 | $folder = $params['folder']; |
---|
| 931 | $msg_range_begin = $params['msg_range_begin']; |
---|
| 932 | $msg_range_end = $params['msg_range_end']; |
---|
| 933 | $msgs_existent = $params['msgs_existent']; |
---|
[449] | 934 | $sort_box_type = $params['sort_box_type']; |
---|
[2] | 935 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 936 | $msgs_in_the_server = array(); |
---|
[53] | 937 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
| 938 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
[51] | 939 | |
---|
| 940 | if(!count($sort_array_msg)) |
---|
| 941 | return array(); |
---|
[449] | 942 | |
---|
[51] | 943 | $num_msgs = (count($sort_array_msg) - imap_num_recent($this->mbox)); |
---|
| 944 | $msgs_in_the_client = explode(",", $msgs_existent); |
---|
| 945 | |
---|
[449] | 946 | |
---|
[2] | 947 | for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= count($sort_array_msg))); $msg_range_begin++) |
---|
| 948 | { |
---|
| 949 | $msgs_in_the_server[] = $sort_array_msg[$msg_range_begin-1]; |
---|
| 950 | } |
---|
| 951 | if ((count($msgs_in_the_server) < 1) && ($msg_range_begin != 0)) |
---|
| 952 | { |
---|
| 953 | $range = $msg_range_end - $msg_range_begin; |
---|
| 954 | $msg_range_begin = $msg_range_begin - $range; |
---|
| 955 | $msg_range_end = $msg_range_end - $range; |
---|
| 956 | for ($msg_range_begin; (($msg_range_begin <= $msg_range_end) && ($msg_range_begin <= count($sort_array_msg))); $msg_range_begin++) |
---|
| 957 | { |
---|
| 958 | $msgs_in_the_server[] = $sort_array_msg[$msg_range_begin-1]; |
---|
| 959 | } |
---|
| 960 | } |
---|
[449] | 961 | |
---|
[2] | 962 | $msg_to_insert = array_diff($msgs_in_the_server, $msgs_in_the_client); |
---|
[271] | 963 | $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); |
---|
[449] | 964 | |
---|
[2] | 965 | $msgs_to_exec = array(); |
---|
| 966 | if ((count($msg_to_insert)) && ($msgs_existent)) |
---|
| 967 | { |
---|
| 968 | foreach($msg_to_insert as $index => $msg_number) |
---|
| 969 | { |
---|
| 970 | if ($msgs_in_the_server[$index+1]) |
---|
| 971 | { |
---|
| 972 | //$msgs_to_exec[$msg_number] = 'Inserir mensage numero ' . $msg_number . ' antes da ' . $msgs_in_the_server[$index+1]; |
---|
| 973 | $msgs_to_exec[$msg_number] = 'box.insertBefore(new_msg, Element("'.$msgs_in_the_server[$index+1].'"));'; |
---|
| 974 | } |
---|
| 975 | else |
---|
| 976 | { |
---|
| 977 | //$msgs_to_exec[$msg_number] = 'Inserir mensage numero ' . $msg_number . ' no final (append)'; |
---|
| 978 | $msgs_to_exec[$msg_number] = 'box.appendChild(new_msg);'; |
---|
| 979 | } |
---|
| 980 | } |
---|
| 981 | ksort($msgs_to_exec); |
---|
| 982 | } |
---|
| 983 | elseif(!$msgs_existent) |
---|
| 984 | { |
---|
| 985 | foreach($msgs_in_the_server as $index => $msg_number) |
---|
| 986 | { |
---|
| 987 | $msgs_to_exec[$msg_number] = 'box.appendChild(new_msg);'; |
---|
| 988 | } |
---|
| 989 | } |
---|
[449] | 990 | |
---|
[2] | 991 | $return = array(); |
---|
| 992 | $i = 0; |
---|
| 993 | foreach($msgs_to_exec as $msg_number => $command) |
---|
| 994 | { |
---|
[535] | 995 | $header = $this->get_header($msg_number); |
---|
[2] | 996 | if (!is_object($header)) |
---|
| 997 | return false; |
---|
[449] | 998 | |
---|
[2] | 999 | $return[$i]['msg_number'] = $msg_number; |
---|
| 1000 | $return[$i]['command'] = $command; |
---|
[449] | 1001 | |
---|
[2] | 1002 | $return[$i]['msg_folder'] = $folder; |
---|
| 1003 | $return[$i]['Recent'] = $header->Recent; |
---|
| 1004 | $return[$i]['Unseen'] = $header->Unseen; |
---|
| 1005 | $return[$i]['Answered'] = $header->Answered; |
---|
| 1006 | $return[$i]['Deleted'] = $header->Deleted; |
---|
| 1007 | $return[$i]['Draft'] = $header->Draft; |
---|
| 1008 | $return[$i]['Flagged'] = $header->Flagged; |
---|
| 1009 | |
---|
[535] | 1010 | $date_msg = gmdate("d/m/Y",$header->udate); |
---|
| 1011 | if (gmdate("d/m/Y") == $date_msg) |
---|
| 1012 | $return[$i]['udate'] = gmdate("H:i",$header->udate); |
---|
[2] | 1013 | else |
---|
| 1014 | $return[$i]['udate'] = $date_msg; |
---|
[449] | 1015 | |
---|
[2] | 1016 | $from = $header->from; |
---|
| 1017 | $return[$i]['from'] = array(); |
---|
| 1018 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
| 1019 | $return[$i]['from']['name'] = $tmp[0]->text; |
---|
| 1020 | $return[$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
[449] | 1021 | //$return[$i]['from']['full'] ='"' . $return[$i]['from']['name'] . '" ' . '<' . $return[$i]['from']['email'] . '>'; |
---|
[2] | 1022 | if(!$return[$i]['from']['name']) |
---|
| 1023 | $return[$i]['from']['name'] = $return[$i]['from']['email']; |
---|
[449] | 1024 | |
---|
[2] | 1025 | /*$toaddress = imap_mime_header_decode($header->toaddress); |
---|
| 1026 | $return[$i]['toaddress'] = ''; |
---|
| 1027 | foreach ($toaddress as $tmp) |
---|
| 1028 | $return[$i]['toaddress'] .= $tmp->text;*/ |
---|
| 1029 | $to = $header->to; |
---|
| 1030 | $return[$i]['to'] = array(); |
---|
| 1031 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
| 1032 | $return[$i]['to']['name'] = $tmp[0]->text; |
---|
| 1033 | $return[$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
| 1034 | $return[$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; |
---|
[449] | 1035 | |
---|
[2] | 1036 | $return[$i]['subject'] = $this->decode_string($header->fetchsubject); |
---|
| 1037 | |
---|
| 1038 | $return[$i]['Size'] = $header->Size; |
---|
| 1039 | $return[$i]['reply_toaddress'] = $header->reply_toaddress; |
---|
[449] | 1040 | |
---|
[2] | 1041 | $return[$i]['attachment'] = array(); |
---|
[51] | 1042 | $return[$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($this->mbox, $msg_number); |
---|
[2] | 1043 | $i++; |
---|
| 1044 | } |
---|
[51] | 1045 | $return['new_msgs'] = imap_num_recent($this->mbox); |
---|
[271] | 1046 | $return['msgs_to_delete'] = $msg_to_delete; |
---|
[411] | 1047 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 1048 | imap_close($this->mbox); |
---|
[2] | 1049 | return $return; |
---|
| 1050 | } |
---|
| 1051 | |
---|
[449] | 1052 | function get_folders_list($params = null) |
---|
[2] | 1053 | { |
---|
[449] | 1054 | $mbox_stream = $this->open_mbox(); |
---|
[115] | 1055 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
[2] | 1056 | $folders_list = imap_getmailboxes($mbox_stream, $serverString, "*"); |
---|
| 1057 | $tmp = array(); |
---|
| 1058 | $result = array(); |
---|
[449] | 1059 | |
---|
[2] | 1060 | if (is_array($folders_list)) { |
---|
| 1061 | reset($folders_list); |
---|
[449] | 1062 | |
---|
[2] | 1063 | $i = 0; |
---|
| 1064 | while (list($key, $val) = each($folders_list)) { |
---|
| 1065 | $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); |
---|
| 1066 | $result[$i]['folder_unseen'] = $status->unseen; |
---|
[449] | 1067 | |
---|
[2] | 1068 | //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); |
---|
| 1069 | $tmp_folder_id = explode("}", mb_convert_encoding($val->name, "ISO_8859-1", "UTF7-IMAP" )); |
---|
| 1070 | $folder_id = $tmp_folder_id[1]; |
---|
| 1071 | $result[$i]['folder_id'] = $folder_id; |
---|
[449] | 1072 | |
---|
[2] | 1073 | $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); |
---|
| 1074 | $result[$i]['folder_name'] = array_pop($tmp_folder_parent); |
---|
[96] | 1075 | $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; |
---|
[325] | 1076 | if (is_numeric($result[$i]['folder_name'])) { |
---|
[469] | 1077 | $this->ldap = new ldap_functions(); |
---|
[432] | 1078 | if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])){ |
---|
[325] | 1079 | $result[$i]['folder_name'] = $cn; |
---|
| 1080 | } |
---|
| 1081 | } |
---|
[449] | 1082 | |
---|
[2] | 1083 | $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); |
---|
| 1084 | $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; |
---|
[449] | 1085 | |
---|
[96] | 1086 | if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) |
---|
[2] | 1087 | $result[$i]['folder_hasChildren'] = 1; |
---|
| 1088 | else |
---|
| 1089 | $result[$i]['folder_hasChildren'] = 0; |
---|
| 1090 | |
---|
[449] | 1091 | $i++; |
---|
[2] | 1092 | } |
---|
| 1093 | } |
---|
[449] | 1094 | |
---|
[2] | 1095 | foreach ($result as $folder_info) |
---|
| 1096 | { |
---|
| 1097 | $array_tmp[] = $folder_info['folder_id']; |
---|
| 1098 | } |
---|
[449] | 1099 | |
---|
[2] | 1100 | natcasesort($array_tmp); |
---|
[449] | 1101 | |
---|
[2] | 1102 | foreach ($array_tmp as $key => $folder_id) |
---|
| 1103 | { |
---|
| 1104 | $result2[] = $result[$key]; |
---|
| 1105 | } |
---|
[449] | 1106 | |
---|
| 1107 | $current_folder = "INBOX"; |
---|
| 1108 | if($params && $params['folder']) |
---|
| 1109 | $current_folder = $params['folder']; |
---|
| 1110 | return array_merge($result2, $this->get_quota(array(folder_id => $current_folder))); |
---|
[2] | 1111 | } |
---|
[449] | 1112 | |
---|
[2] | 1113 | function create_mailbox($arr) |
---|
| 1114 | { |
---|
| 1115 | $namebox = $arr['newp']; |
---|
| 1116 | $mbox_stream = $this->open_mbox(); |
---|
| 1117 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[51] | 1118 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP", "UTF-8"); |
---|
[449] | 1119 | |
---|
[2] | 1120 | $result = "Ok"; |
---|
[51] | 1121 | if(!imap_createmailbox($mbox_stream,"{".$imap_server."}$namebox")) |
---|
[2] | 1122 | { |
---|
| 1123 | $result = implode("<br />\n", imap_errors()); |
---|
[449] | 1124 | } |
---|
| 1125 | |
---|
[51] | 1126 | if($mbox_stream) |
---|
| 1127 | imap_close($mbox_stream); |
---|
[449] | 1128 | |
---|
[2] | 1129 | return $result; |
---|
[449] | 1130 | |
---|
[2] | 1131 | } |
---|
[449] | 1132 | |
---|
[2] | 1133 | function create_extra_mailbox($arr) |
---|
| 1134 | { |
---|
| 1135 | $nameboxs = explode(";",$arr['nw_folders']); |
---|
| 1136 | $result = ""; |
---|
| 1137 | $mbox_stream = $this->open_mbox(); |
---|
| 1138 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[449] | 1139 | foreach($nameboxs as $key=>$tmp){ |
---|
[2] | 1140 | if($tmp != ""){ |
---|
| 1141 | if(!imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}$tmp"))){ |
---|
| 1142 | $result = implode("<br />\n", imap_errors()); |
---|
[51] | 1143 | if($mbox_stream) |
---|
[449] | 1144 | imap_close($mbox_stream); |
---|
[2] | 1145 | return $result; |
---|
| 1146 | } |
---|
| 1147 | } |
---|
| 1148 | } |
---|
[51] | 1149 | if($mbox_stream) |
---|
| 1150 | imap_close($mbox_stream); |
---|
[2] | 1151 | return true; |
---|
| 1152 | } |
---|
[449] | 1153 | |
---|
[2] | 1154 | function delete_mailbox($arr) |
---|
| 1155 | { |
---|
| 1156 | $namebox = $arr['del_past']; |
---|
| 1157 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 1158 | $mbox_stream = $this->open_mbox(); |
---|
| 1159 | //$del_folder = imap_deletemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox"); |
---|
[449] | 1160 | |
---|
[2] | 1161 | $result = "Ok"; |
---|
| 1162 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); |
---|
| 1163 | if(!imap_deletemailbox($mbox_stream,"{".$imap_server."}$namebox")) |
---|
| 1164 | { |
---|
| 1165 | $result = implode("<br />\n", imap_errors()); |
---|
| 1166 | } |
---|
[51] | 1167 | if($mbox_stream) |
---|
| 1168 | imap_close($mbox_stream); |
---|
[2] | 1169 | return $result; |
---|
| 1170 | } |
---|
[449] | 1171 | |
---|
[2] | 1172 | function ren_mailbox($arr) |
---|
| 1173 | { |
---|
| 1174 | $namebox = $arr['current']; |
---|
| 1175 | $new_box = $arr['rename']; |
---|
| 1176 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 1177 | $mbox_stream = $this->open_mbox(); |
---|
| 1178 | //$ren_folder = imap_renamemailbox($mbox_stream,"{".$imap_server."}INBOX.$namebox","{".$imap_server."}INBOX.$new_box"); |
---|
[449] | 1179 | |
---|
[2] | 1180 | $result = "Ok"; |
---|
| 1181 | $namebox = mb_convert_encoding($namebox, "UTF7-IMAP","UTF-8"); |
---|
[51] | 1182 | $new_box = mb_convert_encoding($new_box, "UTF7-IMAP","UTF-8"); |
---|
[449] | 1183 | |
---|
[2] | 1184 | if(!imap_renamemailbox($mbox_stream,"{".$imap_server."}$namebox","{".$imap_server."}$new_box")) |
---|
| 1185 | { |
---|
[449] | 1186 | $result = imap_errors(); |
---|
[2] | 1187 | } |
---|
[51] | 1188 | if($mbox_stream) |
---|
| 1189 | imap_close($mbox_stream); |
---|
[2] | 1190 | return $result; |
---|
[449] | 1191 | |
---|
[2] | 1192 | } |
---|
[449] | 1193 | |
---|
[2] | 1194 | function get_num_msgs($params) |
---|
| 1195 | { |
---|
| 1196 | $folder = $params['folder']; |
---|
[411] | 1197 | if(!$this->mbox || !is_resource($this->mbox)) { |
---|
[2] | 1198 | $this->mbox = $this->open_mbox($folder); |
---|
[411] | 1199 | if(!$this->mbox || !is_resource($this->mbox)) |
---|
[2] | 1200 | return imap_last_error(); |
---|
[449] | 1201 | } |
---|
[2] | 1202 | $num_msgs = imap_num_msg($this->mbox); |
---|
[432] | 1203 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 1204 | imap_close($this->mbox); |
---|
[449] | 1205 | |
---|
[2] | 1206 | return $num_msgs; |
---|
| 1207 | } |
---|
[449] | 1208 | |
---|
[2] | 1209 | function send_mail($params) |
---|
| 1210 | { |
---|
| 1211 | include_once("class.phpmailer.php"); |
---|
| 1212 | $mail = new PHPMailer(); |
---|
| 1213 | include_once("class.db_functions.inc.php"); |
---|
| 1214 | $db = new db_functions(); |
---|
| 1215 | $fromaddress = $params['input_from'] ? explode(';',$params['input_from']) : ""; |
---|
[449] | 1216 | ## |
---|
| 1217 | # @AUTHOR Rodrigo Souza dos Santos |
---|
| 1218 | # @DATE 2008/09/17 |
---|
| 1219 | # @BRIEF Checks if the user has permission to send an email with the email address used. |
---|
| 1220 | ## |
---|
| 1221 | if ( is_array($fromaddress) && ($fromaddress[1] != $_SESSION['phpgw_info']['expressomail']['user']['email']) ) |
---|
| 1222 | { |
---|
| 1223 | $deny = true; |
---|
| 1224 | foreach( $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] as $key => $val ) |
---|
| 1225 | if ( array_key_exists('mail', $val) && $val['mail'][0] == $fromaddress[1] ) |
---|
| 1226 | $deny = false and end($_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes']); |
---|
| 1227 | |
---|
| 1228 | if ( $deny ) |
---|
| 1229 | return "The server denied your request to send a mail, you cannot use this mail address."; |
---|
| 1230 | } |
---|
[2] | 1231 | $toaddress = implode(',',$db->getAddrs(explode(',',$params['input_to']))); |
---|
| 1232 | $ccaddress = implode(',',$db->getAddrs(explode(',',$params['input_cc']))); |
---|
| 1233 | $ccoaddress = implode(',',$db->getAddrs(explode(',',$params['input_cco']))); |
---|
| 1234 | $subject = $params['input_subject']; |
---|
[271] | 1235 | $msg_uid = $params['msg_id']; |
---|
[2] | 1236 | $return_receipt = $params['input_return_receipt']; |
---|
| 1237 | $body = $params['body']; |
---|
| 1238 | //echo "<script language=\"javascript\">javascript:alert('".$body."');</script>"; |
---|
| 1239 | $attachments = $params['FILES']; |
---|
| 1240 | $forwarding_attachments = $params['forwarding_attachments']; |
---|
[449] | 1241 | |
---|
[51] | 1242 | $folder =$params['folder']; |
---|
[449] | 1243 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); |
---|
| 1244 | $folder_name = $params['folder_name']; |
---|
[6] | 1245 | // Fix problem with cyrus delimiter changes. |
---|
[449] | 1246 | // Dots in names: enabled/disabled. |
---|
[6] | 1247 | $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); |
---|
| 1248 | $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); |
---|
| 1249 | // End Fix. |
---|
[449] | 1250 | if ($folder != 'null'){ |
---|
[2] | 1251 | $mail->SaveMessageInFolder = $folder; |
---|
| 1252 | } |
---|
| 1253 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1254 | $mail->SMTPDebug = false; |
---|
[449] | 1255 | |
---|
[2] | 1256 | $mail->IsSMTP(); |
---|
| 1257 | $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; |
---|
| 1258 | $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; |
---|
| 1259 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 1260 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
| 1261 | if($fromaddress){ |
---|
| 1262 | $mail->Sender = $mail->From; |
---|
| 1263 | $mail->SenderName = $mail->FromName; |
---|
| 1264 | $mail->FromName = $fromaddress[0]; |
---|
| 1265 | $mail->From = $fromaddress[1]; |
---|
| 1266 | } |
---|
[449] | 1267 | |
---|
[2] | 1268 | $this->add_recipients("to", $toaddress, &$mail); |
---|
| 1269 | $this->add_recipients("cc", $ccaddress, &$mail); |
---|
| 1270 | $this->add_recipients("cco", $ccoaddress, &$mail); |
---|
| 1271 | $mail->Subject = $subject; |
---|
| 1272 | $mail->IsHTML(true); |
---|
| 1273 | $mail->Body = $params['body']; |
---|
[271] | 1274 | |
---|
[2] | 1275 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[271] | 1276 | // Build CID for embedded Images!!! |
---|
[449] | 1277 | $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; |
---|
[271] | 1278 | $cid_imgs = ''; |
---|
| 1279 | $name_cid_files = array(); |
---|
| 1280 | preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); |
---|
| 1281 | $cid_array = array(); |
---|
[449] | 1282 | foreach($cid_imgs[6] as $j => $val){ |
---|
| 1283 | if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) |
---|
[271] | 1284 | { |
---|
[449] | 1285 | $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); |
---|
[271] | 1286 | } |
---|
[449] | 1287 | $cid = $cid_array[$cid_imgs[4][$j].$val]; |
---|
[271] | 1288 | $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); |
---|
[449] | 1289 | |
---|
| 1290 | if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail? |
---|
[271] | 1291 | { |
---|
[449] | 1292 | $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); |
---|
[271] | 1293 | $fileName = "image_".($j).".jpg"; |
---|
| 1294 | $fileCode = "base64"; |
---|
| 1295 | $fileType = "image/jpg"; |
---|
| 1296 | } |
---|
| 1297 | else |
---|
| 1298 | { |
---|
[449] | 1299 | $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; |
---|
[271] | 1300 | $file_description = unserialize(rawurldecode($attach_img)); |
---|
| 1301 | |
---|
[449] | 1302 | foreach($file_description as $i => $descriptor){ |
---|
[271] | 1303 | $file_description[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
| 1304 | } |
---|
| 1305 | $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64'); |
---|
| 1306 | $fileName = $file_description[2]; |
---|
| 1307 | $fileCode = $file_description[4]; |
---|
| 1308 | $fileType = $this->get_file_type($file_description[2]); |
---|
[449] | 1309 | unset($forwarding_attachments[$cid_imgs[6][$j]-2]); |
---|
[271] | 1310 | } |
---|
| 1311 | $tempDir = ini_get("session.save_path"); |
---|
[449] | 1312 | $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; |
---|
[271] | 1313 | $f = fopen($tempDir.'/'.$file,"w"); |
---|
| 1314 | fputs($f,$fileContent); |
---|
| 1315 | fclose($f); |
---|
| 1316 | if ($fileContent) |
---|
| 1317 | $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); |
---|
| 1318 | //else |
---|
[449] | 1319 | // return "Error loading image attachment content"; |
---|
[271] | 1320 | |
---|
| 1321 | } |
---|
| 1322 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[2] | 1323 | // Build Uploading Attachments!!! |
---|
| 1324 | if (count($attachments)) |
---|
| 1325 | { |
---|
| 1326 | $total_uploaded_size = 0; |
---|
| 1327 | $upload_max_filesize = str_replace("M","",ini_get('upload_max_filesize')) * 1024 * 1024; |
---|
| 1328 | foreach ($attachments as $attach) |
---|
| 1329 | { |
---|
| 1330 | $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); // optional name |
---|
| 1331 | $total_uploaded_size = $total_uploaded_size + $attach['size']; |
---|
| 1332 | } |
---|
| 1333 | if( $total_uploaded_size > $upload_max_filesize) |
---|
[504] | 1334 | return $this->parse_error("message file too big"); |
---|
[449] | 1335 | } |
---|
[2] | 1336 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[271] | 1337 | // Build Forwarding Attachments!!! |
---|
[2] | 1338 | if (count($forwarding_attachments) > 0) |
---|
| 1339 | { |
---|
| 1340 | // Bug fixed for array_search function |
---|
| 1341 | if(count($name_cid_files) > 0) { |
---|
| 1342 | $name_cid_files[count($name_cid_files)] = $name_cid_files[0]; |
---|
| 1343 | $name_cid_files[0] = null; |
---|
[449] | 1344 | } |
---|
| 1345 | |
---|
[2] | 1346 | foreach($forwarding_attachments as $forwarding_attachment) |
---|
| 1347 | { |
---|
[271] | 1348 | $file_description = unserialize(rawurldecode($forwarding_attachment)); |
---|
| 1349 | $tmp = array_values($file_description); |
---|
[449] | 1350 | foreach($file_description as $i => $descriptor){ |
---|
[271] | 1351 | $tmp[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
| 1352 | } |
---|
[449] | 1353 | $file_description = $tmp; |
---|
[271] | 1354 | $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); |
---|
| 1355 | $fileName = $file_description[2]; |
---|
| 1356 | if(!array_search(trim($fileName),$name_cid_files)) { |
---|
| 1357 | $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); |
---|
[63] | 1358 | } |
---|
[2] | 1359 | } |
---|
| 1360 | } |
---|
[37] | 1361 | |
---|
[2] | 1362 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1363 | // Disposition-Notification-To |
---|
| 1364 | if ($return_receipt) |
---|
| 1365 | $mail->ConfirmReadingTo = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 1366 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
[504] | 1367 | |
---|
[117] | 1368 | $sent = $mail->Send(); |
---|
[504] | 1369 | |
---|
[117] | 1370 | if(!$sent) |
---|
[2] | 1371 | { |
---|
[504] | 1372 | return $this->parse_error($mail->ErrorInfo); |
---|
[2] | 1373 | } |
---|
| 1374 | else |
---|
| 1375 | { |
---|
[449] | 1376 | if($_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] == "True") |
---|
[117] | 1377 | { |
---|
| 1378 | $userid = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 1379 | $userip = $_SESSION['phpgw_info']['expressomail']['user']['session_ip']; |
---|
| 1380 | $now = date("d/m/y H:i:s"); |
---|
| 1381 | $addrs = $toaddress.$ccaddress.$ccoaddress; |
---|
[449] | 1382 | $sent = trim($sent); |
---|
[117] | 1383 | error_log("$now - $userip - $sent [$subject] - $userid => $addrs\r\n", 3, "/home/expressolivre/mail_senders.log"); |
---|
| 1384 | } |
---|
[485] | 1385 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['number_of_contacts'] && |
---|
| 1386 | $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_dynamic_contacts']) { |
---|
[469] | 1387 | $contacts = new dynamic_contacts(); |
---|
[485] | 1388 | $new_contacts = $contacts->add_dynamic_contacts($toaddress.",".$ccaddress.",".$ccoaddress); |
---|
| 1389 | return array("success" => true, "new_contacts" => $new_contacts); |
---|
[413] | 1390 | } |
---|
[485] | 1391 | return array("success" => true); |
---|
[2] | 1392 | } |
---|
| 1393 | } |
---|
| 1394 | |
---|
| 1395 | function add_recipients($recipient_type, $full_address, $mail) |
---|
| 1396 | { |
---|
[449] | 1397 | $parse_address = imap_rfc822_parse_adrlist($full_address, ""); |
---|
| 1398 | foreach ($parse_address as $val) |
---|
[2] | 1399 | { |
---|
| 1400 | //echo "<script language=\"javascript\">javascript:alert('".$val->mailbox."@".$val->host."');</script>"; |
---|
| 1401 | if ($val->mailbox == "INVALID_ADDRESS") |
---|
| 1402 | continue; |
---|
[449] | 1403 | |
---|
[2] | 1404 | if (empty($val->personal)) |
---|
| 1405 | { |
---|
| 1406 | switch($recipient_type) |
---|
| 1407 | { |
---|
| 1408 | case "to": |
---|
| 1409 | $mail->AddAddress($val->mailbox."@".$val->host); |
---|
| 1410 | break; |
---|
| 1411 | case "cc": |
---|
| 1412 | $mail->AddCC($val->mailbox."@".$val->host); |
---|
| 1413 | break; |
---|
| 1414 | case "cco": |
---|
| 1415 | $mail->AddBCC($val->mailbox."@".$val->host); |
---|
| 1416 | break; |
---|
| 1417 | } |
---|
| 1418 | } |
---|
| 1419 | else |
---|
| 1420 | { |
---|
| 1421 | switch($recipient_type) |
---|
| 1422 | { |
---|
| 1423 | case "to": |
---|
| 1424 | $mail->AddAddress($val->mailbox."@".$val->host, $val->personal); |
---|
| 1425 | break; |
---|
| 1426 | case "cc": |
---|
| 1427 | $mail->AddCC($val->mailbox."@".$val->host, $val->personal); |
---|
| 1428 | break; |
---|
| 1429 | case "cco": |
---|
| 1430 | $mail->AddBCC($val->mailbox."@".$val->host, $val->personal); |
---|
| 1431 | break; |
---|
| 1432 | } |
---|
| 1433 | } |
---|
| 1434 | } |
---|
| 1435 | return true; |
---|
| 1436 | } |
---|
[449] | 1437 | |
---|
[2] | 1438 | function get_forwarding_attachment($msg_folder, $msg_number, $msg_part, $encoding) |
---|
| 1439 | { |
---|
[449] | 1440 | $mbox_stream = $this->open_mbox($msg_folder); |
---|
| 1441 | $fileContent = imap_fetchbody($mbox_stream, $msg_number, $msg_part, FT_UID); |
---|
[2] | 1442 | if($encoding == 'base64') |
---|
[449] | 1443 | # The function imap_base64 adds a new line |
---|
| 1444 | # at ASCII text, with CRLF line terminators. |
---|
| 1445 | # So is being exchanged for base64_decode. |
---|
| 1446 | # |
---|
| 1447 | #$fileContent = imap_base64($fileContent); |
---|
| 1448 | $fileContent = base64_decode($fileContent); |
---|
[2] | 1449 | else if($encoding == 'quoted-printable') |
---|
[449] | 1450 | $fileContent = quoted_printable_decode($fileContent); |
---|
[2] | 1451 | return $fileContent; |
---|
| 1452 | } |
---|
[449] | 1453 | |
---|
[2] | 1454 | function del_last_caracter($string) |
---|
| 1455 | { |
---|
| 1456 | $string = substr($string,0,(strlen($string) - 1)); |
---|
[449] | 1457 | return $string; |
---|
[2] | 1458 | } |
---|
[449] | 1459 | |
---|
[2] | 1460 | function del_last_two_caracters($string) |
---|
| 1461 | { |
---|
| 1462 | $string = substr($string,0,(strlen($string) - 2)); |
---|
[449] | 1463 | return $string; |
---|
[2] | 1464 | } |
---|
[449] | 1465 | |
---|
[53] | 1466 | function imap_sortfrom($sort_box_reverse, $search_box_type) |
---|
[2] | 1467 | { |
---|
| 1468 | $sortfrom = array(); |
---|
| 1469 | $sortfrom_uid = array(); |
---|
[449] | 1470 | |
---|
[51] | 1471 | $num_msgs = imap_num_msg($this->mbox); |
---|
[2] | 1472 | for ($i=1; $i<=$num_msgs; $i++) |
---|
| 1473 | { |
---|
[539] | 1474 | $header = $this->get_header(imap_uid($this->mbox,$i)); |
---|
[53] | 1475 | // List UNSEEN messages. |
---|
| 1476 | if($search_box_type == "UNSEEN" && (!trim($header->Recent) && !trim($header->Unseen))){ |
---|
| 1477 | continue; |
---|
| 1478 | } |
---|
| 1479 | // List SEEN messages. |
---|
| 1480 | elseif($search_box_type == "SEEN" && (trim($header->Recent) || trim($header->Unseen))){ |
---|
| 1481 | continue; |
---|
| 1482 | } |
---|
[449] | 1483 | // List ANSWERED messages. |
---|
[53] | 1484 | elseif($search_box_type == "ANSWERED" && !trim($header->Answered)){ |
---|
[449] | 1485 | continue; |
---|
[53] | 1486 | } |
---|
[449] | 1487 | // List FLAGGED messages. |
---|
[53] | 1488 | elseif($search_box_type == "FLAGGED" && !trim($header->Flagged)){ |
---|
| 1489 | continue; |
---|
| 1490 | } |
---|
[449] | 1491 | |
---|
| 1492 | if (($header->from[0]->mailbox . "@" . $header->from[0]->host) == $_SESSION['phpgw_info']['expressomail']['user']['email']) |
---|
[2] | 1493 | $from = $header->to; |
---|
| 1494 | else |
---|
| 1495 | $from = $header->from; |
---|
[449] | 1496 | |
---|
| 1497 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
| 1498 | |
---|
[2] | 1499 | if ($tmp[0]->text != "") |
---|
[53] | 1500 | $sortfrom[$i] = $tmp[0]->text; |
---|
[2] | 1501 | else |
---|
[53] | 1502 | $sortfrom[$i] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
[2] | 1503 | } |
---|
[449] | 1504 | |
---|
[2] | 1505 | natcasesort($sortfrom); |
---|
[449] | 1506 | |
---|
[2] | 1507 | foreach($sortfrom as $index => $header_msg) |
---|
[449] | 1508 | { |
---|
[53] | 1509 | $sortfrom_uid[] = imap_uid($this->mbox, $index); |
---|
[2] | 1510 | } |
---|
[449] | 1511 | |
---|
[2] | 1512 | if ($sort_box_reverse) |
---|
| 1513 | $sortfrom_uid = array_reverse($sortfrom_uid); |
---|
[449] | 1514 | |
---|
[2] | 1515 | return $sortfrom_uid; |
---|
| 1516 | } |
---|
[51] | 1517 | |
---|
[449] | 1518 | function move_search_messages($params){ |
---|
| 1519 | $params['selected_messages'] = urldecode($params['selected_messages']); |
---|
[163] | 1520 | $params['new_folder'] = urldecode($params['new_folder']); |
---|
| 1521 | $params['new_folder_name'] = urldecode($params['new_folder_name']); |
---|
| 1522 | $sel_msgs = explode(",", $params['selected_messages']); |
---|
[449] | 1523 | @reset($sel_msgs); |
---|
[163] | 1524 | $sorted_msgs = array(); |
---|
| 1525 | foreach($sel_msgs as $idx => $sel_msg) { |
---|
| 1526 | $sel_msg = explode(";", $sel_msg); |
---|
| 1527 | if(array_key_exists($sel_msg[0], $sorted_msgs)){ |
---|
| 1528 | $sorted_msgs[$sel_msg[0]] .= ",".$sel_msg[1]; |
---|
[449] | 1529 | } |
---|
[163] | 1530 | else { |
---|
| 1531 | $sorted_msgs[$sel_msg[0]] = $sel_msg[1]; |
---|
| 1532 | } |
---|
| 1533 | } |
---|
| 1534 | @ksort($sorted_msgs); |
---|
[449] | 1535 | $last_return = false; |
---|
| 1536 | foreach($sorted_msgs as $folder => $msgs_number) { |
---|
[163] | 1537 | $params['msgs_number'] = $msgs_number; |
---|
[449] | 1538 | $params['folder'] = $folder; |
---|
[163] | 1539 | if($params['new_folder'] && $folder != $params['new_folder']){ |
---|
[449] | 1540 | $last_return = $this -> move_messages($params); |
---|
[163] | 1541 | } |
---|
| 1542 | elseif(!$params['new_folder'] || $params['delete'] ){ |
---|
| 1543 | $last_return = $this -> delete_msgs($params); |
---|
| 1544 | $last_return['deleted'] = true; |
---|
| 1545 | } |
---|
| 1546 | } |
---|
| 1547 | return $last_return; |
---|
| 1548 | } |
---|
[449] | 1549 | |
---|
[2] | 1550 | function move_messages($params) |
---|
| 1551 | { |
---|
[449] | 1552 | $folder = $params['folder']; |
---|
| 1553 | $mbox_stream = $this->open_mbox($folder); |
---|
[51] | 1554 | $newmailbox = ($params['new_folder']); |
---|
| 1555 | $newmailbox = mb_convert_encoding($newmailbox, "UTF7-IMAP","ISO_8859-1"); |
---|
[2] | 1556 | $new_folder_name = $params['new_folder_name']; |
---|
| 1557 | $msgs_number = $params['msgs_number']; |
---|
| 1558 | $return = array('msgs_number' => $msgs_number, |
---|
| 1559 | 'folder' => $folder, |
---|
| 1560 | 'new_folder_name' => $new_folder_name, |
---|
[325] | 1561 | 'border_ID' => $params['border_ID'], |
---|
| 1562 | 'status' => true); //Status foi adicionado para validar as permissoes ACL |
---|
[449] | 1563 | |
---|
[325] | 1564 | //Este bloco tem a finalidade de averiguar as permissoes para pastas compartilhadas |
---|
| 1565 | if (substr($folder,0,4) == 'user'){ |
---|
| 1566 | $acl = $this->getacltouser($folder); |
---|
| 1567 | /* |
---|
| 1568 | * l - lookup (mailbox is visible to LIST/LSUB commands) |
---|
| 1569 | * r - read (SELECT the mailbox, perform CHECK, FETCH, PARTIAL, SEARCH, COPY from mailbox) |
---|
| 1570 | * s - keep seen/unseen information across sessions (STORE SEEN flag) |
---|
| 1571 | * w - write (STORE flags other than SEEN and DELETED) |
---|
| 1572 | * i - insert (perform APPEND, COPY into mailbox) |
---|
| 1573 | * p - post (send mail to submission address for mailbox, not enforced by IMAP4 itself) |
---|
| 1574 | * c - create (CREATE new sub-mailboxes in any implementation-defined hierarchy) |
---|
| 1575 | * d - delete (STORE DELETED flag, perform EXPUNGE) |
---|
| 1576 | * a - administer (perform SETACL) |
---|
| 1577 | */ |
---|
| 1578 | if (strpos($acl, "d") === false){ |
---|
| 1579 | $return['status'] = false; |
---|
| 1580 | return $return; |
---|
| 1581 | } |
---|
| 1582 | } |
---|
[432] | 1583 | //Este bloco tem a finalidade de transformar o CPF das pastas compartilhadas em common name |
---|
| 1584 | if (substr($new_folder_name,0,4) == 'user'){ |
---|
| 1585 | $this->ldap = new ldap_functions(); |
---|
| 1586 | $tmp_folder_name = explode($this->imap_delimiter, $new_folder_name); |
---|
| 1587 | $return['new_folder_name'] = array_pop($tmp_folder_name); |
---|
| 1588 | if (is_numeric($return['new_folder_name'])) |
---|
| 1589 | if( $cn = $this->ldap->uid2cn($return['new_folder_name'])) |
---|
| 1590 | $return['new_folder_name'] = $cn; |
---|
| 1591 | } |
---|
[449] | 1592 | |
---|
| 1593 | // Caso estejamos no box principal, nao eh necessario pegar a informacao da mensagem anterior. |
---|
[51] | 1594 | if (($params['get_previous_msg']) && ($params['border_ID'] != 'null') && ($params['border_ID'] != '')) |
---|
[449] | 1595 | { |
---|
[2] | 1596 | $return['previous_msg'] = $this->get_info_previous_msg($params); |
---|
[449] | 1597 | // Fix problem in unserialize function JS. |
---|
| 1598 | $return['previous_msg']['body'] = str_replace(array('{','}'), array('{','}'), $return['previous_msg']['body']); |
---|
| 1599 | } |
---|
| 1600 | |
---|
| 1601 | $mbox_stream = $this->open_mbox($folder); |
---|
[2] | 1602 | if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { |
---|
| 1603 | imap_expunge($mbox_stream); |
---|
[51] | 1604 | if($mbox_stream) |
---|
| 1605 | imap_close($mbox_stream); |
---|
[2] | 1606 | return $return; |
---|
| 1607 | }else { |
---|
[449] | 1608 | if(strstr(imap_last_error(),'Over quota')) { |
---|
[2] | 1609 | $accountID = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminUsername']; |
---|
[449] | 1610 | $pass = $_SESSION['phpgw_info']['expressomail']['email_server']['imapAdminPW']; |
---|
| 1611 | $userID = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
[2] | 1612 | $server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
[504] | 1613 | $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] | 1614 | if(!$mbox) |
---|
| 1615 | return imap_last_error(); |
---|
[449] | 1616 | $quota = imap_get_quotaroot($mbox_stream, "INBOX"); |
---|
[2] | 1617 | if(! imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, 2.1 * $quota['usage'])) { |
---|
[51] | 1618 | if($mbox_stream) |
---|
| 1619 | imap_close($mbox_stream); |
---|
[449] | 1620 | if($mbox) |
---|
[51] | 1621 | imap_close($mbox); |
---|
[449] | 1622 | return "move_messages(): Error setting quota for MOVE or DELETE!! ". "user".$this->imap_delimiter.$userID." line ".__LINE__."\n"; |
---|
[2] | 1623 | } |
---|
| 1624 | if(imap_mail_move($mbox_stream, $msgs_number, $newmailbox, CP_UID)) { |
---|
| 1625 | imap_expunge($mbox_stream); |
---|
[51] | 1626 | if($mbox_stream) |
---|
| 1627 | imap_close($mbox_stream); |
---|
[2] | 1628 | // return to original quota limit. |
---|
| 1629 | if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { |
---|
[51] | 1630 | if($mbox) |
---|
| 1631 | imap_close($mbox); |
---|
[449] | 1632 | return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; |
---|
[2] | 1633 | } |
---|
[449] | 1634 | return $return; |
---|
[2] | 1635 | } |
---|
| 1636 | else { |
---|
[51] | 1637 | if($mbox_stream) |
---|
| 1638 | imap_close($mbox_stream); |
---|
[2] | 1639 | if(!imap_set_quota($mbox, "user".$this->imap_delimiter.$userID, $quota['limit'])) { |
---|
[51] | 1640 | if($mbox) |
---|
| 1641 | imap_close($mbox); |
---|
[449] | 1642 | return "move_messages(): Error setting quota for MOVE or DELETE!! line ".__LINE__."\n"; |
---|
[2] | 1643 | } |
---|
[449] | 1644 | return imap_last_error(); |
---|
[2] | 1645 | } |
---|
[449] | 1646 | |
---|
[2] | 1647 | } |
---|
| 1648 | else { |
---|
[51] | 1649 | if($mbox_stream) |
---|
| 1650 | imap_close($mbox_stream); |
---|
| 1651 | return "move_messages() line ".__LINE__.": ". imap_last_error()." folder:".$newmailbox; |
---|
[2] | 1652 | } |
---|
[449] | 1653 | } |
---|
[2] | 1654 | } |
---|
[449] | 1655 | |
---|
[2] | 1656 | function save_msg($params) |
---|
| 1657 | { |
---|
[449] | 1658 | |
---|
[271] | 1659 | include_once("class.phpmailer.php"); |
---|
| 1660 | $mail = new PHPMailer(); |
---|
| 1661 | include_once("class.db_functions.inc.php"); |
---|
| 1662 | $toaddress = $params['input_to']; |
---|
| 1663 | $ccaddress = $params['input_cc']; |
---|
| 1664 | $subject = $params['input_subject']; |
---|
[320] | 1665 | $msg_uid = $params['msg_id']; |
---|
[2] | 1666 | $body = $params['body']; |
---|
| 1667 | $body = str_replace("%nbsp;"," ",$params['body']); |
---|
[155] | 1668 | $body = preg_replace("/\n/"," ",$body); |
---|
[51] | 1669 | $body = preg_replace("/\r/","",$body); |
---|
[271] | 1670 | $forwarding_attachments = $params['forwarding_attachments']; |
---|
| 1671 | $attachments = $params['FILES']; |
---|
| 1672 | $return_files = $params['FILES']; |
---|
[449] | 1673 | |
---|
[271] | 1674 | $folder = $params['folder']; |
---|
[449] | 1675 | $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); |
---|
[271] | 1676 | // Fix problem with cyrus delimiter changes. |
---|
[449] | 1677 | // Dots in names: enabled/disabled. |
---|
[271] | 1678 | $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); |
---|
| 1679 | $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); |
---|
| 1680 | // End Fix. |
---|
[449] | 1681 | |
---|
[271] | 1682 | $mail->SaveMessageInFolder = $folder; |
---|
| 1683 | $mail->SMTPDebug = false; |
---|
[449] | 1684 | |
---|
[271] | 1685 | $mail->IsSMTP(); |
---|
| 1686 | $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; |
---|
| 1687 | $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; |
---|
| 1688 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 1689 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
[449] | 1690 | |
---|
[271] | 1691 | $mail->Sender = $mail->From; |
---|
| 1692 | $mail->SenderName = $mail->FromName; |
---|
| 1693 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
| 1694 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
[449] | 1695 | |
---|
[271] | 1696 | $this->add_recipients("to", $toaddress, &$mail); |
---|
| 1697 | $this->add_recipients("cc", $ccaddress, &$mail); |
---|
| 1698 | $mail->Subject = $subject; |
---|
| 1699 | $mail->IsHTML(true); |
---|
| 1700 | $mail->Body = $body; |
---|
[449] | 1701 | |
---|
[320] | 1702 | // Build CID for embedded Images!!! |
---|
[449] | 1703 | $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; |
---|
[320] | 1704 | $cid_imgs = ''; |
---|
| 1705 | $name_cid_files = array(); |
---|
| 1706 | preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); |
---|
| 1707 | $cid_array = array(); |
---|
[449] | 1708 | foreach($cid_imgs[6] as $j => $val){ |
---|
| 1709 | if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) |
---|
[320] | 1710 | { |
---|
[449] | 1711 | $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); |
---|
[320] | 1712 | } |
---|
[449] | 1713 | $cid = $cid_array[$cid_imgs[4][$j].$val]; |
---|
[320] | 1714 | $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); |
---|
[449] | 1715 | |
---|
| 1716 | if ($msg_uid != $cid_imgs[4][$j]) // The image isn't in the same mail? |
---|
[320] | 1717 | { |
---|
[449] | 1718 | $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); |
---|
| 1719 | //prototype: get_forwarding_attachment ( folder, msg number, part, encoding) |
---|
[320] | 1720 | $fileName = "image_".($j).".jpg"; |
---|
| 1721 | $fileCode = "base64"; |
---|
| 1722 | $fileType = "image/jpg"; |
---|
[449] | 1723 | $file_attached[0] = $cid_imgs[2][$j]; |
---|
| 1724 | $file_attached[1] = $cid_imgs[4][$j]; |
---|
| 1725 | $file_attached[2] = $fileName; |
---|
| 1726 | $file_attached[3] = $cid_imgs[6][$j]; |
---|
| 1727 | $file_attached[4] = 'base64'; |
---|
| 1728 | $file_attached[5] = strlen($fileContent); //Size of file |
---|
| 1729 | $return_forward[] = $file_attached; |
---|
[320] | 1730 | } |
---|
| 1731 | else |
---|
| 1732 | { |
---|
[449] | 1733 | $attach_img = $forwarding_attachments[$cid_imgs[6][$j]-2]; |
---|
[320] | 1734 | $file_description = unserialize(rawurldecode($attach_img)); |
---|
[449] | 1735 | foreach($file_description as $i => $descriptor){ |
---|
[320] | 1736 | $file_description[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
| 1737 | } |
---|
| 1738 | $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64'); |
---|
| 1739 | $fileName = $file_description[2]; |
---|
| 1740 | $fileCode = $file_description[4]; |
---|
| 1741 | $fileType = $this->get_file_type($file_description[2]); |
---|
[449] | 1742 | unset($forwarding_attachments[$cid_imgs[6][$j]-2]); |
---|
[320] | 1743 | if (!empty($file_description)) |
---|
| 1744 | { |
---|
| 1745 | $file_description[5] = strlen($fileContent); //Size of file |
---|
| 1746 | $return_forward[] = $file_description; |
---|
| 1747 | } |
---|
| 1748 | } |
---|
| 1749 | $tempDir = ini_get("session.save_path"); |
---|
[449] | 1750 | $file = "cid_image_".base_convert(microtime(), 10, 36).".dat"; |
---|
[320] | 1751 | $f = fopen($tempDir.'/'.$file,"w"); |
---|
| 1752 | fputs($f,$fileContent); |
---|
| 1753 | fclose($f); |
---|
| 1754 | if ($fileContent) |
---|
| 1755 | $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); |
---|
| 1756 | //else |
---|
[449] | 1757 | // return "Error loading image attachment content"; |
---|
[320] | 1758 | |
---|
| 1759 | } |
---|
[449] | 1760 | |
---|
| 1761 | // Build Forwarding Attachments!!! |
---|
[271] | 1762 | if (count($forwarding_attachments) > 0) |
---|
| 1763 | { |
---|
| 1764 | foreach($forwarding_attachments as $forwarding_attachment) |
---|
| 1765 | { |
---|
| 1766 | $file_description = unserialize(rawurldecode($forwarding_attachment)); |
---|
| 1767 | $tmp = array_values($file_description); |
---|
[449] | 1768 | foreach($file_description as $i => $descriptor){ |
---|
[271] | 1769 | $tmp[$i] = eregi_replace('\'*\'','',$descriptor); |
---|
| 1770 | } |
---|
| 1771 | $file_description = $tmp; |
---|
[449] | 1772 | |
---|
[271] | 1773 | $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); |
---|
| 1774 | $fileName = $file_description[2]; |
---|
[449] | 1775 | |
---|
[271] | 1776 | $file_description[5] = strlen($fileContent); //Size of file |
---|
| 1777 | $return_forward[] = $file_description; |
---|
[449] | 1778 | |
---|
[271] | 1779 | $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); |
---|
| 1780 | } |
---|
| 1781 | } |
---|
[449] | 1782 | |
---|
[271] | 1783 | if ((count($return_forward) > 0) && (count($return_files) > 0)) |
---|
| 1784 | $return_files = array_merge_recursive($return_forward,$return_files); |
---|
| 1785 | else |
---|
| 1786 | if (count($return_files) < 1) |
---|
| 1787 | $return_files = $return_forward; |
---|
[449] | 1788 | |
---|
[271] | 1789 | // Build Uploading Attachments!!! |
---|
| 1790 | if (count($attachments)) |
---|
| 1791 | foreach ($attachments as $attach) |
---|
[449] | 1792 | $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); // optional name |
---|
| 1793 | |
---|
| 1794 | |
---|
| 1795 | |
---|
[271] | 1796 | if(!empty($mail->AltBody)) |
---|
| 1797 | $mail->ContentType = "multipart/alternative"; |
---|
| 1798 | |
---|
| 1799 | $mail->error_count = 0; // reset errors |
---|
| 1800 | $mail->SetMessageType(); |
---|
| 1801 | $header = $mail->CreateHeader(); |
---|
| 1802 | $body = $mail->CreateBody(); |
---|
[449] | 1803 | |
---|
[271] | 1804 | if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') |
---|
| 1805 | { |
---|
| 1806 | $imap_options = '/tls/novalidate-cert'; |
---|
| 1807 | } |
---|
| 1808 | else |
---|
| 1809 | { |
---|
| 1810 | $imap_options = '/notls/novalidate-cert'; |
---|
| 1811 | } |
---|
| 1812 | $username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; |
---|
| 1813 | $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; |
---|
| 1814 | $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; |
---|
| 1815 | $imap_port = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; |
---|
| 1816 | $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$folder, $username, $password); |
---|
[449] | 1817 | |
---|
[271] | 1818 | $new_header = str_replace("\n", "\r\n", $header); |
---|
| 1819 | $new_body = str_replace("\n", "\r\n", $body); |
---|
[449] | 1820 | |
---|
[271] | 1821 | $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $new_header . $new_body, "\\Seen \\Draft"); |
---|
| 1822 | $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); |
---|
| 1823 | $return['msg_no'] = $status->uidnext - 1; |
---|
| 1824 | $return['folder_id'] = $folder; |
---|
[449] | 1825 | |
---|
[51] | 1826 | if($mbox_stream) |
---|
| 1827 | imap_close($mbox_stream); |
---|
[449] | 1828 | |
---|
[271] | 1829 | foreach ($return_files as $index => $_attachment) { |
---|
| 1830 | if (array_key_exists("name",$_attachment)){ |
---|
| 1831 | unset($return_files[$index]); |
---|
| 1832 | $return_files[$index] = $_attachment['name']."_SIZE_".$return_files[$index][1] = $_attachment['size']; |
---|
| 1833 | } |
---|
| 1834 | else |
---|
| 1835 | { |
---|
| 1836 | unset($return_files[$index]); |
---|
| 1837 | $return_files[$index] = $_attachment[2]."_SIZE_". $return_files[$index][1] = $_attachment[5]; |
---|
| 1838 | } |
---|
| 1839 | } |
---|
[449] | 1840 | |
---|
[271] | 1841 | $return['files'] = serialize($return_files); |
---|
[449] | 1842 | |
---|
[2] | 1843 | if (!$return['append']) |
---|
| 1844 | $return['append'] = imap_last_error(); |
---|
[449] | 1845 | |
---|
[2] | 1846 | return $return; |
---|
| 1847 | } |
---|
[449] | 1848 | |
---|
[2] | 1849 | function set_messages_flag($params) |
---|
| 1850 | { |
---|
| 1851 | $folder = $params['folder']; |
---|
| 1852 | $msgs_to_set = $params['msgs_to_set']; |
---|
| 1853 | $flag = $params['flag']; |
---|
| 1854 | $return = array(); |
---|
| 1855 | $return["msgs_to_set"] = $msgs_to_set; |
---|
| 1856 | $return["flag"] = $flag; |
---|
[449] | 1857 | |
---|
[411] | 1858 | if(!$this->mbox && !is_resource($this->mbox)) |
---|
[51] | 1859 | $this->mbox = $this->open_mbox($folder); |
---|
[449] | 1860 | |
---|
[2] | 1861 | if ($flag == "unseen") |
---|
[51] | 1862 | $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); |
---|
[2] | 1863 | elseif ($flag == "seen") |
---|
[51] | 1864 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Seen", ST_UID); |
---|
[2] | 1865 | elseif ($flag == "answered"){ |
---|
[51] | 1866 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered", ST_UID); |
---|
| 1867 | imap_clearflag_full($this->mbox, $msgs_to_set, "\\Draft", ST_UID); |
---|
[2] | 1868 | } |
---|
| 1869 | elseif ($flag == "forwarded") |
---|
[51] | 1870 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Answered \\Draft", ST_UID); |
---|
[2] | 1871 | elseif ($flag == "flagged") |
---|
[51] | 1872 | $return["status"] = imap_setflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); |
---|
[2] | 1873 | elseif ($flag == "unflagged") |
---|
[51] | 1874 | $return["status"] = imap_clearflag_full($this->mbox, $msgs_to_set, "\\Flagged", ST_UID); |
---|
[449] | 1875 | |
---|
[411] | 1876 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 1877 | imap_close($this->mbox); |
---|
[2] | 1878 | return $return; |
---|
| 1879 | } |
---|
[449] | 1880 | |
---|
[2] | 1881 | function get_file_type($file_name) |
---|
| 1882 | { |
---|
| 1883 | $file_name = strtolower($file_name); |
---|
| 1884 | $strFileType = strrev(substr(strrev($file_name),0,4)); |
---|
[449] | 1885 | if ($strFileType == ".asf") |
---|
[2] | 1886 | return "video/x-ms-asf"; |
---|
| 1887 | if ($strFileType == ".avi") |
---|
| 1888 | return "video/avi"; |
---|
| 1889 | if ($strFileType == ".doc") |
---|
| 1890 | return "application/msword"; |
---|
| 1891 | if ($strFileType == ".zip") |
---|
| 1892 | return "application/zip"; |
---|
| 1893 | if ($strFileType == ".xls") |
---|
| 1894 | return "application/vnd.ms-excel"; |
---|
| 1895 | if ($strFileType == ".gif") |
---|
| 1896 | return "image/gif"; |
---|
| 1897 | if ($strFileType == ".jpg" || $strFileType == "jpeg") |
---|
| 1898 | return "image/jpeg"; |
---|
| 1899 | if ($strFileType == ".png") |
---|
| 1900 | return "image/png"; |
---|
| 1901 | if ($strFileType == ".wav") |
---|
| 1902 | return "audio/wav"; |
---|
| 1903 | if ($strFileType == ".mp3") |
---|
| 1904 | return "audio/mpeg3"; |
---|
| 1905 | if ($strFileType == ".mpg" || $strFileType == "mpeg") |
---|
| 1906 | return "video/mpeg"; |
---|
| 1907 | if ($strFileType == ".rtf") |
---|
| 1908 | return "application/rtf"; |
---|
| 1909 | if ($strFileType == ".htm" || $strFileType == "html") |
---|
| 1910 | return "text/html"; |
---|
[449] | 1911 | if ($strFileType == ".xml") |
---|
[2] | 1912 | return "text/xml"; |
---|
[449] | 1913 | if ($strFileType == ".xsl") |
---|
[2] | 1914 | return "text/xsl"; |
---|
[449] | 1915 | if ($strFileType == ".css") |
---|
[2] | 1916 | return "text/css"; |
---|
[449] | 1917 | if ($strFileType == ".php") |
---|
[2] | 1918 | return "text/php"; |
---|
[449] | 1919 | if ($strFileType == ".asp") |
---|
[2] | 1920 | return "text/asp"; |
---|
| 1921 | if ($strFileType == ".pdf") |
---|
| 1922 | return "application/pdf"; |
---|
| 1923 | if ($strFileType == ".txt") |
---|
| 1924 | return "text/plain"; |
---|
| 1925 | if ($strFileType == ".wmv") |
---|
| 1926 | return "video/x-ms-wmv"; |
---|
| 1927 | if ($strFileType == ".sxc") |
---|
| 1928 | return "application/vnd.sun.xml.calc"; |
---|
| 1929 | if ($strFileType == ".stc") |
---|
| 1930 | return "application/vnd.sun.xml.calc.template"; |
---|
| 1931 | if ($strFileType == ".sxd") |
---|
| 1932 | return "application/vnd.sun.xml.draw"; |
---|
| 1933 | if ($strFileType == ".std") |
---|
| 1934 | return "application/vnd.sun.xml.draw.template"; |
---|
| 1935 | if ($strFileType == ".sxi") |
---|
| 1936 | return "application/vnd.sun.xml.impress"; |
---|
| 1937 | if ($strFileType == ".sti") |
---|
| 1938 | return "application/vnd.sun.xml.impress.template"; |
---|
| 1939 | if ($strFileType == ".sxm") |
---|
| 1940 | return "application/vnd.sun.xml.math"; |
---|
| 1941 | if ($strFileType == ".sxw") |
---|
| 1942 | return "application/vnd.sun.xml.writer"; |
---|
| 1943 | if ($strFileType == ".sxq") |
---|
| 1944 | return "application/vnd.sun.xml.writer.global"; |
---|
| 1945 | if ($strFileType == ".stw") |
---|
| 1946 | return "application/vnd.sun.xml.writer.template"; |
---|
[449] | 1947 | |
---|
| 1948 | |
---|
| 1949 | return "application/octet-stream"; |
---|
[2] | 1950 | } |
---|
[449] | 1951 | |
---|
[2] | 1952 | function htmlspecialchars_encode($str) |
---|
| 1953 | { |
---|
[449] | 1954 | return str_replace( array('&', '"','\'','<','>','{','}'), array('&','"',''','<','>','{','}'), $str); |
---|
[2] | 1955 | } |
---|
| 1956 | function htmlspecialchars_decode($str) |
---|
| 1957 | { |
---|
[449] | 1958 | return str_replace( array('&','"',''','<','>','{','}'), array('&', '"','\'','<','>','{','}'), $str); |
---|
[2] | 1959 | } |
---|
[449] | 1960 | |
---|
[53] | 1961 | function get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse){ |
---|
[449] | 1962 | |
---|
[411] | 1963 | if(!$this->mbox || !is_resource($this->mbox)){ |
---|
[51] | 1964 | $this->mbox = $this->open_mbox($folder); |
---|
[449] | 1965 | |
---|
[411] | 1966 | } |
---|
[432] | 1967 | |
---|
[2] | 1968 | switch($sort_box_type){ |
---|
| 1969 | case 'SORTFROM': |
---|
[449] | 1970 | return $this->imap_sortfrom($sort_box_reverse, $search_box_type); |
---|
[2] | 1971 | case 'SORTSUBJECT': |
---|
[449] | 1972 | return imap_sort($this->mbox, SORTSUBJECT, $sort_box_reverse, SE_UID, $search_box_type); |
---|
[2] | 1973 | case 'SORTSIZE': |
---|
[449] | 1974 | return imap_sort($this->mbox, SORTSIZE, $sort_box_reverse, SE_UID, $search_box_type); |
---|
[53] | 1975 | default: |
---|
[449] | 1976 | return imap_sort($this->mbox, SORTARRIVAL, $sort_box_reverse, SE_UID, $search_box_type); |
---|
| 1977 | } |
---|
| 1978 | } |
---|
| 1979 | |
---|
[53] | 1980 | function get_info_next_msg($params) |
---|
| 1981 | { |
---|
| 1982 | $msg_number = $params['msg_number']; |
---|
| 1983 | $folder = $params['msg_folder']; |
---|
| 1984 | $sort_box_type = $params['sort_box_type']; |
---|
| 1985 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 1986 | $reuse_border = $params['reuse_border']; |
---|
| 1987 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
[449] | 1988 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
| 1989 | |
---|
[320] | 1990 | $success = false; |
---|
| 1991 | if (is_array($sort_array_msg)) |
---|
[2] | 1992 | { |
---|
[320] | 1993 | foreach ($sort_array_msg as $i => $value){ |
---|
| 1994 | if ($value == $msg_number) |
---|
| 1995 | { |
---|
| 1996 | $success = true; |
---|
| 1997 | break; |
---|
| 1998 | } |
---|
| 1999 | } |
---|
[2] | 2000 | } |
---|
| 2001 | |
---|
[320] | 2002 | if (! $success || $i >= sizeof($sort_array_msg)-1) |
---|
[2] | 2003 | { |
---|
| 2004 | $params['status'] = 'false'; |
---|
| 2005 | $params['command_to_exec'] = "delete_border('". $reuse_border ."');"; |
---|
| 2006 | return $params; |
---|
| 2007 | } |
---|
[449] | 2008 | |
---|
[2] | 2009 | $params = array(); |
---|
| 2010 | $params['msg_number'] = $sort_array_msg[($i+1)]; |
---|
| 2011 | $params['msg_folder'] = $folder; |
---|
[449] | 2012 | |
---|
| 2013 | $return = $this->get_info_msg($params); |
---|
[2] | 2014 | $return["reuse_border"] = $reuse_border; |
---|
| 2015 | return $return; |
---|
| 2016 | } |
---|
| 2017 | |
---|
| 2018 | function get_info_previous_msg($params) |
---|
| 2019 | { |
---|
| 2020 | $msg_number = $params['msgs_number']; |
---|
| 2021 | $folder = $params['folder']; |
---|
| 2022 | $sort_box_type = $params['sort_box_type']; |
---|
| 2023 | $sort_box_reverse = $params['sort_box_reverse']; |
---|
| 2024 | $reuse_border = $params['reuse_border']; |
---|
[53] | 2025 | $search_box_type = $params['search_box_type'] != "ALL" && $params['search_box_type'] != "" ? $params['search_box_type'] : false; |
---|
| 2026 | $sort_array_msg = $this -> get_msgs($folder, $sort_box_type, $search_box_type, $sort_box_reverse); |
---|
[449] | 2027 | |
---|
[320] | 2028 | $success = false; |
---|
| 2029 | if (is_array($sort_array_msg)) |
---|
[2] | 2030 | { |
---|
[320] | 2031 | foreach ($sort_array_msg as $i => $value){ |
---|
| 2032 | if ($value == $msg_number) |
---|
| 2033 | { |
---|
| 2034 | $success = true; |
---|
| 2035 | break; |
---|
| 2036 | } |
---|
| 2037 | } |
---|
[2] | 2038 | } |
---|
[320] | 2039 | if (! $success || $i == 0) |
---|
| 2040 | { |
---|
[2] | 2041 | $params['status'] = 'false'; |
---|
| 2042 | $params['command_to_exec'] = "delete_border('". $reuse_border ."');"; |
---|
| 2043 | return $params; |
---|
| 2044 | } |
---|
[449] | 2045 | |
---|
[2] | 2046 | $params = array(); |
---|
| 2047 | $params['msg_number'] = $sort_array_msg[($i-1)]; |
---|
| 2048 | $params['msg_folder'] = $folder; |
---|
[449] | 2049 | |
---|
[2] | 2050 | $return = $this->get_info_msg($params); |
---|
| 2051 | $return["reuse_border"] = $reuse_border; |
---|
| 2052 | return $return; |
---|
| 2053 | } |
---|
[449] | 2054 | |
---|
[2] | 2055 | // This function updates the values: quota, paging and new messages menu. |
---|
| 2056 | function get_menu_values($params){ |
---|
| 2057 | $return_array = array(); |
---|
| 2058 | $return_array = $this->get_quota($params); |
---|
[449] | 2059 | |
---|
[2] | 2060 | $mbox_stream = $this->open_mbox($params['folder']); |
---|
[449] | 2061 | $return_array['num_msgs'] = imap_num_msg($mbox_stream); |
---|
[51] | 2062 | if($mbox_stream) |
---|
| 2063 | imap_close($mbox_stream); |
---|
[449] | 2064 | |
---|
| 2065 | return $return_array; |
---|
[2] | 2066 | } |
---|
[449] | 2067 | |
---|
[325] | 2068 | function get_quota($params){ |
---|
[449] | 2069 | // folder_id = user/{uid} for shared folders |
---|
| 2070 | if(substr($params['folder_id'],0,5) != 'INBOX' && preg_match('/user\\'.$this->imap_delimiter.'/i', $params['folder_id'])){ |
---|
| 2071 | $array_folder = explode($this->imap_delimiter,$params['folder_id']); |
---|
| 2072 | $folder_id = "user".$this->imap_delimiter.$array_folder[1]; |
---|
| 2073 | } |
---|
| 2074 | // folder_id = INBOX for inbox folders |
---|
| 2075 | else |
---|
| 2076 | $folder_id = "INBOX"; |
---|
| 2077 | |
---|
| 2078 | if(!$this->mbox) |
---|
[51] | 2079 | $this->mbox = $this->open_mbox(); |
---|
[345] | 2080 | |
---|
[325] | 2081 | $quota = imap_get_quotaroot($this->mbox, $folder_id); |
---|
[411] | 2082 | if($this->mbox && is_resource($this->mbox)) |
---|
[51] | 2083 | imap_close($this->mbox); |
---|
[449] | 2084 | |
---|
[2] | 2085 | if (!$quota){ |
---|
| 2086 | return array( |
---|
| 2087 | 'quota_percent' => 0, |
---|
| 2088 | 'quota_used' => 0, |
---|
| 2089 | 'quota_limit' => 0 |
---|
| 2090 | ); |
---|
| 2091 | } |
---|
[449] | 2092 | |
---|
[2] | 2093 | if(count($quota) && $quota['limit']) { |
---|
| 2094 | $quota_limit = (($quota['limit']/1024)* 100 + .5 )* .01; |
---|
| 2095 | $quota_used = (($quota['usage']/1024)* 100 + .5 )* .01; |
---|
| 2096 | if($quota_used >= $quota_limit) |
---|
| 2097 | $quota_used = $quota_limit; |
---|
| 2098 | $quotaPercent = ($quota_used / $quota_limit)*100; |
---|
| 2099 | $quotaPercent = (($quotaPercent)* 100 + .5 )* .01; |
---|
| 2100 | |
---|
| 2101 | return array( |
---|
| 2102 | 'quota_percent' => floor($quotaPercent), |
---|
| 2103 | 'quota_used' => floor($quota_used), |
---|
| 2104 | 'quota_limit' => floor($quota_limit) |
---|
| 2105 | ); |
---|
| 2106 | } |
---|
[449] | 2107 | else |
---|
[2] | 2108 | return array(); |
---|
| 2109 | } |
---|
[449] | 2110 | |
---|
[2] | 2111 | function send_notification($params){ |
---|
| 2112 | require_once("class.phpmailer.php"); |
---|
| 2113 | $mail = new PHPMailer(); |
---|
[449] | 2114 | |
---|
[2] | 2115 | $toaddress = $params['notificationto']; |
---|
[449] | 2116 | |
---|
| 2117 | $subject = 'Confirmação de leitura: ' . $params['subject']; |
---|
[2] | 2118 | $body = 'Sua mensagem: ' . $params['subject'] . '<br>'; |
---|
| 2119 | $body .= 'foi lida por: ' . $_SESSION['phpgw_info']['expressomail']['user']['fullname'] . ' <' . $_SESSION['phpgw_info']['expressomail']['user']['email'] . '> em ' . date("d/m/Y H:i"); |
---|
| 2120 | $mail->SMTPDebug = false; |
---|
| 2121 | $mail->IsSMTP(); |
---|
| 2122 | $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; |
---|
| 2123 | $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; |
---|
| 2124 | $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
| 2125 | $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
| 2126 | $mail->AddAddress($toaddress); |
---|
| 2127 | $mail->Subject = $this->htmlspecialchars_decode($subject); |
---|
| 2128 | |
---|
| 2129 | $mail->IsHTML(true); |
---|
| 2130 | $mail->Body = $body; |
---|
[449] | 2131 | |
---|
[2] | 2132 | if(!$mail->Send()){ |
---|
| 2133 | return $mail->ErrorInfo; |
---|
| 2134 | } |
---|
| 2135 | else |
---|
| 2136 | return true; |
---|
| 2137 | } |
---|
[449] | 2138 | |
---|
[2] | 2139 | function empty_trash() |
---|
| 2140 | { |
---|
[449] | 2141 | $folder = 'INBOX' . $this->imap_delimiter . $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']; |
---|
[2] | 2142 | $mbox_stream = $this->open_mbox($folder); |
---|
| 2143 | $return = imap_delete($mbox_stream,'1:*'); |
---|
[51] | 2144 | if($mbox_stream) |
---|
| 2145 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 2146 | return $return; |
---|
| 2147 | } |
---|
[449] | 2148 | |
---|
[2] | 2149 | function search($params) |
---|
| 2150 | { |
---|
| 2151 | include("class.imap_attachment.inc.php"); |
---|
[449] | 2152 | $imap_attachment = new imap_attachment(); |
---|
[2] | 2153 | $criteria = $params['criteria']; |
---|
| 2154 | $return = array(); |
---|
| 2155 | $folders = $this->get_folders_list(); |
---|
[449] | 2156 | |
---|
[2] | 2157 | $j = 0; |
---|
| 2158 | foreach($folders as $folder) |
---|
| 2159 | { |
---|
| 2160 | $mbox_stream = $this->open_mbox($folder); |
---|
| 2161 | $messages = imap_search($mbox_stream, $criteria, SE_UID); |
---|
[449] | 2162 | |
---|
[2] | 2163 | if ($messages == '') |
---|
| 2164 | continue; |
---|
[449] | 2165 | |
---|
[2] | 2166 | $i = 0; |
---|
| 2167 | $return[$j] = array(); |
---|
| 2168 | $return[$j]['folder_name'] = $folder['name']; |
---|
[449] | 2169 | |
---|
[2] | 2170 | foreach($messages as $msg_number) |
---|
| 2171 | { |
---|
[535] | 2172 | $header = $this->get_header($msg_number); |
---|
[2] | 2173 | if (!is_object($header)) |
---|
| 2174 | return false; |
---|
[449] | 2175 | |
---|
[2] | 2176 | $return[$j][$i]['msg_folder'] = $folder['name']; |
---|
| 2177 | $return[$j][$i]['msg_number'] = $msg_number; |
---|
| 2178 | $return[$j][$i]['Recent'] = $header->Recent; |
---|
| 2179 | $return[$j][$i]['Unseen'] = $header->Unseen; |
---|
| 2180 | $return[$j][$i]['Answered'] = $header->Answered; |
---|
| 2181 | $return[$j][$i]['Deleted'] = $header->Deleted; |
---|
| 2182 | $return[$j][$i]['Draft'] = $header->Draft; |
---|
| 2183 | $return[$j][$i]['Flagged'] = $header->Flagged; |
---|
[449] | 2184 | |
---|
[535] | 2185 | $date_msg = gmdate("d/m/Y",$header->udate); |
---|
| 2186 | if (gmdate("d/m/Y") == $date_msg) |
---|
| 2187 | $return[$j][$i]['udate'] = gmdate("H:i",$header->udate); |
---|
[2] | 2188 | else |
---|
| 2189 | $return[$j][$i]['udate'] = $date_msg; |
---|
[449] | 2190 | |
---|
[2] | 2191 | $fromaddress = imap_mime_header_decode($header->fromaddress); |
---|
| 2192 | $return[$j][$i]['fromaddress'] = ''; |
---|
| 2193 | foreach ($fromaddress as $tmp) |
---|
| 2194 | $return[$j][$i]['fromaddress'] .= $this->replace_maior_menor($tmp->text); |
---|
[449] | 2195 | |
---|
[2] | 2196 | $from = $header->from; |
---|
| 2197 | $return[$j][$i]['from'] = array(); |
---|
| 2198 | $tmp = imap_mime_header_decode($from[0]->personal); |
---|
| 2199 | $return[$j][$i]['from']['name'] = $tmp[0]->text; |
---|
| 2200 | $return[$j][$i]['from']['email'] = $from[0]->mailbox . "@" . $from[0]->host; |
---|
[449] | 2201 | $return[$j][$i]['from']['full'] ='"' . $return[$j][$i]['from']['name'] . '" ' . '<' . $return[$j][$i]['from']['email'] . '>'; |
---|
[2] | 2202 | |
---|
| 2203 | $to = $header->to; |
---|
| 2204 | $return[$j][$i]['to'] = array(); |
---|
| 2205 | $tmp = imap_mime_header_decode($to[0]->personal); |
---|
| 2206 | $return[$j][$i]['to']['name'] = $tmp[0]->text; |
---|
| 2207 | $return[$j][$i]['to']['email'] = $to[0]->mailbox . "@" . $to[0]->host; |
---|
[449] | 2208 | $return[$j][$i]['to']['full'] ='"' . $return[$i]['to']['name'] . '" ' . '<' . $return[$i]['to']['email'] . '>'; |
---|
[2] | 2209 | |
---|
| 2210 | $subject = imap_mime_header_decode($header->fetchsubject); |
---|
| 2211 | $return[$j][$i]['subject'] = ''; |
---|
| 2212 | foreach ($subject as $tmp) |
---|
| 2213 | $return[$j][$i]['subject'] .= $tmp->text; |
---|
| 2214 | |
---|
| 2215 | $return[$j][$i]['Size'] = $header->Size; |
---|
| 2216 | $return[$j][$i]['reply_toaddress'] = $header->reply_toaddress; |
---|
[449] | 2217 | |
---|
[2] | 2218 | $return[$j][$i]['attachment'] = array(); |
---|
| 2219 | $return[$j][$i]['attachment'] = $imap_attachment->get_attachment_headerinfo($mbox_stream, $msg_number); |
---|
[449] | 2220 | |
---|
[2] | 2221 | $i++; |
---|
| 2222 | } |
---|
| 2223 | $j++; |
---|
[51] | 2224 | if($mbox_stream) |
---|
| 2225 | imap_close($mbox_stream); |
---|
[2] | 2226 | } |
---|
[449] | 2227 | |
---|
[2] | 2228 | return $return; |
---|
| 2229 | } |
---|
[449] | 2230 | |
---|
[2] | 2231 | function delete_and_show_previous_message($params) |
---|
| 2232 | { |
---|
| 2233 | $return = $this->get_info_previous_msg($params); |
---|
[449] | 2234 | |
---|
[2] | 2235 | $params_tmp1 = array(); |
---|
| 2236 | $params_tmp1['msgs_to_delete'] = $params['msg_number']; |
---|
| 2237 | $params_tmp1['folder'] = $params['msg_folder']; |
---|
| 2238 | $return_tmp1 = $this->delete_msg($params_tmp1); |
---|
[449] | 2239 | |
---|
[2] | 2240 | $return['msg_number_deleted'] = $return_tmp1; |
---|
[449] | 2241 | |
---|
[2] | 2242 | return $return; |
---|
| 2243 | } |
---|
[449] | 2244 | |
---|
| 2245 | |
---|
[2] | 2246 | function automatic_trash_cleanness($params) |
---|
| 2247 | { |
---|
| 2248 | $before_date = date("m/d/Y", strtotime("-".$params['before_date']." day")); |
---|
| 2249 | $criteria = 'BEFORE "'.$before_date.'"'; |
---|
[325] | 2250 | $mbox_stream = $this->open_mbox('INBOX'.$this->imap_delimiter.$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']); |
---|
[2] | 2251 | $messages = imap_search($mbox_stream, $criteria, SE_UID); |
---|
| 2252 | if (is_array($messages)){ |
---|
| 2253 | foreach ($messages as $msg_number){ |
---|
| 2254 | imap_delete($mbox_stream, $msg_number, FT_UID); |
---|
| 2255 | } |
---|
| 2256 | } |
---|
[51] | 2257 | if($mbox_stream) |
---|
| 2258 | imap_close($mbox_stream, CL_EXPUNGE); |
---|
[2] | 2259 | return $messages; |
---|
| 2260 | } |
---|
| 2261 | // Fix the search problem with special characters!!!! |
---|
| 2262 | function remove_accents($string) { |
---|
[449] | 2263 | return strtr($string, |
---|
| 2264 | "?Ó??ó?Ý?úÁÀÃÂÄÇÉÈÊËÍÌ?ÎÏÑÕÔÓÒÖÚÙ?ÛÜ?áàãâäçéèêëíì?îïñóòõôöúù?ûüýÿ", |
---|
[2] | 2265 | "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); |
---|
| 2266 | } |
---|
| 2267 | |
---|
[469] | 2268 | function search_msg($params = ''){ |
---|
[2] | 2269 | $retorno = ""; |
---|
[271] | 2270 | $mbox_stream = ""; |
---|
[2] | 2271 | $search = explode(",",$params['condition']); |
---|
| 2272 | if($search){ |
---|
| 2273 | $search_criteria = ''; |
---|
[271] | 2274 | foreach($search as $tmp) |
---|
| 2275 | { |
---|
[2] | 2276 | $tmp1 = explode("##",$tmp); |
---|
| 2277 | $name_box = $tmp1[0]; |
---|
[372] | 2278 | unset($filter); |
---|
| 2279 | foreach($tmp1 as $index => $criteria) |
---|
| 2280 | { |
---|
| 2281 | if ($index != 0 && strlen($criteria) != 0) |
---|
| 2282 | { |
---|
| 2283 | $filter_array = explode("<=>",rawurldecode($criteria)); |
---|
| 2284 | $filter .= " ".$filter_array[0]; |
---|
| 2285 | $filter .= '"'.$filter_array[1].'"'; |
---|
| 2286 | } |
---|
[449] | 2287 | } |
---|
| 2288 | $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" ); |
---|
[372] | 2289 | $filter = $this->remove_accents($filter); |
---|
[469] | 2290 | //Este bloco tem a finalidade de transformar o CPF das pastas compartilhadas em common name |
---|
[432] | 2291 | $folder_name = explode($this->imap_delimiter,$name_box); |
---|
[469] | 2292 | if (is_numeric($folder_name[1])) { |
---|
| 2293 | $this->ldap = new ldap_functions(); |
---|
| 2294 | if ($cn = $this->ldap->uid2cn($folder_name[1])) { |
---|
| 2295 | $folder_name[1] = $cn; |
---|
[432] | 2296 | } |
---|
| 2297 | } |
---|
| 2298 | $folder_name = implode($this->imap_delimiter,$folder_name); |
---|
[449] | 2299 | |
---|
[271] | 2300 | if(!is_resource($mbox_stream)) |
---|
[372] | 2301 | $mbox_stream = $this->open_mbox($name_box); |
---|
[271] | 2302 | else |
---|
| 2303 | imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); |
---|
[449] | 2304 | |
---|
| 2305 | if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search |
---|
| 2306 | |
---|
[271] | 2307 | $all_criterias = array ("TO","SUBJECT","FROM","CC"); |
---|
| 2308 | foreach($all_criterias as $criteria_fixed) |
---|
| 2309 | { |
---|
[372] | 2310 | $_filter = $criteria_fixed . substr($filter,4); |
---|
[449] | 2311 | |
---|
[372] | 2312 | $search_criteria = imap_search($mbox_stream, $_filter, SE_UID); |
---|
[449] | 2313 | |
---|
[271] | 2314 | if($search_criteria && count($search_criteria) < 50) |
---|
| 2315 | { |
---|
[2] | 2316 | foreach($search_criteria as $new_search){ |
---|
[449] | 2317 | $m_token = trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n"); |
---|
[271] | 2318 | if(!@strstr($retorno,$m_token)) |
---|
[2] | 2319 | $retorno .= $m_token; |
---|
| 2320 | } |
---|
[449] | 2321 | } |
---|
| 2322 | else if(count($search_criteria) >= 50) |
---|
| 2323 | return "many results"; |
---|
[2] | 2324 | } |
---|
[271] | 2325 | } |
---|
[2] | 2326 | else { |
---|
[271] | 2327 | $search_criteria = imap_search($mbox_stream, $filter, SE_UID); |
---|
[372] | 2328 | if( is_array( $search_criteria) ) |
---|
| 2329 | { |
---|
| 2330 | foreach($search_criteria as $new_search) |
---|
[449] | 2331 | $retorno .= trim("##".mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n"); |
---|
[2] | 2332 | } |
---|
| 2333 | } |
---|
| 2334 | } |
---|
[271] | 2335 | } |
---|
| 2336 | if($mbox_stream) |
---|
[449] | 2337 | imap_close($mbox_stream); |
---|
| 2338 | |
---|
[2] | 2339 | return $retorno ? $retorno : "none"; |
---|
| 2340 | } |
---|
[449] | 2341 | |
---|
[271] | 2342 | function get_msg($uid_msg,$name_box, $mbox_stream ) |
---|
| 2343 | { |
---|
[535] | 2344 | $header = $this->get_header($uid_msg); |
---|
[163] | 2345 | $subject = $this->decode_string($header->fetchsubject); |
---|
| 2346 | $from = $header->from[0]->mailbox; |
---|
[2] | 2347 | if($header->from[0]->personal != "") |
---|
| 2348 | $from = $header->from[0]->personal; |
---|
[535] | 2349 | $ret_msg = $this->decode_string($from) . "--" . $subject . "--". gmdate("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size); |
---|
[449] | 2350 | return $ret_msg; |
---|
| 2351 | } |
---|
| 2352 | |
---|
[2] | 2353 | function size_msg($size){ |
---|
| 2354 | $var = floor($size/1024); |
---|
| 2355 | if($var >= 1){ |
---|
[449] | 2356 | return $var." kb"; |
---|
[2] | 2357 | }else{ |
---|
[449] | 2358 | return $size ." b"; |
---|
[2] | 2359 | } |
---|
| 2360 | } |
---|
| 2361 | |
---|
| 2362 | function ob_array($the_object) |
---|
| 2363 | { |
---|
| 2364 | $the_array=array(); |
---|
| 2365 | if(!is_scalar($the_object)) |
---|
| 2366 | { |
---|
| 2367 | foreach($the_object as $id => $object) |
---|
| 2368 | { |
---|
| 2369 | if(is_scalar($object)) |
---|
| 2370 | { |
---|
| 2371 | $the_array[$id]=$object; |
---|
| 2372 | } |
---|
| 2373 | else |
---|
| 2374 | { |
---|
| 2375 | $the_array[$id]=$this->ob_array($object); |
---|
| 2376 | } |
---|
| 2377 | } |
---|
| 2378 | return $the_array; |
---|
| 2379 | } |
---|
| 2380 | else |
---|
| 2381 | { |
---|
| 2382 | return $the_object; |
---|
| 2383 | } |
---|
| 2384 | } |
---|
[449] | 2385 | |
---|
[2] | 2386 | function getacl() |
---|
| 2387 | { |
---|
| 2388 | $this->ldap = new ldap_functions(); |
---|
[449] | 2389 | |
---|
[2] | 2390 | $return = array(); |
---|
[449] | 2391 | $mbox_stream = $this->open_mbox(); |
---|
[2] | 2392 | $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); |
---|
[449] | 2393 | |
---|
[2] | 2394 | $i = 0; |
---|
| 2395 | foreach ($mbox_acl as $user => $acl) |
---|
| 2396 | { |
---|
| 2397 | if ($user != $this->username) |
---|
| 2398 | { |
---|
| 2399 | $return[$i]['uid'] = $user; |
---|
| 2400 | $return[$i]['cn'] = $this->ldap->uid2cn($user); |
---|
| 2401 | } |
---|
| 2402 | $i++; |
---|
| 2403 | } |
---|
| 2404 | return $return; |
---|
| 2405 | } |
---|
[449] | 2406 | |
---|
[2] | 2407 | function setacl($params) |
---|
| 2408 | { |
---|
| 2409 | $old_users = $this->getacl(); |
---|
| 2410 | if (!count($old_users)) |
---|
| 2411 | $old_users = array(); |
---|
[449] | 2412 | |
---|
[2] | 2413 | $tmp_array = array(); |
---|
| 2414 | foreach ($old_users as $index => $user_info) |
---|
| 2415 | { |
---|
| 2416 | $tmp_array[$index] = $user_info['uid']; |
---|
| 2417 | } |
---|
| 2418 | $old_users = $tmp_array; |
---|
[449] | 2419 | |
---|
[2] | 2420 | $users = unserialize($params['users']); |
---|
| 2421 | if (!count($users)) |
---|
| 2422 | $users = array(); |
---|
[449] | 2423 | |
---|
[2] | 2424 | //$add_share = array_diff($users, $old_users); |
---|
| 2425 | $remove_share = array_diff($old_users, $users); |
---|
| 2426 | |
---|
| 2427 | $mbox_stream = $this->open_mbox(); |
---|
| 2428 | |
---|
| 2429 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 2430 | $mailboxes_list = imap_getmailboxes($mbox_stream, $serverString, "user".$this->imap_delimiter.$this->username."*"); |
---|
| 2431 | |
---|
| 2432 | /*if (count($add_share)) |
---|
| 2433 | { |
---|
| 2434 | foreach ($add_share as $index=>$uid) |
---|
| 2435 | { |
---|
| 2436 | if (is_array($mailboxes_list)) |
---|
| 2437 | { |
---|
| 2438 | foreach ($mailboxes_list as $key => $val) |
---|
| 2439 | { |
---|
| 2440 | $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); |
---|
| 2441 | imap_setacl ($mbox_stream, $folder, "$uid", "lrswipcda"); |
---|
| 2442 | } |
---|
| 2443 | } |
---|
| 2444 | } |
---|
| 2445 | }*/ |
---|
[449] | 2446 | |
---|
[2] | 2447 | if (count($remove_share)) |
---|
| 2448 | { |
---|
| 2449 | foreach ($remove_share as $index=>$uid) |
---|
| 2450 | { |
---|
| 2451 | if (is_array($mailboxes_list)) |
---|
| 2452 | { |
---|
| 2453 | foreach ($mailboxes_list as $key => $val) |
---|
| 2454 | { |
---|
| 2455 | $folder = str_replace($serverString, "", imap_utf7_decode($val->name)); |
---|
| 2456 | imap_setacl ($mbox_stream, $folder, "$uid", ""); |
---|
| 2457 | } |
---|
| 2458 | } |
---|
[449] | 2459 | } |
---|
[2] | 2460 | } |
---|
[449] | 2461 | |
---|
[2] | 2462 | return true; |
---|
| 2463 | } |
---|
[449] | 2464 | |
---|
[2] | 2465 | function getaclfromuser($params) |
---|
| 2466 | { |
---|
| 2467 | $useracl = $params['user']; |
---|
[449] | 2468 | |
---|
[2] | 2469 | $return = array(); |
---|
| 2470 | $return[$useracl] = 'false'; |
---|
[449] | 2471 | $mbox_stream = $this->open_mbox(); |
---|
[2] | 2472 | $mbox_acl = imap_getacl($mbox_stream, 'INBOX'); |
---|
[449] | 2473 | |
---|
[2] | 2474 | foreach ($mbox_acl as $user => $acl) |
---|
| 2475 | { |
---|
| 2476 | if (($user != $this->username) && ($user == $useracl)) |
---|
| 2477 | { |
---|
| 2478 | $return[$user] = $acl; |
---|
| 2479 | } |
---|
| 2480 | } |
---|
| 2481 | return $return; |
---|
| 2482 | } |
---|
| 2483 | |
---|
| 2484 | function getacltouser($user) |
---|
| 2485 | { |
---|
| 2486 | $return = array(); |
---|
| 2487 | $mbox_stream = $this->open_mbox(); |
---|
[325] | 2488 | //Alterado, antes era 'imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); |
---|
| 2489 | //Afim de tratar as pastas compartilhadas, verificandos as permissoes de operacao sobre as mesmas |
---|
| 2490 | //No caso de se tratar da caixa do proprio usuario logado, utiliza a sintaxe abaixo |
---|
| 2491 | if(substr($user,0,4) != 'user') |
---|
[449] | 2492 | $mbox_acl = imap_getacl($mbox_stream, 'user'.$this->imap_delimiter.$user); |
---|
[325] | 2493 | else |
---|
| 2494 | $mbox_acl = imap_getacl($mbox_stream, $user); |
---|
[2] | 2495 | return $mbox_acl[$this->username]; |
---|
| 2496 | } |
---|
[449] | 2497 | |
---|
[2] | 2498 | |
---|
| 2499 | function setaclfromuser($params) |
---|
| 2500 | { |
---|
| 2501 | $user = $params['user']; |
---|
| 2502 | $acl = $params['acl']; |
---|
[449] | 2503 | |
---|
[2] | 2504 | $mbox_stream = $this->open_mbox(); |
---|
| 2505 | |
---|
| 2506 | $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"; |
---|
| 2507 | $mailboxes_list = imap_getmailboxes($mbox_stream, $serverString, "user".$this->imap_delimiter.$this->username."*"); |
---|
| 2508 | |
---|
| 2509 | if (is_array($mailboxes_list)) |
---|
| 2510 | { |
---|
| 2511 | foreach ($mailboxes_list as $key => $val) |
---|
| 2512 | { |
---|
[449] | 2513 | $folder = str_replace($serverString, "", imap_utf7_encode($val->name)); |
---|
| 2514 | $folder = str_replace("&-", "&", $folder); |
---|
[2] | 2515 | if (!imap_setacl ($mbox_stream, $folder, $user, $acl)) |
---|
| 2516 | { |
---|
[449] | 2517 | $return = imap_last_error(); |
---|
[2] | 2518 | } |
---|
| 2519 | } |
---|
| 2520 | } |
---|
[449] | 2521 | if (isset($return)) |
---|
| 2522 | return $return; |
---|
| 2523 | else |
---|
| 2524 | return true; |
---|
[2] | 2525 | } |
---|
[449] | 2526 | |
---|
[51] | 2527 | function download_attachment($msg,$msgno) |
---|
| 2528 | { |
---|
[449] | 2529 | $array_parts_attachments = array(); |
---|
[51] | 2530 | $array_parts_attachments['names'] = ''; |
---|
| 2531 | include("class.imap_attachment.inc.php"); |
---|
[449] | 2532 | $imap_attachment = new imap_attachment(); |
---|
| 2533 | |
---|
[51] | 2534 | if (count($msg->fname[$msgno]) > 0) |
---|
| 2535 | { |
---|
| 2536 | $i = 0; |
---|
| 2537 | foreach ($msg->fname[$msgno] as $index=>$fname) |
---|
| 2538 | { |
---|
| 2539 | $array_parts_attachments[$i]['pid'] = $msg->pid[$msgno][$index]; |
---|
| 2540 | $array_parts_attachments[$i]['name'] = $imap_attachment->flat_mime_decode($fname); |
---|
| 2541 | $array_parts_attachments[$i]['name'] = $array_parts_attachments[$i]['name'] ? $array_parts_attachments[$i]['name'] : "attachment.bin"; |
---|
| 2542 | $array_parts_attachments[$i]['encoding'] = $msg->encoding[$msgno][$index]; |
---|
| 2543 | $array_parts_attachments['names'] .= $array_parts_attachments[$i]['name'] . ', '; |
---|
| 2544 | $array_parts_attachments[$i]['fsize'] = $msg->fsize[$msgno][$index]; |
---|
| 2545 | $i++; |
---|
| 2546 | } |
---|
| 2547 | } |
---|
| 2548 | $array_parts_attachments['names'] = substr($array_parts_attachments['names'],0,(strlen($array_parts_attachments['names']) - 2)); |
---|
| 2549 | return $array_parts_attachments; |
---|
[449] | 2550 | } |
---|
[69] | 2551 | |
---|
| 2552 | function spam($params) |
---|
| 2553 | { |
---|
| 2554 | $is_spam = $params['spam']; |
---|
| 2555 | $folder = $params['folder']; |
---|
| 2556 | $mbox_stream = $this->open_mbox($folder); |
---|
| 2557 | $msgs_number = explode(',',$params['msgs_number']); |
---|
| 2558 | |
---|
| 2559 | foreach($msgs_number as $msg_number) { |
---|
| 2560 | $header = imap_fetchheader($mbox_stream, imap_msgno($mbox_stream, $msg_number)); |
---|
| 2561 | $body = imap_body($mbox_stream, imap_msgno($mbox_stream, $msg_number)); |
---|
| 2562 | $msg = $header . $body; |
---|
| 2563 | $email = $_SESSION['phpgw_info']['expressomail']['user']['email']; |
---|
[449] | 2564 | $username = $this->username; |
---|
[69] | 2565 | strtok($email, '@'); |
---|
| 2566 | $domain = strtok('@'); |
---|
| 2567 | |
---|
[449] | 2568 | //Encontrar a assinatura do dspam no cabecalho |
---|
| 2569 | $v = explode("\r\n", $header); |
---|
| 2570 | foreach ($v as $linha){ |
---|
| 2571 | if (eregi("^X-DSPAM-Signature", $linha)) { |
---|
| 2572 | |
---|
| 2573 | $args = explode(" ",$linha); |
---|
| 2574 | $signature = $args[1]; |
---|
| 2575 | } |
---|
| 2576 | } |
---|
| 2577 | |
---|
[69] | 2578 | // feed dspam |
---|
[449] | 2579 | switch($is_spam){ |
---|
| 2580 | case 'true': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam']; break; |
---|
| 2581 | case 'false': $cmd = $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham']; break; |
---|
| 2582 | } |
---|
| 2583 | $tags = array('##EMAIL##', '##USERNAME##', '##DOMAIN##', '##SIGNATURE##'); |
---|
| 2584 | $cmd = str_replace($tags,array($email,$username,$domain,$signature),$cmd); |
---|
[78] | 2585 | system($cmd); |
---|
[69] | 2586 | } |
---|
| 2587 | imap_close($mbox_stream); |
---|
| 2588 | return false; |
---|
| 2589 | } |
---|
[535] | 2590 | function get_header($msg_number){ |
---|
| 2591 | $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); |
---|
| 2592 | if (!is_object($header)) |
---|
| 2593 | return false; |
---|
| 2594 | // Prepare udate from mailDate (DateTime arrived with TZ) for fixing summertime problem. |
---|
| 2595 | $pdate = date_parse($header->MailDate); |
---|
| 2596 | $header->udate += $pdate['zone']*(-60); |
---|
| 2597 | return $header; |
---|
| 2598 | } |
---|
[2] | 2599 | } |
---|
[278] | 2600 | ?> |
---|