Commit 59563d85 authored by Sebastian Kummer's avatar Sebastian Kummer

ZO-83 handle KOP forward/reply flags in SendMail request processor, send

email when replacemime is set even if fwmessage (source message) can not
be opened.
parent 800eb79a
...@@ -436,29 +436,6 @@ class BackendZarafa implements IBackend, ISearchProvider { ...@@ -436,29 +436,6 @@ class BackendZarafa implements IBackend, ISearchProvider {
return false; return false;
} }
// Acacia ZO-6: grep for the OL header and set flags accordingly.
// The header has the values verb/message-source-key/folder-source-key
if (preg_match("/X-Push-Flags: (\d{3})\/([\da-f]+)\/([\da-f]+)/i", $sm->mime, $ol_flags)) {
// "reply" and "reply-all" are handled as "reply"
if ($ol_flags[1] == 102 || $ol_flags[1] == 103) {
$sm->replyflag = true;
$sm->forwardflag = false;
}
else if ($ol_flags[1] == 104) {
$sm->replyflag = false;
$sm->forwardflag = true;
}
// set source folder+item and replacemime
if (!isset($sm->source)) {
$sm->source = new SyncSendMailSource();
}
$sm->source->itemid = $ol_flags[2];
$sm->source->folderid = $ol_flags[3];
$sm->replacemime = true;
ZLog::Write(LOGLEVEL_DEBUG, "ZarafaBackend->SendMail(): Outlook support: overwrite reply/forward flag, set parent-id and item-id, replacemime-do not attach original message.");
}
// delayed logging to log to potentially log the parameters set for ZO-6 // delayed logging to log to potentially log the parameters set for ZO-6
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZarafaBackend->SendMail(): RFC822: %d bytes forward-id: '%s' reply-id: '%s' parent-id: '%s' SaveInSent: '%s' ReplaceMIME: '%s'", ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZarafaBackend->SendMail(): RFC822: %d bytes forward-id: '%s' reply-id: '%s' parent-id: '%s' SaveInSent: '%s' ReplaceMIME: '%s'",
strlen($sm->mime), Utils::PrintAsString($sm->forwardflag), Utils::PrintAsString($sm->replyflag), strlen($sm->mime), Utils::PrintAsString($sm->forwardflag), Utils::PrintAsString($sm->replyflag),
...@@ -541,75 +518,80 @@ class BackendZarafa implements IBackend, ISearchProvider { ...@@ -541,75 +518,80 @@ class BackendZarafa implements IBackend, ISearchProvider {
if ($entryid) if ($entryid)
$fwmessage = mapi_msgstore_openentry($this->store, $entryid); $fwmessage = mapi_msgstore_openentry($this->store, $entryid);
if(!isset($fwmessage) || !$fwmessage) 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 and last_verb when forwarding or replying message
// reply-all (verb 103) is not supported, as we cannot really detect this case
// update icon and last_verb when forwarding or replying message if ($sm->forwardflag) {
// reply-all (verb 103) is not supported, as we cannot really detect this case $updateProps = array(
if ($sm->forwardflag) { PR_ICON_INDEX => 262,
$updateProps = array( PR_LAST_VERB_EXECUTED => 104,
PR_ICON_INDEX => 262, );
PR_LAST_VERB_EXECUTED => 104,
);
}
elseif ($sm->replyflag) {
$updateProps = array(
PR_ICON_INDEX => 261,
PR_LAST_VERB_EXECUTED => 102,
);
}
if (isset($updateProps)) {
$updateProps[PR_LAST_VERB_EXECUTION_TIME] = time();
mapi_setprops($fwmessage, $updateProps);
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
if (!isset($body)) {
$body = MAPIUtils::readPropStream($mapimessage, PR_BODY);
} }
if (!isset($bodyHtml)) { elseif ($sm->replyflag) {
$bodyHtml = MAPIUtils::readPropStream($mapimessage, PR_HTML); $updateProps = array(
PR_ICON_INDEX => 261,
PR_LAST_VERB_EXECUTED => 102,
);
} }
$cpid = mapi_getprops($fwmessage, array($sendMailProps["internetcpid"])); if (isset($updateProps)) {
if($sm->forwardflag) { $updateProps[PR_LAST_VERB_EXECUTION_TIME] = time();
// attach the original attachments to the outgoing message mapi_setprops($fwmessage, $updateProps);
$this->copyAttachments($mapimessage, $fwmessage); mapi_savechanges($fwmessage);
} }
// regarding the conversion @see ZP-470 // only attach the original message if the mobile does not send it itself
if (strlen($body) > 0) { if (!isset($sm->replacemime)) {
$fwbody = MAPIUtils::readPropStream($fwmessage, PR_BODY); // get message's body in order to append forward or reply text
// if only the old message's cpid is set, convert from old charset to utf-8 if (!isset($body)) {
if (isset($cpid[$sendMailProps["internetcpid"]]) && $cpid[$sendMailProps["internetcpid"]] != INTERNET_CPID_UTF8) { $body = MAPIUtils::readPropStream($mapimessage, PR_BODY);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZarafaBackend->SendMail(): convert plain forwarded message charset (only fw set) from '%s' to '65001'", $cpid[$sendMailProps["internetcpid"]]));
$fwbody = Utils::ConvertCodepageStringToUtf8($cpid[$sendMailProps["internetcpid"]], $fwbody);
} }
// otherwise to the general conversion if (!isset($bodyHtml)) {
else { $bodyHtml = MAPIUtils::readPropStream($mapimessage, PR_HTML);
ZLog::Write(LOGLEVEL_DEBUG, "ZarafaBackend->SendMail(): no charset conversion done for plain forwarded message"); }
$fwbody = w2u($fwbody); $cpid = mapi_getprops($fwmessage, array($sendMailProps["internetcpid"]));
if($sm->forwardflag) {
// attach the original attachments to the outgoing message
$this->copyAttachments($mapimessage, $fwmessage);
} }
$mapiprops[$sendMailProps["body"]] = $body."\r\n\r\n".$fwbody; // regarding the conversion @see ZP-470
} if (strlen($body) > 0) {
$fwbody = MAPIUtils::readPropStream($fwmessage, PR_BODY);
// if only the old message's cpid is set, convert from old charset to utf-8
if (isset($cpid[$sendMailProps["internetcpid"]]) && $cpid[$sendMailProps["internetcpid"]] != INTERNET_CPID_UTF8) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZarafaBackend->SendMail(): convert plain forwarded message charset (only fw set) from '%s' to '65001'", $cpid[$sendMailProps["internetcpid"]]));
$fwbody = Utils::ConvertCodepageStringToUtf8($cpid[$sendMailProps["internetcpid"]], $fwbody);
}
// otherwise to the general conversion
else {
ZLog::Write(LOGLEVEL_DEBUG, "ZarafaBackend->SendMail(): no charset conversion done for plain forwarded message");
$fwbody = w2u($fwbody);
}
if (strlen($bodyHtml) > 0) { $mapiprops[$sendMailProps["body"]] = $body."\r\n\r\n".$fwbody;
$fwbodyHtml = MAPIUtils::readPropStream($fwmessage, PR_HTML);
// if only new message's cpid is set, convert to UTF-8
if (isset($cpid[$sendMailProps["internetcpid"]]) && $cpid[$sendMailProps["internetcpid"]] != INTERNET_CPID_UTF8) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZarafaBackend->SendMail(): convert html forwarded message charset (only fw set) from '%s' to '65001'", $cpid[$sendMailProps["internetcpid"]]));
$fwbodyHtml = Utils::ConvertCodepageStringToUtf8($cpid[$sendMailProps["internetcpid"]], $fwbodyHtml);
}
// otherwise to the general conversion
else {
ZLog::Write(LOGLEVEL_DEBUG, "ZarafaBackend->SendMail(): no charset conversion done for html forwarded message");
$fwbodyHtml = w2u($fwbodyHtml);
} }
$mapiprops[$sendMailProps["html"]] = $bodyHtml."<br><br>".$fwbodyHtml; if (strlen($bodyHtml) > 0) {
$fwbodyHtml = MAPIUtils::readPropStream($fwmessage, PR_HTML);
// if only new message's cpid is set, convert to UTF-8
if (isset($cpid[$sendMailProps["internetcpid"]]) && $cpid[$sendMailProps["internetcpid"]] != INTERNET_CPID_UTF8) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZarafaBackend->SendMail(): convert html forwarded message charset (only fw set) from '%s' to '65001'", $cpid[$sendMailProps["internetcpid"]]));
$fwbodyHtml = Utils::ConvertCodepageStringToUtf8($cpid[$sendMailProps["internetcpid"]], $fwbodyHtml);
}
// otherwise to the general conversion
else {
ZLog::Write(LOGLEVEL_DEBUG, "ZarafaBackend->SendMail(): no charset conversion done for html forwarded message");
$fwbodyHtml = w2u($fwbodyHtml);
}
$mapiprops[$sendMailProps["html"]] = $bodyHtml."<br><br>".$fwbodyHtml;
}
}
}
else {
// no fwmessage could be opened and we need it because we do not replace mime
if (!isset($sm->replacemime) || $sm->replacemime == false) {
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);
} }
} }
} }
......
...@@ -87,6 +87,28 @@ class SendMail extends RequestProcessor { ...@@ -87,6 +87,28 @@ class SendMail extends RequestProcessor {
// no wbxml output is provided, only a http OK // no wbxml output is provided, only a http OK
$sm->saveinsent = Request::GetGETSaveInSent(); $sm->saveinsent = Request::GetGETSaveInSent();
} }
// KOP ZO-6: grep for the OL header and set flags accordingly.
// The header has the values verb/message-source-key/folder-source-key
if (preg_match("/X-Push-Flags: (\d{3})\/([\da-f]+)\/([\da-f]+)/i", $sm->mime, $ol_flags)) {
// "reply" and "reply-all" are handled as "reply"
if ($ol_flags[1] == 102 || $ol_flags[1] == 103) {
$reply = true;
}
else if ($ol_flags[1] == 104) {
$forward = true;
}
// set source folder+item and replacemime
if (!isset($sm->source)) {
$sm->source = new SyncSendMailSource();
}
$sm->source->itemid = $ol_flags[2];
$sm->source->folderid = $ol_flags[3];
$sm->replacemime = true;
ZLog::Write(LOGLEVEL_DEBUG, "SendMail(): KOP support: overwrite reply/forward flag, set parent-id and item-id, replacemime - original message should not be attached.");
}
// Check if it is a reply or forward. Two cases are possible: // Check if it is a reply or forward. Two cases are possible:
// 1. Either $smartreply or $smartforward are set after reading WBXML // 1. Either $smartreply or $smartforward are set after reading WBXML
// 2. Either $reply or $forward are set after geting the request parameters // 2. Either $reply or $forward are set after geting the request parameters
...@@ -111,10 +133,10 @@ class SendMail extends RequestProcessor { ...@@ -111,10 +133,10 @@ class SendMail extends RequestProcessor {
$sm->forwardflag = true; $sm->forwardflag = true;
if (!isset($sm->source->folderid)) if (!isset($sm->source->folderid))
ZLog::Write(LOGLEVEL_ERROR, sprintf("No parent folder id while replying or forwarding message:'%s'", (($reply) ? $reply : $forward))); ZLog::Write(LOGLEVEL_ERROR, sprintf("SendMail(): No parent folder id while replying or forwarding message:'%s'", (($reply) ? $reply : $forward)));
} }
self::$topCollector->AnnounceInformation(sprintf("Sending email with %d bytes", strlen($sm->mime)), true); self::$topCollector->AnnounceInformation(sprintf("SendMail(): Sending email with %d bytes", strlen($sm->mime)), true);
try { try {
$status = self::$backend->SendMail($sm); $status = self::$backend->SendMail($sm);
......
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