Skip to content

Commit

Permalink
Fix user reply to a notification being incorrectly cropped - closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Dec 11, 2023
1 parent 895af2d commit f1839bc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
18 changes: 14 additions & 4 deletions app/Console/Commands/FetchEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,15 @@ public function processMessage($message, $message_id, $mailbox, $mailboxes, $ext
// Get body and do not replace :cid with images base64
$html_body = $message->getHTMLBody(false);
}
$is_html = true;
if ($html_body) {
$body = $this->separateReply($html_body, true, $is_reply);
$body = $html_body;
} else {
$is_html = false;
$body = $message->getTextBody();
$body = $this->separateReply($body, false, $is_reply);
}
$body = $this->separateReply($body, $is_html, $is_reply, !$message_from_customer);

// We have to fetch absolutely all emails, even with empty body.
// if (!$body) {
// $this->logError('Message body is empty');
Expand Down Expand Up @@ -1230,7 +1233,7 @@ public function processAttachmentName($name)
*
* @return string
*/
public function separateReply($body, $is_html, $is_reply)
public function separateReply($body, $is_html, $is_reply, $user_reply_to_notification = false)
{
$cmp_reply_length_desc = function ($a, $b) {
if (mb_strlen($a) == mb_strlen($b)) {
Expand Down Expand Up @@ -1280,12 +1283,19 @@ public function separateReply($body, $is_html, $is_reply)
if ($is_reply) {
// Check all separators and choose the shortest reply
$reply_bodies = [];

$reply_separators = Mail::$alternative_reply_separators;

if (!empty($this->mailbox->before_reply)) {
$reply_separators[] = $this->mailbox->before_reply;
}

// If user replied to the email notification use only predefined reply separator.
// https://github.com/freescout-helpdesk/freescout/issues/3580
if ($user_reply_to_notification && strstr($result, \MailHelper::REPLY_SEPARATOR_NOTIFICATION)) {
$reply_separators = [\MailHelper::REPLY_SEPARATOR_NOTIFICATION];
}

foreach ($reply_separators as $reply_separator) {
if (\Str::startsWith($reply_separator, 'regex:')) {
$regex = preg_replace("/^regex:/", '', $reply_separator);
Expand All @@ -1294,7 +1304,7 @@ public function separateReply($body, $is_html, $is_reply)
$parts = explode($reply_separator, $result);
}
if (count($parts) > 1) {
// Check if past contains any real text.
// Check if part contains any real text.
$text = \Helper::htmlToText($parts[0]);
$text = trim($text);
$text = preg_replace('/^\s+/mu', '', $text);
Expand Down
1 change: 1 addition & 0 deletions app/Misc/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Mail
*/
const REPLY_SEPARATOR_HTML = 'fsReplyAbove';
const REPLY_SEPARATOR_TEXT = '-- Please reply above this line --';
const REPLY_SEPARATOR_NOTIFICATION = 'fsNotificationReplyAbove';

/**
* Message-ID prefixes for outgoing emails.
Expand Down
2 changes: 1 addition & 1 deletion resources/views/emails/customer/reply_fancy.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</style>
</head>
<body style="-webkit-text-size-adjust:none;">
<div id="{{ App\Misc\Mail::REPLY_SEPARATOR_HTML }}" class="{{ App\Misc\Mail::REPLY_SEPARATOR_HTML }}" style="width:100%!important; margin:0; padding:0">
<div id="{{ App\Misc\Mail::REPLY_SEPARATOR_HTML }}" class="{{ App\Misc\Mail::REPLY_SEPARATOR_HTML }}" data-fs="{{ App\Misc\Mail::REPLY_SEPARATOR_HTML }}" style="width:100%!important; margin:0; padding:0">
@php
$is_forwarded = !empty($threads[0]) ? $threads[0]->isForwarded() : false;
@endphp
Expand Down
2 changes: 1 addition & 1 deletion resources/views/emails/user/notification.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<![endif]-->
</head>
<body bgcolor="#f8f9f9" style="-webkit-text-size-adjust:none; margin: 0;">
<table bgcolor="#f8f9f9" cellspacing="0" border="0" cellpadding="0" width="100%">
<table bgcolor="#f8f9f9" cellspacing="0" border="0" cellpadding="0" width="100%" id="{{ \MailHelper::REPLY_SEPARATOR_NOTIFICATION }}" class="{{ \MailHelper::REPLY_SEPARATOR_NOTIFICATION }}" data-fs="{{ \MailHelper::REPLY_SEPARATOR_NOTIFICATION }}">
<tr>
<td>
<table class="content" width="100%" border="0" cellspacing="0" cellpadding="0">
Expand Down

0 comments on commit f1839bc

Please sign in to comment.