1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Qodeboy\Mailman\Transport; |
4
|
|
|
|
5
|
|
|
use Swift_Mailer; |
6
|
|
|
use Swift_Transport; |
7
|
|
|
use Illuminate\Foundation\Application; |
8
|
|
|
use Illuminate\Mail\Transport\Transport; |
9
|
|
|
use Qodeboy\Mailman\Message\MailmanMimeMessage; |
10
|
|
|
|
11
|
|
|
class MailmanTransport extends Transport |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Laravel application container. |
15
|
|
|
* |
16
|
|
|
* @var \Illuminate\Foundation\Application |
17
|
|
|
*/ |
18
|
|
|
private $app; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Create a new Mailman transport instance. |
22
|
|
|
* |
23
|
|
|
* @param \Illuminate\Foundation\Application $app |
24
|
|
|
*/ |
25
|
|
|
public function __construct(Application $app) |
26
|
|
|
{ |
27
|
|
|
$this->app = $app; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function send(\Swift_Mime_SimpleMessage $message, &$failedRecipients = null) |
34
|
|
|
{ |
35
|
|
|
$mailmanMessage = new MailmanMimeMessage($message); |
|
|
|
|
36
|
|
|
$this->beforeSendPerformed($message); |
37
|
|
|
|
38
|
|
|
// Deny email delivery if environment is not allowed in the config |
39
|
|
|
if (! in_array($this->app->environment(), config('mailman.delivery.environments'))) { |
40
|
|
|
$mailmanMessage->deny(); |
41
|
|
|
|
42
|
|
|
$recipients = array_keys($mailmanMessage->getTo()); |
43
|
|
|
$allowedRecipients = config('mailman.delivery.recipients'); |
44
|
|
|
|
45
|
|
|
$recipientsDiff = array_diff($recipients, $allowedRecipients); |
46
|
|
|
|
47
|
|
|
// If all recipients are allowed to receive emails |
48
|
|
|
// from denied environments - allow email delivery. |
49
|
|
|
if (count($recipientsDiff) === 0) { |
50
|
|
|
$mailmanMessage->allow(); |
51
|
|
|
} |
52
|
|
|
} else { |
53
|
|
|
$mailmanMessage->allow(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if (config('mailman.log.enabled')) { |
57
|
|
|
$logger = app('mailman.logger'); |
58
|
|
|
$logger->log($mailmanMessage); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ($mailmanMessage->allowed()) { |
62
|
|
|
/** @var Swift_Transport $transport */ |
63
|
|
|
$transport = $this->app['swift.transport']->driver(config('mailman.delivery.driver')); |
64
|
|
|
|
65
|
|
|
with(new Swift_Mailer($transport))->send($mailmanMessage->getSwiftMessage()); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: