diff options
author | Marcin Czołnowski <marcin@czolnowski.net> | 2014-06-26 16:07:44 +0400 |
---|---|---|
committer | Marcin Czołnowski <marcin@czolnowski.net> | 2014-06-26 16:07:44 +0400 |
commit | 1caad6f468464b7c1278619840ed516dc58c92c6 (patch) | |
tree | 0247e4f90e42112f7ac5767a4dff139538de64b5 /core/Mail.php | |
parent | 5ad27d7a9a3c77ece4990f3244ceac4d29f62cf6 (diff) |
Parse replay-to header in the same way like from - with {DOMAIN} placeholder.
Diffstat (limited to 'core/Mail.php')
-rw-r--r-- | core/Mail.php | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/core/Mail.php b/core/Mail.php index 8bbb581dd5..d26b08b154 100644 --- a/core/Mail.php +++ b/core/Mail.php @@ -50,20 +50,25 @@ class Mail extends Zend_Mail */ public function setFrom($email, $name = null) { - $hostname = Config::getInstance()->mail['defaultHostnameIfEmpty']; - $piwikHost = Url::getCurrentHost($hostname); + return parent::setFrom( + $this->parseDomainPlaceholderAsPiwikHostName($email), + $name + ); + } - // If known Piwik URL, use it instead of "localhost" - $piwikUrl = SettingsPiwik::getPiwikUrl(); - $url = parse_url($piwikUrl); - if (isset($url['host']) - && $url['host'] != 'localhost' - && $url['host'] != '127.0.0.1' - ) { - $piwikHost = $url['host']; - } - $email = str_replace('{DOMAIN}', $piwikHost, $email); - return parent::setFrom($email, $name); + /** + * Set Reply-To Header + * + * @param string $email + * @param null|string $name + * @return Zend_Mail + */ + public function setReplyTo($email, $name = null) + { + return parent::setReplyTo( + $this->parseDomainPlaceholderAsPiwikHostName($email), + $name + ); } /** @@ -100,4 +105,32 @@ class Mail extends Zend_Mail return parent::send($transport); } } + + /** + * @param string $email + * @return string + */ + protected function parseDomainPlaceholderAsPiwikHostName($email) + { + $hostname = Config::getInstance()->mail['defaultHostnameIfEmpty']; + $piwikHost = Url::getCurrentHost($hostname); + + // If known Piwik URL, use it instead of "localhost" + $piwikUrl = SettingsPiwik::getPiwikUrl(); + $url = parse_url($piwikUrl); + if ($this->isHostDefinedAndNotLocal($url)) { + $piwikHost = $url['host']; + } + + return str_replace('{DOMAIN}', $piwikHost, $email); + } + + /** + * @param array $url + * @return bool + */ + protected function isHostDefinedAndNotLocal($url) + { + return isset($url['host']) && !in_array($url['host'], array('localhost', '127.0.0.1'), true); + } } |