From 1caad6f468464b7c1278619840ed516dc58c92c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Czo=C5=82nowski?= Date: Thu, 26 Jun 2014 14:07:44 +0200 Subject: Parse replay-to header in the same way like from - with {DOMAIN} placeholder. --- core/Mail.php | 59 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 13 deletions(-) (limited to 'core/Mail.php') 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); + } } -- cgit v1.2.3