Skip to content

Commit d0d300b

Browse files
authored
Merge pull request #20 from webfox/feature_custom_model
Allow defining a custom model for InboundEmail
2 parents 7e7ded0 + 33b5e25 commit d0d300b

File tree

6 files changed

+37
-4
lines changed

6 files changed

+37
-4
lines changed

config/mailbox.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
*/
1111
'driver' => env('MAILBOX_DRIVER', 'log'),
1212

13+
/*
14+
* The model class to use when converting an incoming email to a message.
15+
* It must extend the default model class
16+
*/
17+
'model' => \BeyondCode\Mailbox\InboundEmail::class,
18+
1319
/*
1420
* The path for driver specific routes. This is where
1521
* you need to point your driver specific callbacks

src/Drivers/Log.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public function register()
1515

1616
public function processLog(MessageLogged $log)
1717
{
18-
$email = InboundEmail::fromMessage($log->message);
18+
/** @var InboundEmail $modelClass */
19+
$modelClass = config('mailbox.model');
20+
$email = $modelClass::fromMessage($log->message);
1921

2022
Mailbox::callMailboxes($email);
2123
}

src/Http/Requests/MailgunRequest.php

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

2828
public function email()
2929
{
30-
return InboundEmail::fromMessage($this->get('body-mime'));
30+
/** @var InboundEmail $modelClass */
31+
$modelClass = config('mailbox.model');
32+
33+
return $modelClass::fromMessage($this->get('body-mime'));
3134
}
3235

3336
protected function verifySignature()

src/Http/Requests/PostmarkRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public function validator()
1717

1818
public function email()
1919
{
20-
return InboundEmail::fromMessage($this->get('RawEmail'));
20+
/** @var InboundEmail $modelClass */
21+
$modelClass = config('mailbox.model');
22+
23+
return $modelClass::fromMessage($this->get('RawEmail'));
2124
}
2225
}

src/Http/Requests/SendGridRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public function validator()
1717

1818
public function email()
1919
{
20-
return InboundEmail::fromMessage($this->get('email'));
20+
/** @var InboundEmail $modelClass */
21+
$modelClass = config('mailbox.model');
22+
23+
return $modelClass::fromMessage($this->get('email'));
2124
}
2225
}

tests/InboundEmailTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ public function it_can_reply_to_mails()
140140

141141
Mail::assertSent(ReplyMail::class);
142142
}
143+
144+
/** @test */
145+
public function it_uses_the_configured_model()
146+
{
147+
$this->app['config']['mailbox.model'] = ExtendedInboundEmail::class;
148+
149+
Mailbox::from('[email protected]', function ($email) {
150+
$this->assertInstanceOf(ExtendedInboundEmail::class, $email);
151+
});
152+
153+
Mail::to('[email protected]')->send(new TestMail);
154+
}
143155
}
144156

145157
class TestMail extends Mailable
@@ -161,3 +173,7 @@ public function build()
161173
->html('Hi!');
162174
}
163175
}
176+
177+
class ExtendedInboundEmail extends InboundEmail
178+
{
179+
}

0 commit comments

Comments
 (0)