replace original message header with fieldset in html and convert it to plain as before

This commit is contained in:
ralf 2022-05-10 11:51:35 +02:00
parent 5791ef0117
commit c4e0989bf9
2 changed files with 52 additions and 22 deletions

View File

@ -273,7 +273,7 @@ class Html
chr(161), chr(161),
chr(162), chr(162),
chr(163), chr(163),
'(C)',//chr(169),// copyrighgt '(C)',//chr(169),// copyright
'(R)',//chr(174),// registered '(R)',//chr(174),// registered
'(TM)',// trade '(TM)',// trade
"'", "'",
@ -282,6 +282,16 @@ class Html
); );
$_html = preg_replace($Rules, $Replace, $_html); $_html = preg_replace($Rules, $Replace, $_html);
// replace fieldset with legend used for original message header
$_html = preg_replace_callback('#<fieldset[^>]*>\s*<legend>(.*)</legend>\s*(.*)\s*</fieldset>#sm',
static function($matches)
{
$len_legend = strlen($legend = $matches[1]);
$content = preg_replace('/<([^@> ]+@[^> ]+)>/', '#lower#than#$1#greater#than#', $matches[2]);
return "<br>".str_repeat('-', (64-$len_legend-2)>>1).' '.$legend.' '.str_repeat('-', (64-$len_legend-2+1)>>1)."<br>".
$content.str_repeat('-', 64)."<br>";
}, $_html);
// removing carriage return linefeeds, preserve those enclosed in <pre> </pre> tags // removing carriage return linefeeds, preserve those enclosed in <pre> </pre> tags
if ($stripcrl === true ) if ($stripcrl === true )
{ {

View File

@ -2261,7 +2261,7 @@ class mail_compose
//_debug_array($bodyParts); //_debug_array($bodyParts);
$styles = Mail::getStyles($bodyParts); $styles = Mail::getStyles($bodyParts);
$fromAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$headers['FROM'])); $fromAddress = implode(', ', $headers['FROM']);
$toAddressA = array(); $toAddressA = array();
$toAddress = ''; $toAddress = '';
@ -2270,8 +2270,8 @@ class mail_compose
} }
if (count($toAddressA)>0) if (count($toAddressA)>0)
{ {
$toAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$toAddressA)); $toAddress = implode(', ', $toAddressA);
$toAddress = @htmlspecialchars(lang("to")).": ".$toAddress.($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n"); $toAddress = htmlspecialchars(lang("to").": ".$toAddress).($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n");
} }
$ccAddressA = array(); $ccAddressA = array();
$ccAddress = ''; $ccAddress = '';
@ -2280,15 +2280,18 @@ class mail_compose
} }
if (count($ccAddressA)>0) if (count($ccAddressA)>0)
{ {
$ccAddress = implode(', ', str_replace(array('<','>'),array('[',']'),$ccAddressA)); $ccAddress = implode(', ', $ccAddressA);
$ccAddress = @htmlspecialchars(lang("cc")).": ".$ccAddress.($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n"); $ccAddress = htmlspecialchars(lang("cc").": ".$ccAddress).($bodyParts['0']['mimeType'] == 'text/html'?"<br>":"\r\n");
} }
if($bodyParts['0']['mimeType'] == 'text/html') { // create original message header in users preferred font and -size
$this->sessionData['body'] = "<br>"."<div>".'----------------'.lang("original message").'-----------------'."".'<br>'. $this->sessionData['body'] = self::wrapBlockWithPreferredFont(
@htmlspecialchars(lang("from")).": ".$fromAddress."<br>". htmlspecialchars(lang("from").": ".$fromAddress)."<br>".
$toAddress.$ccAddress. $toAddress.$ccAddress.
@htmlspecialchars(lang("date").": ".Mail::_strtotime($headers['DATE'],'r',true),ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."<br>". htmlspecialchars(lang("date").": ".Mail::_strtotime($headers['DATE'],'r',true),ENT_QUOTES | ENT_IGNORE, Mail::$displayCharset, false),
'----------------------------------------------------------'."</div>"; lang("original message"), 'originalMessage');
if($bodyParts['0']['mimeType'] == 'text/html')
{
$this->sessionData['mimeType'] = 'html'; $this->sessionData['mimeType'] = 'html';
if (!empty($styles)) $this->sessionData['body'] .= $styles; if (!empty($styles)) $this->sessionData['body'] .= $styles;
$this->sessionData['body'] .= '<blockquote type="cite">'; $this->sessionData['body'] .= '<blockquote type="cite">';
@ -2314,14 +2317,12 @@ class mail_compose
$this->sessionData['body'] .= '</blockquote><br>'; $this->sessionData['body'] .= '</blockquote><br>';
$this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'html'); $this->sessionData['body'] = mail_ui::resolve_inline_images($this->sessionData['body'], $_folder, $_uid, $_partID, 'html');
} else { }
//$this->sessionData['body'] = @htmlspecialchars(lang("on")." ".$headers['DATE']." ".$mail_bo->decode_header($fromAddress), ENT_QUOTES) . " ".lang("wrote").":\r\n"; else
// take care the way the ReplyHeader is created here, is used later on in uicompose::compose, in case you force replys to be HTML (prefs) {
$this->sessionData['body'] = " \r\n \r\n".'----------------'.lang("original message").'-----------------'."\r\n". // convert original message header to plain-text
@htmlspecialchars(lang("from")).": ".$fromAddress."\r\n". $this->sessionData['body'] = self::convertHTMLToText($this->sessionData['body'], true, false, true);
$toAddress.$ccAddress.
@htmlspecialchars(lang("date").": ".Mail::_strtotime($headers['DATE'],'r',true), ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."\r\n".
'-------------------------------------------------'."\r\n \r\n ";
$this->sessionData['mimeType'] = 'plain'; $this->sessionData['mimeType'] = 'plain';
foreach($bodyParts as $i => &$bodyPart) foreach($bodyParts as $i => &$bodyPart)
{ {
@ -2368,11 +2369,30 @@ class mail_compose
} }
/**
* Wrap html block in given tag with preferred font and -size set
*
* @param string $content
* @param string $legend
* @param ?string $class
* @return string
*/
static function wrapBlockWithPreferredFont($content, $legend, $class=null)
{
$options = ' style="border: 2px solid silver; border-left: none; border-right: none;'.
'font-family: '.($GLOBALS['egw_info']['user']['preferences']['common']['rtf_font'] ?? 'arial, helvetica, sans-serif').
'; font-size: '.($GLOBALS['egw_info']['user']['preferences']['common']['rtf_size'] ?? '10').'pt"';
if (!empty($class)) $options .= ' class="'.htmlspecialchars($class).'"';
return Api\Html::fieldset($content, $legend, $options);
}
/** /**
* HTML cleanup * HTML cleanup
* *
* @param type $_body message * @param type $_body message
* @param type $_useTidy = false, if true tidy extention will be loaded and tidy will try to clean body message * @param type $_useTidy = false, if true tidy extension will be loaded and tidy will try to clean body message
* since the tidy causes segmentation fault ATM, we set the default to false. * since the tidy causes segmentation fault ATM, we set the default to false.
* @return type * @return type
*/ */