restore/ensure basic functionality on activesync for mail app

This commit is contained in:
Klaus Leithoff 2014-01-14 15:21:54 +00:00
parent ac7b5271a9
commit 1834389fec
2 changed files with 27 additions and 23 deletions

View File

@ -458,7 +458,8 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
} }
// initialize our mail_bo // initialize our mail_bo
if (!isset($this->mail)) $this->mail = mail_bo::getInstance(false,self::$profileID); if (!isset($this->mail)) $this->mail = mail_bo::getInstance(false,self::$profileID);
$activeMailProfile = $this->mail->mailPreferences->getIdentity(self::$profileID, true); $activeMailProfiles = $this->mail->getAccountIdentities(self::$profileID);
$activeMailProfile = array_shift($activeMailProfiles);
if ($this->debugLevel>2) debugLog(__METHOD__.__LINE__.' ProfileID:'.self::$profileID.' ActiveMailProfile:'.array2string($activeMailProfile)); if ($this->debugLevel>2) debugLog(__METHOD__.__LINE__.' ProfileID:'.self::$profileID.' ActiveMailProfile:'.array2string($activeMailProfile));
// initialize the new egw_mailer object for sending // initialize the new egw_mailer object for sending
@ -466,9 +467,9 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
$mailObject->CharSet = 'utf-8'; // set charset always to utf-8 $mailObject->CharSet = 'utf-8'; // set charset always to utf-8
// default, should this be forced? // default, should this be forced?
$mailObject->IsSMTP(); $mailObject->IsSMTP();
$mailObject->Sender = $activeMailProfile->emailAddress; $mailObject->Sender = $activeMailProfile['ident_email'];
$mailObject->From = $activeMailProfile->emailAddress; $mailObject->From = $activeMailProfile['ident_email'];
$mailObject->FromName = $mailObject->EncodeHeader($activeMailProfile->realName); $mailObject->FromName = $mailObject->EncodeHeader(mail_bo::generateIdentityString($activeMailProfile,false));
$mailObject->AddCustomHeader('X-Mailer: mail-Activesync'); $mailObject->AddCustomHeader('X-Mailer: mail-Activesync');
$mimeParams = array('decode_headers' => true, $mimeParams = array('decode_headers' => true,
@ -821,7 +822,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
$signature = $_signature->fm_signature; $signature = $_signature->fm_signature;
if ((isset($preferencesArray['disableRulerForSignatureSeparation']) && if ((isset($preferencesArray['disableRulerForSignatureSeparation']) &&
$preferencesArray['disableRulerForSignatureSeparation']) || $preferencesArray['disableRulerForSignatureSeparation']) ||
empty($signature) || trim($this->mail->convertHTMLToText($signature)) =='') empty($signature) || trim(translation::convertHTMLToText($signature)) =='')
{ {
$disableRuler = true; $disableRuler = true;
} }
@ -836,13 +837,13 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
} }
$sigText = $this->mail->merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id'))); $sigText = $this->mail->merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
if ($this->debugLevel>0) debugLog(__METHOD__.__LINE__.' Signature to use:'.$sigText); if ($this->debugLevel>0) debugLog(__METHOD__.__LINE__.' Signature to use:'.$sigText);
$body .= $before.($mailObject->ContentType=='text/html'?$sigText:$this->mail->convertHTMLToText($sigText)); $body .= $before.($mailObject->ContentType=='text/html'?$sigText:translation::convertHTMLToText($sigText));
//debugLog(__METHOD__.__LINE__.' -> '.$body); //debugLog(__METHOD__.__LINE__.' -> '.$body);
// remove carriage-returns from body, set the body of the mailObject // remove carriage-returns from body, set the body of the mailObject
if (trim($body) =='' && trim($mailObject->Body)==''/* && $attachmentNames*/) $body .= ($attachmentNames?$attachmentNames:lang('no text body supplied, check attachments for message text')); // to avoid failure on empty messages with attachments if (trim($body) =='' && trim($mailObject->Body)==''/* && $attachmentNames*/) $body .= ($attachmentNames?$attachmentNames:lang('no text body supplied, check attachments for message text')); // to avoid failure on empty messages with attachments
//debugLog(__METHOD__.__LINE__.' -> '.$body); //debugLog(__METHOD__.__LINE__.' -> '.$body);
$mailObject->Body = $body ;//= str_replace("\r\n", "\n", $body); // if there is a <pre> this needs \r\n so DO NOT replace them $mailObject->Body = $body ;//= str_replace("\r\n", "\n", $body); // if there is a <pre> this needs \r\n so DO NOT replace them
if ($mailObject->ContentType=='text/html') $mailObject->AltBody = $this->mail->convertHTMLToText($body); if ($mailObject->ContentType=='text/html') $mailObject->AltBody = translation::convertHTMLToText($body);
//advanced debugging //advanced debugging
if (strtolower($mailObject->CharSet) != 'utf-8') if (strtolower($mailObject->CharSet) != 'utf-8')
@ -922,7 +923,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
} }
$asf = ($send ? true:false); // initalize accordingly $asf = ($send ? true:false); // initalize accordingly
if (($smartdata['saveinsentitems']==1 || !isset($smartdata['saveinsentitems'])) && $send==true && $this->mail->mailPreferences->preferences['sendOptions'] != 'send_only') if (($smartdata['saveinsentitems']==1 || !isset($smartdata['saveinsentitems'])) && $send==true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
{ {
$asf = false; $asf = false;
$sentFolder = $this->mail->getSentFolder(); $sentFolder = $this->mail->getSentFolder();
@ -1033,9 +1034,9 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
// start AS12 Stuff (bodypreference === false) case = old behaviour // start AS12 Stuff (bodypreference === false) case = old behaviour
if ($this->debugLevel>0) debugLog(__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers)); if ($this->debugLevel>0) debugLog(__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
if ($bodypreference === false) { if ($bodypreference === false) {
$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', '', true); $bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true);
$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct); $body = $this->mail->getdisplayableBody($this->mail,$bodyStruct);
$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body)); //$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
if (stripos($body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $body); // in case there is only a html part if (stripos($body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $body); // in case there is only a html part
// remove all other html // remove all other html
$body = strip_tags($body); $body = strip_tags($body);
@ -1065,7 +1066,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
if ($this->debugLevel>0) debugLog("airsyncbasebody!"); if ($this->debugLevel>0) debugLog("airsyncbasebody!");
// fetch the body (try to gather data only once) // fetch the body (try to gather data only once)
$css =''; $css ='';
$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', '', true); $bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true);
if ($this->debugLevel>2) debugLog(__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct)); if ($this->debugLevel>2) debugLog(__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true);//$this->ui->getdisplayableBody($bodyStruct,false); $body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true);//$this->ui->getdisplayableBody($bodyStruct,false);
if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__.' html_only:'.$body); if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__.' html_only:'.$body);
@ -1078,21 +1079,21 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
// plain text Message // plain text Message
if ($this->debugLevel>0) debugLog("MIME Body".' Type:plain, fetch text (HTML, if no text available)'); if ($this->debugLevel>0) debugLog("MIME Body".' Type:plain, fetch text (HTML, if no text available)');
$output->airsyncbasenativebodytype=1; $output->airsyncbasenativebodytype=1;
$bodyStruct = $this->mail->getMessageBody($id,'never_display', '', '', true); //'only_if_no_text'); $bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true); //'only_if_no_text');
if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct)); if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct);//$this->ui->getdisplayableBody($bodyStruct,false); $body = $this->mail->getdisplayableBody($this->mail,$bodyStruct);//$this->ui->getdisplayableBody($bodyStruct,false);
if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__.' never display html(plain text only):'.$body); if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__.' never display html(plain text only):'.$body);
} }
// whatever format decode (using the correct encoding) // whatever format decode (using the correct encoding)
if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__."MIME Body".' Type:'.($output->airsyncbasenativebodytype==2?' html ':' plain ').$body); if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__."MIME Body".' Type:'.($output->airsyncbasenativebodytype==2?' html ':' plain ').$body);
$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body)); //$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
// prepare plaintextbody // prepare plaintextbody
if ($output->airsyncbasenativebodytype == 2) if ($output->airsyncbasenativebodytype == 2)
{ {
$bodyStructplain = $this->mail->getMessageBody($id,'never_display', '', '', true); //'only_if_no_text'); $bodyStructplain = $this->mail->getMessageBody($id,'never_display', '', null, true); //'only_if_no_text');
if($bodyStructplain[0]['error']==1) if($bodyStructplain[0]['error']==1)
{ {
$plainBody = $this->mail->convertHTMLToText($body,true); // always display with preserved HTML $plainBody = translation::convertHTMLToText($body,true); // always display with preserved HTML
} }
else else
{ {
@ -1571,7 +1572,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
private function fetchMessages($folderid, $cutoffdate=NULL, $_id=NULL) private function fetchMessages($folderid, $cutoffdate=NULL, $_id=NULL)
{ {
if ($this->debugLevel>1) $gstarttime = microtime (true); if ($this->debugLevel>1) $gstarttime = microtime (true);
debugLog(__METHOD__.__LINE__); //debugLog(__METHOD__.__LINE__);
$rv_messages = array(); $rv_messages = array();
// if the message is still available within the class, we use it instead of fetching it again // if the message is still available within the class, we use it instead of fetching it again
if (is_array($_id) && count($_id)==1 && is_array($this->messages) && isset($this->messages[$_id[0]]) && is_array($this->messages[$_id[0]])) if (is_array($_id) && count($_id)==1 && is_array($this->messages) && isset($this->messages[$_id[0]]) && is_array($this->messages[$_id[0]]))
@ -1947,7 +1948,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
} }
// this may be a bit rude, it may be sufficient that GetMessageList does not list messages flagged as deleted // this may be a bit rude, it may be sufficient that GetMessageList does not list messages flagged as deleted
if ($this->mail->mailPreferences->preferences['deleteOptions'] == 'mark_as_deleted') if ($this->mail->mailPreferences['deleteOptions'] == 'mark_as_deleted')
{ {
// ignore mark as deleted -> Expunge! // ignore mark as deleted -> Expunge!
//$this->mail->icServer->expunge(); // do not expunge as GetMessageList does not List messages flagged as deleted //$this->mail->icServer->expunge(); // do not expunge as GetMessageList does not List messages flagged as deleted

View File

@ -4484,7 +4484,7 @@ class mail_bo
{ {
$_structure = $this->getStructure($_uid, $_partID); $_structure = $this->getStructure($_uid, $_partID);
} }
if (!$_structure || !$_structure->contentTypeMap()) return array();
foreach($_structure->contentTypeMap() as $mime_id => $mime_type) foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
{ {
$part = $_structure->getPart($mime_id); $part = $_structure->getPart($mime_id);
@ -5401,8 +5401,10 @@ class mail_bo
if (isset($replyTo['replace@import.action'])) if (isset($replyTo['replace@import.action']))
{ {
$mailObject->ClearReplyTos(); $mailObject->ClearReplyTos();
$activeMailProfile = $this->mailPreferences->getIdentity($this->profileID, true); $activeMailProfiles = $this->mail->getAccountIdentities($this->profileID);
$mailObject->AddReplyTo(self::$idna2->encode($activeMailProfile->emailAddress),$activeMailProfile->realName); $activeMailProfile = array_shift($activeMailProfiles);
$mailObject->AddReplyTo(self::$idna2->encode($activeMailProfile['ident_email']),mail_bo::generateIdentityString($activeMailProfile,false));
} }
foreach ($SendAndMergeTocontacts as $k => $val) foreach ($SendAndMergeTocontacts as $k => $val)
{ {
@ -5421,9 +5423,10 @@ class mail_bo
//error_log(__METHOD__.__LINE__.' ID:'.$val.' Data:'.array2string($contact)); //error_log(__METHOD__.__LINE__.' ID:'.$val.' Data:'.array2string($contact));
$email = ($contact['email'] ? $contact['email'] : $contact['email_home']); $email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']); $nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
$activeMailProfile = $this->mailPreferences->getIdentity($this->profileID, true); $activeMailProfiles = $this->mail->getAccountIdentities($this->profileID);
$activeMailProfile = array_shift($activeMailProfiles);
//error_log(__METHOD__.__LINE__.array2string($activeMailProfile)); //error_log(__METHOD__.__LINE__.array2string($activeMailProfile));
$mailObject->From = $activeMailProfile->emailAddress; $mailObject->From = $activeMailProfile['ident_email'];
//$mailObject->From = $_identity->emailAddress; //$mailObject->From = $_identity->emailAddress;
$mailObject->FromName = $mailObject->EncodeHeader(self::generateIdentityString($activeMailProfile,false)); $mailObject->FromName = $mailObject->EncodeHeader(self::generateIdentityString($activeMailProfile,false));
@ -5450,7 +5453,7 @@ class mail_bo
//error_log(__METHOD__.__LINE__.' Result:'.$mailObject->Body.' error:'.array2string($e)); //error_log(__METHOD__.__LINE__.' Result:'.$mailObject->Body.' error:'.array2string($e));
if (!empty($AltBody)) $mailObject->AltBody = $bo_merge->merge_string($AltBody, $val, $e, $mailObject->AltBodyContentType, array(), self::$displayCharset); if (!empty($AltBody)) $mailObject->AltBody = $bo_merge->merge_string($AltBody, $val, $e, $mailObject->AltBodyContentType, array(), self::$displayCharset);
$ogServer = $this->mailPreferences->getOutgoingServer($this->profileID); $ogServer = emailadmin_account::read($_profileID)->smtpServer();
#_debug_array($ogServer); #_debug_array($ogServer);
$mailObject->Host = $ogServer->host; $mailObject->Host = $ogServer->host;
$mailObject->Port = $ogServer->port; $mailObject->Port = $ogServer->port;