Changeset 4795
- Timestamp:
- 07/19/11 09:32:37 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.imap_functions.inc.php
r4784 r4795 88 88 } 89 89 // This condition verifies if SESSION is expired. 90 elseif(!count($_SESSION)) 90 elseif(!count($_SESSION)) 91 91 return "nosession"; 92 92 … … 288 288 */ 289 289 function decode_string($string) 290 { 291 292 290 { 291 if ((strpos(strtolower($string), '=?iso-8859-1') !== false) || (strpos(strtolower($string), '=?windows-1252') !== false)) 292 { 293 293 $retun = ''; 294 295 294 $tmp = imap_mime_header_decode($string); 295 foreach ($tmp as $tmp1) 296 296 { 297 297 $return .= $this->htmlspecialchars_encode($tmp1->text); 298 298 } 299 299 300 300 return str_replace("\t", "", $return); 301 302 303 304 305 306 307 308 $charset = strtolower($elements[$i]->charset); 309 $text = $elements[$i]->text; 310 311 312 313 314 315 316 317 318 319 301 } 302 else if (strpos(strtolower($string), '=?utf-8') !== false) 303 { 304 $elements = imap_mime_header_decode($string); 305 306 for($i = 0;$i < count($elements);$i++) 307 { 308 $charset = strtolower($elements[$i]->charset); 309 $text = $elements[$i]->text; 310 if(!strcasecmp($charset, "utf-8") || !strcasecmp($charset, "utf-7")) 311 $decoded .= $this->functions->utf8_to_ncr($text); 312 else 313 { 314 if( strcasecmp($charset,"default") ) 315 $decoded .= $this->htmlspecialchars_encode(iconv($charset, "iso-8859-1", $text)); 316 else 317 $decoded .= $this->htmlspecialchars_encode($text); 318 } 319 } 320 320 321 321 return str_replace("\t", "", $decoded); 322 322 } 323 323 else if(strpos(strtolower($string), '=?us-ascii') !== false) 324 324 { … … 335 335 336 336 337 338 337 return $this->htmlspecialchars_encode($string); 338 } 339 339 /** 340 340 * Função que importa arquivos .eml exportados pelo expresso para a caixa do usuário. Testado apenas … … 581 581 return $return; 582 582 } 583 583 584 584 /** 585 585 * @license http://www.gnu.org/copyleft/gpl.html GPL … … 822 822 823 823 if(preg_match('(.+)(_[a-zA-Z0-9]+)',$msg_number,$matches)) { //Verifies if it comes from a tab diferent of the main one. 824 $msg_number = $matches[1]; 825 $plus_id = $matches[2]; 826 } 827 else { 828 $plus_id = ''; 829 } 830 824 $msg_number = $matches[1]; 825 $plus_id = $matches[2]; 826 } 827 else { 828 $plus_id = ''; 829 } 830 831 831 if(!$this->mbox || !is_resource($this->mbox)) 832 $this->mbox = $this->open_mbox($msg_folder); 832 $this->mbox = $this->open_mbox($msg_folder); 833 833 834 834 $header = $this->get_header($msg_number); 835 835 if (!$header) { 836 $return['status_get_msg_info'] = "false"; 836 $return['status_get_msg_info'] = "false"; 837 837 return $return; 838 838 } 839 840 $header_ = imap_fetchheader($this->mbox, $msg_number, FT_UID); 839 840 $header_ = imap_fetchheader($this->mbox, $msg_number, FT_UID); 841 841 $return_get_body = $this->get_body_msg($msg_number, $msg_folder); 842 842 $body = $return_get_body['body']; 843 843 844 844 if($return_get_body['body']=='isCripted'){ 845 845 $exporteml = new ExportEml(); … … 851 851 //return $return; 852 852 }else{ 853 854 855 856 857 853 $return['body'] = $body; 854 $return['attachments'] = $return_get_body['attachments']; 855 $return['thumbs'] = $return_get_body['thumbs']; 856 $return['signature'] = $return_get_body['signature']; 857 } 858 858 $pattern = '/^[ \t]*Disposition-Notification-To:[ ]*<?[[:alnum:]\._-]+@[[:alnum:]_-]+[\.[:alnum:]]+>?/sm'; 859 859 if (preg_match($pattern, $header_, $fields)) 860 860 { 861 if(preg_match('/[[:alnum:]\._\-]+@[[:alnum:]_\-\.]+/',$fields[0], $matches)){ 862 $return['DispositionNotificationTo'] = "<".$matches[0].">"; 863 } 861 if(preg_match('/[[:alnum:]\._\-]+@[[:alnum:]_\-\.]+/',$fields[0], $matches)){ 862 $return['DispositionNotificationTo'] = "<".$matches[0].">"; 863 } 864 864 } 865 865 866 866 $return['Recent'] = $header->Recent; 867 867 $return['Unseen'] = $header->Unseen; 868 $return['Deleted'] = $header->Deleted; 868 $return['Deleted'] = $header->Deleted; 869 869 $return['Flagged'] = $header->Flagged; 870 870 … … 872 872 $return['Forwarded'] = 'F'; 873 873 } 874 874 875 875 else { 876 876 $return['Answered'] = $header->Answered; 877 $return['Draft'] = $header->Draft; 878 } 879 880 $return['msg_number'] = $msg_number.$plus_id; 877 $return['Draft'] = $header->Draft; 878 } 879 880 $return['msg_number'] = $msg_number.$plus_id; 881 881 $return['msg_folder'] = $msg_folder; 882 882 883 883 $date_msg = gmdate("d/m/Y",$header->udate); 884 884 if (date("d/m/Y") == $date_msg) … … 886 886 else 887 887 $return['udate'] = $date_msg; 888 889 $return['msg_day'] = $date_msg; 888 889 $return['msg_day'] = $date_msg; 890 890 $return['msg_hour'] = gmdate("H:i",$header->udate); 891 891 892 892 if (date("d/m/Y") == $date_msg) //no dia 893 893 { … … 895 895 $return['smalldate'] = gmdate("H:i",$header->udate); 896 896 897 $timestamp_now = strtotime("now") + $offset; 897 $timestamp_now = strtotime("now") + $offset; 898 898 $timestamp_msg_time = $header->udate; 899 899 // $timestamp_now is GMT and $timestamp_msg_time is MailDate TZ. … … 901 901 $pdate = date_parse($header->MailDate); 902 902 $timestamp_diff = $timestamp_now - $timestamp_msg_time + ($pdate['zone']*(-60)); 903 903 904 904 if (gmdate("H",$timestamp_diff) > 0) 905 905 { … … 923 923 $return['smalldate'] = gmdate("d/m/Y",$header->udate); 924 924 } 925 925 926 926 $from = $header->from; 927 927 $return['from'] = array(); … … 937 937 else 938 938 $return['from']['full'] = $return['from']['email']; 939 939 940 940 // Sender attribute 941 941 $sender = $header->sender; 942 $return['sender'] = array(); 942 $return['sender'] = array(); 943 943 $return['sender']['name'] = $this->decode_string($sender[0]->personal); 944 944 $return['sender']['email'] = $this->decode_string($sender[0]->mailbox . "@" . $sender[0]->host); … … 989 989 $return['toaddress2'] = ""; 990 990 } 991 991 992 992 $cc = $header->cc; 993 993 $return['cc'] = ""; … … 1017 1017 { 1018 1018 $return['cc'] = ""; 1019 } 1019 } 1020 1020 1021 1021 ## … … 1025 1025 ## 1026 1026 1027 1027 $bcc = $header->bcc; 1028 1028 $return['bcc'] = ""; 1029 1029 if (!empty($bcc)) … … 1052 1052 { 1053 1053 $return['bcc'] = ""; 1054 } 1054 } 1055 1055 1056 1056 $reply_to = $header->reply_to; … … 1082 1082 $return['reply_to'] = $this->decode_string($return['reply_to']); 1083 1083 $return['subject'] = $this->decode_string($header->fetchsubject); 1084 $return['Size'] = $header->Size; 1084 $return['Size'] = $header->Size; 1085 1085 $return['reply_toaddress'] = $header->reply_toaddress; 1086 1086 1087 1087 //All this is to help in local messages 1088 1088 $return['timestamp'] = $header->udate; 1089 1089 $return['login'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id'];//$GLOBALS['phpgw_info']['user']['account_id']; 1090 1090 $return['reply_toaddress'] = $header->reply_toaddress; 1091 1091 1092 1092 return $return; 1093 1093 } … … 1099 1099 */ 1100 1100 function utf8_to_html ($data) 1101 { 1101 { 1102 1102 return preg_replace("/([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)/e", '$this->_utf8_to_html("\\1")', $data); 1103 1103 } 1104 1104 1105 1105 function _utf8_to_html ($data) 1106 1106 { 1107 1107 $ret = 0; 1108 1108 foreach((str_split(strrev(chr((ord($data{0}) % 252 % 248 % 240 % 224 % 192) + 128) . substr($data, 1)))) as $k => $v) 1109 1109 $ret += (ord($v) % 128) * pow(64, $k); 1110 1110 return "&#$ret;"; 1111 1111 } 1112 1112 //------------------------------------------------------------------------------// 1113 1114 1113 1114 1115 1115 1116 1116 … … 1122 1122 */ 1123 1123 function decodeMailPart($part, $encode, $html = true) 1124 1124 { 1125 1125 switch (strtolower($encode)) 1126 1126 { 1127 1127 case 'iso-8859-1': 1128 1128 return $part; … … 1132 1132 if ($html) 1133 1133 return $this->utf8_to_html($part); 1134 else 1134 else 1135 1135 return utf8_decode ($part); 1136 1136 break; … … 1138 1138 default: 1139 1139 return mb_convert_encoding($part, 'iso-8859-1'); 1140 1141 1142 1143 1140 break; 1141 } 1142 } 1143 1144 1144 1145 1145 function get_body_msg($msg_number, $msg_folder) … … 1151 1151 require_once $_SESSION['rootPath'].'/library/mime/mimeDecode.php'; 1152 1152 require_once $_SESSION['rootPath'].'/expressoMail1_2/inc/class.attachment.inc.php'; 1153 include_once("class.message_components.inc.php");1153 include_once("class.message_components.inc.php"); 1154 1154 //--------------------------------------------------------------------// 1155 1155 1156 1156 $return = array(); 1157 1157 1158 1159 1158 $msg = &new message_components($this->mbox); 1159 $msg->fetch_structure($msg_number); 1160 1160 1161 1161 $content = ''; … … 1190 1190 //----------------------------------------------// 1191 1191 1192 1193 1192 if(!$this->has_cid) 1193 { 1194 1194 $return['thumbs'] = $this->get_thumbs($images,$msg_number,$msg_folder); 1195 1196 1195 $return['signature'] = $this->get_signature($msg,$msg_number,$msg_folder); 1196 } 1197 1197 1198 1198 switch (strtolower($structure->ctype_primary)) 1199 1199 { 1200 1200 case 'text': 1201 1201 if(strtolower($structure->ctype_secondary) == 'x-pkcs7-mime') 1202 1202 { 1203 1204 1205 1203 $return['body']='isCripted'; 1204 return $return; 1205 } 1206 1206 $attachment = array(); 1207 1207 … … 1210 1210 1211 1211 if(($msg_subtype == "html" || $msg_subtype == 'plain') && ($disposition != 'attachment')) 1212 1213 1212 { 1213 1214 1214 1215 1215 if(strtolower($msg_subtype) == 'plain') 1216 { 1216 { 1217 1217 $content = $this->decodeMailPart($structure->body, $structure->ctype_parameters['charset'],false); 1218 $content = str_replace(array('<', '>'), array(' #$<$# ', ' #$>$# '), $content);1219 $content = htmlentities($content); 1218 $content = str_replace( array( '<', '>' ), array( ' #$<$# ', ' #$>$# ' ), $content ); 1219 $content = htmlentities( $content ); 1220 1220 $this->replace_links($content); 1221 $content = str_replace(array(' #$<$# ', ' #$>$# '), array('<', '>'), $content); 1222 $content = '<pre>' . $content . '</pre>'; 1223 $return[ 'body' ] = $content;1224 return $return; 1225 } 1221 $content = str_replace( array( ' #$<$# ', ' #$>$# ' ), array( '<', '>' ), $content ); 1222 $content = '<pre>' . $content . '</pre>'; 1223 $return[ 'body' ] = $content; 1224 return $return; 1225 } 1226 1226 $content = $this->decodeMailPart($structure->body, $structure->ctype_parameters['charset']); 1227 1227 } 1228 1228 1229 1229 break; … … 1236 1236 case 'message': 1237 1237 if(!is_array($structure->parts)) 1238 1238 { 1239 1239 $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 1240 1240 $content .= '<pre>'.htmlentities($this->decodeMailPart($structure->body, $structure->ctype_parameters['charset'],false)).'</pre>'; 1241 1241 $content .= "<hr align='left' width='95%' style='border:1px solid #DCDCDC'>"; 1242 1243 else1242 } 1243 else 1244 1244 $this->builderMsgBody($structure , $content,true); 1245 1245 … … 1250 1250 $content .= ''; 1251 1251 else 1252 {1252 { 1253 1253 $content .= $this->functions->getLang('Message not supported') . '. '; 1254 1254 $content .= $this->functions->getLang('Type') . ': ' . $structure->ctype_primary . '/' . $structure->ctype_secondary; 1255 }1255 } 1256 1256 break; 1257 } 1257 } 1258 1258 1259 1259 $params = array('folder' => $msg_folder, "msgs_to_set" => $msg_number, "flag" => "seen"); 1260 1260 $this->set_messages_flag($params); 1261 1261 $content = $this->process_embedded_images($images,$msg_number,$content, $msg_folder); 1262 1262 $content = $this->replace_special_characters($content); 1263 1263 $this->replace_links($content); 1264 1264 $return['body'] = &$content; 1265 1265 1266 return $return; 1266 return $return; 1267 1267 } 1268 1268 … … 1391 1391 { 1392 1392 $body = quoted_printable_decode($body); 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1393 1394 } 1395 else if ($encoding == 'base64') 1396 { 1397 $body = base64_decode($body); 1398 } 1399 // All other encodings are returned raw. 1400 if (strtolower($charset) == "utf-8") 1401 return utf8_decode($body); 1402 else 1403 return $body; 1404 } 1405 1405 1406 1406 … … 1417 1417 1418 1418 foreach ($images as $image) 1419 { 1419 { 1420 1420 $image['cid'] = eregi_replace("<", "", $image['cid']); 1421 1421 $image['cid'] = eregi_replace(">", "", $image['cid']); 1422 1422 $body = eregi_replace("<br/>", "", $body); 1423 1423 $body = str_replace("src=\"cid:".$image['cid']."\"", " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=".$image['pid']."\" ", $body); 1424 1424 $body = str_replace("src='cid:".$image['cid']."'", " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=".$image['pid']."\" ", $body); 1425 1425 $body = str_replace("src=cid:".$image['cid'], " src=\"./inc/show_embedded_attach.php?msg_folder=$msg_folder&msg_num=$msgno&msg_part=".$image['pid']."\" ", $body); 1426 1427 1426 } 1427 return $body; 1428 1428 } 1429 1429 … … 1432 1432 // Suspected TAGS! 1433 1433 // $tag_list = Array('blink','object','meta','html','link','frame','iframe','layer','ilayer','plaintext','script','style','img','applet','embed','head','frameset','xml','xmp'); 1434 1434 1435 1435 // remove MS Office's proprietary tag 1436 1436 //$body = mb_ereg_replace('<!\-\-\[if [^!]* mso .*\]>.*<!\[endif\]\-\->', '', $body); 1437 1437 1438 // Layout problem: Change html elements 1439 // with absolute position to relate position, CASE INSENSITIVE. 1440 1438 // Layout problem: Change html elements 1439 // with absolute position to relate position, CASE INSENSITIVE. 1440 $body = @mb_eregi_replace("POSITION: ABSOLUTE;","",$body); 1441 1441 1442 1442 // tags to be removed doe to security reasons … … 1446 1446 'applet','embed','frameset','xml','xmp' 1447 1447 ); 1448 1448 1449 1449 foreach($tag_list as $index => $tag) { 1450 1450 $body = @mb_eregi_replace("<$tag\\b[^>]*>(.*?)</$tag>", "<!-- TAG <$tag> Removed by ExpressoMail -->", $body); 1451 }1451 } 1452 1452 1453 1453 //try to wrap CSS code instead of remove STYLE tags … … 1478 1478 //skip selecto '*' 1479 1479 continue; 1480 } 1480 } 1481 1481 1482 1482 $selector = eregi_replace('[^#\.]*body.*', '', $selector); … … 1497 1497 $body = str_replace($rest[1][$i],"<".$rest[2][$i].$rest[3][$i].$rest[7][$i].">",$body); 1498 1498 } 1499 1499 1500 1500 /* 1501 1501 * Remove deslocamento a esquerda colocado pelo Outlook. … … 1506 1506 $body = mb_ereg_replace("(<p[^>]*)(margin-left:[^>;]*-[^>;]*;)([^>]*>)","\\1\\3",$body); 1507 1507 //--------------------------------------------------------------------------------------------// 1508 1509 //$body = $this->replace_links($body); 1510 1511 //Remoção de tags <span></span> para correção de erro no firefox 1512 $body = mb_eregi_replace("<span><span>","",$body); 1513 $body = mb_eregi_replace("</span></span>","",$body); 1514 $body = preg_replace("/text-indent:.*;/i","", $body); 1508 1515 1509 //$body = $this->replace_links($body); 1510 1511 //Remoção de tags <span></span> para correção de erro no firefox 1512 $body = mb_eregi_replace("<span><span>","",$body); 1513 $body = mb_eregi_replace("</span></span>","",$body); 1514 $body = preg_replace("/text-indent:.*;/i","", $body); 1516 //Correção para compatibilização com Outlook, ao visualizar a mensagem 1517 $body = mb_ereg_replace('<!--\[','<!-- [',$body); 1518 $body = mb_ereg_replace('<!\[endif\]-->', '<![endif]-->', $body); 1515 1519 1516 //Correção para compatibilização com Outlook, ao visualizar a mensagem1517 $body = mb_ereg_replace('<!--\[','<!-- [',$body);1518 $body = mb_ereg_replace('<!\[endif\]-->', '<![endif]-->', $body);1519 1520 1520 return "<div class=\"$wrapper_class\"><span>".$body.'</span></div>'; 1521 } 1522 1523 1524 1521 } 1522 1523 1524 1525 1525 function replace_links_callback($matches) 1526 1526 { … … 1529 1529 else 1530 1530 $pref = $matches[3] = 'http'; 1531 1531 1532 1532 return '<a href="'.$pref.'://'.$matches[4].$matches[5].'" target="_blank">'.$matches[4].$matches[5].'</a>'; 1533 1533 } 1534 1535 1534 1535 1536 1536 /** 1537 1537 * @license http://www.gnu.org/copyleft/gpl.html GPL … … 1540 1540 */ 1541 1541 function replace_links(&$body) 1542 { 1542 { 1543 1543 // Trata urls do tipo aaaa.bbb.empresa 1544 1544 // Usadas na intranet. … … 1546 1546 $replacement = '<a href="://$4$5" target="_blank">$4$5</a>'; 1547 1547 $body = preg_replace_callback($pattern,array( &$this, 'replace_links_callback'), $body); 1548 // E-mail address in the text should create a new e-mail on ExpressoMail 1548 // E-mail address in the text should create a new e-mail on ExpressoMail 1549 1549 $pattern = '/( |<|<|>)([A-Za-z0-9\.~?\/_=#\-]*@[A-Za-z0-9\.~?\/_=#\-]*)( |>|>|<)/im'; 1550 $replacement = '$1<a href="mailto:$2">$2</a>$3'; 1551 $body = preg_replace( $pattern, $replacement, $body);1552 1553 } 1550 $replacement = '$1<a href="mailto:$2">$2</a>$3'; 1551 $body = preg_replace( $pattern, $replacement, $body ); 1552 1553 } 1554 1554 1555 1555 function get_signature($msg, $msg_number, $msg_folder) … … 1667 1667 { 1668 1668 1669 1670 1669 $thumbs_array = array(); 1670 $i = 0; 1671 1671 1672 1672 foreach ($images as $x => $image) 1673 1673 { 1674 1674 if($x && $x == 'names') 1675 1675 continue; … … 1679 1679 $anchor = "<a class=\"expressomail-thumbs-link\" onMouseDown='save_image(event,this,\"".$image['type']."\")' href=\"".$href."\" onclick=\"window.open('".$href."','mywindow','width=700,height=600,scrollbars=yes');return false;\">". $img ."</a>"; 1680 1680 $thumbs_array[] = $anchor; 1681 1681 $i++; 1682 1682 1683 1684 1683 } 1684 return $thumbs_array; 1685 1685 } 1686 1686 … … 1702 1702 function delete_msgs($params) 1703 1703 { 1704 1704 1705 1705 $folder = $params['folder']; 1706 1706 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO-8859-1"); 1707 1707 $msgs_number = explode(",",$params['msgs_number']); 1708 1708 $border_ID = $params['border_ID']; 1709 1709 1710 1710 $return = array(); 1711 1711 1712 1712 if ($params['get_previous_msg']){ 1713 1713 $return['previous_msg'] = $this->get_info_previous_msg($params); … … 1716 1716 } 1717 1717 1718 //$mbox_stream = $this->open_mbox($folder); 1718 //$mbox_stream = $this->open_mbox($folder); 1719 1719 $mbox_stream = @imap_open("{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$folder, $this->username, $this->password) or die(serialize(array('imap_error' => $this->parse_error(imap_last_error())))); 1720 1720 1721 1721 foreach ($msgs_number as $msg_number) 1722 1722 { … … 1724 1724 $return['msgs_number'][] = $msg_number; 1725 1725 } 1726 1726 1727 1727 $return['folder'] = $folder; 1728 1728 $return['border_ID'] = $border_ID; 1729 1729 1730 1730 if($mbox_stream) 1731 1731 imap_close($mbox_stream, CL_EXPUNGE); … … 2484 2484 * @param $forwarding_attachments anexos 2485 2485 */ 2486 function buildEmbeddedImages(&$mail,$msg_uid,&$forwarding_attachments) 2487 { 2488 // Build CID for embedded Images!!!2489 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 2490 $cid_imgs = ''; 2491 preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 2492 $cid_array = array(); 2493 2494 foreach($cid_imgs[6] as $j => $val){ 2495 if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) 2496 { 2497 $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 2498 } 2499 $cid = $cid_array[$cid_imgs[4][$j].$val]; 2500 2501 $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 2486 function buildEmbeddedImages(&$mail,$msg_uid,&$forwarding_attachments) 2487 { 2488 // Build CID for embedded Images!!! 2489 $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&(amp;)?msg_num=(.+)?&(amp;)?msg_part=(.+)?)"/isU'; 2490 $cid_imgs = ''; 2491 preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 2492 $cid_array = array(); 2493 2494 foreach($cid_imgs[6] as $j => $val){ 2495 if ( !array_key_exists($cid_imgs[4][$j].$val, $cid_array) ) 2496 { 2497 $cid_array[$cid_imgs[4][$j].$val] = base_convert(microtime(), 10, 36); 2498 } 2499 $cid = $cid_array[$cid_imgs[4][$j].$val]; 2500 2501 $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 2502 2502 2503 2503 $count = strlen($cid_imgs[6][$j]); … … 2514 2514 // The image is not in the same mail? 2515 2515 if ($msg_uid != $cid_imgs[4][$j]) 2516 { 2517 $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 2516 { 2517 $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[4][$j], $cid_imgs[6][$j], 'base64'); 2518 2518 $fileName = ($msg_uid != 'undefined') ? "image_".($j).".jpg" : $file_description[2]; 2519 $fileCode = "base64"; 2520 $fileType = "image/jpg"; 2521 $file_attached[0] = $cid_imgs[2][$j]; 2522 $file_attached[1] = $cid_imgs[4][$j]; 2523 $file_attached[2] = $fileName; 2519 $fileCode = "base64"; 2520 $fileType = "image/jpg"; 2521 $file_attached[0] = $cid_imgs[2][$j]; 2522 $file_attached[1] = $cid_imgs[4][$j]; 2523 $file_attached[2] = $fileName; 2524 2524 $file_attached[3] = '0.'.($j+1); 2525 $file_attached[4] = 'base64'; 2526 $file_attached[5] = strlen($fileContent); //Size of file 2525 $file_attached[4] = 'base64'; 2526 $file_attached[5] = strlen($fileContent); //Size of file 2527 2527 $file_attached[6] = $cid_imgs[6][$j]; 2528 $return_forward[] = $file_attached; 2528 $return_forward[] = $file_attached; 2529 2529 2530 2530 if ($file_attached[3] == $file_description[3] || $msg_uid == 'undefined') 2531 2531 unset($forwarding_attachments[$position]); 2532 2532 2533 } 2534 else 2535 { 2536 $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64'); 2537 $fileName = $file_description[2]; 2538 $fileCode = $file_description[4]; 2533 } 2534 else 2535 { 2536 $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64'); 2537 $fileName = $file_description[2]; 2538 $fileCode = $file_description[4]; 2539 2539 $file_description[3] = '0.'.($j+1); 2540 2540 $file_description[6] = $cid_imgs[6][$j]; 2541 $fileType = $this->get_file_type($file_description[2]); 2541 $fileType = $this->get_file_type($file_description[2]); 2542 2542 unset($forwarding_attachments[$position]); 2543 if (!empty($file_description)) 2544 { 2545 $file_description[5] = strlen($fileContent); //Size of file 2546 $return_forward[] = $file_description; 2547 } 2548 } 2543 if (!empty($file_description)) 2544 { 2545 $file_description[5] = strlen($fileContent); //Size of file 2546 $return_forward[] = $file_description; 2547 } 2548 } 2549 2549 $tempDir = '/tmp'; 2550 $file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat"; 2551 $f = fopen($tempDir.'/'.$file,"w"); 2552 fputs($f,$fileContent); 2553 fclose($f); 2554 2555 if ($fileContent) 2556 $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 2557 } 2558 2559 return $return_forward; 2560 } 2550 $file = "cidimage_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].$cid_imgs[6][$j].".dat"; 2551 $f = fopen($tempDir.'/'.$file,"w"); 2552 fputs($f,$fileContent); 2553 fclose($f); 2554 2555 if ($fileContent) 2556 $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 2557 } 2558 2559 return $return_forward; 2560 } 2561 2561 function add_recipients_cert($full_address) 2562 2562 { … … 2874 2874 { 2875 2875 2876 2876 include_once("class.phpmailer.php"); 2877 2877 $mail = new PHPMailer(); 2878 2878 include_once("class.db_functions.inc.php"); 2879 $toaddress 2880 $ccaddress 2879 $toaddress = $params['input_to']; 2880 $ccaddress = $params['input_cc']; 2881 2881 $ccoaddress = $params['input_cco']; 2882 2883 2884 $subject 2885 $msg_uid 2886 $body 2882 $return_receipt = $params['input_return_receipt']; 2883 $is_important = $params['input_important_message']; 2884 $subject = $params['input_subject']; 2885 $msg_uid = $params['msg_id']; 2886 $body = $params['body']; 2887 2887 $body = str_replace("%nbsp;"," ",$body); 2888 2888 $body = preg_replace("/\n/"," ",$body); 2889 2889 $body = preg_replace("/\r/","",$body); 2890 2890 $forwarding_attachments = $params['forwarding_attachments']; 2891 $attachments 2891 $attachments = $params['FILES']; 2892 2892 $return_files = $params['FILES']; 2893 2893 2894 2894 2895 2895 $folder = $params['folder']; 2896 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 2896 $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"); 2897 2897 // Fix problem with cyrus delimiter changes. 2898 // Dots in names: enabled/disabled. 2898 // Dots in names: enabled/disabled. 2899 2899 $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 2900 2900 $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 2901 2901 // End Fix. 2902 2902 2903 2903 $mail->SaveMessageInFolder = $folder; 2904 2904 $mail->SMTPDebug = false; 2905 2905 2906 2906 $mail->IsSMTP(); 2907 2907 $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; … … 2909 2909 $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; 2910 2910 $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 2911 2911 2912 2912 $mail->Sender = $mail->From; 2913 2913 $mail->SenderName = $mail->FromName; 2914 2914 $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 2915 2915 $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; 2916 2916 2917 2917 $this->add_recipients("to", $toaddress, &$mail); 2918 2918 $this->add_recipients("cc", $ccaddress, &$mail); … … 2920 2920 $mail->IsHTML(true); 2921 2921 $mail->Body = $body; 2922 2922 2923 2923 $return_forward = $this->buildEmbeddedImages($mail,$msg_uid,$forwarding_attachments); 2924 2924 $imagesParts = array(); 2925 2925 2926 2926 foreach ($return_forward as $value) 2927 2927 $imagesParts[$value[6]] = $value[3]; 2928 2928 2929 //Build Forwarding Attachments!!!2930 foreach($forwarding_attachments as $forwarding_attachment)2931 {2932 $file_description = unserialize(rawurldecode($forwarding_attachment));2929 // Build Forwarding Attachments!!! 2930 foreach($forwarding_attachments as $forwarding_attachment) 2931 { 2932 $file_description = unserialize(rawurldecode($forwarding_attachment)); 2933 2933 $file_description = array_values($file_description); 2934 2934 2935 foreach($file_description as $i => $descriptor){ 2935 foreach($file_description as $i => $descriptor){ 2936 2936 $file_description[$i] = eregi_replace('\'*\'','',$descriptor); 2937 } 2938 $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 2939 $fileName = $file_description[2]; 2940 2941 $file_description[5] = strlen($fileContent); //Size of file 2942 $return_forward[] = $file_description; 2943 2944 $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 2945 }2946 2937 } 2938 $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 2939 $fileName = $file_description[2]; 2940 2941 $file_description[5] = strlen($fileContent); //Size of file 2942 $return_forward[] = $file_description; 2943 2944 $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 2945 } 2946 2947 2947 if ((count($return_forward) > 0) && (count($return_files) > 0)) 2948 2948 { … … 2951 2951 else if (count($return_files) < 1) 2952 2952 { 2953 $return_files = $return_forward;2954 } 2955 2956 // Build Uploading Attachments!!!2953 $return_files = $return_forward; 2954 } 2955 2956 // Build Uploading Attachments!!! 2957 2957 $sizeof_attachments = count($attachments); 2958 2958 if ($sizeof_attachments) … … 2965 2965 switch ($image_type) 2966 2966 { 2967 2968 2967 // Do not corrupt animated gif 2968 //case 1: $image_big = imagecreatefromgif($attach['tmp_name']);break; 2969 2969 case 2: 2970 2970 $image_big = imagecreatefromjpeg($attach['tmp_name']); break; 2971 2971 case 3: 2972 2972 $image_big = imagecreatefrompng($attach['tmp_name']); break; 2973 2974 2975 2976 2977 2978 2973 case 6: 2974 require_once("gd_functions.php"); 2975 $image_big = imagecreatefrombmp($attach['tmp_name']); break; 2976 default: 2977 $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); 2978 break; 2979 2979 } 2980 2980 header('Content-type: image/jpeg'); … … 3008 3008 $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); 3009 3009 3010 }3011 } 3012 3010 } 3011 } 3012 3013 3013 if(!empty($mail->AltBody)) 3014 3014 $mail->ContentType = "multipart/alternative"; 3015 3015 3016 3016 $mail->error_count = 0; // reset errors 3017 3017 $mail->SetMessageType(); 3018 3018 $header = $mail->CreateHeader(); 3019 $body = $mail->CreateBody();3020 3021 $mbox_stream = $this->open_mbox($folder); 3022 $new_header 3023 $new_body 3019 $body = $mail->CreateBody(); 3020 3021 $mbox_stream = $this->open_mbox($folder); 3022 $new_header = str_replace("\n", "\r\n", $header); 3023 $new_body = str_replace("\n", "\r\n", $body); 3024 3024 $return['append'] = imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, $new_header . $new_body, "\\Seen \\Draft"); 3025 $status 3025 $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 3026 3026 $return['msg_no'] = $status->uidnext - 1; 3027 3027 $return['folder_id'] = $folder; … … 3037 3037 if (array_key_exists("name", $_attachment)) 3038 3038 { 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 } 3049 3039 unset($return_files[$index]); 3040 $return_files[$index] = $_attachment['name']."_SIZE_".$return_files[$index][1] = $_attachment['size']; 3041 } 3042 else 3043 { 3044 unset($return_files[$index]); 3045 $return_files[$index] = $_attachment[2]."_SIZE_". $return_files[$index][1] = $_attachment[5]; 3046 } 3047 } 3048 } 3049 3050 3050 $return['files'] = serialize($return_files); 3051 3051 $return["subject"] = $subject; 3052 3052 3053 3053 if (!$return['append']) 3054 3054 $return['append'] = imap_last_error(); … … 3569 3569 "SOZsozYYuAAAAACEEEEIIIIINOOOOOUUUUUsaaaaaceeeeiiiiinooooouuuuuyy"); 3570 3570 } 3571 3572 function make_search_date($date,$before = false){ 3571 3572 function make_search_date($date,$before = false){ 3573 3573 3574 3574 //TODO: Adaptar a data de acordo com o locale do sistema. 3575 3575 list($day,$month,$year) = explode("/", $date); 3576 $before?$day=(int)$day+1:$day=(int)$day; 3577 $timestamp = mktime(0,0,0,(int)$month,$day,(int)$year);3578 3576 $before?$day=(int)$day+1:$day=(int)$day; 3577 $timestamp = mktime(0,0,0,(int)$month,$day,(int)$year); 3578 $search_date = date('d-M-Y',$timestamp); 3579 3579 return $search_date; 3580 3580 3581 }3581 } 3582 3582 3583 3583 function search_msg( $params = false ) … … 3623 3623 if(trim($filter_array[0]) == 'BEFORE' ) 3624 3624 { 3625 $filter .= '"'.$this->make_search_date($filter_array[1],true).'"'; 3626 }else{ 3627 $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; 3628 }3625 $filter .= '"'.$this->make_search_date($filter_array[1],true).'"'; 3626 }else{ 3627 $filter .= '"'.$this->make_search_date($filter_array[1]).'"'; 3628 } 3629 3629 } 3630 3630 } … … 3671 3671 $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); 3672 3672 $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ); 3673 $elem['uid'] = $new_search; 3674 /* compare dates in ordering */ 3675 $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); 3673 $elem['uid'] = $new_search; 3674 /* compare dates in ordering */ 3675 $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); 3676 3676 $retorno[] = $elem; 3677 3677 } … … 3717 3717 $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); 3718 3718 $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ); 3719 $elem['uid'] = $new_search; 3720 /* compare dates in ordering */ 3719 $elem['uid'] = $new_search; 3720 /* compare dates in ordering */ 3721 3721 $elem['udatecomp'] = substr ($elem['udate'], -4) ."-". substr ($elem['udate'], 3, 2) ."-". substr ($elem['udate'], 0, 2); 3722 3722 $retorno[] = $elem; … … 4070 4070 function get_header($msg_number) 4071 4071 { 4072 $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255);4072 $header = @imap_headerinfo($this->mbox, imap_msgno($this->mbox, $msg_number), 80, 255); 4073 4073 if (!is_object($header)) 4074 4074 return false; … … 4106 4106 $f = fopen($file,"w"); 4107 4107 fputs($f,base64_encode($source)); 4108 fclose($f); 4108 fclose($f); 4109 4109 $command = "python ".$_SESSION['rootPatch']."/expressoMail1_2/imap.py ".escapeshellarg($imap_server)." ".escapeshellarg($imap_port)." ".escapeshellarg($username)." ".escapeshellarg($password)." ".escapeshellarg($timestamp)." ".escapeshellarg($folder)." ".escapeshellarg($file); 4110 4110 $return['command']=exec(escapeshellcmd($command));
Note: See TracChangeset
for help on using the changeset viewer.