Skip to content

Commit

Permalink
Fixed banner removal for Outlook clients
Browse files Browse the repository at this point in the history
  • Loading branch information
willbrowningme committed Nov 10, 2022
1 parent 2fa8523 commit fa5a7a8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
17 changes: 13 additions & 4 deletions app/Mail/ReplyToEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ public function build()

if ($this->emailText) {
$this->email->text('emails.reply.text')->with([
'text' => $this->removeRealEmailAndBanner(base64_decode($this->emailText))
'text' => $this->removeRealEmailAndTextBanner(base64_decode($this->emailText))
]);
}

if ($this->emailHtml) {
$this->email->view('emails.reply.html')->with([
'html' => $this->removeRealEmailAndBanner(base64_decode($this->emailHtml))
'html' => $this->removeRealEmailAndHtmlBanner(base64_decode($this->emailHtml))
]);
}

Expand Down Expand Up @@ -205,8 +205,17 @@ private function needsDkimSignature()
return $this->alias->isCustomDomain() ? $this->alias->aliasable->isVerifiedForSending() : false;
}

private function removeRealEmailAndBanner($text)
private function removeRealEmailAndTextBanner($text)
{
return Str::of(str_ireplace($this->sender, '', $text))->replaceMatches('/(?s)(<!--banner-info-->).*?(<!--banner-info-->)/', '');
return Str::of(str_ireplace($this->sender, '', $text))
->replaceMatches('/(?s)(<!--banner-info-->).*?(<!--banner-info-->)/', '');
}

private function removeRealEmailAndHtmlBanner($html)
{
return Str::of(str_ireplace($this->sender, '', $html))
->replaceMatches('/(?s)(<!--banner-info-->).*?(<!--banner-info-->)/mi', '')
// Outlook changing the ID to x_banner-info
->replaceMatches('/(?s)(<tr id="(x_)?banner-info">).*?(<\/tr>)/mi', '');
}
}
17 changes: 13 additions & 4 deletions app/Mail/SendFromEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ public function build()

if ($this->emailText) {
$this->email->text('emails.reply.text')->with([
'text' => $this->removeRealEmailAndBanner(base64_decode($this->emailText))
'text' => $this->removeRealEmailAndTextBanner(base64_decode($this->emailText))
]);
}

if ($this->emailHtml) {
$this->email->view('emails.reply.html')->with([
'html' => $this->removeRealEmailAndBanner(base64_decode($this->emailHtml))
'html' => $this->removeRealEmailAndHtmlBanner(base64_decode($this->emailHtml))
]);
}

Expand Down Expand Up @@ -191,8 +191,17 @@ private function needsDkimSignature()
return $this->alias->isCustomDomain() ? $this->alias->aliasable->isVerifiedForSending() : false;
}

private function removeRealEmailAndBanner($text)
private function removeRealEmailAndTextBanner($text)
{
return Str::of(str_ireplace($this->sender, '', $text))->replaceMatches('/(?s)(<!--banner-info-->).*?(<!--banner-info-->)/', '');
return Str::of(str_ireplace($this->sender, '', $text))
->replaceMatches('/(?s)(<!--banner-info-->).*?(<!--banner-info-->)/mi', '');
}

private function removeRealEmailAndHtmlBanner($html)
{
return Str::of(str_ireplace($this->sender, '', $html))
->replaceMatches('/(?s)(<!--banner-info-->).*?(<!--banner-info-->)/mi', '')
// Outlook changing the ID to x_banner-info
->replaceMatches('/(?s)(<tr id="(x_)?banner-info">).*?(<\/tr>)/mi', '');
}
}
11 changes: 3 additions & 8 deletions resources/views/emails/forward/html_banner.blade.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<!--banner-info-->
<tr>
<tr id="banner-info">
<td>
<div style="margin:0px auto;max-width:896px;padding:10px 20px;background-color:#f5f7fa;text-align:center;line-height:1.5;font-size:12px;width:100%;border-left: 3px solid #19216c;font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';color:#323f4b;">
<div style="margin:0px auto;max-width:896px;padding:10px 20px;background-color:#f5f7fa;text-align:center;line-height:1.5;font-size:12px;width:100%;border-left: 3px solid #19216c;font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';color:#323f4b;overflow-wrap:break-word;">
This email was sent to <span style="font-weight:500;color:#19216c;">{{ $aliasEmail }}</span>{{ $aliasDescription ? ' (' . $aliasDescription . ')' : '' }} from <span style="font-weight:500;color:#19216c;">{{ $fromEmail }}</span>{{ $replacedSubject }}<br>Click <a href="{{ $deactivateUrl }}" style="color:#2d3a8c;text-decoration:underline;" target="_blank" rel="noreferrer noopener nofollow">here</a> to deactivate this alias
</div>
</td>
</tr>
<!--banner-info-->



</tr>
2 changes: 1 addition & 1 deletion resources/views/mail/spam_reply_send_attempt.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Attempted Reply/Send Failed

An attempt to send or reply from your alias **{{ $aliasEmail }}** was just made from **{{ $recipient }}** which failed because it didn't pass authentication checks and could be a spoofed.
An attempt to send or reply from your alias **{{ $aliasEmail }}** was just made from **{{ $recipient }}** which failed because it didn't pass authentication checks and could be spoofed.

In order to send or reply from an alias there must be a valid DMARC policy present for **{{ \Illuminate\Support\Str::afterLast($recipient, '@') }}** and your message must be permitted by that DMARC policy.

Expand Down
4 changes: 1 addition & 3 deletions tests/emails/email_reply.eml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ Content-Transfer-Encoding: quoted-printable

<table style="width:100%;">
<tbody>
<!--banner-info-->
<tr>
<tr id="banner-info">
<td>
<div style="margin:0px auto;max-width:896px;padding:10px 20px;background-color:#f5f7fa;text-align:center;line-height:1.5;font-size:12px;width:100%;border-left: 3px solid #19216c;font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';color:#3e4c59;">
This email was sent to <span style="font-weight:500;color:#19216c;">[email protected]</span> (ebay.com) from <span style="font-weight:500;color:#19216c;">[email protected]</span><br>Click <a href="https://anonaddy.test/deactivate/xyz" style="color:#2d3a8c;text-decoration:underline;" target="_blank" rel="noreferrer noopener nofollow">here</a> to deactivate this alias
</div>
</td>
</tr>
<!--banner-info-->
<tr>
<td style="padding:10px 0;width:100%;">
Hi,<br>
Expand Down

0 comments on commit fa5a7a8

Please sign in to comment.