Procházet zdrojové kódy

Added anonaddy.com as domain

Will Browning před 6 roky
rodič
revize
2bf682d885

+ 1 - 0
.env.example

@@ -44,6 +44,7 @@ ENVOY_RUN_TESTS="ssh -tt -p22 vagrant@192.168.10.10 '/path/to/homestead/app/vend
 
 ANONADDY_ADMIN_USERNAME=johndoe
 ANONADDY_DOMAIN=anonaddy.me
+ANONADDY_ALL_DOMAINS=anonaddy.me,anonaddy.com
 ANONADDY_SECRET=long-random-string
 ANONADDY_NEWSLETTER_URL=https://newsletter.yourdomain.com/subscribe
 ANONADDY_NEWSLETTER_LIST=your-list-id

+ 9 - 2
app/Console/Commands/ReceiveEmail.php

@@ -13,6 +13,7 @@ use Illuminate\Console\Command;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Mail;
 use Illuminate\Support\Facades\Redis;
+use Illuminate\Support\Str;
 use PhpMimeMailParser\Parser;
 
 class ReceiveEmail extends Command
@@ -77,7 +78,13 @@ class ReceiveEmail extends Command
             $this->size = $this->option('size') / ($recipientCount ? $recipientCount : 1);
 
             foreach ($recipients as $key => $recipient) {
-                $subdomain = substr($recipient['domain'], 0, strrpos($recipient['domain'], '.'.config('anonaddy.domain'))); // e.g. johndoe
+                $parentDomain = collect(config('anonaddy.all_domains'))
+                    ->filter(function ($name) use ($recipient) {
+                        return Str::endsWith($recipient['domain'], $name);
+                    })
+                    ->first();
+
+                $subdomain = substr($recipient['domain'], 0, strrpos($recipient['domain'], '.'.$parentDomain)); // e.g. johndoe
 
                 $displayTo = $this->parser->getAddresses('to')[$key]['display'];
 
@@ -96,7 +103,7 @@ class ReceiveEmail extends Command
                     }
 
                     // Check if this is the root domain e.g. anonaddy.me
-                    if ($recipient['domain'] === config('anonaddy.domain') && !empty(config('anonaddy.admin_username'))) {
+                    if ($recipient['domain'] === $parentDomain && !empty(config('anonaddy.admin_username'))) {
                         $user = User::where('username', config('anonaddy.admin_username'))->first();
                     }
                 }

+ 5 - 5
composer.lock

@@ -3979,16 +3979,16 @@
         },
         {
             "name": "filp/whoops",
-            "version": "2.4.0",
+            "version": "2.4.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/filp/whoops.git",
-                "reference": "1a1a1044ad00e285bd2825fac4c3a0443d90ad33"
+                "reference": "6fb502c23885701a991b0bba974b1a8eb6673577"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/filp/whoops/zipball/1a1a1044ad00e285bd2825fac4c3a0443d90ad33",
-                "reference": "1a1a1044ad00e285bd2825fac4c3a0443d90ad33",
+                "url": "https://api.github.com/repos/filp/whoops/zipball/6fb502c23885701a991b0bba974b1a8eb6673577",
+                "reference": "6fb502c23885701a991b0bba974b1a8eb6673577",
                 "shasum": ""
             },
             "require": {
@@ -4036,7 +4036,7 @@
                 "throwable",
                 "whoops"
             ],
-            "time": "2019-06-23T09:00:00+00:00"
+            "time": "2019-07-04T09:00:00+00:00"
         },
         {
             "name": "friendsofphp/php-cs-fixer",

+ 12 - 0
config/anonaddy.php

@@ -26,6 +26,18 @@ return [
 
     'domain' => env('ANONADDY_DOMAIN'),
 
+    /*
+    |--------------------------------------------------------------------------
+    | All Domains
+    |--------------------------------------------------------------------------
+    |
+    | If you would like to have other domains to use e.g. @username.yourdomain2.com
+    | enter a comma separated list in your .env file like so, anonaddy.me,anonaddy.com
+    |
+    */
+
+    'all_domains' => explode(',', env('ANONADDY_ALL_DOMAINS')),
+
     /*
     |--------------------------------------------------------------------------
     | Secret

+ 42 - 2
tests/Feature/ReceiveEmailTest.php

@@ -24,8 +24,6 @@ class ReceiveEmailTest extends TestCase
     {
         parent::setUp();
 
-        config(['anonaddy.limit' => 1000]);
-
         $this->user = factory(User::class)->create(['username' => 'johndoe']);
         $this->user->recipients()->save($this->user->defaultRecipient);
     }
@@ -651,4 +649,46 @@ class ReceiveEmailTest extends TestCase
             NearBandwidthLimit::class
         );
     }
+
+    /** @test */
+    public function it_can_forward_email_from_file_for_all_domains()
+    {
+        Mail::fake();
+        Notification::fake();
+
+        Mail::assertNothingSent();
+
+        $this->artisan(
+            'anonaddy:receive-email',
+            [
+                'file' => base_path('tests/emails/email_other_domain.eml'),
+                '--sender' => 'will@anonaddy.com',
+                '--recipient' => ['ebay@johndoe.anonaddy.com'],
+                '--local_part' => ['ebay'],
+                '--extension' => [''],
+                '--domain' => ['johndoe.anonaddy.com'],
+                '--size' => '1000'
+            ]
+        )->assertExitCode(0);
+
+        $this->assertDatabaseHas('aliases', [
+            'email' => 'ebay@johndoe.anonaddy.com',
+            'local_part' => 'ebay',
+            'domain' => 'johndoe.anonaddy.com',
+            'emails_forwarded' => 1,
+            'emails_blocked' => 0
+        ]);
+        $this->assertEquals(1, $this->user->aliases()->count());
+        $this->assertDatabaseHas('users', [
+            'id' => $this->user->id,
+            'username' => 'johndoe',
+            'bandwidth' => '1000'
+        ]);
+
+        Mail::assertQueued(ForwardEmail::class, function ($mail) {
+            return $mail->hasTo($this->user->email);
+        });
+
+        Notification::assertNothingSent();
+    }
 }

+ 6 - 0
tests/TestCase.php

@@ -15,6 +15,12 @@ abstract class TestCase extends BaseTestCase
     {
         parent::setUp();
 
+        config([
+            'anonaddy.limit' => 1000,
+            'anonaddy.domain' => 'anonaddy.me',
+            'anonaddy.all_domains' => ['anonaddy.me','anonaddy.com']
+        ]);
+
         //$this->withoutExceptionHandling();
 
         TestResponse::macro('data', function ($key) {

+ 28 - 0
tests/emails/email_other_domain.eml

@@ -0,0 +1,28 @@
+Date: Wed, 20 Feb 2019 15:00:00 +0100 (CET)
+From: Will <will@anonaddy.com>
+To: <ebay@johndoe.anonaddy.com>
+Subject: Test Email
+Content-Type: multipart/mixed; boundary="----=_Part_10031_1199410393.1550677940425"
+
+------=_Part_10031_1199410393.1550677940425
+Content-Type: text/html; charset=UTF-8
+Content-Transfer-Encoding: quoted-printable
+
+Hi,<br>
+<br>
+This is a test email.<br>
+<br>
+Will
+
+
+------=_Part_10031_1199410393.1550677940425
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: quoted-printable
+
+Hi,
+
+This is a test email.
+
+Will
+
+------=_Part_10031_1199410393.1550677940425--