From 369585763a3e6d65115e876b6f498eda5bbaf39f Mon Sep 17 00:00:00 2001 From: ralf Date: Fri, 29 Apr 2022 12:49:41 +0200 Subject: [PATCH] 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 --- mail/inc/class.mail_compose.inc.php | 62 ++++++++++++----------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/mail/inc/class.mail_compose.inc.php b/mail/inc/class.mail_compose.inc.php index ac84d3c56d..1adc3d5f00 100644 --- a/mail/inc/class.mail_compose.inc.php +++ b/mail/inc/class.mail_compose.inc.php @@ -358,8 +358,8 @@ class mail_compose { $_content = array_merge((array)$_content, $this->getComposeFrom( // Parameters needed for fetching appropriate data - $replyID, $_GET['part_id'], $_GET['from'], - // Additionally may be changed + $replyID, $_GET['part_id'] ?? null, $_GET['from'] ?? null, + // additionally these can be changed $_focusElement, $suppressSigOnTop, $isReply )); if (Mail\Smime::get_acc_smime($this->mail_bo->profileID)) @@ -491,7 +491,7 @@ class mail_compose { $buttonClicked = $suppressSigOnTop = 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: $_content['to'];$_content['cc'];$_content['bcc']; @@ -525,7 +525,7 @@ class mail_compose 'content' => $_content, )); - if ($success==false) + if (!$success) { $sendOK=false; $message = $this->errorInfo; @@ -622,20 +622,12 @@ class mail_compose if ($activeProfile != $composeProfile) $this->changeProfile($activeProfile); $insertSigOnTop = false; - $content = (is_array($_content)?$_content:array()); + $content = $_content ?? []; if ($_contentHasMimeType) { // mimeType is now a checkbox; convert it here to match expectations // ToDo: match Code to meet checkbox value - if ($content['mimeType']==1) - { - $_content['mimeType'] = $content['mimeType']='html'; - } - else - { - $_content['mimeType'] = $content['mimeType']='plain'; - } - + $_content['mimetype'] = $content['mimeType'] = !empty($content['mimeType']) ? 'html' : 'plain'; } // user might have switched desired mimetype, so we should convert if (!empty($content['is_html']) && $content['mimeType'] === 'plain') @@ -676,10 +668,9 @@ class mail_compose $content['is_plain'] = false; } - $content['body'] = ($content['body'] ? $content['body'] : $content['mail_'.($content['mimeType'] == 'html'?'html':'plain').'text']); - unset($_content['body']); - unset($_content['mail_htmltext']); - unset($_content['mail_plaintext']); + $content['body'] = $content['body'] ?? $content['mail_'.($content['mimeType'] === 'html'?'html':'plain').'text'] ?? + ($content['mimeType'] === 'html' ? '
' : ''); + unset($_content['body'], $_content['mail_htmltext'], $_content['mail_plaintext']); $_currentMode = $_content['mimeType']; // 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? // only the following values are supported (and make sense) // no => means -2 @@ -1255,6 +1241,7 @@ class mail_compose str_replace('"','',$identities[$this->mail_bo->getDefaultIdentity()])) { // preserve/restore the value to content. + /** @noinspection UnsupportedStringOffsetOperationsInspection */ $content[strtolower($destination)][]=$value; continue; } @@ -1264,6 +1251,7 @@ class mail_compose if ($addressObject->host === '.SYNTAX-ERROR.') continue; $address = imap_rfc822_write_address($addressObject->mailbox,$addressObject->host,$addressObject->personal); //$address = Mail::htmlentities($address, $this->displayCharset); + /** @noinspection UnsupportedStringOffsetOperationsInspection */ $content[strtolower($destination)][]=$address; $destinationRows++; } @@ -2309,7 +2297,7 @@ class mail_compose $ccAddress = @htmlspecialchars(lang("cc")).": ".$ccAddress.($bodyParts['0']['mimeType'] == 'text/html'?"
":"\r\n"); } if($bodyParts['0']['mimeType'] == 'text/html') { - $this->sessionData['body'] = /*"
".*//*" ".*/"
".'----------------'.lang("original message").'-----------------'."".'
'. + $this->sessionData['body'] = "
"."
".'----------------'.lang("original message").'-----------------'."".'
'. @htmlspecialchars(lang("from")).": ".$fromAddress."
". $toAddress.$ccAddress. @htmlspecialchars(lang("date").": ".Mail::_strtotime($headers['DATE'],'r',true),ENT_QUOTES | ENT_IGNORE,Mail::$displayCharset, false)."
". @@ -2318,22 +2306,23 @@ class mail_compose if (!empty($styles)) $this->sessionData['body'] .= $styles; $this->sessionData['body'] .= '
'; - for($i=0; $i &$bodyPart) + { if($i>0) { $this->sessionData['body'] .= '
'; } - if($bodyParts[$i]['mimeType'] == 'text/plain') { - #$bodyParts[$i]['body'] = nl2br($bodyParts[$i]['body'])."
"; - $bodyParts[$i]['body'] = "
".$bodyParts[$i]['body']."
"; + if($bodyPart['mimeType'] == 'text/plain') { + #$bodyPart['body'] = nl2br($bodyPart['body'])."
"; + $bodyPart['body'] = "
".$bodyPart['body']."
"; } - 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; Mail::$htmLawed_config['comment'] = 2; Mail::$htmLawed_config['transform_anchor'] = false; - $this->sessionData['body'] .= "
".self::_getCleanHTML(Api\Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet'])); + $this->sessionData['body'] .= "
".self::_getCleanHTML(Api\Translation::convert_jsonsafe($bodyPart['body'], $bodyPart['charSet'])); 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'] .= '

'; @@ -2347,15 +2336,15 @@ class mail_compose @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'; - $countBodyParts = count((array)$bodyParts); - for($i=0; $i<$countBodyParts; $i++) { + foreach($bodyParts as $i => &$bodyPart) + { if($i>0) { $this->sessionData['body'] .= "
"; } // add line breaks to $bodyParts - $newBody2 = Api\Translation::convert_jsonsafe($bodyParts[$i]['body'],$bodyParts[$i]['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')); + $newBody2 = Api\Translation::convert_jsonsafe($bodyPart['body'],$bodyPart['charSet']); + #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'); $this->sessionData['body'] .= "\r\n"; $hasSignature = false; @@ -2564,7 +2553,7 @@ class mail_compose $_mailObject->setHtmlBody($body, null, false); // false = no automatic alternative, we called setBody() break; case 'openpgp': - $_mailObject->setOpenPgpBody($_formData['body']); + $_mailObject->setOpenPgpBody($_formData['body'].$attachment_links); break; default: $body = $this->convertHTMLToText($_formData['body'],false, false, true, true); @@ -3023,6 +3012,7 @@ class mail_compose // create the messages and store inline images $inline_images = $this->createMessage($mail, $_formData, $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?'>':''); #print "
". $mail->getMessageHeader() ."


"; #print "
". $mail->getMessageBody() ."


";