Преглед на файлове

Remove email banner for replies

Will Browning преди 2 години
родител
ревизия
2fa852383c

+ 4 - 2
README.md

@@ -462,13 +462,15 @@ For full details please see the [self-hosting instructions file](SELF-HOSTING.md
 
 
 ## My sponsors
 ## My sponsors
 
 
-Thanks to [Vlad Timofeev](https://github.com/vlad-timofeev), [Patrick Dobler](https://github.com/patrickdobler), [Luca Steeb](https://github.com/steebchen) and [Laiteux](https://github.com/Laiteux) for supporting me by sponsoring the project on GitHub!
+Thanks to [Vlad Timofeev](https://github.com/vlad-timofeev), [Patrick Dobler](https://github.com/patrickdobler), [Luca Steeb](https://github.com/steebchen), [Laiteux](https://github.com/Laiteux) and [narolinus](https://github.com/narolinus) for supporting me by sponsoring the project on GitHub!
 
 
 Also an extra special thanks to [CrazyMax](https://github.com/crazy-max) for sponsoring me and also creating and maintaining the awesome [AnonAddy Docker image](https://github.com/anonaddy/docker)!
 Also an extra special thanks to [CrazyMax](https://github.com/crazy-max) for sponsoring me and also creating and maintaining the awesome [AnonAddy Docker image](https://github.com/anonaddy/docker)!
 
 
 ## Thanks
 ## Thanks
 
 
-Thanks to [https://gitlab.com/mailcare/mailcare](https://gitlab.com/mailcare/mailcare) and [https://github.com/niftylettuce/forward-email](https://github.com/niftylettuce/forward-email) for their awesome open-source projects that helped me along the way.
+Huge thank you to [Stjin](https://twitter.com/Stjinchan) and [KhalidWar](https://github.com/KhalidWar) for their amazing mobile apps.
+
+Also to [https://gitlab.com/mailcare/mailcare](https://gitlab.com/mailcare/mailcare) and [https://github.com/niftylettuce/forward-email](https://github.com/niftylettuce/forward-email) for their awesome open-source projects that helped me along the way.
 
 
 ## License
 ## License
 
 

+ 9 - 1
app/Http/Controllers/Api/AliasController.php

@@ -19,8 +19,16 @@ class AliasController extends Controller
         $aliases = user()->aliases()->with('recipients')
         $aliases = user()->aliases()->with('recipients')
             ->when($request->input('sort'), function ($query, $sort) {
             ->when($request->input('sort'), function ($query, $sort) {
                 $direction = strpos($sort, '-') === 0 ? 'desc' : 'asc';
                 $direction = strpos($sort, '-') === 0 ? 'desc' : 'asc';
+                $sort = ltrim($sort, '-');
 
 
-                return $query->orderBy(ltrim($sort, '-'), $direction);
+                if ($sort === 'created_at') {
+                    return $query->orderBy($sort, $direction);
+                }
+
+                // Secondary order by latest first
+                return $query
+                    ->orderBy($sort, $direction)
+                    ->orderBy('created_at', 'desc');
             }, function ($query) {
             }, function ($query) {
                 return $query->latest();
                 return $query->latest();
             })
             })

+ 8 - 3
app/Mail/ForwardEmail.php

@@ -37,7 +37,8 @@ class ForwardEmail extends Mailable implements ShouldQueue, ShouldBeEncrypted
     protected $emailAttachments;
     protected $emailAttachments;
     protected $emailInlineAttachments;
     protected $emailInlineAttachments;
     protected $deactivateUrl;
     protected $deactivateUrl;
-    protected $bannerLocation;
+    protected $bannerLocationText;
+    protected $bannerLocationHtml;
     protected $fingerprint;
     protected $fingerprint;
     protected $encryptedParts;
     protected $encryptedParts;
     protected $fromEmail;
     protected $fromEmail;
@@ -88,7 +89,7 @@ class ForwardEmail extends Mailable implements ShouldQueue, ShouldBeEncrypted
 
 
         $this->fingerprint = $recipient->should_encrypt && !$this->isAlreadyEncrypted() ? $recipient->fingerprint : null;
         $this->fingerprint = $recipient->should_encrypt && !$this->isAlreadyEncrypted() ? $recipient->fingerprint : null;
 
 
-        $this->bannerLocation = $this->isAlreadyEncrypted() ? 'off' : $this->alias->user->banner_location;
+        $this->bannerLocationText = $this->bannerLocationHtml = $this->isAlreadyEncrypted() ? 'off' : $this->alias->user->banner_location;
     }
     }
 
 
     /**
     /**
@@ -215,6 +216,9 @@ class ForwardEmail extends Mailable implements ShouldQueue, ShouldBeEncrypted
         }
         }
 
 
         if ($this->emailHtml) {
         if ($this->emailHtml) {
+            // Turn off the banner for the plain text version
+            $this->bannerLocationText = 'off';
+
             $this->email->view('emails.forward.html')->with([
             $this->email->view('emails.forward.html')->with([
                 'html' => base64_decode($this->emailHtml)
                 'html' => base64_decode($this->emailHtml)
             ]);
             ]);
@@ -240,7 +244,8 @@ class ForwardEmail extends Mailable implements ShouldQueue, ShouldBeEncrypted
         $this->checkRules('Forwards');
         $this->checkRules('Forwards');
 
 
         $this->email->with([
         $this->email->with([
-            'location' => $this->bannerLocation,
+            'locationText' => $this->bannerLocationText,
+            'locationHtml' => $this->bannerLocationHtml,
             'deactivateUrl' => $this->deactivateUrl,
             'deactivateUrl' => $this->deactivateUrl,
             'aliasEmail' => $this->alias->email,
             'aliasEmail' => $this->alias->email,
             'aliasDomain' => $this->alias->domain,
             'aliasDomain' => $this->alias->domain,

+ 8 - 2
app/Mail/ReplyToEmail.php

@@ -13,6 +13,7 @@ use Illuminate\Contracts\Queue\ShouldBeEncrypted;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Mail\Mailable;
 use Illuminate\Mail\Mailable;
 use Illuminate\Queue\SerializesModels;
 use Illuminate\Queue\SerializesModels;
+use Illuminate\Support\Str;
 use Symfony\Component\Mime\Email;
 use Symfony\Component\Mime\Email;
 
 
 class ReplyToEmail extends Mailable implements ShouldQueue, ShouldBeEncrypted
 class ReplyToEmail extends Mailable implements ShouldQueue, ShouldBeEncrypted
@@ -116,13 +117,13 @@ class ReplyToEmail extends Mailable implements ShouldQueue, ShouldBeEncrypted
 
 
         if ($this->emailText) {
         if ($this->emailText) {
             $this->email->text('emails.reply.text')->with([
             $this->email->text('emails.reply.text')->with([
-                'text' => str_ireplace($this->sender, '', base64_decode($this->emailText))
+                'text' => $this->removeRealEmailAndBanner(base64_decode($this->emailText))
             ]);
             ]);
         }
         }
 
 
         if ($this->emailHtml) {
         if ($this->emailHtml) {
             $this->email->view('emails.reply.html')->with([
             $this->email->view('emails.reply.html')->with([
-                'html' => str_ireplace($this->sender, '', base64_decode($this->emailHtml))
+                'html' => $this->removeRealEmailAndBanner(base64_decode($this->emailHtml))
             ]);
             ]);
         }
         }
 
 
@@ -203,4 +204,9 @@ class ReplyToEmail extends Mailable implements ShouldQueue, ShouldBeEncrypted
     {
     {
         return $this->alias->isCustomDomain() ? $this->alias->aliasable->isVerifiedForSending() : false;
         return $this->alias->isCustomDomain() ? $this->alias->aliasable->isVerifiedForSending() : false;
     }
     }
+
+    private function removeRealEmailAndBanner($text)
+    {
+        return Str::of(str_ireplace($this->sender, '', $text))->replaceMatches('/(?s)(<!--banner-info-->).*?(<!--banner-info-->)/', '');
+    }
 }
 }

+ 8 - 2
app/Mail/SendFromEmail.php

@@ -13,6 +13,7 @@ use Illuminate\Contracts\Queue\ShouldBeEncrypted;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Mail\Mailable;
 use Illuminate\Mail\Mailable;
 use Illuminate\Queue\SerializesModels;
 use Illuminate\Queue\SerializesModels;
+use Illuminate\Support\Str;
 use Symfony\Component\Mime\Email;
 use Symfony\Component\Mime\Email;
 
 
 class SendFromEmail extends Mailable implements ShouldQueue, ShouldBeEncrypted
 class SendFromEmail extends Mailable implements ShouldQueue, ShouldBeEncrypted
@@ -102,13 +103,13 @@ class SendFromEmail extends Mailable implements ShouldQueue, ShouldBeEncrypted
 
 
         if ($this->emailText) {
         if ($this->emailText) {
             $this->email->text('emails.reply.text')->with([
             $this->email->text('emails.reply.text')->with([
-                'text' => str_ireplace($this->sender, '', base64_decode($this->emailText))
+                'text' => $this->removeRealEmailAndBanner(base64_decode($this->emailText))
             ]);
             ]);
         }
         }
 
 
         if ($this->emailHtml) {
         if ($this->emailHtml) {
             $this->email->view('emails.reply.html')->with([
             $this->email->view('emails.reply.html')->with([
-                'html' => str_ireplace($this->sender, '', base64_decode($this->emailHtml))
+                'html' => $this->removeRealEmailAndBanner(base64_decode($this->emailHtml))
             ]);
             ]);
         }
         }
 
 
@@ -189,4 +190,9 @@ class SendFromEmail extends Mailable implements ShouldQueue, ShouldBeEncrypted
     {
     {
         return $this->alias->isCustomDomain() ? $this->alias->aliasable->isVerifiedForSending() : false;
         return $this->alias->isCustomDomain() ? $this->alias->aliasable->isVerifiedForSending() : false;
     }
     }
+
+    private function removeRealEmailAndBanner($text)
+    {
+        return Str::of(str_ireplace($this->sender, '', $text))->replaceMatches('/(?s)(<!--banner-info-->).*?(<!--banner-info-->)/', '');
+    }
 }
 }

+ 6 - 6
composer.lock

@@ -8325,16 +8325,16 @@
         },
         },
         {
         {
             "name": "filp/whoops",
             "name": "filp/whoops",
-            "version": "2.14.5",
+            "version": "2.14.6",
             "source": {
             "source": {
                 "type": "git",
                 "type": "git",
                 "url": "https://github.com/filp/whoops.git",
                 "url": "https://github.com/filp/whoops.git",
-                "reference": "a63e5e8f26ebbebf8ed3c5c691637325512eb0dc"
+                "reference": "f7948baaa0330277c729714910336383286305da"
             },
             },
             "dist": {
             "dist": {
                 "type": "zip",
                 "type": "zip",
-                "url": "https://api.github.com/repos/filp/whoops/zipball/a63e5e8f26ebbebf8ed3c5c691637325512eb0dc",
-                "reference": "a63e5e8f26ebbebf8ed3c5c691637325512eb0dc",
+                "url": "https://api.github.com/repos/filp/whoops/zipball/f7948baaa0330277c729714910336383286305da",
+                "reference": "f7948baaa0330277c729714910336383286305da",
                 "shasum": ""
                 "shasum": ""
             },
             },
             "require": {
             "require": {
@@ -8384,7 +8384,7 @@
             ],
             ],
             "support": {
             "support": {
                 "issues": "https://github.com/filp/whoops/issues",
                 "issues": "https://github.com/filp/whoops/issues",
-                "source": "https://github.com/filp/whoops/tree/2.14.5"
+                "source": "https://github.com/filp/whoops/tree/2.14.6"
             },
             },
             "funding": [
             "funding": [
                 {
                 {
@@ -8392,7 +8392,7 @@
                     "type": "github"
                     "type": "github"
                 }
                 }
             ],
             ],
-            "time": "2022-01-07T12:00:00+00:00"
+            "time": "2022-11-02T16:23:29+00:00"
         },
         },
         {
         {
             "name": "friendsofphp/php-cs-fixer",
             "name": "friendsofphp/php-cs-fixer",

+ 6 - 6
package-lock.json

@@ -9352,9 +9352,9 @@
             }
             }
         },
         },
         "node_modules/yargs": {
         "node_modules/yargs": {
-            "version": "17.6.0",
-            "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.6.0.tgz",
-            "integrity": "sha512-8H/wTDqlSwoSnScvV2N/JHfLWOKuh5MVla9hqLjK3nsfyy6Y4kDSYSvkU5YCUEPOSnRXfIyx3Sq+B/IWudTo4g==",
+            "version": "17.6.1",
+            "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.6.1.tgz",
+            "integrity": "sha512-leBuCGrL4dAd6ispNOGsJlhd0uZ6Qehkbu/B9KCR+Pxa/NVdNwi+i31lo0buCm6XxhJQFshXCD0/evfV4xfoUg==",
             "dependencies": {
             "dependencies": {
                 "cliui": "^8.0.1",
                 "cliui": "^8.0.1",
                 "escalade": "^3.1.1",
                 "escalade": "^3.1.1",
@@ -16180,9 +16180,9 @@
             "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg=="
             "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg=="
         },
         },
         "yargs": {
         "yargs": {
-            "version": "17.6.0",
-            "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.6.0.tgz",
-            "integrity": "sha512-8H/wTDqlSwoSnScvV2N/JHfLWOKuh5MVla9hqLjK3nsfyy6Y4kDSYSvkU5YCUEPOSnRXfIyx3Sq+B/IWudTo4g==",
+            "version": "17.6.1",
+            "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.6.1.tgz",
+            "integrity": "sha512-leBuCGrL4dAd6ispNOGsJlhd0uZ6Qehkbu/B9KCR+Pxa/NVdNwi+i31lo0buCm6XxhJQFshXCD0/evfV4xfoUg==",
             "requires": {
             "requires": {
                 "cliui": "^8.0.1",
                 "cliui": "^8.0.1",
                 "escalade": "^3.1.1",
                 "escalade": "^3.1.1",

+ 5 - 13
resources/views/emails/forward/html.blade.php

@@ -1,26 +1,18 @@
-@if($location === 'off')
+@if($locationHtml === 'off')
     {!! $html !!}
     {!! $html !!}
 @else
 @else
     <table style="width:100%;">
     <table style="width:100%;">
         <tbody>
         <tbody>
-            @if($location === 'top')
-            <tr>
-                <td style="padding:10px 20px;background-color:#fff;text-align:center;line-height:1.5;border-bottom:1px solid #cbd2d9;font-size:12px;width:100%;">
-                This email was sent to {{ $aliasEmail }}{{ $aliasDescription ? ' (' . $aliasDescription . ')' : '' }} from {{ $fromEmail }}{{ $replacedSubject }} and has been forwarded by <a href="https://anonaddy.com" style="color:#2d3a8c;text-decoration:underline;" target="_blank" rel="noreferrer noopener nofollow">AnonAddy</a><br>Click <a href="{{ $deactivateUrl }}" style="color:#2d3a8c;text-decoration:underline;" target="_blank" rel="noreferrer noopener nofollow">here</a> to deactivate this alias
-                </td>
-            </tr>
+            @if($locationHtml === 'top')
+                @include('emails.forward.html_banner')
             @endif
             @endif
             <tr>
             <tr>
                 <td style="padding:10px 0;width:100%;">
                 <td style="padding:10px 0;width:100%;">
                     {!! $html !!}
                     {!! $html !!}
                 </td>
                 </td>
             </tr>
             </tr>
-            @if($location === 'bottom')
-            <tr>
-                <td style="padding:10px 20px;background-color:#fff;text-align:center;line-height:1.5;border-top:1px solid #cbd2d9;font-size:12px;width:100%;">
-                This email was sent to {{ $aliasEmail }}{{ $aliasDescription ? ' (' . $aliasDescription . ')' : '' }} from {{ $fromEmail }}{{ $replacedSubject }} and has been forwarded by <a href="https://anonaddy.com" style="color:#2d3a8c;text-decoration:underline;" target="_blank" rel="noreferrer noopener nofollow">AnonAddy</a><br>Click <a href="{{ $deactivateUrl }}" style="color:#2d3a8c;text-decoration:underline;" target="_blank" rel="noreferrer noopener nofollow">here</a> to deactivate this alias
-                </td>
-            </tr>
+            @if($locationHtml === 'bottom')
+                @include('emails.forward.html_banner')
             @endif
             @endif
         </tbody>
         </tbody>
     </table>
     </table>

+ 12 - 0
resources/views/emails/forward/html_banner.blade.php

@@ -0,0 +1,12 @@
+<!--banner-info-->
+<tr>
+    <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;">
+            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-->
+
+
+

+ 4 - 14
resources/views/emails/forward/text.blade.php

@@ -1,21 +1,11 @@
-@if($location === 'top')
-This email was sent to {{ $aliasEmail }}{{ $aliasDescription ? ' (' . $aliasDescription . ')' : '' }} from {{ $fromEmail }}{!! $replacedSubject !!} and has been forwarded by AnonAddy.
-To deactivate this alias copy and paste the url below into your web browser.
-
-{{ $deactivateUrl }}
-
------
+@if($locationText === 'top')
+    @include('emails.forward.text_banner')
 
 
 
 
 @endif
 @endif
 {!! $text !!}
 {!! $text !!}
-@if($location === 'bottom')
-
-
------
+@if($locationText === 'bottom')
 
 
-This email was sent to {{ $aliasEmail }}{{ $aliasDescription ? ' (' . $aliasDescription . ')' : '' }} from {{ $fromEmail }}{!! $replacedSubject !!} and has been forwarded by AnonAddy.
-To deactivate this alias copy and paste the url below into your web browser.
 
 
-{{ $deactivateUrl }}
+    @include('emails.forward.text_banner')
 @endif
 @endif

+ 6 - 0
resources/views/emails/forward/text_banner.blade.php

@@ -0,0 +1,6 @@
+<!--banner-info-->
+This email was sent to {{ $aliasEmail }}{{ $aliasDescription ? ' (' . $aliasDescription . ')' : '' }} from {{ $fromEmail }}{!! $replacedSubject !!}.
+To deactivate this alias copy and paste the url below into your web browser.
+
+{{ $deactivateUrl }}
+<!--banner-info-->

+ 22 - 5
tests/emails/email_reply.eml

@@ -10,11 +10,28 @@ Content-Type: multipart/mixed; boundary="----=_Part_10031_1199410393.15506779404
 Content-Type: text/html; charset=UTF-8
 Content-Type: text/html; charset=UTF-8
 Content-Transfer-Encoding: quoted-printable
 Content-Transfer-Encoding: quoted-printable
 
 
-Hi,<br>
-<br>
-This is a test email.<br>
-<br>
-Will
+<table style="width:100%;">
+    <tbody>
+        <!--banner-info-->
+        <tr>
+            <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;">ebay@johndoe.anonaddy.com</span> (ebay.com) from <span style="font-weight:500;color:#19216c;">will@anonaddy.com</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>
+                <br>
+                This is a test email.<br>
+                <br>
+                Will
+            </td>
+        </tr>
+    </tbody>
+</table>
 
 
 
 
 ------=_Part_10031_1199410393.1550677940425
 ------=_Part_10031_1199410393.1550677940425