From 61e5f1fde5e6e1df7f356784e8393c41a3871bb2 Mon Sep 17 00:00:00 2001 From: FreeScout Date: Tue, 21 May 2024 11:36:15 -0700 Subject: [PATCH] Fix fetching emails forwarded using @fwd command - closes #4036 --- app/Console/Commands/FetchEmails.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/FetchEmails.php b/app/Console/Commands/FetchEmails.php index b646dcb86..cb33fd413 100644 --- a/app/Console/Commands/FetchEmails.php +++ b/app/Console/Commands/FetchEmails.php @@ -623,7 +623,6 @@ public function processMessage($message, $message_id, $mailbox, $mailboxes, $ext $body = $message->getTextBody() ?? ''; $body = htmlspecialchars($body); } - $body = $this->separateReply($body, $is_html, $is_reply, !$message_from_customer, (($message_from_customer && $prev_thread) ? $prev_thread->getMessageId($mailbox) : '')); // We have to fetch absolutely all emails, even with empty body. // if (!$body) { @@ -646,7 +645,7 @@ public function processMessage($message, $message_id, $mailbox, $mailboxes, $ext // It will always return an empty value as it's Bcc. $bcc = $this->formatEmailList($message->getBcc()); - + // If existing user forwarded customer's email to the mailbox // we are creating a new conversation as if it was sent by the customer. if ($in_reply_to @@ -683,6 +682,12 @@ public function processMessage($message, $message_id, $mailbox, $mailboxes, $ext } } + // separateReply() function may distort original HTML if email + // is mentioned as and it will interpret it as a tag. + // https://github.com/freescout-helpdesk/freescout/issues/4036 + + $body = $this->separateReply($body, $is_html, $is_reply, !$message_from_customer, (($message_from_customer && $prev_thread) ? $prev_thread->getMessageId($mailbox) : '')); + // Create customers $emails = array_merge( $this->attrToArray($message->getFrom()), @@ -839,6 +844,7 @@ public function getOriginalSenderFromFwd($body) $email = $b[1] ?? ''; // https://github.com/freescout-helpdesk/freescout/issues/2517 $email = preg_replace("#.*<(.*)>.*#", "$1", $email); + return Email::sanitizeEmail($email); }