add empty line above signature / replied message and ruler to start writing message

also some code cleanups and fix undefined array-key or variable warnings
This commit is contained in:
ralf 2022-04-29 12:49:41 +02:00
parent 21d362b5fa
commit ddc2b082c1

View File

@ -358,8 +358,8 @@ class mail_compose
{ {
$_content = array_merge((array)$_content, $this->getComposeFrom( $_content = array_merge((array)$_content, $this->getComposeFrom(
// Parameters needed for fetching appropriate data // Parameters needed for fetching appropriate data
$replyID, $_GET['part_id'], $_GET['from'], $replyID, $_GET['part_id'] ?? null, $_GET['from'] ?? null,
// Additionally may be changed // additionally these can be changed
$_focusElement, $suppressSigOnTop, $isReply $_focusElement, $suppressSigOnTop, $isReply
)); ));
if (Mail\Smime::get_acc_smime($this->mail_bo->profileID)) if (Mail\Smime::get_acc_smime($this->mail_bo->profileID))
@ -491,7 +491,7 @@ class mail_compose
{ {
$buttonClicked = $suppressSigOnTop = true; $buttonClicked = $suppressSigOnTop = true;
$sendOK = true; $sendOK = true;
$_content['body'] = ($_content['body'] ? $_content['body'] : $_content['mail_'.($_content['mimeType'] == 'html'?'html':'plain').'text']); $_content['body'] = $_content['body'] ?? $_content['mail_'.($_content['mimeType'] == 'html'?'html':'plain').'text'] ?? null;
/* /*
perform some simple checks, before trying to send on: perform some simple checks, before trying to send on:
$_content['to'];$_content['cc'];$_content['bcc']; $_content['to'];$_content['cc'];$_content['bcc'];
@ -525,7 +525,7 @@ class mail_compose
'content' => $_content, 'content' => $_content,
)); ));
if ($success==false) if (!$success)
{ {
$sendOK=false; $sendOK=false;
$message = $this->errorInfo; $message = $this->errorInfo;
@ -622,20 +622,12 @@ class mail_compose
if ($activeProfile != $composeProfile) $this->changeProfile($activeProfile); if ($activeProfile != $composeProfile) $this->changeProfile($activeProfile);
$insertSigOnTop = false; $insertSigOnTop = false;
$content = (is_array($_content)?$_content:array()); $content = $_content ?? [];
if ($_contentHasMimeType) if ($_contentHasMimeType)
{ {
// mimeType is now a checkbox; convert it here to match expectations // mimeType is now a checkbox; convert it here to match expectations
// ToDo: match Code to meet checkbox value // ToDo: match Code to meet checkbox value
if ($content['mimeType']==1) $_content['mimetype'] = $content['mimeType'] = !empty($content['mimeType']) ? 'html' : 'plain';
{
$_content['mimeType'] = $content['mimeType']='html';
}
else
{
$_content['mimeType'] = $content['mimeType']='plain';
}
} }
// user might have switched desired mimetype, so we should convert // user might have switched desired mimetype, so we should convert
if (!empty($content['is_html']) && $content['mimeType'] === 'plain') if (!empty($content['is_html']) && $content['mimeType'] === 'plain')
@ -676,10 +668,9 @@ class mail_compose
$content['is_plain'] = false; $content['is_plain'] = false;
} }
$content['body'] = ($content['body'] ? $content['body'] : $content['mail_'.($content['mimeType'] == 'html'?'html':'plain').'text']); $content['body'] = $content['body'] ?? $content['mail_'.($content['mimeType'] === 'html'?'html':'plain').'text'] ??
unset($_content['body']); ($content['mimeType'] === 'html' ? '<br>' : '');
unset($_content['mail_htmltext']); unset($_content['body'], $_content['mail_htmltext'], $_content['mail_plaintext']);
unset($_content['mail_plaintext']);
$_currentMode = $_content['mimeType']; $_currentMode = $_content['mimeType'];
// we have to keep comments to be able to changing signatures // we have to keep comments to be able to changing signatures
@ -1119,11 +1110,6 @@ class mail_compose
} }
} }
if ($content['mimeType'] == 'html' && Api\Html::htmlarea_availible()===false)
{
$_content['mimeType'] = $content['mimeType'] = 'plain';
$content['body'] = $this->convertHTMLToText($content['body']);
}
// is a certain signature requested? // is a certain signature requested?
// only the following values are supported (and make sense) // only the following values are supported (and make sense)
// no => means -2 // no => means -2
@ -1245,6 +1231,7 @@ class mail_compose
str_replace('"','',$identities[$this->mail_bo->getDefaultIdentity()])) str_replace('"','',$identities[$this->mail_bo->getDefaultIdentity()]))
{ {
// preserve/restore the value to content. // preserve/restore the value to content.
/** @noinspection UnsupportedStringOffsetOperationsInspection */
$content[strtolower($destination)][]=$value; $content[strtolower($destination)][]=$value;
continue; continue;
} }
@ -1254,6 +1241,7 @@ class mail_compose
if ($addressObject->host === '.SYNTAX-ERROR.') continue; if ($addressObject->host === '.SYNTAX-ERROR.') continue;
$address = imap_rfc822_write_address($addressObject->mailbox,$addressObject->host,$addressObject->personal); $address = imap_rfc822_write_address($addressObject->mailbox,$addressObject->host,$addressObject->personal);
//$address = Mail::htmlentities($address, $this->displayCharset); //$address = Mail::htmlentities($address, $this->displayCharset);
/** @noinspection UnsupportedStringOffsetOperationsInspection */
$content[strtolower($destination)][]=$address; $content[strtolower($destination)][]=$address;
$destinationRows++; $destinationRows++;
} }
@ -2299,7 +2287,7 @@ class mail_compose
$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') { if($bodyParts['0']['mimeType'] == 'text/html') {
$this->sessionData['body'] = /*"<br>".*//*"&nbsp;".*/"<div>".'----------------'.lang("original message").'-----------------'."".'<br>'. $this->sessionData['body'] = "<br>"."<div>".'----------------'.lang("original message").'-----------------'."".'<br>'.
@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)."<br>".
@ -2308,22 +2296,23 @@ class mail_compose
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">';
for($i=0; $i<count($bodyParts); $i++) { foreach($bodyParts as $i => &$bodyPart)
{
if($i>0) { if($i>0) {
$this->sessionData['body'] .= '<hr>'; $this->sessionData['body'] .= '<hr>';
} }
if($bodyParts[$i]['mimeType'] == 'text/plain') { if($bodyPart['mimeType'] == 'text/plain') {
#$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body'])."<br>"; #$bodyPart['body'] = nl2br($bodyPart['body'])."<br>";
$bodyParts[$i]['body'] = "<pre>".$bodyParts[$i]['body']."</pre>"; $bodyPart['body'] = "<pre>".$bodyPart['body']."</pre>";
} }
if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Mail::detect_encoding($bodyParts[$i]['body']); if ($bodyPart['charSet']===false) $bodyPart['charSet'] = Mail::detect_encoding($bodyPart['body']);
$_htmlConfig = Mail::$htmLawed_config; $_htmlConfig = Mail::$htmLawed_config;
Mail::$htmLawed_config['comment'] = 2; Mail::$htmLawed_config['comment'] = 2;
Mail::$htmLawed_config['transform_anchor'] = false; Mail::$htmLawed_config['transform_anchor'] = false;
$this->sessionData['body'] .= "<br>".self::_getCleanHTML(Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet'])); $this->sessionData['body'] .= "<br>".self::_getCleanHTML(Api\Translation::convert_jsonsafe($bodyPart['body'], $bodyPart['charSet']));
Mail::$htmLawed_config = $_htmlConfig; Mail::$htmLawed_config = $_htmlConfig;
#error_log( "GetReplyData (HTML) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1')); #error_log( "GetReplyData (HTML) CharSet:".mb_detect_encoding($bodyPart['body'] . 'a' , strtoupper($bodyPart['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
} }
$this->sessionData['body'] .= '</blockquote><br>'; $this->sessionData['body'] .= '</blockquote><br>';
@ -2337,15 +2326,15 @@ class mail_compose
@htmlspecialchars(lang("date").": ".Mail::_strtotime($headers['DATE'],'r',true), ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."\r\n". @htmlspecialchars(lang("date").": ".Mail::_strtotime($headers['DATE'],'r',true), ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."\r\n".
'-------------------------------------------------'."\r\n \r\n "; '-------------------------------------------------'."\r\n \r\n ";
$this->sessionData['mimeType'] = 'plain'; $this->sessionData['mimeType'] = 'plain';
$countBodyParts = count((array)$bodyParts); foreach($bodyParts as $i => &$bodyPart)
for($i=0; $i<$countBodyParts; $i++) { {
if($i>0) { if($i>0) {
$this->sessionData['body'] .= "<hr>"; $this->sessionData['body'] .= "<hr>";
} }
// add line breaks to $bodyParts // add line breaks to $bodyParts
$newBody2 = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'],$bodyParts[$i]['charSet']); $newBody2 = Api\Translation::convert_jsonsafe($bodyPart['body'],$bodyPart['charSet']);
#error_log( "GetReplyData (Plain) CharSet:".mb_detect_encoding($bodyParts[$i]['body'] . 'a' , strtoupper($bodyParts[$i]['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1')); #error_log( "GetReplyData (Plain) CharSet:".mb_detect_encoding($bodyPart['body'] . 'a' , strtoupper($bodyPart['charSet']).','.strtoupper($this->displayCharset).',UTF-8, ISO-8859-1'));
$newBody = mail_ui::resolve_inline_images($newBody2, $_folder, $_uid, $_partID, 'plain'); $newBody = mail_ui::resolve_inline_images($newBody2, $_folder, $_uid, $_partID, 'plain');
$this->sessionData['body'] .= "\r\n"; $this->sessionData['body'] .= "\r\n";
$hasSignature = false; $hasSignature = false;
@ -2554,7 +2543,7 @@ class mail_compose
$_mailObject->setHtmlBody($body, null, false); // false = no automatic alternative, we called setBody() $_mailObject->setHtmlBody($body, null, false); // false = no automatic alternative, we called setBody()
break; break;
case 'openpgp': case 'openpgp':
$_mailObject->setOpenPgpBody($_formData['body']); $_mailObject->setOpenPgpBody($_formData['body'].$attachment_links);
break; break;
default: default:
$body = $this->convertHTMLToText($_formData['body'],false, false, true, true); $body = $this->convertHTMLToText($_formData['body'],false, false, true, true);
@ -3013,6 +3002,7 @@ class mail_compose
// create the messages and store inline images // create the messages and store inline images
$inline_images = $this->createMessage($mail, $_formData, $identity); $inline_images = $this->createMessage($mail, $_formData, $identity);
// remember the identity // remember the identity
/** @noinspection MissingIssetImplementationInspection */
if (!empty($mail->From) && ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on')) $fromAddress = $mail->From;//$mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':''); if (!empty($mail->From) && ($_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on')) $fromAddress = $mail->From;//$mail->FromName.($mail->FromName?' <':'').$mail->From.($mail->FromName?'>':'');
#print "<pre>". $mail->getMessageHeader() ."</pre><hr><br>"; #print "<pre>". $mail->getMessageHeader() ."</pre><hr><br>";
#print "<pre>". $mail->getMessageBody() ."</pre><hr><br>"; #print "<pre>". $mail->getMessageBody() ."</pre><hr><br>";