Skip to content

Commit

Permalink
mailjet#26 Does not initializes the name property if not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Gautreau committed Feb 25, 2019
1 parent bd1c115 commit d4db161
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
17 changes: 13 additions & 4 deletions SwiftMailer/MessageFormat/MessagePayloadV31.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,19 @@ private static function getMailjetHeaders() {
* @return array|null
*/
private function getReplyTo(Swift_Mime_Message $message) {
if (is_array($message->getReplyTo())) {
return array('Email' => key($message->getReplyTo()), 'Name' => current($message->getReplyTo()));
} elseif (is_string($message->getReplyTo())) {
return array('Email' => $message->getReplyTo());
$replyTo = $message->getReplyTo();

if (is_array($replyTo)) {
$email = key($replyTo);
$name = current($replyTo);

if (empty($name)){
return array('Email' => $email);
}

return array('Email' => $email, 'Name' => $name);
} elseif (is_string($replyTo)) {
return array('Email' => $replyTo);
} else {
return null;
}
Expand Down
26 changes: 26 additions & 0 deletions Tests/SwiftMailer/MailjetTransportv31Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,32 @@ public function testBulkSendMessages() {
}
}

public function testReplyToWithoutName(){
$message = new \Swift_Message('Test Subject', '<p>Foo bar</p>', 'text/html');
$message->setReplyTo('[email protected]');
$message->setFrom('[email protected]');
$message->setTo('[email protected]');
$message->setBody("Hello world!", 'text/plain');

$transport = $this->createTransport();
$mailjetMessage = $transport->messageFormat->getMailjetMessage($message)['Messages'][0];

$this->assertEquals(["Email" => '[email protected]'], $mailjetMessage['ReplyTo']);
}

public function testReplyTo(){
$message = new \Swift_Message('Test Subject', '<p>Foo bar</p>', 'text/html');
$message->setReplyTo('[email protected]', 'Alice');
$message->setFrom('[email protected]');
$message->setTo('[email protected]');
$message->setBody("Hello world!", 'text/plain');

$transport = $this->createTransport();
$mailjetMessage = $transport->messageFormat->getMailjetMessage($message)['Messages'][0];

$this->assertEquals(["Email" => '[email protected]', "Name" => "Alice"], $mailjetMessage['ReplyTo']);
}

/**
* @param string $email
* @param string $name
Expand Down

0 comments on commit d4db161

Please sign in to comment.