diff options
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); + } } |