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