From 8b2a51b89fe8a5a9e94a343a71a540f6f26c87bf Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Fri, 21 Nov 2014 13:47:23 +0000 Subject: [PATCH] make sure (or at least try) there is an emailaddress set for ident_email when fetching identities for the current user --- .../inc/class.emailadmin_account.inc.php | 5 ++--- .../inc/class.emailadmin_imapbase.inc.php | 22 +++++++++++++++++-- mail/inc/class.mail_activesync.inc.php | 4 +++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/emailadmin/inc/class.emailadmin_account.inc.php b/emailadmin/inc/class.emailadmin_account.inc.php index 20d1f35cd2..1c0f198dde 100644 --- a/emailadmin/inc/class.emailadmin_account.inc.php +++ b/emailadmin/inc/class.emailadmin_account.inc.php @@ -487,7 +487,7 @@ class emailadmin_account implements ArrayAccess return new egw_db_callback_iterator($rs, // process each row - function($row) use ($replace_placeholders, $field) + function($row) use ($replace_placeholders, $field, $user) { // set email from imap-username (evtl. set from session, if acc_imap_logintype specified) if (in_array($field, array('name', 'ident_email', 'params')) && @@ -495,8 +495,7 @@ class emailadmin_account implements ArrayAccess { $row = array_merge($row, emailadmin_credentials::from_session($row)); } - if (empty($row['ident_email'])) $row['ident_email'] = $row['acc_imap_username']; - + if (empty($row['ident_email'])||strpos($row['ident_email'],'@')===false) $row['ident_email'] = ($user == $GLOBALS['egw_info']['user']['account_id'] && $GLOBALS['egw_info']['user']['account_email']? $GLOBALS['egw_info']['user']['account_email'] :$row['acc_imap_username']); if ($field != 'name') { $data = $replace_placeholders ? array_merge($row, emailadmin_account::replace_placeholders($row)) : $row; diff --git a/emailadmin/inc/class.emailadmin_imapbase.inc.php b/emailadmin/inc/class.emailadmin_imapbase.inc.php index 0f71dd0078..fab10fd176 100644 --- a/emailadmin/inc/class.emailadmin_imapbase.inc.php +++ b/emailadmin/inc/class.emailadmin_imapbase.inc.php @@ -5433,6 +5433,24 @@ class emailadmin_imapbase ); } + /** + * getStandardIdentityForProfile + * get either the first identity out of the given identities or the one matching the profile_id + * @param object $_identities identity iterator object with identities from emailadmin_account + * @param integer $_profile_id the acc_id/profileID the identity with the matching key is the standard one + * @return array the identity + */ + static function getStandardIdentityForProfile($_identities, $_profile_id) + { + $c = 0; + // use the standardIdentity + foreach($_identities as $key => $acc) { + if ($c==0) $identity = $acc; + if ($key==$_profile_id) $identity = $acc; + $c++; + } + return $identity; + } /** * createHeaderInfoSection - creates a textual headersection from headerobject * @param array header headerarray may contain SUBJECT,FROM,SENDER,TO,CC,BCC,DATE,PRIORITY,IMPORTANCE @@ -5894,7 +5912,7 @@ class emailadmin_imapbase { $mailObject->ClearReplyTos(); $activeMailProfiles = $this->mail->getAccountIdentities($this->profileID); - $activeMailProfile = array_shift($activeMailProfiles); + $activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID); $mailObject->AddReplyTo(self::$idna2->encode($activeMailProfile['ident_email']),emailadmin_imapbase::generateIdentityString($activeMailProfile,false)); } @@ -5916,7 +5934,7 @@ class emailadmin_imapbase $email = ($contact['email'] ? $contact['email'] : $contact['email_home']); $nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']); $activeMailProfiles = $this->getAccountIdentities($this->profileID); - $activeMailProfile = array_shift($activeMailProfiles); + $activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID); //error_log(__METHOD__.' ('.__LINE__.') '.array2string($activeMailProfile)); $mailObject->From = $activeMailProfile['ident_email']; //$mailObject->From = $_identity->emailAddress; diff --git a/mail/inc/class.mail_activesync.inc.php b/mail/inc/class.mail_activesync.inc.php index cdb436abf0..490741bb19 100644 --- a/mail/inc/class.mail_activesync.inc.php +++ b/mail/inc/class.mail_activesync.inc.php @@ -440,7 +440,9 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send // initialize our mail_bo if (!isset($this->mail)) $this->mail = mail_bo::getInstance(false,self::$profileID,true,false,true); $activeMailProfiles = $this->mail->getAccountIdentities(self::$profileID); - $activeMailProfile = array_shift($activeMailProfiles); + // use the standardIdentity + $activeMailProfile = mail_bo::getStandardIdentityForProfile($activeMailProfiles,self::$profileID); + if ($this->debugLevel>2) debugLog(__METHOD__.__LINE__.' ProfileID:'.self::$profileID.' ActiveMailProfile:'.array2string($activeMailProfile)); // initialize the new egw_mailer object for sending