From b0f7f9fa13554384ee9bc6135ac7f31a5f503b27 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Mon, 29 Aug 2016 16:51:22 +0300 Subject: [PATCH] Header set shortcut methods added to `Message` --- CHANGELOG.md | 3 ++ Message.php | 88 ++++++++++++++++++++++++++++++++++++++++++++++----- tests/MessageTest.php | 8 +++++ 3 files changed, 91 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b63c72..32a6994 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,10 @@ Yii Framework 2 swiftmailer extension Change Log ----------------------- - Enh #6: Added ability to specify custom mail header at `yii\swiftmailer\Message` (klimov-paul) +- Enh #23: Added `yii\swiftmailer\Message::setReturnPath()` shortcut method (klimov-paul) - Enh #27: Added ability to specify message signature (klimov-paul) +- Enh #32: Added `yii\swiftmailer\Message::setReadReceiptTo()` shortcut method (klimov-paul) +- Enh: Added `yii\swiftmailer\Message::setPriority()` shortcut method (klimov-paul) 2.0.5 March 17, 2016 diff --git a/Message.php b/Message.php index 4884843..9c2994d 100644 --- a/Message.php +++ b/Message.php @@ -399,6 +399,25 @@ class Message extends BaseMessage } /** + * @inheritdoc + */ + public function toString() + { + return $this->getSwiftMessage()->toString(); + } + + /** + * Creates the Swift email message instance. + * @return \Swift_Message email message instance. + */ + protected function createSwiftMessage() + { + return new \Swift_Message(); + } + + // Headers setup : + + /** * Adds custom header value to the message. * Several invocations of this method with the same name will add multiple header values. * @param string $name header name. @@ -454,20 +473,73 @@ class Message extends BaseMessage return $headers; } + // SwiftMessage shortcuts : + /** - * @inheritdoc + * Set the return-path (the bounce address) of this message. + * @param string $address the bounce email address. + * @return $this self reference. + * @since 2.0.6 */ - public function toString() + public function setReturnPath($address) { - return $this->getSwiftMessage()->toString(); + $this->getSwiftMessage()->setReturnPath($address); + return $this; } /** - * Creates the Swift email message instance. - * @return \Swift_Message email message instance. + * Returns the return-path (the bounce address) of this message. + * @return string the bounce email address. + * @since 2.0.6 */ - protected function createSwiftMessage() + public function getReturnPath() { - return new \Swift_Message(); + return $this->getSwiftMessage()->getReturnPath(); + } + + /** + * Set the priority of this message. + * @param integer $priority priority value, should be an integer in range: `1..5`, + * where 1 is the highest priority and 5 is the lowest. + * @return $this self reference. + * @since 2.0.6 + */ + public function setPriority($priority) + { + $this->getSwiftMessage()->setPriority($priority); + return $this; + } + + /** + * Returns the priority of this message. + * @return integer priority value as integer in range: `1..5`, + * where 1 is the highest priority and 5 is the lowest. + * @since 2.0.6 + */ + public function getPriority() + { + return $this->getSwiftMessage()->getPriority(); + } + + /** + * Sets the ask for a delivery receipt from the recipient to be sent to $addresses. + * @param string|array $addresses receipt receive email address(es). + * @return $this self reference. + * @since 2.0.6 + */ + public function setReadReceiptTo($addresses) + { + $this->getSwiftMessage()->setReadReceiptTo($addresses); + return $this; + } + + /** + * Get the addresses to which a read-receipt will be sent. + * @return string receipt receive email addresses. + * @since 2.0.6 + */ + public function getReadReceiptTo() + { + return $this->getSwiftMessage()->getReadReceiptTo(); } -} +} \ No newline at end of file diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 37833b8..2722f2a 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -185,6 +185,8 @@ class MessageTest extends TestCase $to = 'someuser@somedomain.com'; $cc = 'ccuser@somedomain.com'; $bcc = 'bccuser@somedomain.com'; + $returnPath = 'bounce@somedomain.com'; + $readReceiptTo = 'notify@somedomain.com'; $messageString = $this->createTestMessage() ->setCharset($charset) @@ -194,6 +196,9 @@ class MessageTest extends TestCase ->setTo($to) ->setCc($cc) ->setBcc($bcc) + ->setReturnPath($returnPath) + ->setPriority(2) + ->setReadReceiptTo($readReceiptTo) ->toString(); $this->assertContains('charset=' . $charset, $messageString, 'Incorrect charset!'); @@ -203,6 +208,9 @@ class MessageTest extends TestCase $this->assertContains('To: ' . $to, $messageString, 'Incorrect "To" header!'); $this->assertContains('Cc: ' . $cc, $messageString, 'Incorrect "Cc" header!'); $this->assertContains('Bcc: ' . $bcc, $messageString, 'Incorrect "Bcc" header!'); + $this->assertContains("Return-Path: <{$returnPath}>", $messageString, 'Incorrect "Return-Path" header!'); + $this->assertContains("X-Priority: 2 (High)", $messageString, 'Incorrect "Priority" header!'); + $this->assertContains('Disposition-Notification-To: ' . $readReceiptTo, $messageString, 'Incorrect "Disposition-Notification-To" header!'); } public function testSetupSignature()