1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* @copyright 2019 Mautic Contributors. All rights reserved |
5
|
|
|
* @author Mautic |
6
|
|
|
* |
7
|
|
|
* @link http://mautic.org |
8
|
|
|
* |
9
|
|
|
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Mautic\EmailBundle\Swiftmailer\Transport; |
13
|
|
|
|
14
|
|
|
use Mautic\EmailBundle\Swiftmailer\Spool\DelegatingSpool; |
15
|
|
|
|
16
|
|
|
class SpoolTransport extends \Swift_Transport_SpoolTransport |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var \Swift_Events_EventDispatcher |
20
|
|
|
*/ |
21
|
|
|
private $eventDispatcher; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var DelegatingSpool |
25
|
|
|
*/ |
26
|
|
|
private $spool; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* SpoolTransport constructor. |
30
|
|
|
*/ |
31
|
|
|
public function __construct(\Swift_Events_EventDispatcher $eventDispatcher, DelegatingSpool $delegatingSpool) |
32
|
|
|
{ |
33
|
|
|
$this->eventDispatcher = $eventDispatcher; |
34
|
|
|
$this->spool = $delegatingSpool; |
35
|
|
|
|
36
|
|
|
parent::__construct($eventDispatcher, $delegatingSpool); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Sends or queues the given message. |
41
|
|
|
* |
42
|
|
|
* @param string[] $failedRecipients An array of failures by-reference |
43
|
|
|
* |
44
|
|
|
* @return int The number of sent e-mails |
45
|
|
|
* |
46
|
|
|
* @throws \Swift_IoException |
47
|
|
|
*/ |
48
|
|
|
public function send(\Swift_Mime_SimpleMessage $message, &$failedRecipients = null) |
49
|
|
|
{ |
50
|
|
|
if ($evt = $this->eventDispatcher->createSendEvent($this, $message)) { |
51
|
|
|
$this->eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed'); |
52
|
|
|
if ($evt->bubbleCancelled()) { |
53
|
|
|
return 0; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$count = $this->spool->delegateMessage($message, $failedRecipients); |
58
|
|
|
|
59
|
|
|
if ($evt) { |
|
|
|
|
60
|
|
|
$successResult = $this->spool->wasMessageSpooled() ? \Swift_Events_SendEvent::RESULT_SPOOLED : \Swift_Events_SendEvent::RESULT_SUCCESS; |
61
|
|
|
$evt->setResult($count ? $successResult : \Swift_Events_SendEvent::RESULT_FAILED); |
62
|
|
|
$this->eventDispatcher->dispatchEvent($evt, 'sendPerformed'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $count; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function supportsTokenization(): bool |
69
|
|
|
{ |
70
|
|
|
return $this->spool->isTokenizationEnabled(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getMaxBatchLimit() |
74
|
|
|
{ |
75
|
|
|
return $this->spool->getRealTransport()->getMaxBatchLimit(); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getBatchRecipientCount(\Swift_Message $message, $toBeAdded = 1, $type = 'to') |
79
|
|
|
{ |
80
|
|
|
return $this->spool->getRealTransport()->getBatchRecipientCount($message, $toBeAdded, $type); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|