Commit f41d6996 authored by mku's avatar mku

ZP-119 #comment Replied/forwarded message does not contain the original message #time 3h

git-svn-id: https://z-push.org/svn/z-push/trunk@1326 b7dd7b3b-3a3c-0410-9da9-bee62a6cc5b5
parent d3e0456c
...@@ -439,10 +439,6 @@ class BackendZarafa implements IBackend, ISearchProvider { ...@@ -439,10 +439,6 @@ class BackendZarafa implements IBackend, ISearchProvider {
$ab = mapi_openaddressbook($this->session); $ab = mapi_openaddressbook($this->session);
mapi_inetmapi_imtomapi($this->session, $this->store, $ab, $mapimessage, $sm->mime, array()); mapi_inetmapi_imtomapi($this->session, $this->store, $ab, $mapimessage, $sm->mime, array());
mapi_setprops($mapimessage, $mapiprops);
$this->addRecipients($message->headers, $mapimessage);
// Delete the PR_SENT_REPRESENTING_* properties because some android devices // Delete the PR_SENT_REPRESENTING_* properties because some android devices
// do not send neither From nor Sender header causing empty PR_SENT_REPRESENTING_NAME and // do not send neither From nor Sender header causing empty PR_SENT_REPRESENTING_NAME and
// PR_SENT_REPRESENTING_EMAIL_ADDRESS properties and "broken" PR_SENT_REPRESENTING_ENTRYID // PR_SENT_REPRESENTING_EMAIL_ADDRESS properties and "broken" PR_SENT_REPRESENTING_ENTRYID
...@@ -452,6 +448,42 @@ class BackendZarafa implements IBackend, ISearchProvider { ...@@ -452,6 +448,42 @@ class BackendZarafa implements IBackend, ISearchProvider {
array( $sendMailProps["sentrepresentingname"], $sendMailProps["sentrepresentingemail"], $sendMailProps["representingentryid"], array( $sendMailProps["sentrepresentingname"], $sendMailProps["sentrepresentingemail"], $sendMailProps["representingentryid"],
$sendMailProps["sentrepresentingaddt"], $sendMailProps["sentrepresentinsrchk"])); $sendMailProps["sentrepresentingaddt"], $sendMailProps["sentrepresentinsrchk"]));
if(isset($sm->source->itemid) && $sm->source->itemid) {
$entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($sm->source->folderid), hex2bin($sm->source->itemid));
if ($entryid)
$fwmessage = mapi_msgstore_openentry($this->store, $entryid);
if(!isset($fwmessage) || !$fwmessage)
throw new StatusException(sprintf("ZarafaBackend->SendMail(): Could not open message id '%s' in folder id '%s' to be replied/forwarded: 0x%X", $sm->source->itemid, $sm->source->folderid, mapi_last_hresult()), SYNC_COMMONSTATUS_ITEMNOTFOUND);
//update icon when forwarding or replying message
if ($sm->forwardflag) mapi_setprops($fwmessage, array(PR_ICON_INDEX=>262));
elseif ($sm->replyflag) mapi_setprops($fwmessage, array(PR_ICON_INDEX=>261));
mapi_savechanges($fwmessage);
// only attach the original message if the mobile does not send it itself
if (!isset($sm->replacemime)) {
// get message's body in order to append forward or reply text
$body = MAPIUtils::readPropStream($mapimessage, PR_BODY);
$bodyHtml = MAPIUtils::readPropStream($mapimessage, PR_HTML);
if($sm->forwardflag) {
// attach the original attachments to the outgoing message
$this->copyAttachments($mapimessage, $fwmessage);
}
if (strlen($body) > 0) {
$fwbody = MAPIUtils::readPropStream($fwmessage, PR_BODY);
$mapiprops[$sendMailProps["body"]] = $body."\r\n\r\n".$fwbody;
}
if (strlen($bodyHtml) > 0) {
$fwbodyHtml = MAPIUtils::readPropStream($fwmessage, PR_HTML);
$mapiprops[$sendMailProps["html"]] = $bodyHtml."<br><br>".$fwbodyHtml;
}
}
}
mapi_setprops($mapimessage, $mapiprops);
mapi_message_savechanges($mapimessage); mapi_message_savechanges($mapimessage);
mapi_message_submitmessage($mapimessage); mapi_message_submitmessage($mapimessage);
$hr = mapi_last_hresult(); $hr = mapi_last_hresult();
...@@ -580,48 +612,15 @@ class BackendZarafa implements IBackend, ISearchProvider { ...@@ -580,48 +612,15 @@ class BackendZarafa implements IBackend, ISearchProvider {
// only attach the original message if the mobile does not send it itself // only attach the original message if the mobile does not send it itself
if (!isset($sm->replacemime)) { if (!isset($sm->replacemime)) {
$stream = mapi_openproperty($fwmessage, PR_BODY, IID_IStream, 0, 0); $fwbody = MAPIUtils::readPropStream($fwmessage, PR_BODY);
$fwbody = ""; $fwbodyHtml = MAPIUtils::readPropStream($fwmessage, PR_HTML);
while(1) {
$data = mapi_stream_read($stream, 1024);
if(strlen($data) == 0)
break;
$fwbody .= $data;
}
$stream = mapi_openproperty($fwmessage, PR_HTML, IID_IStream, 0, 0);
$fwbody_html = "";
while(1) {
$data = mapi_stream_read($stream, 1024);
if(strlen($data) == 0)
break;
$fwbody_html .= $data;
}
if($sm->forwardflag) { if($sm->forwardflag) {
// During a forward, we have to add the forward header ourselves. This is because // During a forward, we have to add the forward header ourselves. This is because
// normally the forwarded message is added as an attachment. However, we don't want this // normally the forwarded message is added as an attachment. However, we don't want this
// because it would be rather complicated to copy over the entire original message due // because it would be rather complicated to copy over the entire original message due
// to the lack of IMessage::CopyTo .. // to the lack of IMessage::CopyTo ..
$fwheader = $this->getForwardHeaders($fwmessage);
$fwmessageprops = mapi_getprops($fwmessage, array(PR_SENT_REPRESENTING_NAME, PR_DISPLAY_TO, PR_DISPLAY_CC, PR_SUBJECT, PR_CLIENT_SUBMIT_TIME));
$fwheader = "\r\n\r\n";
$fwheader .= "-----Original Message-----\r\n";
if(isset($fwmessageprops[PR_SENT_REPRESENTING_NAME]))
$fwheader .= "From: " . $fwmessageprops[PR_SENT_REPRESENTING_NAME] . "\r\n";
if(isset($fwmessageprops[PR_DISPLAY_TO]) && strlen($fwmessageprops[PR_DISPLAY_TO]) > 0)
$fwheader .= "To: " . $fwmessageprops[PR_DISPLAY_TO] . "\r\n";
if(isset($fwmessageprops[PR_DISPLAY_CC]) && strlen($fwmessageprops[PR_DISPLAY_CC]) > 0)
$fwheader .= "Cc: " . $fwmessageprops[PR_DISPLAY_CC] . "\r\n";
if(isset($fwmessageprops[PR_CLIENT_SUBMIT_TIME]))
$fwheader .= "Sent: " . strftime("%x %X", $fwmessageprops[PR_CLIENT_SUBMIT_TIME]) . "\r\n";
if(isset($fwmessageprops[PR_SUBJECT]))
$fwheader .= "Subject: " . $fwmessageprops[PR_SUBJECT] . "\r\n";
$fwheader .= "\r\n";
// add fwheader to body and body_html // add fwheader to body and body_html
$body .= $fwheader; $body .= $fwheader;
...@@ -629,44 +628,14 @@ class BackendZarafa implements IBackend, ISearchProvider { ...@@ -629,44 +628,14 @@ class BackendZarafa implements IBackend, ISearchProvider {
$body_html .= str_ireplace("\r\n", "<br>", $fwheader); $body_html .= str_ireplace("\r\n", "<br>", $fwheader);
// attach the original attachments to the outgoing message // attach the original attachments to the outgoing message
$attachtable = mapi_message_getattachmenttable($fwmessage); $this->copyAttachments($mapimessage, $fwmessage);
$rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
foreach($rows as $row) {
if(isset($row[PR_ATTACH_NUM])) {
$attach = mapi_message_openattach($fwmessage, $row[PR_ATTACH_NUM]);
$newattach = mapi_message_createattach($mapimessage);
// Copy all attachments from old to new attachment
$attachprops = mapi_getprops($attach);
mapi_setprops($newattach, $attachprops);
if(isset($attachprops[mapi_prop_tag(PT_ERROR, mapi_prop_id(PR_ATTACH_DATA_BIN))])) {
// Data is in a stream
$srcstream = mapi_openpropertytostream($attach, PR_ATTACH_DATA_BIN);
$dststream = mapi_openpropertytostream($newattach, PR_ATTACH_DATA_BIN, MAPI_MODIFY | MAPI_CREATE);
while(1) {
$data = mapi_stream_read($srcstream, 4096);
if(strlen($data) == 0)
break;
mapi_stream_write($dststream, $data);
}
mapi_stream_commit($dststream);
}
mapi_savechanges($newattach);
}
}
} }
if(strlen($body) > 0) if(strlen($body) > 0)
$body .= $fwbody; $body .= $fwbody;
if (strlen($body_html) > 0) if (strlen($body_html) > 0)
$body_html .= $fwbody_html; $body_html .= $fwbodyHtml;
} }
} }
...@@ -1498,7 +1467,6 @@ class BackendZarafa implements IBackend, ISearchProvider { ...@@ -1498,7 +1467,6 @@ class BackendZarafa implements IBackend, ISearchProvider {
/** /**
* Adds the recipients to an email message from a RFC822 message headers. * Adds the recipients to an email message from a RFC822 message headers.
* *
* Enter description here ...
* @param MIMEMessageHeader $headers * @param MIMEMessageHeader $headers
* @param MAPIMessage $mapimessage * @param MAPIMessage $mapimessage
*/ */
...@@ -1537,6 +1505,74 @@ class BackendZarafa implements IBackend, ISearchProvider { ...@@ -1537,6 +1505,74 @@ class BackendZarafa implements IBackend, ISearchProvider {
mapi_message_modifyrecipients($mapimessage, 0, $recips); mapi_message_modifyrecipients($mapimessage, 0, $recips);
} }
/**
* Get headers for the forwarded message
*
* @param MAPIMessage $fwmessage
*
* @return string
*/
private function getForwardHeaders($message) {
$messageprops = mapi_getprops($message, array(PR_SENT_REPRESENTING_NAME, PR_DISPLAY_TO, PR_DISPLAY_CC, PR_SUBJECT, PR_CLIENT_SUBMIT_TIME));
$fwheader = "\r\n\r\n";
$fwheader .= "-----Original Message-----\r\n";
if(isset($messageprops[PR_SENT_REPRESENTING_NAME]))
$fwheader .= "From: " . $messageprops[PR_SENT_REPRESENTING_NAME] . "\r\n";
if(isset($messageprops[PR_DISPLAY_TO]) && strlen($messageprops[PR_DISPLAY_TO]) > 0)
$fwheader .= "To: " . $messageprops[PR_DISPLAY_TO] . "\r\n";
if(isset($messageprops[PR_DISPLAY_CC]) && strlen($messageprops[PR_DISPLAY_CC]) > 0)
$fwheader .= "Cc: " . $messageprops[PR_DISPLAY_CC] . "\r\n";
if(isset($messageprops[PR_CLIENT_SUBMIT_TIME]))
$fwheader .= "Sent: " . strftime("%x %X", $messageprops[PR_CLIENT_SUBMIT_TIME]) . "\r\n";
if(isset($messageprops[PR_SUBJECT]))
$fwheader .= "Subject: " . $messageprops[PR_SUBJECT] . "\r\n";
return $fwheader."\r\n";
}
/**
* Copies attachments from one message to another.
*
* @param MAPIMessage $toMessage
* @param MAPIMessage $fromMessage
*
* @return void
*/
private function copyAttachments(&$toMessage, $fromMessage) {
$attachtable = mapi_message_getattachmenttable($fromMessage);
$rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
foreach($rows as $row) {
if(isset($row[PR_ATTACH_NUM])) {
$attach = mapi_message_openattach($fromMessage, $row[PR_ATTACH_NUM]);
$newattach = mapi_message_createattach($toMessage);
// Copy all attachments from old to new attachment
$attachprops = mapi_getprops($attach);
mapi_setprops($newattach, $attachprops);
if(isset($attachprops[mapi_prop_tag(PT_ERROR, mapi_prop_id(PR_ATTACH_DATA_BIN))])) {
// Data is in a stream
$srcstream = mapi_openpropertytostream($attach, PR_ATTACH_DATA_BIN);
$dststream = mapi_openpropertytostream($newattach, PR_ATTACH_DATA_BIN, MAPI_MODIFY | MAPI_CREATE);
while(1) {
$data = mapi_stream_read($srcstream, 4096);
if(strlen($data) == 0)
break;
mapi_stream_write($dststream, $data);
}
mapi_stream_commit($dststream);
}
mapi_savechanges($newattach);
}
}
}
/** /**
* Function will create a search folder in FINDER_ROOT folder * Function will create a search folder in FINDER_ROOT folder
* if folder exists then it will open it * if folder exists then it will open it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment