From: Jim W. <spi...@us...> - 2007-01-22 23:15:37
|
Update of /cvsroot/moregroupware/mgw/modules/webmail2/inc In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv32528/inc Modified Files: readmessage_inc.php Log Message: Removing a lot of unused code both to reduce confusion and reduce memory usage. Also reduced the size of cache files by eliminating and variable not required. Not sure if I like the way caching is done (dynamically written php include files!). Not just memory usage, but some fixes for handling very large plain text email parts are in this patch. It should now be possible to read multiple megabyte text/plain and un-mimed messages. Still much to be done in terms of streamlining memory usage. The webmail2 module is still grossly out of control. Also some attachment forwarding issues need to be handled in a more graceful way. Index: readmessage_inc.php =================================================================== RCS file: /cvsroot/moregroupware/mgw/modules/webmail2/inc/readmessage_inc.php,v retrieving revision 1.74 retrieving revision 1.75 diff -C2 -d -r1.74 -r1.75 *** readmessage_inc.php 6 Jan 2007 05:52:25 -0000 1.74 --- readmessage_inc.php 22 Jan 2007 23:15:31 -0000 1.75 *************** *** 121,168 **** } - //function quotedPrintableDecode($input) - //{ - // // Remove soft line breaks - // $input = preg_replace("/=\r?\n/", '', $input); - // - // // Replace encoded characters - // if (preg_match_all('/=[a-f0-9]{2}/i', $input, $matches)) { - // $matches = array_unique($matches[0]); - // foreach ($matches as $value) { - // $input = str_replace($value, chr(hexdec(substr($value,1))), $input); - // } - // } - // return $input; - //} - - //function findboundary2($line,$boundarys) { - // $length = strlen($line); - // $result = false; - // if ($length>10) { // and $length<81 - // if (substr($line,0,2)=="--") { - // $line = str_replace("\r","",$line); - // foreach ($boundarys as $boundary) { - // if ($boundary!="" and ("--".$boundary==$line or "--".$boundary."--"==$line)) { - // $result = true; - // break; - // } - // } - // } - // } - // return $result; - //} - - //function make_proto2($line) { - // global $filename; - // if ($line == "") { $line = "@leer@"; } - // echo htmlspecialchars($line); - // if (strlen($line)<8) { - // for ($i=0;$i < strlen($line);$i++) { - // echo ord($line[$i]).","; - // } - // } - // if ($filename != "") {echo " - ".$filename."<br>\n";} else { echo "<br>\n"; } - //} - function create_filename($filename, $account, $msg_no, $partno) { global $msg_cache, $mime_types, $username, $message_id; --- 121,124 ---- *************** *** 198,206 **** global $account, $msg_no; - $my_body_plain=""; $my_body_show=""; $mail_attachments=array(); $mail_structure=array(); if (isset($structure->headers["disposition-notification-to"]) and $structure->headers["disposition-notification-to"]!="") $notify = true; --- 154,162 ---- global $account, $msg_no; $my_body_show=""; $mail_attachments=array(); $mail_structure=array(); + if (isset($structure->headers["disposition-notification-to"]) and $structure->headers["disposition-notification-to"]!="") $notify = true; *************** *** 265,273 **** if (!isset($gpg_decrypt)) $gpg_decrypt = array(); - // if just plain text, then there are no parts, we then create one - // if (!isset($structure->parts)) { - // TTT - // $structure->parts[0]=$structure; - // } if (!isset($structure->parts)) { if (isset($structure->headers)) { --- 221,224 ---- *************** *** 299,303 **** // end of code to remove text part when html and text parts are there - $partno=0; foreach ($structure->parts as $part) { --- 250,253 ---- *************** *** 340,345 **** $dispo2 = " ($name)"; $mail_structure[] = $ctype_full.$dispo.$dispo2." ".$partno; ! ! if ($ctype_full=="multipart/alternative" || $ctype_full=="multipart/mixed") { $both_parts_key = get_both_html_and_plain_version_key($part); if ($both_parts_key > 0) { --- 290,298 ---- $dispo2 = " ($name)"; $mail_structure[] = $ctype_full.$dispo.$dispo2." ".$partno; ! // TODO: multipart/related is being treated the same as alt and mixed ! // since CID (content-id) processing isn't really being done anyway. ! if ($ctype_full=="multipart/alternative" || ! $ctype_full=="multipart/mixed" || ! $ctype_full=="multipart/related") { $both_parts_key = get_both_html_and_plain_version_key($part); if ($both_parts_key > 0) { *************** *** 347,360 **** } foreach ($part->parts as $party) { ! list($tmp_body_plain,$tmp_body_show,$tmp_result)=make_emailbox_array($party); $my_body_show.=$tmp_body_show; - $my_body_plain.=$tmp_body_plain; } } elseif ($ctype_full=="message/rfc822") { foreach ($part->parts as $party) { ! list($tmp_body_plain,$tmp_body_show,$tmp_result)=make_emailbox_array($party); $my_body_show.=make_emailbox_html($tmp_result); $my_body_show.=$tmp_body_show; - $my_body_plain.=$tmp_body_plain; } // only save if an attachment --- 300,311 ---- } foreach ($part->parts as $party) { ! list($tmp_body_show,$tmp_result)=make_emailbox_array($party); $my_body_show.=$tmp_body_show; } } elseif ($ctype_full=="message/rfc822") { foreach ($part->parts as $party) { ! list($tmp_body_show,$tmp_result)=make_emailbox_array($party); $my_body_show.=make_emailbox_html($tmp_result); $my_body_show.=$tmp_body_show; } // only save if an attachment *************** *** 400,408 **** } $my_body_show .= modify_html(trim($part->body))."<br>"; - $text = strip_tags(str_replace("<br>","#mybr#",trim($part->body))); - $text = preg_replace("/(\015\012)|(\015)|(\012)/","",$text); - $text = str_replace("#mybr#","\r\n",$text); - $text = my_decodeHTML($text); - $my_body_plain .= $text; } elseif ($ctype_full=="text/plain" || $ctype_full=="application/pgp-signature") { if (isset($MGW->settings["wm2_gpg_use"]) and $MGW->settings["wm2_gpg_use"] and (strpos(substr($body2,0,100),"BEGIN PGP MESSAGE") or --- 351,354 ---- *************** *** 425,431 **** } } - if (isset($part->body)) { - $my_body_plain .= $part->body; - } } else { // default: show it --- 371,374 ---- *************** *** 435,442 **** } $my_body_show .= modify_text(htmlspecialchars(trim($part->body)))."<br>"; - $text = strip_tags(str_replace("<br>","#mybr#",trim($part->body))); - $text = preg_replace("/(\015\012)|(\015)|(\012)/","",$text); $text = str_replace("#mybr#","\r\n",$text); - $text = my_decodeHTML($text); - $my_body_plain .= $text; } } --- 378,381 ---- *************** *** 444,448 **** } // end foreach $emailbox_array=array($from,$subject,$date,$cc,$bcc,$to,$replyto,0,$priority,$mail_structure,'',$mail_attachments,$gpg_signature,$gpg_decrypt); ! $result=array($my_body_plain,$my_body_show,$emailbox_array); return $result; } --- 383,387 ---- } // end foreach $emailbox_array=array($from,$subject,$date,$cc,$bcc,$to,$replyto,0,$priority,$mail_structure,'',$mail_attachments,$gpg_signature,$gpg_decrypt); ! $result=array($my_body_show,$emailbox_array); return $result; } *************** *** 556,560 **** $Mail_RFC822->validate=false; $from2 = $Mail_RFC822->parseAddressList(strtolower($from1)." (abc)", '', TRUE); - // $from2 = explode(" ",str_replace(">","",str_replace("<","",$from))); if (PEAR::isError($from2)) { --- 495,498 ---- *************** *** 573,578 **** $to1 = str_replace(array(""",">","<"),array("\"",">","<"),$to); $to2 = $Mail_RFC822->parseAddressList(strtolower($to1)." (abc)", '', FALSE); - // $to2 = explode(" ",str_replace(">","",str_replace("<","",$to))); - // if (count($settings_replyto) > 1 or count($settings_replyto) < 1 or (count($settings_replyto)==1 and !in_array(strtolower($to2[0]),$settings_replyto))) { if (count($settings_replyto) != 1 or (count($settings_replyto)==1 and !in_array(strtolower($to2[0]->mailbox."@".$to2[0]->host),$settings_replyto))) { --- 511,514 ---- *************** *** 839,874 **** if ($MGW->settings["wm2_securehtmlmails"]) $text = clean_html($text); - /* - $i = 0; - $start = 0; - $len = strlen($text); - - // echo strlen($text)."<br>"; - - while ($len>=0) { - - $step = 10000; - $subtext[$i] = substr($text,$start,$step); - $start = $start + $step; - $len = $len - $step; - - $pattern = '=(.*)<a.[^>]*href\=[ ]*[\'"]([^#"]*)[\'"][^>]*>(.*)</a>(.*)=msiU'; - $subtext[$i] = preg_replace_callback($pattern, "modify_my_callback", $subtext[$i]); - - $pattern = '=(.*)<img(.*)src\=[ ]*[\'"]([^"]*)[\'"](.*)>(.*)=msiU'; - $repl = '\\1<img\\2\\4 src="noimg.php?download='.$MGW->settings["wm2_dontdownloadobjects"].'&url=\\3">\\5'; - $subtext[$i] = preg_replace($pattern, $repl, $subtext[$i]); - $pattern = '=(.*)background(.*)src\=[ ]*[\'"]([^"]*)[\'"](.*)>(.*)=msiU'; - $repl = '\\1<img\\2 src="noimg.php?download='.$MGW->settings["wm2_dontdownloadobjects"].'&url=\\3"\\4>\\5'; - $subtext[$i] = preg_replace($pattern, $repl, $subtext[$i]); - $i++; - } - - $text = ""; - for ($i2=0;$i2<$i;$i2++) { - $text .= $subtext[$i2]; - } - */ $pattern = '=(.*)<a.[^>]*href\=\s*[\'"]([^#"]*)[\'"][^>]*>(.*)</a>(.*)=msiU'; $text = preg_replace_callback($pattern, "modify_my_callback", $text); --- 775,779 ---- *************** *** 881,895 **** $text = preg_replace($pattern, $repl, $text); - /* - $text = substr($text,0,15000); - - $pattern = '=(.*)<a.*href\=[ ]*[\'"]([^#"]*)[\'"][^>]*>(.*)</a>(.*)=msiU'; - $repl = '\\1<a target="_blank" href="norefer.php?url=\\2">\\3</a>\\4'; - $text = preg_replace_callback($pattern, "modify_my_callback", $text); - - $pattern = '=(.*)<img(.*)src\=[ ]*[\'"]([^"]*)[\'"][^>](.*)>(.*)=msiU'; - $repl = '\\1<img\\2\\4 src="noimg.php?download='.$MGW->settings["wm2_dontdownloadobjects"].'&url=\\3">\\5'; - $text = preg_replace($pattern, $repl, $text); - */ return $text; } --- 786,789 ---- *************** *** 909,915 **** global $MGW; ! //$text = ereg_replace("([_]+){2,}","<hr size=\"1\">",$text); ! // $text = preg_replace("/(\012)/","",$text); ! $text = preg_replace("/(\015\012)|(\015)|(\012)/","<br>\n",$text); $text = wordwrap($text,130,"<br>",1); $text = str_replace("<<br>br>","<br>",$text); --- 803,825 ---- global $MGW; ! // If the text part is over 1 mb this is not a normal email. Treat it ! // as preformatted bulk text. ! if (strlen($text) > 1048576) { ! return "<PRE>" . $text . "</PRE>"; ! } ! ! // for performance sake, lets assume server (or remote client) is ! // sending one type of line ending. ! if (strstr($text,"\r\n")) { ! // msdos line endings ! $text = str_replace("\r\n","<br>\n",$text); ! } else if (strstr($text,"\n")) { ! // unix newline line endings ! $text = str_replace("\n","<br>\n",$text); ! } else if (strstr($text,"\r")) { ! // carriage return only line endings ! $text = str_replace("\r","<br>\n",$text); ! } ! $text = wordwrap($text,130,"<br>",1); $text = str_replace("<<br>br>","<br>",$text); *************** *** 918,922 **** $text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a target=\"_blank\" href=\"norefer.php?url=\\0\">\\0</a>", $text); $text = ereg_replace("([A-Za-z0-9_.\-]+\@[A-Za-z0-9_\.\-]+[.]+[a-zA-Z]+)","<a target='rightframe' href=\"sendmail.php?to=\\1\">\\1</a>",$text); - // $text = ereg_replace("([A-Za-z0-9_.\-]+\@[A-Za-z0-9_\-\.]+[.]+[a-zA-Z]+)","<a target='rightframe' href=\"sendmail.php?to=\\1\">\\1</a>",$text); if ($MGW->settings["wm2_show_emoticons"]) { --- 828,831 ---- *************** *** 936,951 **** } - function modify_text2($text) { - - $text = preg_replace("/(\015\012)|(\015)|(\012)/","<br>\n",$text); - $text = wordwrap($text,130,"<br>",1); - $text = str_replace("<<br>br>","<br>",$text); - $text = str_replace("<b<br>r>","<br>",$text); - $text = str_replace("<br<br>>","<br>",$text); - $text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a target=\"_blank\" href=\"norefer.php?url=\\0\">\\0</a>", $text); - $text = ereg_replace("([A-Za-z0-9_.\-]+\@[A-Za-z0-9_\.\-]+[.]+[a-zA-Z]+)","<a target='rightframe' href=\"sendmail.php?to=\\1\">\\1</a>",$text); - - return $text; - } - ?> --- 845,847 ---- |