Skip to content

Commit 729ac73

Browse files
committed
Fix Mailgun issue and store catchAll mails
1 parent a7b2e3d commit 729ac73

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

src/Http/Requests/MailgunRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function validator()
2727

2828
public function email()
2929
{
30-
return InboundEmail::fromMessage($this->get('body-mime '));
30+
return InboundEmail::fromMessage($this->get('body-mime'));
3131
}
3232

3333
protected function verifySignature()

src/Routing/Router.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,22 @@ public function callMailboxes(InboundEmail $email)
7575
$route->run($email);
7676
});
7777

78-
if ($matchedRoutes->isEmpty()) {
79-
$this->callFallback($email);
78+
if ($matchedRoutes->isEmpty() && $this->fallbackRoute) {
79+
$matchedRoutes[] = $this->fallbackRoute;
80+
$this->fallbackRoute->run($email);
8081
}
8182

82-
$this->callCatchAll($email);
83+
if ($this->catchAllRoute) {
84+
$matchedRoutes[] = $this->catchAllRoute;
85+
$this->catchAllRoute->run($email);
86+
}
8387

8488
if ($this->shouldStoreInboundEmails() && $this->shouldStoreAllInboundEmails($matchedRoutes)) {
8589
$this->storeEmail($email);
8690
}
8791
}
8892
}
8993

90-
protected function callFallback(InboundEmail $email)
91-
{
92-
if ($this->fallbackRoute) {
93-
$this->fallbackRoute->run($email);
94-
}
95-
}
96-
97-
protected function callCatchAll(InboundEmail $email)
98-
{
99-
if ($this->catchAllRoute) {
100-
$this->catchAllRoute->run($email);
101-
}
102-
}
103-
10494
protected function shouldStoreInboundEmails(): bool
10595
{
10696
return config('mailbox.store_incoming_emails_for_days') > 0;

tests/InboundEmailTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,46 @@ public function it_can_use_catchall()
7474
Mail::assertSent(ReplyMail::class);
7575
}
7676

77+
/** @test */
78+
public function it_stores_inbound_emails_with_catchall()
79+
{
80+
Mailbox::catchAll(function ($email) {
81+
});
82+
83+
Mail::to('[email protected]')->send(new TestMail);
84+
Mail::to('[email protected]')->send(new TestMail);
85+
86+
$this->assertSame(2, InboundEmail::query()->count());
87+
}
88+
89+
/** @test */
90+
public function it_stores_inbound_emails_with_fallback()
91+
{
92+
Mailbox::fallback(function ($email) {
93+
});
94+
95+
Mail::to('[email protected]')->send(new TestMail);
96+
Mail::to('[email protected]')->send(new TestMail);
97+
98+
$this->assertSame(2, InboundEmail::query()->count());
99+
}
100+
101+
/** @test */
102+
public function it_stores_inbound_emails_with_fallback_and_catchall_only_once()
103+
{
104+
Mailbox::fallback(function ($email) {
105+
});
106+
107+
Mailbox::catchAll(function ($email) {
108+
});
109+
110+
Mail::to('[email protected]')->send(new TestMail);
111+
Mail::to('[email protected]')->send(new TestMail);
112+
113+
$this->assertSame(2, InboundEmail::query()->count());
114+
}
115+
116+
77117
/** @test */
78118
public function it_does_not_store_inbound_emails_if_configured()
79119
{

0 commit comments

Comments
 (0)