Elgg  Version 4.3
ThreadHeadersHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Email;
4 
11 
20  public function __invoke(\Elgg\Hook $hook) {
21  $email = $hook->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.
Models an event passed to hook handlers.
Definition: Hook.php:11
Email message.
Definition: Email.php:13
$notification
Definition: body.php:13
__invoke(\Elgg\Hook $hook)
Adds default thread SMTP headers to group messages correctly.
$container
Definition: delete.php:23
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:547
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
Sets the thread headers for emails.