From 73e2243b33daad6508cf8aab1793a4d6eeadd710 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Mon, 24 Apr 2017 11:39:02 +0200 Subject: [PATCH] Fix email identity with no domain part set --- admin/inc/class.admin_mail.inc.php | 6 ++++++ api/src/Mail.php | 16 ++++++++++++++++ mail/inc/class.mail_sieve.inc.php | 28 ++++++++-------------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/admin/inc/class.admin_mail.inc.php b/admin/inc/class.admin_mail.inc.php index 612e8f0483..3b1f31d0d7 100644 --- a/admin/inc/class.admin_mail.inc.php +++ b/admin/inc/class.admin_mail.inc.php @@ -1336,6 +1336,12 @@ class admin_mail } $content['admin_actions'] = (bool)$admin_actions; + //try to fix identities with no domain part set e.g. alias as identity + if (!strpos($content['ident_email'], '@')) + { + $content['ident_email'] = Mail::fixInvalidAliasAddress (Api\Accounts::id2name($content['acc_imap_account_id'], 'account_email'), $content['ident_email']); + } + $tpl->exec(static::APP_CLASS.'edit', $content, $sel_options, $readonlys, $content, 2); } diff --git a/api/src/Mail.php b/api/src/Mail.php index b0ce372711..dff6f6c78c 100644 --- a/api/src/Mail.php +++ b/api/src/Mail.php @@ -296,6 +296,22 @@ class Mail return self::$instances[$_profileID]; } + /** + * This method tries to fix alias address lacking domain part + * by trying to add domain part 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 + */ + public static function fixInvalidAliasAddress($refrence, $address) + { + $parts = explode('@', $refrence); + if (!strpos($address,'@') && !empty($parts[1])) $address .= '@'.$parts[1]; + return $address; + } + /** * store given ProfileID to Session and pref * diff --git a/mail/inc/class.mail_sieve.inc.php b/mail/inc/class.mail_sieve.inc.php index 25c1e62c35..d85be88d30 100644 --- a/mail/inc/class.mail_sieve.inc.php +++ b/mail/inc/class.mail_sieve.inc.php @@ -418,7 +418,7 @@ class mail_sieve * * @param string $accountID * - * @return array return multi-dimentional array of vacation and aliases + * @return array return multi-dimensional array of vacation and aliases */ function getVacation($accountID = null) { @@ -445,21 +445,25 @@ class mail_sieve } if (is_null($accountID)) $accountID = $GLOBALS['egw_info']['user']['account_id']; + $account_email = Api\Accounts::id2name($accountID, 'account_email'); $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 !=''? + // Fix ident_email with no domain part set + array(Mail::fixInvalidAliasAddress($account_email, $this->account->ident_email)) + : array(); foreach ($accAllIdentities as &$val) { if ($val['type'] !='default') { // 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']); + $allAliases[] = Mail::fixInvalidAliasAddress($account_email, $val['address']); } } // try to fix already stored aliases foreach ($vacation['addresses'] as &$address) { - $address = self::fixInvalidAliasAddress($this->account->ident_email, $address); + $address = Mail::fixInvalidAliasAddress($account_email, $address); } asort($allAliases); return array( @@ -468,22 +472,6 @@ 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 *