diff --git a/src/Routing/Router.php b/src/Routing/Router.php index 390d839..1bc6a3b 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -84,7 +84,13 @@ protected function createRoute(string $subject, string $pattern, $action): Route public function callMailboxes(InboundEmail $email) { if ($email->isValid()) { - $matchedRoutes = $this->routes->match($email)->map(function (Route $route) use ($email) { + $matchedRoutes = $this->routes->match($email); + + if ($this->shouldStoreInboundEmails() && $this->shouldStoreAllInboundEmails($matchedRoutes)) { + $this->storeEmail($email); + } + + $matchedRoutes->map(function (Route $route) use ($email) { $route->run($email); }); @@ -97,10 +103,6 @@ public function callMailboxes(InboundEmail $email) $matchedRoutes[] = $this->catchAllRoute; $this->catchAllRoute->run($email); } - - if ($this->shouldStoreInboundEmails() && $this->shouldStoreAllInboundEmails($matchedRoutes)) { - $this->storeEmail($email); - } } }