Skip to content

Commit

Permalink
Attempts to compensate for bad SMTP 'from' addresses, esp the old def…
Browse files Browse the repository at this point in the history
…ault one [#921 state:resolved]
  • Loading branch information
dleffler committed Feb 16, 2013
1 parent 433fa38 commit 26a61a6
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions framework/core/subsystems/expMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ public function quickSend($params = array()) {
} else {
trim($params['from']);
}
$this->message->setFrom((array)$params['from']); //FIXME we need to use this->addFrom() instead
// $this->message->setFrom((array)$params['from']); //FIXME we need to use this->addFrom() instead
$this->addFrom($params['from']);

$this->message->setSubject($params['subject'] = !empty($params['subject']) ? $params['subject'] : 'Message from '.SITE_TITLE);

Expand Down Expand Up @@ -371,7 +372,8 @@ public function quickBatchSend() {
} else {
trim($params['from']);
}
$this->message->setFrom($params['from']); //FIXME we need to use this->addFrom() instead
// $this->message->setFrom($params['from']); //FIXME we need to use this->addFrom() instead
$this->addFrom($params['from']);

$this->addSubject($params['subject'] = !empty($params['subject']) ? $params['subject'] : 'Message from '.SITE_TITLE);

Expand Down Expand Up @@ -432,12 +434,11 @@ public function quickBatchSend() {
* # Path Headers
* Path headers are like very-restricted mailbox headers. They contain a single email address with no associated name. The Return-Path header of a message is a path header.
*/
//FIXME the $headers parameter is wiped out with the 2nd line
public function addHeaders($headers) {
$headers = $this->message->getHeaders();
foreach ($headers as $header => $value) {
//new SWIFT 4 way
$headers->addTextHeader($header, $value);
$headers->addTextHeader($header, $value);
}
}

Expand Down Expand Up @@ -738,15 +739,23 @@ public function addBcc($email, $name = null) {
* @param string $email This is the email address you want to use as the sender.
* @param string $name This is the name associated with the above email address.
*/
public function addFrom($email = null, $name = null) {
//FIXME we need to ensure this is a valid mail address as Swiftmailer send will fail otherwise
if (!empty($email) && !empty($name)) {
$this->from = array($email, $name);
$this->message->setFrom($email, $name);
} else {
$this->from = $email;
$this->message->setFrom($email);
}
public function addFrom($email = null) {
// attempt to fix a bad from address
if (is_array($email)) {
foreach ($email as $address=>$name) {
if (strstr($address,'.') === false) {
$email[$name] .= '.net';
}
}
} else {
if (strstr($email,'.') === false) {
$email .= '.net';
}
}
$this->from = $email;
if (!empty($email)) {
$this->message->setFrom($email);
}
}

/**
Expand Down

0 comments on commit 26a61a6

Please sign in to comment.