Skip to content

Commit

Permalink
Replies to UUID aliases now come from the alias
Browse files Browse the repository at this point in the history
  • Loading branch information
willbrowningme committed Oct 24, 2019
1 parent a59fdf3 commit f2ff02e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ I am very passionite about this project. I use it myself everyday and will be ke

#### **Is the application tested?**

Yes it has over 100 automated PHPUnit tests written.
Yes it has over 130 automated PHPUnit tests written.

#### **How do I host this myself?**

Expand Down
5 changes: 4 additions & 1 deletion app/Console/Commands/ReceiveEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Notifications\NearBandwidthLimit;
use App\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -231,8 +232,10 @@ protected function checkBandwidthLimit($user)
exit(1);
}

if ($user->nearBandwidthLimit()) {
if ($user->nearBandwidthLimit() && ! Cache::has("user:{$user->username}:near-bandwidth")) {
$user->notify(new NearBandwidthLimit());

Cache::put("user:{$user->username}:near-bandwidth", now()->toDateTimeString(), now()->addDay());
}
}

Expand Down
13 changes: 9 additions & 4 deletions app/Mail/ReplyToEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,24 @@ public function __construct(User $user, Alias $alias, EmailData $emailData)
public function build()
{
$fromName = $this->user->from_name ? $this->user->from_name : $this->alias->email.' via '.config('app.name');
$fromAddress = $this->alias->isUuid() ? $this->alias->email : config('mail.from.address');
$returnPath = $this->alias->isUuid() ? $this->alias->email : config('anonaddy.return_path');

$email = $this
->from(config('mail.from.address'), $fromName)
->replyTo($this->alias->email, $fromName)
->from($fromAddress, $fromName)
->subject(base64_decode($this->emailSubject))
->text('emails.reply.text')->with([
'text' => base64_decode($this->emailText)
])
->withSwiftMessage(function ($message) {
->withSwiftMessage(function ($message) use ($returnPath) {
$message->getHeaders()
->addTextHeader('Return-Path', config('anonaddy.return_path'));
->addTextHeader('Return-Path', $returnPath);
});

if (! $this->alias->isUuid()) {
$email->replyTo($this->alias->email, $fromName);
}

if ($this->emailHtml) {
$email->view('emails.reply.html')->with([
'html' => base64_decode($this->emailHtml)
Expand Down
45 changes: 45 additions & 0 deletions tests/Feature/ReceiveEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Recipient;
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
Expand Down Expand Up @@ -896,6 +897,50 @@ public function it_can_send_near_bandwidth_limit_notification()
);
}

/** @test */
public function it_does_not_send_near_bandwidth_limit_notification_more_than_once_per_day()
{
Notification::fake();

Notification::assertNothingSent();

Cache::put("user:{$this->user->username}:near-bandwidth", now()->toDateTimeString(), now()->addDay());

$this->user->update(['bandwidth' => 9485760]);

$this->artisan(
'anonaddy:receive-email',
[
'file' => base_path('tests/emails/email.eml'),
'--sender' => '[email protected]',
'--recipient' => ['[email protected]'],
'--local_part' => ['ebay'],
'--extension' => [''],
'--domain' => ['johndoe.anonaddy.com'],
'--size' => '1000'
]
)->assertExitCode(0);

$this->assertDatabaseHas('aliases', [
'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
'local_part' => 'ebay',
'domain' => 'johndoe.'.config('anonaddy.domain'),
'emails_forwarded' => 1,
'emails_blocked' => 0
]);
$this->assertEquals(1, $this->user->aliases()->count());
$this->assertDatabaseHas('users', [
'id' => $this->user->id,
'username' => 'johndoe',
'bandwidth' => '9486760'
]);

Notification::assertNotSentTo(
$this->user,
NearBandwidthLimit::class
);
}

/** @test */
public function it_can_forward_email_from_file_for_all_domains()
{
Expand Down

0 comments on commit f2ff02e

Please sign in to comment.