Commit | Line | Data |
---|---|---|
bdf67e28 SL |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | Copyright CiviCRM LLC. All rights reserved. | | |
5 | | | | |
6 | | This work is published under the GNU AGPLv3 license with some | | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
9 | +--------------------------------------------------------------------+ | |
10 | */ | |
11 | namespace Civi\FlexMailer\Listener; | |
12 | ||
13 | use Civi\FlexMailer\Event\ComposeBatchEvent; | |
14 | ||
15 | class BounceTracker extends BaseListener { | |
16 | ||
17 | /** | |
18 | * Inject bounce-tracking codes. | |
19 | * | |
20 | * @param \Civi\FlexMailer\Event\ComposeBatchEvent $e | |
21 | */ | |
22 | public function onCompose(ComposeBatchEvent $e) { | |
23 | if (!$this->isActive()) { | |
24 | return; | |
25 | } | |
26 | ||
27 | $mailing = $e->getMailing(); | |
28 | ||
29 | foreach ($e->getTasks() as $task) { | |
30 | /** @var \Civi\FlexMailer\FlexMailerTask $task */ | |
31 | list($verp) = $mailing->getVerpAndUrlsAndHeaders( | |
32 | $e->getJob()->id, $task->getEventQueueId(), $task->getHash(), | |
33 | $task->getAddress()); | |
34 | ||
35 | if (!$task->getMailParam('Return-Path')) { | |
36 | $task->setMailParam('Return-Path', $verp['bounce']); | |
37 | } | |
38 | if (!$task->getMailParam('X-CiviMail-Bounce')) { | |
39 | $task->setMailParam('X-CiviMail-Bounce', $verp['bounce']); | |
40 | } | |
41 | } | |
42 | } | |
43 | ||
44 | } |