Skip to content

Commit 3f813a0

Browse files
Improve MSO comments processing in incoming emails - closes #5068
1 parent 19e765f commit 3f813a0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

app/Thread.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@ public function getCleanBody($body = '')
316316
// Cut out "collapse" class as it hides elements.
317317
$body = preg_replace("/(<[^<>\r\n]+class=([\"'][^\"']* |[\"']))(collapse|hidden)([\"' ])/", '$1$4', $body) ?: $body;
318318

319+
// Take care of MSO-comments.
320+
// https://github.com/freescout-help-desk/freescout/issues/5068
321+
// Step 1: Completely remove the MSO-specific blocks.
322+
// The 's' flag allows '.' to match newlines, and 'i' makes it case-insensitive.
323+
$body = preg_replace('/<!--\[if mso\]>.*?<!\[endif\]-->/is', '', $body);
324+
// Step 2: Unwrap the standard HTML from the "not mso" comments.
325+
// This reveals the standard <a> tag for the purifier.
326+
$body = preg_replace('/<!--\[if !mso\]><!--\s*-->(.*?)<!--\s*<!\[endif\]-->/is', '$1', $body);
327+
319328
// Remove only the <!--[if !mso]><!--> and <!--<![endif]--> around the elements.
320329
// https://github.com/freescout-helpdesk/freescout/pull/3865#issuecomment-1990758149
321330
$body = preg_replace('/<!\-\-\[if [^>]+\]><!\-\->(.*?)<![ ]+\-\-<!\[endif\]\-\->/s', '$1', $body);

0 commit comments

Comments
 (0)