From 99797c36398df3902c8026bc25ea872a4462bef0 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Fri, 12 Apr 2013 13:30:54 +0000 Subject: [PATCH] handle text/plain in preview --- mail/inc/class.mail_bo.inc.php | 47 ++++++++++++++++++++++++++++++++++ mail/inc/class.mail_ui.inc.php | 6 ++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/mail/inc/class.mail_bo.inc.php b/mail/inc/class.mail_bo.inc.php index 522e01c474..7f161b8589 100644 --- a/mail/inc/class.mail_bo.inc.php +++ b/mail/inc/class.mail_bo.inc.php @@ -3504,6 +3504,53 @@ class mail_bo return $message; } + static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith=false) + { + $lines = explode("\n", $str); + $newStr = ''; + foreach($lines as $line) + { + // replace tabs by 8 space chars, or any tab only counts one char + //$line = str_replace("\t"," ",$line); + //$newStr .= wordwrap($line, $cols, $cut); + $allowedLength = $cols-strlen($cut); + if (strlen($line) > $allowedLength && + ($dontbreaklinesstartingwith==false || + ($dontbreaklinesstartingwith && + strlen($dontbreaklinesstartingwith)>=1 && + substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith + ) + ) + ) + { + $s=explode(" ", $line); + $line = ""; + $linecnt = 0; + foreach ($s as $k=>$v) { + $cnt = strlen($v); + // only break long words within the wordboundaries, + // but it may destroy links, so we check for href and dont do it if we find one + // we check for any html within the word, because we do not want to break html by accident + if($cnt > $allowedLength && stripos($v,'href=')===false && stripos($v,'onclick=')===false && $cnt == strlen(html_entity_decode($v))) + { + $v=wordwrap($v, $allowedLength, $cut, true); + } + // the rest should be broken at the start of the new word that exceeds the limit + if ($linecnt+$cnt > $allowedLength) { + $v=$cut.$v; + #$linecnt = 0; + $linecnt =strlen($v)-strlen($cut); + } else { + $linecnt += $cnt; + } + if (strlen($v)) $line .= (strlen($line) ? " " : "").$v; + } + } + $newStr .= $line . "\n"; + } + return $newStr; + } + /** * getMessageRawHeader * get parsed headers from message diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index fe367c46f1..b23eaf4964 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -1688,7 +1688,7 @@ blockquote[type=cite] { $singleBodyPart['body'] = utf8_encode($singleBodyPart['body']); } } - //error_log($singleBodyPart['body']); + //error_log(__METHOD__.__LINE__.array2string($singleBodyPart)); #$CharSetUsed = mb_detect_encoding($singleBodyPart['body'] . 'a' , strtoupper($singleBodyPart['charSet']).','.strtoupper(mail_bo::$displayCharset).',UTF-8, ISO-8859-1'); if($singleBodyPart['mimeType'] == 'text/plain') @@ -1727,7 +1727,7 @@ blockquote[type=cite] { // since we do not display the message as HTML anymore we may want to insert good linebreaking (for visibility). //error_log($newBody); // dont break lines that start with > (> as the text was processed with htmlentities before) - //TODO:$newBody = "
".felamimail_bo::wordwrap($newBody,90,"\n",'>')."
"; + $newBody = "
".mail_bo::wordwrap($newBody,90,"\n",'>')."
"; //$newBody = "
".$newBody."
"; } else @@ -2118,7 +2118,7 @@ blockquote[type=cite] { * * @return xajax response */ - function loadEmailBody($_messageID) + function loadEmailBody($_messageID=null) { if (!$_messageID) $_messageID = $_GET['_messageID']; if(mail_bo::$debug); error_log(__METHOD__."->".$_flag.':'.print_r($_messageID,true));