attempt to get Sendmail working in zpush implementation

This commit is contained in:
Klaus Leithoff 2015-06-23 15:36:12 +00:00
parent 2a14ec0576
commit ee02151c3a
2 changed files with 109 additions and 80 deletions

View File

@ -396,23 +396,39 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
* want it in 'sent items', then the next sync on the 'sent items' folder should return * want it in 'sent items', then the next sync on the 'sent items' folder should return
* the new message as any other new message in a folder. * the new message as any other new message in a folder.
* *
* @param string $rfc822 mail * @param array $smartdata = IMAP-SendMail: SyncSendMail (
* @param array $smartdata =array() values for keys: * (S) clientid => SendMail-30722448149304
* 'task': 'forward', 'new', 'reply' * (S) saveinsent => empty
* 'itemid': id of message if it's an reply or forward * (S) replacemime => null
* 'folderid': folder * (S) accountid => null
* 'replacemime': false = send as is, false = decode and recode for whatever reason ??? * (S) source => SyncSendMailSource (
* 'saveinsentitems': 1 or absent? * (S) folderid => 101000000000
* @param boolean|double $protocolversion =false * (S) itemid => 33776
* (S) longid => null
* (S) instanceid => null
* unsetVars(Array) size: 0
* flags => false
* content => null
* )
* (S) mime => Date: Tue, 23 Jun 2015 14:13:23 +0200
*Subject: AW: Blauer himmel
*....
* (S) replyflag => true
* (S) forwardflag => null
* unsetVars(Array) size: 0
* flags => false
* content => null
*)
*
* @return boolean true on success, false on error * @return boolean true on success, false on error
* *
* @see eg. BackendIMAP::SendMail() * @see eg. BackendIMAP::SendMail()
* @todo implement either here or in mail backend * @todo implement either here or in mail backend
* (maybe sending here and storing to sent folder in plugin, as sending is supposed to always work in EGroupware) * (maybe sending here and storing to sent folder in plugin, as sending is supposed to always work in EGroupware)
*/ */
public function SendMail($rfc822, $smartdata=array(), $protocolversion = false) public function SendMail($smartdata)
{ {
//$this->debugLevel=3; $this->debugLevel=3;
$ClientSideMeetingRequest = false; $ClientSideMeetingRequest = false;
$allowSendingInvitations = 'sendifnocalnotif'; $allowSendingInvitations = 'sendifnocalnotif';
if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']) && if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']) &&
@ -425,10 +441,10 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
{ {
$allowSendingInvitations = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']; $allowSendingInvitations = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'];
} }
$smartdata_task = ($smartdata->replyflag?'reply':($smartdata->forwardflag?'forward':'new'));
if ($protocolversion < 14.0) debugLog(__METHOD__.__LINE__ . (isset($smartdata->mime) ? $smartdata->mime : ""). "task: ".(isset($smartdata_task) ? $smartdata_task : "")." itemid: ".(isset($smartdata->source->itemid) ? $smartdata->source->itemid : "")." folder: ".(isset($smartdata->source->folderid) ? $smartdata->source->folderid : ""));
debugLog("IMAP-SendMail: " . (isset($rfc822) ? $rfc822 : ""). "task: ".(isset($smartdata['task']) ? $smartdata['task'] : "")." itemid: ".(isset($smartdata['itemid']) ? $smartdata['itemid'] : "")." folder: ".(isset($smartdata['folderid']) ? $smartdata['folderid'] : "")); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
if ($this->debugLevel>0) debugLog("IMAP-Sendmail: Smartdata = ".array2string($smartdata));
//error_log("IMAP-Sendmail: Smartdata = ".array2string($smartdata)); //error_log("IMAP-Sendmail: Smartdata = ".array2string($smartdata));
// initialize our mail_bo // initialize our mail_bo
@ -437,11 +453,11 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
// use the standardIdentity // use the standardIdentity
$activeMailProfile = mail_bo::getStandardIdentityForProfile($activeMailProfiles,self::$profileID); $activeMailProfile = mail_bo::getStandardIdentityForProfile($activeMailProfiles,self::$profileID);
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
$mailObject = new egw_mailer(); $mailObject = new egw_mailer();
$this->mail->parseRawMessageIntoMailObject($mailObject,$rfc822); $this->mail->parseRawMessageIntoMailObject($mailObject,$smartdata->mime);
// Horde SMTP Class uses utf-8 by default. as we set charset always to utf-8 // Horde SMTP Class uses utf-8 by default. as we set charset always to utf-8
$mailObject->Sender = $activeMailProfile['ident_email']; $mailObject->Sender = $activeMailProfile['ident_email'];
$mailObject->From = $activeMailProfile['ident_email']; $mailObject->From = $activeMailProfile['ident_email'];
@ -454,21 +470,21 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
foreach(emailadmin_imapbase::parseAddressList($mailObject->getHeader("To")) as $addressObject) { foreach(emailadmin_imapbase::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
if (!$addressObject->valid) continue; if (!$addressObject->valid) continue;
if ($this->debugLevel>0) debugLog("Header Sentmail To: ".array2string($addressObject) ); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) );
//$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal); //$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal); $toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
} }
// CC // CC
foreach(emailadmin_imapbase::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) { foreach(emailadmin_imapbase::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
if (!$addressObject->valid) continue; if (!$addressObject->valid) continue;
if ($this->debugLevel>0) debugLog("Header Sentmail CC: ".array2string($addressObject) ); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) );
//$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal); //$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal); $ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
} }
// BCC // BCC
foreach(emailadmin_imapbase::parseAddressList($mailObject->getHeader("Bcc")) as $addressObject) { foreach(emailadmin_imapbase::parseAddressList($mailObject->getHeader("Bcc")) as $addressObject) {
if (!$addressObject->valid) continue; if (!$addressObject->valid) continue;
if ($this->debugLevel>0) debugLog("Header Sentmail BCC: ".array2string($addressObject) ); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) );
//$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal); //$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal); $bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
} }
@ -485,15 +501,15 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
} }
// save the original content-type header for the body part when forwarding // save the original content-type header for the body part when forwarding
if ($smartdata['task'] == 'forward' && $smartdata['itemid'] && !$use_orgbody) { if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody) {
//continue; // ignore //continue; // ignore
} }
// horde/egw_ mailer does everything as utf-8, the following should not be needed // horde/egw_ mailer does everything as utf-8, the following should not be needed
//$org_charset = $ContentType; //$org_charset = $ContentType;
//$ContentType = preg_replace("/charset=([A-Za-z0-9-\"']+)/", "charset=\"utf-8\"", $ContentType); //$ContentType = preg_replace("/charset=([A-Za-z0-9-\"']+)/", "charset=\"utf-8\"", $ContentType);
// if the message is a multipart message, then we should use the sent body // if the message is a multipart message, then we should use the sent body
if (($smartdata['task'] == 'new' || $smartdata['task'] == 'reply' || $smartdata['task'] == 'forward') && if (($smartdata_task == 'new' || $smartdata_task == 'reply' || $smartdata_task == 'forward') &&
((isset($smartdata['replacemime']) && $smartdata['replacemime'] == true) || ((isset($smartdata->replacemime) && $smartdata->replacemime == true) ||
$k == "Content-Type" && preg_match("/multipart/i", $ContentType))) { $k == "Content-Type" && preg_match("/multipart/i", $ContentType))) {
$use_orgbody = true; $use_orgbody = true;
} }
@ -509,13 +525,13 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
{ {
$Body = $body; $Body = $body;
$AltBody = "<pre>".nl2br($body)."</pre>"; $AltBody = "<pre>".nl2br($body)."</pre>";
if ($this->debugLevel>1) debugLog("IMAP-Sendmail: fetched Body as :". $simpleBodyType.'=> Created AltBody'); if ($this->debugLevel>1) debugLog(__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created AltBody');
} }
else else
{ {
$AltBody = $body; $AltBody = $body;
$Body = trim(translation::convertHTMLToText($body)); $Body = trim(translation::convertHTMLToText($body));
if ($this->debugLevel>1) debugLog("IMAP-Sendmail: fetched Body as :". $simpleBodyType.'=> Created Body'); if ($this->debugLevel>1) debugLog(__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created Body');
} }
} }
else else
@ -527,20 +543,20 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]", $AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null); ($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null);
} }
if ($this->debugLevel>1 && $Body) debugLog("IMAP-Sendmail: fetched Body as with MessageContentType:". $ContentType.'=>'.$Body); if ($this->debugLevel>1 && $Body) debugLog(__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
if ($this->debugLevel>1 && $AltBody) debugLog("IMAP-Sendmail: fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody); if ($this->debugLevel>1 && $AltBody) debugLog(__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
//error_log(__METHOD__.__LINE__.array2string($mailObject)); //error_log(__METHOD__.__LINE__.array2string($mailObject));
// if this is a multipart message with a boundary, we must use the original body // if this is a multipart message with a boundary, we must use the original body
//if ($this->debugLevel>2) debugLog(__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject)); //if ($this->debugLevel>2) debugLog(__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject));
if ($use_orgbody) { if ($use_orgbody) {
if ($this->debugLevel>0) debugLog("IMAP-Sendmail: use_orgbody = true ContentType:".$ContentType); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
// if it is a ClientSideMeetingRequest, we report it as send at all times // if it is a ClientSideMeetingRequest, we report it as send at all times
if (stripos($ContentType,'text/calendar') !== false ) if (stripos($ContentType,'text/calendar') !== false )
{ {
$body = ($text_body = $mailObject->findBody('calendar')) ? $text_body->getContents() : null; $body = ($text_body = $mailObject->findBody('calendar')) ? $text_body->getContents() : null;
$Body = $body; $Body = $body;
$AltBody = "<pre>".nl2br($body)."</pre>"; $AltBody = "<pre>".nl2br($body)."</pre>";
if ($this->debugLevel>0) debugLog("IMAP-Sendmail: we have a Client Side Meeting Request"); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") we have a Client Side Meeting Request");
// try figuring out the METHOD -> [ContentType] => text/calendar; name=meeting.ics; method=REQUEST // try figuring out the METHOD -> [ContentType] => text/calendar; name=meeting.ics; method=REQUEST
$tA = explode(' ',$ContentType); $tA = explode(' ',$ContentType);
foreach ((array)$tA as $k => $p) foreach ((array)$tA as $k => $p)
@ -615,15 +631,15 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
$sigTextPlain = $beforePlain.translation::convertHTMLToText($sigText); $sigTextPlain = $beforePlain.translation::convertHTMLToText($sigText);
$isreply = $isforward = false; $isreply = $isforward = false;
// reply --------------------------------------------------------------------------- // reply ---------------------------------------------------------------------------
if ($smartdata['task'] == 'reply' && isset($smartdata['itemid']) && if ($smartdata_task == 'reply' && isset($smartdata->source->itemid) &&
isset($smartdata['folderid']) && $smartdata['itemid'] && $smartdata['folderid'] && isset($smartdata->source->folderid) && $smartdata->source->itemid && $smartdata->source->folderid &&
(!isset($smartdata['replacemime']) || (!isset($smartdata->replacemime) ||
(isset($smartdata['replacemime']) && $smartdata['replacemime'] == false))) (isset($smartdata->replacemime) && $smartdata->replacemime == false)))
{ {
// now get on, and fetch the original mail // now get on, and fetch the original mail
$uid = $smartdata['itemid']; $uid = $smartdata->source->itemid;
if ($this->debugLevel>0) debugLog("IMAP Smartreply is called with FolderID:".$smartdata['folderid'].' and ItemID:'.$smartdata['itemid']); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
$this->splitID($smartdata['folderid'], $account, $folder); $this->splitID($smartdata->source->folderid, $account, $folder);
$this->mail->reopen($folder); $this->mail->reopen($folder);
$bodyStruct = $this->mail->getMessageBody($uid, 'html_only'); $bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
@ -631,17 +647,17 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml); if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) { if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
// may be html // may be html
if ($this->debugLevel>0) debugLog("MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml; $AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
$isreply = true; $isreply = true;
} }
// plain text Message part // plain text Message part
if ($this->debugLevel>0) debugLog("MIME Body".' Type:plain, fetch text:'); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain // if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display'); $bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct);//$this->ui->getdisplayableBody($bodyStruct,false); $bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct);//$this->ui->getdisplayableBody($bodyStruct,false);
if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) { if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
if ($this->debugLevel>0) debugLog("MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain; $Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
$isreply = true; $isreply = true;
} }
@ -657,10 +673,10 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
$preferencesArray =& $GLOBALS['egw_info']['user']['preferences']['mail']; $preferencesArray =& $GLOBALS['egw_info']['user']['preferences']['mail'];
// forward ------------------------------------------------------------------------- // forward -------------------------------------------------------------------------
if ($smartdata['task'] == 'forward' && isset($smartdata['itemid']) && if ($smartdata_task == 'forward' && isset($smartdata->source->itemid) &&
isset($smartdata['folderid']) && $smartdata['itemid'] && $smartdata['folderid'] && isset($smartdata->source->folderid) && $smartdata->source->itemid && $smartdata->source->folderid &&
(!isset($smartdata['replacemime']) || (!isset($smartdata->replacemime) ||
(isset($smartdata['replacemime']) && $smartdata['replacemime'] == false))) (isset($smartdata->replacemime) && $smartdata->replacemime == false)))
{ {
//force the default for the forwarding -> asmail //force the default for the forwarding -> asmail
if (is_array($preferencesArray)) { if (is_array($preferencesArray)) {
@ -671,9 +687,9 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
$preferencesArray['message_forwarding'] = 'asmail'; $preferencesArray['message_forwarding'] = 'asmail';
} }
// construct the uid of the message out of the itemid - seems to be the uid, no construction needed // construct the uid of the message out of the itemid - seems to be the uid, no construction needed
$uid = $smartdata['itemid']; $uid = $smartdata->source->itemid;
if ($this->debugLevel>0) debugLog("IMAP Smartfordward is called with FolderID:".$smartdata['folderid'].' and ItemID:'.$smartdata['itemid']); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
$this->splitID($smartdata['folderid'], $account, $folder); $this->splitID($smartdata->source->folderid, $account, $folder);
$this->mail->reopen($folder); $this->mail->reopen($folder);
// receive entire mail (header + body) // receive entire mail (header + body)
@ -683,8 +699,8 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
if ($preferencesArray['message_forwarding'] == 'asmail') if ($preferencesArray['message_forwarding'] == 'asmail')
{ {
$rawHeader=''; $rawHeader='';
$rawHeader = $this->mail->getMessageRawHeader($smartdata['itemid'], $_partID,$folder); $rawHeader = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID,$folder);
$rawBody = $this->mail->getMessageRawBody($smartdata['itemid'], $_partID,$folder); $rawBody = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID,$folder);
$mailObject->AddStringAttachment($rawHeader.$rawBody, $headers['SUBJECT'].'.eml', 'message/rfc822'); $mailObject->AddStringAttachment($rawHeader.$rawBody, $headers['SUBJECT'].'.eml', 'message/rfc822');
$AltBody = $AltBody."</br>".lang("See Attachments for Content of the Orignial Mail").$sigTextHtml; $AltBody = $AltBody."</br>".lang("See Attachments for Content of the Orignial Mail").$sigTextHtml;
$Body = $Body."\r\n".lang("See Attachments for Content of the Orignial Mail").$sigTextPlain; $Body = $Body."\r\n".lang("See Attachments for Content of the Orignial Mail").$sigTextPlain;
@ -693,9 +709,9 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
else else
{ {
// now get on, and fetch the original mail // now get on, and fetch the original mail
$uid = $smartdata['itemid']; $uid = $smartdata->source->itemid;
if ($this->debugLevel>0) debugLog("IMAP Smartreply is called with FolderID:".$smartdata['folderid'].' and ItemID:'.$smartdata['itemid']); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
$this->splitID($smartdata['folderid'], $account, $folder); $this->splitID($smartdata->source->folderid, $account, $folder);
$this->mail->reopen($folder); $this->mail->reopen($folder);
$bodyStruct = $this->mail->getMessageBody($uid, 'html_only'); $bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
@ -703,17 +719,17 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml); if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) { if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
// may be html // may be html
if ($this->debugLevel>0) debugLog("MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml; $AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
$isforward = true; $isforward = true;
} }
// plain text Message part // plain text Message part
if ($this->debugLevel>0) debugLog("MIME Body".' Type:plain, fetch text:'); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain // if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display'); $bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct);//$this->ui->getdisplayableBody($bodyStruct,false); $bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct);//$this->ui->getdisplayableBody($bodyStruct,false);
if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) { if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
if ($this->debugLevel>0) debugLog("MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF); if ($this->debugLevel>0) debugLog(__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain; $Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
$isforward = true; $isforward = true;
} }
@ -763,7 +779,7 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
//advanced debugging //advanced debugging
// Horde SMTP Class uses utf-8 by default. // Horde SMTP Class uses utf-8 by default.
//debugLog("IMAP-SendMail: parsed message: ". print_r($message,1)); //debugLog("IMAP-SendMail: parsed message: ". print_r($message,1));
if ($this->debugLevel>2) debugLog("IMAP-SendMail: MailObject:".array2string($mailObject)); if ($this->debugLevel>2) debugLog(__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
// set a higher timeout for big messages // set a higher timeout for big messages
@set_time_limit(120); @set_time_limit(120);
@ -774,15 +790,15 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
$mailObject->Send(); $mailObject->Send();
} }
catch(phpmailerException $e) { catch(phpmailerException $e) {
debugLog("The email could not be sent. Last-SMTP-error: ". $e->getMessage()); debugLog(__METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ". $e->getMessage());
$send = false; $send = false;
} }
if (( $smartdata['task'] == 'reply' || $smartdata['task'] == 'forward') && $send == true) if (( $smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
{ {
$uid = $smartdata['itemid']; $uid = $smartdata->source->itemid;
if ($this->debugLevel>0) debugLog(__METHOD__.__LINE__.' tASK:'.$smartdata['task']." FolderID:".$smartdata['folderid'].' and ItemID:'.$smartdata['itemid']); if ($this->debugLevel>0) debugLog(__METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
$this->splitID($smartdata['folderid'], $account, $folder); $this->splitID($smartdata->source->folderid, $account, $folder);
//error_log(__METHOD__.__LINE__.' Folder:'.$folder.' Uid:'.$uid); //error_log(__METHOD__.__LINE__.' Folder:'.$folder.' Uid:'.$uid);
$this->mail->reopen($folder); $this->mail->reopen($folder);
// if the draft folder is a starting part of the messages folder, the draft message will be deleted after the send // if the draft folder is a starting part of the messages folder, the draft message will be deleted after the send
@ -792,7 +808,7 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
$this->mail->deleteMessages(array($uid),$folder); $this->mail->deleteMessages(array($uid),$folder);
} else { } else {
$this->mail->flagMessages("answered", array($uid),$folder); $this->mail->flagMessages("answered", array($uid),$folder);
if ($smartdata['task']== "forward") if ($smartdata_task== "forward")
{ {
$this->mail->flagMessages("forwarded", array($uid),$folder); $this->mail->flagMessages("forwarded", array($uid),$folder);
} }
@ -800,7 +816,7 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
} }
$asf = ($send ? true:false); // initalize accordingly $asf = ($send ? true:false); // initalize accordingly
if (($smartdata['saveinsentitems']==1 || !isset($smartdata['saveinsentitems'])) && $send==true && $this->mail->mailPreferences['sendOptions'] != 'send_only') if (($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && $send==true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
{ {
$asf = false; $asf = false;
$sentFolder = $this->mail->getSentFolder(); $sentFolder = $this->mail->getSentFolder();
@ -814,7 +830,7 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
// No Sent folder set, try defaults // No Sent folder set, try defaults
else else
{ {
debugLog("IMAP-SendMail: No Sent mailbox set"); debugLog(__METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
// we dont try guessing // we dont try guessing
$asf = true; $asf = true;
} }
@ -855,13 +871,13 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
//$asf = false; //$asf = false;
debugLog(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$mailObject->getHeader('Subject'),$folderName)); debugLog(__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$mailObject->getHeader('Subject'),$folderName));
} }
debugLog("IMAP-SendMail: Outgoing mail saved in configured 'Sent' folder '".$folderName."': ". (($asf)?"success":"failed")); debugLog(__METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ". (($asf)?"success":"failed"));
} }
//$this->mail->closeConnection(); //$this->mail->closeConnection();
} }
} }
//$this->debugLevel=0; $this->debugLevel=0;
if ($send && $asf) if ($send && $asf)
{ {
@ -888,6 +904,7 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
*/ */
public function GetMessage($folderid, $id, $contentparameters) public function GetMessage($folderid, $id, $contentparameters)
{ {
$this->debugLevel=4;
debugLog(__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id); debugLog(__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id);
$truncsize = Utils::GetTruncSize($contentparameters->GetTruncation()); $truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
$mimesupport = $contentparameters->GetMimeSupport(); $mimesupport = $contentparameters->GetMimeSupport();
@ -1225,16 +1242,16 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
$attachment->attmethod = 1; $attachment->attmethod = 1;
$attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key; $attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key;
} }
$attachment->displayname = $attach['name']; $attachment->displayname = $attach['name'];
//error_log(__METHOD__.__LINE__.'->'.$folderid . ":" . $id . ":" . $attach['partID']); //error_log(__METHOD__.__LINE__.'->'.$folderid . ":" . $id . ":" . $attach['partID']);
$attachment->attoid = "";//isset($part->headers['content-id']) ? trim($part->headers['content-id']) : ""; $attachment->attoid = "";//isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
if (!empty($attach['cid']) && $attach['cid'] <> 'NIL' ) if (!empty($attach['cid']) && $attach['cid'] <> 'NIL' )
{ {
$attachment->isinline=true; $attachment->isinline=true;
if (Request::GetProtocolVersion() >= 12.0) { if (Request::GetProtocolVersion() >= 12.0) {
$attachment->attmethod=1; $attachment->method=1;
$attachment->contentid= str_replace(array("<",">"), "",$attach['cid']); $attachment->contentid= str_replace(array("<",">"), "",$attach['cid']);
} else { } else {
$attachment->attmethod=6; $attachment->attmethod=6;
@ -1243,8 +1260,6 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
// debugLog("'".$part->headers['content-id']."' ".$attachment->contentid); // debugLog("'".$part->headers['content-id']."' ".$attachment->contentid);
$attachment->contenttype = trim($attach['mimeType']); $attachment->contenttype = trim($attach['mimeType']);
// debugLog("'".$part->headers['content-type']."' ".$attachment->contentid); // debugLog("'".$part->headers['content-type']."' ".$attachment->contentid);
} else {
$attachment->attmethod=1;
} }
if (Request::GetProtocolVersion() >= 12.0) { if (Request::GetProtocolVersion() >= 12.0) {
array_push($output->asattachments, $attachment); array_push($output->asattachments, $attachment);
@ -1256,8 +1271,10 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
//$this->debugLevel=0; //$this->debugLevel=0;
// end handle Attachments // end handle Attachments
if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__.array2string($output)); if ($this->debugLevel>3) debugLog(__METHOD__.__LINE__.array2string($output));
$this->debugLevel=0;
return $output; return $output;
} }
$this->debugLevel=0;
return false; return false;
} }
@ -1389,22 +1406,34 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
} }
/** /**
* This function is called when a message has been changed on the PDA. You should parse the new * Called when a message has been changed on the mobile.
* message here and save the changes to disk. The return value must be whatever would be returned * Added support for FollowUp flag
* from StatMessage() after the message has been saved. This means that both the 'flags' and the 'mod'
* properties of the StatMessage() item may change via ChangeMessage().
* Note that this function will never be called on E-mail items as you can't change e-mail items, you
* can only set them as 'read'.
* *
* @param string $folderid * @param string $folderid id of the folder
* @param int $id for change | empty for create new * @param string $id id of the message
* @param SyncMail $message object to SyncObject to create * @param SyncXXX $message the SyncObject containing a message
* @param ContentParameters $contentParameters * @param ContentParameters $contentParameters
*
* @access public
* @return array same return value as StatMessage()
* @throws StatusException could throw specific SYNC_STATUS_* exceptions
*/ */
function ChangeMessage($folderid, $id, $message, $contentParameters) function ChangeMessage($folderid, $id, $message, $contentParameters)
{ {
unset($folderid, $id, $message, $contentParameters); debugLog(__METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
return false; //unset($folderid, $id, $message, $contentParameters);
$account = $folder = null;
$this->splitID($folderid, $account, $folder);
if (isset($message->flag)) {
if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder);
debugLog(__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
} else {
$rv = $this->mail->flagMessages("unflagged", $id,$folder);
debugLog(__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv);
}
}
return $this->StatMessage($folderid, $id);
} }
/** /**

View File

@ -476,7 +476,7 @@ class egw_mailer extends Horde_Mime_Mail
try { try {
parent::send($this->account->smtpTransport(), true, // true: keep Message-ID parent::send($this->account->smtpTransport(), true, // true: keep Message-ID
$this->_body->getType() != 'multipart/encrypted'); // no flowed for encrypted messages $this->_body && $this->_body->getType() != 'multipart/encrypted'); // no flowed for encrypted messages
} }
catch (Exception $e) { catch (Exception $e) {
// in case of errors/exceptions call hook again with previous returned mail_id and error-message to log // in case of errors/exceptions call hook again with previous returned mail_id and error-message to log