Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add reply to list support #1096

Closed
wants to merge 5 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 54 additions & 0 deletions lib/mail/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class Mail implements \JsonSerializable
/** @var $reply_to ReplyTo Email to be use when replied to */
private $reply_to;

/** @var $reply_to_list ReplyToList Email to be use when replied to */
private $reply_to_list;

/** @var $personalization Personalization[] Messages and their metadata */
private $personalization;

Expand Down Expand Up @@ -982,6 +985,56 @@ public function getReplyTo()
return $this->reply_to;
}

/**
* Add the reply to email address to a Mail object
*
* @param $list array
* both of next formats are supported
* 'replytolist' => [
* [
* 'email' => 'email1@domain.com',
* 'name' => 'name one',
* ], [
* 'email' => 'email2@domain.com',
* 'name' => 'name two',
* ],
* ],
* 'replytolist' => [
* 'email1@domain.com',
* 'email2@domain.com',
* '',
* ],
*/
public function setReplyToList(array $list)
{
foreach ($list as $l) {
if ($l instanceof ReplyTo ) {
$this->reply_to_list[] = $l;
} else {
if (is_array($l)) {
if (!empty($l) && $l['email'] !== '') {
$this->reply_to_list[] = new ReplyTo($l['email'], $l['name']);
}
} else {
if ($l !=='') {
$this->reply_to_list[] = new ReplyTo($l);
}
}
}
}
}
Comment on lines +1010 to +1025
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the addition! Could you add some unit tests to validate the logic here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added unit tests please check


/**
* Retrieve the reply to list to information attached to a Mail object
*
* @return ReplyToList
*/

public function getReplyToList()
{
return $this->reply_to_list;
}

/**
* Add a subject to a Mail object
*
Expand Down Expand Up @@ -1971,6 +2024,7 @@ static function ($value) {
)),
'from' => $this->getFrom(),
'reply_to' => $this->getReplyTo(),
'reply_to_list' => $this->getReplyToList(),
'subject' => $this->getGlobalSubject(),
'content' => $this->getContents(),
'attachments' => $this->getAttachments(),
Expand Down