Skip to content

Commit

Permalink
SMTPSUPORT-5 - Multiple Reply-To Emails Were Not Working
Browse files Browse the repository at this point in the history
  • Loading branch information
smusmanobjects committed Dec 28, 2022
1 parent 619dbfc commit 24c9425
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Postman/Postman-Email-Log/PostmanEmailLogService.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ private function createLog( PostmanEmailLog $log, PostmanMessage $message = null
$log->bccRecipients = $this->flattenEmails( $message->getBccRecipients() );
$log->subject = $message->getSubject();
$log->body = $message->getBody();
if ( null !== $message->getReplyTo() ) {
$log->replyTo = $message->getReplyTo()->format();
if ( $message->getReplyTo() ) {
$log->replyTo = $this->flattenEmails( $message->getReplyTo() );
}
}
$log->success = $success;
Expand Down
34 changes: 22 additions & 12 deletions Postman/Postman-Mail/PostmanMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function __construct() {
$this->toRecipients = array();
$this->ccRecipients = array();
$this->bccRecipients = array();
$this->replyTo = array();
}

function __get( $name ) {
Expand Down Expand Up @@ -251,10 +252,6 @@ public function applyFilters() {
* Throw an exception if an error is found
*/
private function internalValidate() {
// check the reply-to address for errors
if ( isset( $this->replyTo ) ) {
$this->getReplyTo()->validate( 'Reply-To' );
}

// check the from address for errors
$this->getFromAddress()->validate( 'From' );
Expand All @@ -273,6 +270,12 @@ private function internalValidate() {
foreach ( ( array ) $this->getBccRecipients() as $bccRecipient ) {
$bccRecipient->validate( 'Bcc' );
}

// validate the Reply To recipients
foreach ( ( array ) $this->getReplyTo() as $reply_to ) {
$reply_to->validate( 'Reply-To' );
}

}

/**
Expand Down Expand Up @@ -339,6 +342,19 @@ public function addCc( $cc ) {
public function addBcc( $bcc ) {
$this->addRecipients( $this->bccRecipients, $bcc );
}


/**
* Add Reply Tos
*
* @since 2.3.0
* @version 1.0.0
*/
public function add_reply_to( $replyTo ) {

$this->addRecipients( $this->replyTo, $replyTo );

}
/**
*
* @param mixed $recipients
Expand Down Expand Up @@ -450,13 +466,7 @@ private function processHeader( $name, $content ) {
break;
case 'reply-to' :
$this->logProcessHeader( 'Reply-To', $name, $content );
$pattern = '/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';
preg_match_all($pattern, $content, $matches);

if ( isset( $matches[0] ) && isset( $matches[0][0] ) && filter_var( $matches[0][0], FILTER_VALIDATE_EMAIL ) ) {
$this->setReplyTo( $content );
}

$this->setReplyTo( $content );
break;
case 'sender' :
$this->logProcessHeader( 'Sender', $name, $content );
Expand Down Expand Up @@ -543,7 +553,7 @@ function setFrom( $email, $name = null ) {
}
function setReplyTo( $replyTo ) {
if ( ! empty( $replyTo ) ) {
$this->replyTo = new PostmanEmailAddress( $replyTo );
$this->add_reply_to( $replyTo );
}
}
function setMessageId( $messageId ) {
Expand Down
9 changes: 4 additions & 5 deletions Postman/Postman-Mail/PostmanZendMailEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,10 @@ public function send( PostmanMessage $message ) {
$mail->addBcc( $recipient->getEmail(), $recipient->getName() );
}

// add the reply-to
$replyTo = $message->getReplyTo();
// $replyTo is null or a PostmanEmailAddress object
if ( isset( $replyTo ) ) {
$mail->setReplyTo( $replyTo->getEmail(), $replyTo->getName() );
// add reply to recipients
foreach ( ( array ) $message->getReplyTo() as $recipient ) {
$recipient->log( $this->logger, 'Reply-To' );
$mail->setReplyTo( $recipient->getEmail(), $recipient->getName() );
}

// add the date
Expand Down
7 changes: 0 additions & 7 deletions Postman/Postman-Mail/Zend-1.12.10/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,13 +698,6 @@ public function setFrom($email, $name = null)
*/
public function setReplyTo($email, $name = null)
{
if (null !== $this->_replyTo) {
/**
* @see Postman_Zend_Mail_Exception
*/
// require_once 'Zend/Mail/Exception.php';
throw new Postman_Zend_Mail_Exception('Reply-To Header set twice');
}

$name = $this->_filterName($name);
$this->_replyTo = $email;
Expand Down

0 comments on commit 24c9425

Please sign in to comment.