Elgg  Version master
ThreadHeadersHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Email;
4 
11 
20  public function __invoke(\Elgg\Event $event) {
21  $email = $event->getValue();
22  if (!$email instanceof \Elgg\Email) {
23  return;
24  }
25 
26  $params = $email->getParams();
27 
28  $notification = elgg_extract('notification', $params);
29  if (!$notification instanceof \Elgg\Notifications\Notification) {
30  return;
31  }
32 
33  $object = elgg_extract('object', $notification->params);
34  if (!$object instanceof \ElggEntity) {
35  return;
36  }
37 
38  $event = elgg_extract('event', $notification->params);
39  if (!$event instanceof \Elgg\Notifications\NotificationEvent) {
40  return;
41  }
42 
43  $message_id = $email->createEntityMessageID($object, $event->getAction() !== 'create');
44  $email->addHeader('Message-ID', $message_id);
45 
46  // let's just thread comments by default
47  $container = $object->getContainerEntity();
48  if ($container instanceof \ElggEntity && $object instanceof \ElggComment) {
49  $thread_message_id = "<{$email->createEntityMessageID($container)}>";
50 
51  $email->addHeader('In-Reply-To', $thread_message_id);
52  $email->addHeader('References', $thread_message_id);
53  }
54 
55  return $email;
56  }
57 }
$email
Definition: change_email.php:7
Notification container.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
__invoke(\Elgg\Event $event)
Adds default thread SMTP headers to group messages correctly.
Email message.
Definition: Email.php:13
$notification
Definition: body.php:13
$container
Definition: delete.php:23
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
Sets the thread headers for emails.
Models an event passed to event handlers.
Definition: Event.php:11