Merge pull request #17736 from civicrm/5.27
[civicrm-core.git] / ext / flexmailer / src / Listener / BasicHeaders.php
CommitLineData
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 */
11namespace Civi\FlexMailer\Listener;
12
13use Civi\FlexMailer\Event\ComposeBatchEvent;
14
15class BasicHeaders extends BaseListener {
16
17 /**
18 * Inject basic headers
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
32 if ($task->hasContent()) {
33 continue;
34 }
35
36 list($verp) = $mailing->getVerpAndUrlsAndHeaders(
37 $e->getJob()->id, $task->getEventQueueId(), $task->getHash(),
38 $task->getAddress());
39
40 $mailParams = array();
41 $mailParams['List-Unsubscribe'] = "<mailto:{$verp['unsubscribe']}>";
42 \CRM_Mailing_BAO_Mailing::addMessageIdHeader($mailParams, 'm', $e->getJob()->id, $task->getEventQueueId(), $task->getHash());
43 $mailParams['Precedence'] = 'bulk';
44 $mailParams['job_id'] = $e->getJob()->id;
45
46 $mailParams['From'] = "\"{$mailing->from_name}\" <{$mailing->from_email}>";
47
48 // This old behavior for choosing Reply-To feels flawed to me -- if
49 // the user has chosen a Reply-To that matches the From, then it uses VERP?!
50 // $mailParams['Reply-To'] = $verp['reply'];
51 // if ($mailing->replyto_email && ($mailParams['From'] != $mailing->replyto_email)) {
52 // $mailParams['Reply-To'] = $mailing->replyto_email;
53 // }
54
55 if (!$mailing->override_verp) {
56 $mailParams['Reply-To'] = $verp['reply'];
57 }
58 elseif ($mailing->replyto_email && ($mailParams['From'] != $mailing->replyto_email)) {
59 $mailParams['Reply-To'] = $mailing->replyto_email;
60 }
61
62 $task->setMailParams(array_merge(
63 $mailParams,
64 $task->getMailParams()
65 ));
66 }
67 }
68
69}