diff --git a/Classes/Aspect/DebuggingAspect.php b/Classes/Aspect/DebuggingAspect.php index e07a4f6..bdeae35 100644 --- a/Classes/Aspect/DebuggingAspect.php +++ b/Classes/Aspect/DebuggingAspect.php @@ -10,6 +10,7 @@ /** * @Flow\Aspect + * @Flow\Introduce("class(Neos\SwiftMailer\Message)", traitName="FormatD\Mailer\Traits\InterceptionTrait") */ class DebuggingAspect { @@ -18,7 +19,7 @@ class DebuggingAspect { * @var array */ protected $settings; - + /** * Intercept all emails or add bcc according to package configuration * @@ -35,6 +36,7 @@ public function interceptEmails(\Neos\Flow\Aop\JoinPointInterface $joinPoint) { $message = $joinPoint->getProxy(); if ($this->settings['interceptAll']['active']) { + $oldTo = $message->getTo(); $oldCc = $message->getCc(); $oldBcc = $message->getBcc(); @@ -48,8 +50,14 @@ public function interceptEmails(\Neos\Flow\Aop\JoinPointInterface $joinPoint) { } } + // stop if this aspect is executed twice (happens if QueueAdaptor is installed) + if ($message->isIntercepted()) { + return; + } + $interceptedRecipients = key($oldTo) . ($oldCc ? ' CC: ' . key($oldCc) : '') . ($oldBcc ? ' BCC: ' . key($oldBcc) : ''); $message->setSubject('[intercepted '.$interceptedRecipients.'] '.$message->getSubject()); + $message->setIntercepted(true); $message->setCc(array()); $message->setBcc(array()); diff --git a/Classes/Traits/InterceptionTrait.php b/Classes/Traits/InterceptionTrait.php new file mode 100644 index 0000000..55a8a25 --- /dev/null +++ b/Classes/Traits/InterceptionTrait.php @@ -0,0 +1,36 @@ +intercepted; + } + + /** + * @param bool $intercepted + */ + public function setIntercepted(bool $intercepted): void + { + $this->intercepted = $intercepted; + } + +} + +?>