handle text/plain in preview

This commit is contained in:
Klaus Leithoff 2013-04-12 13:30:54 +00:00
parent ccc75e2bc7
commit 99797c3639
2 changed files with 50 additions and 3 deletions

View File

@ -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

View File

@ -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 = "<pre>".felamimail_bo::wordwrap($newBody,90,"\n",'&gt;')."</pre>";
$newBody = "<pre>".mail_bo::wordwrap($newBody,90,"\n",'&gt;')."</pre>";
//$newBody = "<pre>".$newBody."</pre>";
}
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));