new: [mail] Add reference for event alert emails

pull/6967/head
Jakub Onderka 2021-02-06 13:54:07 +01:00
parent 17fb5db3cf
commit 56508cce17
3 changed files with 32 additions and 3 deletions

View File

@ -441,15 +441,25 @@ class SendEmail
if ($body instanceof SendEmailTemplate) { if ($body instanceof SendEmailTemplate) {
$body->set('canEncryptSmime', $canEncryptSmime); $body->set('canEncryptSmime', $canEncryptSmime);
$body->set('canEncryptGpg', $canEncryptGpg); $body->set('canEncryptGpg', $canEncryptGpg);
$body = $body->render($hideDetails); $bodyContent = $body->render($hideDetails);
} else { } else {
if ($hideDetails && $bodyWithoutEncryption) { if ($hideDetails && $bodyWithoutEncryption) {
$body = $bodyWithoutEncryption; $body = $bodyWithoutEncryption;
} }
$body = new CakeEmailBody($body); $bodyContent = new CakeEmailBody($body);
} }
$email = $this->create($user, $subject, $body, [], $replyToUser); $email = $this->create($user, $subject, $bodyContent, [], $replyToUser);
// Generate `In-Reply-To` and `References` to group emails
if ($body instanceof SendEmailTemplate && $body->referenceId()) {
$reference = sha1($body->referenceId() . '|' . Configure::read('MISP.uuid'));
$reference = "<$reference@{$email->domain()}>";
$email->addHeaders([
'In-Reply-To' => $reference,
'References' => $reference,
]);
}
$signed = false; $signed = false;
if (Configure::read('GnuPG.sign')) { if (Configure::read('GnuPG.sign')) {

View File

@ -7,12 +7,29 @@ class SendEmailTemplate
/** @var string */ /** @var string */
private $viewName; private $viewName;
/** @var string|null */
private $referenceId;
public function __construct($viewName) public function __construct($viewName)
{ {
$this->viewName = $viewName; $this->viewName = $viewName;
} }
/** /**
* This value will be used for grouping emails in mail client.
* @param string|null $referenceId
* @return string
*/
public function referenceId($referenceId = null)
{
if ($referenceId === null) {
return $this->referenceId ;
}
$this->referenceId = $referenceId;
}
/**
* Set template variable.
* @param string $key * @param string $key
* @param mixed $value * @param mixed $value
*/ */
@ -29,6 +46,7 @@ class SendEmailTemplate
public function render($hideDetails = false) public function render($hideDetails = false)
{ {
$View = new View(); $View = new View();
$View->autoLayout = false;
$View->helpers = ['TextColour']; $View->helpers = ['TextColour'];
$View->loadHelpers(); $View->loadHelpers();

View File

@ -3247,6 +3247,7 @@ class Event extends AppModel
$template->set('distributionLevels', $this->distributionLevels); $template->set('distributionLevels', $this->distributionLevels);
$template->set('analysisLevels', $this->analysisLevels); $template->set('analysisLevels', $this->analysisLevels);
$template->set('tlp', $this->getEmailSubjectMarkForEvent($event)); $template->set('tlp', $this->getEmailSubjectMarkForEvent($event));
$template->referenceId("event-alert|{$event['Event']['id']}");
return $template; return $template;
} }