Browse Source

Header set shortcut methods added to `Message`

tags/2.0.6
Klimov Paul 8 years ago
parent
commit
b0f7f9fa13
  1. 3
      CHANGELOG.md
  2. 86
      Message.php
  3. 8
      tests/MessageTest.php

3
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 #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 #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 2.0.5 March 17, 2016

86
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. * Adds custom header value to the message.
* Several invocations of this method with the same name will add multiple header values. * Several invocations of this method with the same name will add multiple header values.
* @param string $name header name. * @param string $name header name.
@ -454,20 +473,73 @@ class Message extends BaseMessage
return $headers; 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. * Returns the return-path (the bounce address) of this message.
* @return \Swift_Message email message instance. * @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();
} }
} }

8
tests/MessageTest.php

@ -185,6 +185,8 @@ class MessageTest extends TestCase
$to = 'someuser@somedomain.com'; $to = 'someuser@somedomain.com';
$cc = 'ccuser@somedomain.com'; $cc = 'ccuser@somedomain.com';
$bcc = 'bccuser@somedomain.com'; $bcc = 'bccuser@somedomain.com';
$returnPath = 'bounce@somedomain.com';
$readReceiptTo = 'notify@somedomain.com';
$messageString = $this->createTestMessage() $messageString = $this->createTestMessage()
->setCharset($charset) ->setCharset($charset)
@ -194,6 +196,9 @@ class MessageTest extends TestCase
->setTo($to) ->setTo($to)
->setCc($cc) ->setCc($cc)
->setBcc($bcc) ->setBcc($bcc)
->setReturnPath($returnPath)
->setPriority(2)
->setReadReceiptTo($readReceiptTo)
->toString(); ->toString();
$this->assertContains('charset=' . $charset, $messageString, 'Incorrect charset!'); $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('To: ' . $to, $messageString, 'Incorrect "To" header!');
$this->assertContains('Cc: ' . $cc, $messageString, 'Incorrect "Cc" header!'); $this->assertContains('Cc: ' . $cc, $messageString, 'Incorrect "Cc" header!');
$this->assertContains('Bcc: ' . $bcc, $messageString, 'Incorrect "Bcc" 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() public function testSetupSignature()

Loading…
Cancel
Save