Commit 3838b501 by Carsten Brandt

refactored Debug Mail panel to work with different vendors

implementation checks for instanceof for additional swiftmailer capabilities. issue #2870
parent 4c09aef2
......@@ -38,6 +38,11 @@ td, th {
word-break: break-all;
}
.not-set {
color: #c55;
font-style: italic;
}
.detail-grid-view th {
white-space: nowrap;
}
......
......@@ -13,6 +13,7 @@ use yii\debug\models\search\Mail;
use yii\debug\Panel;
use yii\mail\BaseMailer;
use yii\helpers\FileHelper;
use yii\mail\MessageInterface;
/**
* Debugger panel that collects and displays the generated emails.
......@@ -39,27 +40,37 @@ class MailPanel extends Panel
parent::init();
Event::on(BaseMailer::className(), BaseMailer::EVENT_AFTER_SEND, function ($event) {
$message = $event->message->getSwiftMessage();
$textBody = $message->getBody();
$fileName = $event->sender->generateMessageFileName();
FileHelper::createDirectory(Yii::getAlias($this->mailPath));
file_put_contents(Yii::getAlias($this->mailPath) . '/' . $fileName, $message->toString());
$this->_messages[] = [
/** @var MessageInterface $message */
$message = $event->message;
$messageData = [
'isSuccessful' => $event->isSuccessful,
'time' => $message->getDate(),
'headers' => $message->getHeaders(),
'from' => $this->convertParams($message->getFrom()),
'to' => $this->convertParams($message->getTo()),
'reply' => $this->convertParams($message->getReplyTo()),
'cc' => $this->convertParams($message->getCc()),
'bcc' => $this->convertParams($message->getBcc()),
'subject' => $message->getSubject(),
'body' => $textBody,
'charset' => $message->getCharset(),
'file' => $fileName,
];
// add more information when message is a SwiftMailer message
if ($message instanceof \yii\swiftmailer\Message) {
/** @var \Swift_Message $swiftMessage */
$swiftMessage = $message->getSwiftMessage();
$messageData['body'] = $swiftMessage->getBody();
$messageData['time'] = $swiftMessage->getDate();
$messageData['headers'] = $swiftMessage->getHeaders();
}
// store message as file
$fileName = $event->sender->generateMessageFileName();
FileHelper::createDirectory(Yii::getAlias($this->mailPath));
file_put_contents(Yii::getAlias($this->mailPath) . '/' . $fileName, $message->toString());
$messageData['file'] = $fileName;
$this->_messages[] = $messageData;
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment