* Mail: Fix vacation notice can not deal with aliases, which have no domain set

This commit is contained in:
Hadi Nategh 2017-04-21 11:08:39 +02:00
parent c2dd93aca6
commit fe9d41785a
2 changed files with 37 additions and 9 deletions

View File

@ -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 .= "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; $first = 1;
foreach ($vacation['addresses'] as $vaddress) { if (!empty($vacation['addresses'][0]))
if (!$first) $newscriptbody .= ", "; {
$newscriptbody .= "\"" . trim($vaddress) . "\""; $newscriptbody .= " :addresses [";
$first = 0; foreach ($vacation['addresses'] as $vaddress) {
if (!$first) $newscriptbody .= ", ";
$newscriptbody .= "\"" . trim($vaddress) . "\"";
$first = 0;
}
$newscriptbody .= "] ";
} }
$message = $vacation['text']; $message = $vacation['text'];
if ($vacation['start_date'] || $vacation['end_date']) if ($vacation['start_date'] || $vacation['end_date'])
@ -459,7 +464,7 @@ class Script
date($format_date,$vacation['end_date']), date($format_date,$vacation['end_date']),
),$message); ),$message);
} }
$newscriptbody .= "] text:\n" . $message . "\n.\n;\n\n"; $newscriptbody .= " text:\n" . $message . "\n.\n;\n\n";
} }
// update with any changes. // update with any changes.

View File

@ -447,13 +447,20 @@ class mail_sieve
$accAllIdentities = $this->account->smtpServer()->getAccountEmailAddress(Api\Accounts::id2name($accountID)); $accAllIdentities = $this->account->smtpServer()->getAccountEmailAddress(Api\Accounts::id2name($accountID));
$allAliases = $this->account->ident_email !=''? array($this->account->ident_email): array(); $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); asort($allAliases);
return array( return array(
'vacation' =>$vacation, '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 * Vacation edit
* *