improve convertHTMLToText, for toggle editor and mail2infolog process; better control of insert Signature at Top. Only insert the signature, when the compose window is opened the first time (compose/reply/forward), dont do it if sending failes, and the compose window is refreshed (in general when mySigID is set)

This commit is contained in:
Klaus Leithoff 2010-08-31 14:29:01 +00:00
parent 574ff9a59a
commit 57c63c6c29
8 changed files with 81 additions and 15 deletions

View File

@ -49,7 +49,7 @@
function addACL($_accountName, $_aclData)
{
if($this->_debug) error_log("ajaxfelamimail::addACL");
if($this->_debug) error_log("ajaxfelamimail::addACL for ".$_accountName."->".array2string($_aclData));
$response = new xajaxResponse();
if(!empty($_accountName)) {
@ -252,7 +252,15 @@
$bocompose->replaceEmailAdresses($_content);
} else {
$this->sessionData['mimeType'] = 'text';
$_content = str_replace(array("\r\n","\n","\r"),array("<br>","<br>","<br>"),$_content);
if (stripos($_content,'<pre>')!==false)
{
$contentArr = html::splithtmlByPRE($_content);
foreach ($contentArr as $k =>&$elem)
{
if (stripos($elem,'<pre>')!==false) $elem = str_replace(array("\r\n","\n","\r"),array("<br>","<br>","<br>"),$elem);
}
$_content = implode('',$contentArr);
}
$_content = $bocompose->_getCleanHTML($_content);
$_content = $bocompose->convertHTMLToText($_content);
}

View File

@ -634,7 +634,7 @@
$numberOfChars = strspn(trim($value), ">");
$appendString = str_repeat('>', $numberOfChars + 1);
$bodyAppend = $this->bofelamimail->wordwrap($value, 76-strlen("\r\n$appendString "), "\r\n$appendString ");
$bodyAppend = $this->bofelamimail->wordwrap($value, 76-strlen("\r\n$appendString "), "\r\n$appendString ",'>');
if($bodyAppend[0] == '>') {
$bodyAppend = '>'. $bodyAppend;

View File

@ -2795,7 +2795,7 @@
return $userACL;
}
static function wordwrap($str, $cols, $cut)
static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith=false)
{
$lines = explode("\n", $str);
$newStr = '';
@ -2805,7 +2805,15 @@
//$line = str_replace("\t"," ",$line);
//$newStr .= wordwrap($line, $cols, $cut);
$allowedLength = $cols-strlen($cut);
if (strlen($line) > $allowedLength) {
if (strlen($line) > $allowedLength &&
($dontbreaklinesstartingwith==false ||
($dontbreaklinesstartingwith &&
strlen($dontbreaklinesstartingwith)>=1 &&
substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
)
)
)
{
$s=explode(" ", $line);
$line = "";
$linecnt = 0;

View File

@ -32,6 +32,7 @@ class bosieve
$bopreferences = CreateObject('felamimail.bopreferences',$_restoreSession);
$mailPreferences = $bopreferences->getPreferences();
$icServer = $mailPreferences->getIncomingServer(0);
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.'->LoginName:'.$icServer->loginName);
$icServer->setVacationUser($icServer->loginName,$_vacation['scriptName'],$_vacation);
}
}

View File

@ -64,8 +64,6 @@
$this->rowColor[0] = $GLOBALS['egw_info']["theme"]["bg01"];
$this->rowColor[1] = $GLOBALS['egw_info']["theme"]["bg02"];
}
function unhtmlentities ($string)
@ -440,7 +438,10 @@
$disableRuler = true;
}
$insertSigOnTop = false;
if (isset($this->bocompose->preferencesArray['insertSignatureAtTopOfMessage']) && $this->bocompose->preferencesArray['insertSignatureAtTopOfMessage'])
if (isset($this->bocompose->preferencesArray['insertSignatureAtTopOfMessage']) &&
$this->bocompose->preferencesArray['insertSignatureAtTopOfMessage'] &&
!(isset($_POST['mySigID']) && !empty($_POST['mySigID']))
)
{
$insertSigOnTop = true;
if($sessionData['mimeType'] == 'html') {
@ -453,7 +454,6 @@
$sigText = bofelamimail::merge($signature->fm_signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
$sessionData['body'] = $before.($sessionData['mimeType'] == 'html'?$sigText:$this->bocompose->convertHTMLToText($sigText)).$inbetween.$sessionData['body'];
}
// prepare body
if($sessionData['mimeType'] == 'html') {
$mode = 'simple';

View File

@ -1665,6 +1665,7 @@ class infolog_ui
if ($bodyParts[$i]['mimeType'] == 'text/html') {
// convert HTML to text, as we dont want HTML in infologs
$newBody = html::purify($newBody);
$newBody = $bofelamimail->convertHTMLToText($newBody,true);
$bofelamimail->getCleanHTML($newBody); // new Body passed by reference
$message .= $newBody;

View File

@ -1531,5 +1531,30 @@ class html
}
}
}
/**
* split html by PRE tag, return array with all content pre-sections isolated in array elements
* @author Leithoff, Klaus
* @param string html
* @return mixed array of parts or unaffected html
*/
static function splithtmlByPRE($html)
{
if (($pos = stripos($html,'<pre>')) === false)
{
return $html;
}
$html2ret[] = substr($html,0,$pos);
while ($pos!==false)
{
$endofpre = stripos($html,'</pre>',$pos);
$length = $endofpre-$pos+6;
$html2ret[] = substr($html,$pos,$length);
$pos = stripos($html,'<pre>', $endofpre+6);
$html2ret[] = ($pos ? substr($html,$endofpre+6,$pos-($endofpre+6)): substr($html,$endofpre+6));
//$pos=false;
}
return $html2ret;
}
}
html::_init_static();

View File

@ -1139,6 +1139,7 @@ class translation
'@&(pound|#163);@i', // Pound
'@&(copy|#169);@i', // Copyright
'@&(reg|#174);@i', // Registered
'@&#39;@i', // singleQuote
);
$Replace = array ('',
'"',
@ -1151,11 +1152,26 @@ class translation
chr(163),
chr(169),
chr(174),
"'",
);
$_html = preg_replace($Rules, $Replace, $_html);
// removing carriage return linefeeds
if ($stripcrl === true ) $_html = preg_replace('@(\r\n)@i',' ',$_html);
// removing carriage return linefeeds, preserve those enclosed in <pre> </pre> tags
if ($stripcrl === true )
{
if (stripos($_html,'<pre>')!==false)
{
$contentArr = html::splithtmlByPRE($_html);
foreach ($contentArr as $k =>&$elem)
{
if (stripos($elem,'<pre>')===false)
{
$elem = preg_replace('@(\r\n)@i',' ',$elem);
}
}
$_html = implode('',$contentArr);
}
}
$tags = array (
0 => '~<h[123][^>]*>\r*\n*~si',
1 => '~<h[456][^>]*>\r*\n*~si',
@ -1168,6 +1184,9 @@ class translation
8 => '~<div[^>]*>\r*\n*~si',
9 => '~<hr[^>]*>\r*\n*~si',
10 => '/<blockquote type="cite">/',
11 => '/<blockquote>/',
12 => '~</blockquote>~si',
13 => '~<blockquote[^>]*>~si',
);
$Replace = array (
0 => "\r\n",
@ -1181,6 +1200,9 @@ class translation
8 => "\r\n",
9 => "\r\n__________________________________________________\r\n",
10 => '#blockquote#type#cite#',
11 => '#blockquote#type#cite#',
12 => '#blockquote#end#cite#',
13 => '#blockquote#type#cite#',
);
$_html = preg_replace($tags,$Replace,$_html);
$_html = preg_replace('~</t(d|h)>\s*<t(d|h)[^>]*>~si',' - ',$_html);
@ -1200,7 +1222,7 @@ class translation
#$_html = preg_replace('~^\s+~m','',$_html);
#$_html = preg_replace('~\s+$~m','',$_html);
// restoring the preserved blockquote
$_html = preg_replace('~#blockquote#type#cite#~s','<blockquote type="cite">',$_html);
//$_html = str_replace('#blockquote#type#cite#','<blockquote type="cite">',$_html);
$_html = html_entity_decode($_html, ENT_COMPAT, $displayCharset);
@ -1214,14 +1236,15 @@ class translation
$indent = 0;
$indentString = '';
$quoteParts = preg_split('/<blockquote type="cite">/', $_html, -1, PREG_SPLIT_OFFSET_CAPTURE);
//$quoteParts = preg_split('/<blockquote type="cite">/', $_html, -1, PREG_SPLIT_OFFSET_CAPTURE);
$quoteParts = preg_split('/#blockquote#type#cite#/', $_html, -1, PREG_SPLIT_OFFSET_CAPTURE);
foreach($quoteParts as $quotePart) {
if($quotePart[1] > 0) {
$indent++;
$indentString .= '>';
}
$quoteParts2 = preg_split('/<\/blockquote>/', $quotePart[0], -1, PREG_SPLIT_OFFSET_CAPTURE);
//$quoteParts2 = preg_split('/<\/blockquote>/', $quotePart[0], -1, PREG_SPLIT_OFFSET_CAPTURE);
$quoteParts2 = preg_split('/#blockquote#end#cite#/', $quotePart[0], -1, PREG_SPLIT_OFFSET_CAPTURE);
foreach($quoteParts2 as $quotePart2) {
if($quotePart2[1] > 0) {