From 524296b7570c3e8b1ec252995911f5d3111511aa Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Fri, 21 Apr 2017 11:08:39 +0200 Subject: [PATCH] * Mail: Fix vacation notice can not deal with aliases, which have no domain set --- api/src/Mail/Script.php | 17 +++++++++++------ mail/inc/class.mail_sieve.inc.php | 29 ++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/api/src/Mail/Script.php b/api/src/Mail/Script.php index 33991a9ce9..d1a5d38d37 100644 --- a/api/src/Mail/Script.php +++ b/api/src/Mail/Script.php @@ -442,12 +442,17 @@ class Script $newscriptbody .= "if header :contains ".'"X-Spam-Status" '.'"YES"'."{\n\tstop;\n}\n"; //stop vacation reply if it is spam } } - $newscriptbody .= "vacation :days " . $vacation['days'] . " :addresses ["; + $newscriptbody .= "vacation :days " . $vacation['days']; $first = 1; - foreach ($vacation['addresses'] as $vaddress) { - if (!$first) $newscriptbody .= ", "; - $newscriptbody .= "\"" . trim($vaddress) . "\""; - $first = 0; + if (!empty($vacation['addresses'][0])) + { + $newscriptbody .= " :addresses ["; + foreach ($vacation['addresses'] as $vaddress) { + if (!$first) $newscriptbody .= ", "; + $newscriptbody .= "\"" . trim($vaddress) . "\""; + $first = 0; + } + $newscriptbody .= "] "; } $message = $vacation['text']; if ($vacation['start_date'] || $vacation['end_date']) @@ -459,7 +464,7 @@ class Script date($format_date,$vacation['end_date']), ),$message); } - $newscriptbody .= "] text:\n" . $message . "\n.\n;\n\n"; + $newscriptbody .= " text:\n" . $message . "\n.\n;\n\n"; } // update with any changes. diff --git a/mail/inc/class.mail_sieve.inc.php b/mail/inc/class.mail_sieve.inc.php index a94fbd2483..25c1e62c35 100644 --- a/mail/inc/class.mail_sieve.inc.php +++ b/mail/inc/class.mail_sieve.inc.php @@ -447,13 +447,20 @@ class mail_sieve $accAllIdentities = $this->account->smtpServer()->getAccountEmailAddress(Api\Accounts::id2name($accountID)); $allAliases = $this->account->ident_email !=''? array($this->account->ident_email): array(); - foreach ($accAllIdentities as &$arrVal) + foreach ($accAllIdentities as &$val) { - if ($arrVal['type'] !='default') + if ($val['type'] !='default') { - $allAliases[] = $arrVal['address']; + // if the alias has no domain part set try to add + // default domain extracted from ident_email address + $allAliases[] = self::fixInvalidAliasAddress($this->account->ident_email, $val['address']); } } + // try to fix already stored aliases + foreach ($vacation['addresses'] as &$address) + { + $address = self::fixInvalidAliasAddress($this->account->ident_email, $address); + } asort($allAliases); return array( 'vacation' =>$vacation, @@ -461,6 +468,22 @@ class mail_sieve ); } + /** + * This method tries to fix alias address lacking domain part + * by trying to add domain extracted from given reference address + * + * @param string $refrence email address to be used for domain extraction + * @param string $address alias address + * + * @return string returns alias address with appended default domain + */ + static function fixInvalidAliasAddress($refrence, $address) + { + $parts = explode('@', $refrence); + if (!strpos($address,'@') && !empty($parts[1])) $address .= '@'.$parts[1]; + return $address; + } + /** * Vacation edit *