Skip to content

Commit

Permalink
Fix fetching emails forwarded using @fwd command - closes #4036
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed May 21, 2024
1 parent 4f253bf commit 61e5f1f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/Console/Commands/FetchEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -683,6 +682,12 @@ public function processMessage($message, $message_id, $mailbox, $mailboxes, $ext
}
}

// separateReply() function may distort original HTML if email
// is mentioned as <[email protected]> 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()),
Expand Down Expand Up @@ -839,6 +844,7 @@ public function getOriginalSenderFromFwd($body)
$email = $b[1] ?? '';
// https://github.com/freescout-helpdesk/freescout/issues/2517
$email = preg_replace("#.*&lt(.*)&gt.*#", "$1", $email);
return Email::sanitizeEmail($email);
}
Expand Down

0 comments on commit 61e5f1f

Please sign in to comment.