forked from extern/egroupware
return full mime message as stream without any conversation and without caching it, as this probably caused high memory usage when syncing with Outlook
This commit is contained in:
parent
6085e9fb67
commit
1b4bef13f5
@ -5456,15 +5456,16 @@ class Mail
|
|||||||
* @param string/int $_uid the messageuid,
|
* @param string/int $_uid the messageuid,
|
||||||
* @param string/int $_partID = '' , the partID, may be omitted
|
* @param string/int $_partID = '' , the partID, may be omitted
|
||||||
* @param string $_folder folder to work on
|
* @param string $_folder folder to work on
|
||||||
|
* @param boolean $_stream =false true: return a stream, false: return string, stream suppresses any caching
|
||||||
* @return string the message body
|
* @return string the message body
|
||||||
*/
|
*/
|
||||||
function getMessageRawBody($_uid, $_partID = '', $_folder='')
|
function getMessageRawBody($_uid, $_partID = '', $_folder='', $_stream=false)
|
||||||
{
|
{
|
||||||
//TODO: caching einbauen static!
|
//TODO: caching einbauen static!
|
||||||
static $rawBody;
|
static $rawBody;
|
||||||
if (is_null($rawBody)) $rawBody = array();
|
if (is_null($rawBody)) $rawBody = array();
|
||||||
if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
|
if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
|
||||||
if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
|
if (!$_stream && isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
|
||||||
{
|
{
|
||||||
//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
|
//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
|
||||||
return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
|
return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
|
||||||
@ -5487,7 +5488,7 @@ class Mail
|
|||||||
));
|
));
|
||||||
if (is_object($headersNew)) {
|
if (is_object($headersNew)) {
|
||||||
foreach($headersNew as &$_headerObject) {
|
foreach($headersNew as &$_headerObject) {
|
||||||
$body = $_headerObject->getFullMsg();
|
$body = $_headerObject->getFullMsg($_stream);
|
||||||
if ($_partID != '')
|
if ($_partID != '')
|
||||||
{
|
{
|
||||||
$mailStructureObject = $_headerObject->getStructure();
|
$mailStructureObject = $_headerObject->getStructure();
|
||||||
@ -5496,14 +5497,17 @@ class Mail
|
|||||||
{
|
{
|
||||||
if ($mime_id==$_partID)
|
if ($mime_id==$_partID)
|
||||||
{
|
{
|
||||||
$body = $_headerObject->getBodyPart($mime_id);
|
$body = $_headerObject->getBodyPart($mime_id, $_stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//error_log(__METHOD__.' ('.__LINE__.') '."[$this->icServer->ImapServerId][$_folder][$_uid][".(empty($_partID)?'NIL':$_partID)."]");
|
//error_log(__METHOD__.' ('.__LINE__.') '."[$this->icServer->ImapServerId][$_folder][$_uid][".(empty($_partID)?'NIL':$_partID)."]");
|
||||||
|
if (!$_stream)
|
||||||
|
{
|
||||||
$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)] = $body;
|
$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)] = $body;
|
||||||
|
}
|
||||||
return $body;
|
return $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -905,6 +905,21 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
|
|||||||
ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
|
ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
|
||||||
// set the protocoll class
|
// set the protocoll class
|
||||||
$output->asbody = new SyncBaseBody();
|
$output->asbody = new SyncBaseBody();
|
||||||
|
|
||||||
|
// return full mime-message without any (charset) conversation directly as stream
|
||||||
|
if ($bpReturnType==SYNC_BODYPREFERENCE_MIME)
|
||||||
|
{
|
||||||
|
//SYNC_BODYPREFERENCE_MIME
|
||||||
|
$output->asbody->type = SYNC_BODYPREFERENCE_MIME;
|
||||||
|
$stream = $this->mail->getMessageRawBody($id, '', $_folderName, true);
|
||||||
|
$fstat = fstat($stream);
|
||||||
|
fseek($stream, 0, SEEK_SET);
|
||||||
|
$output->asbody->data = $stream;
|
||||||
|
$output->asbody->estimatedDataSize = $fstat['size'];
|
||||||
|
ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." bodypreference 4=SYNC_BODYPREFERENCE_MIME=full mime message requested, size=$fstat[size]");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// 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', '', null, true,$_folderName);
|
$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName);
|
||||||
@ -949,20 +964,8 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
|
|||||||
$plainBody = strip_tags($plainBody);
|
$plainBody = strip_tags($plainBody);
|
||||||
if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
|
if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
|
||||||
//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
|
//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
|
||||||
if ($bpReturnType==SYNC_BODYPREFERENCE_MIME)//4)//$mimesupport==2 || $mimesupport ==1 && stristr($headers['CONTENT-TYPE'],'signed') !== false)
|
|
||||||
{
|
if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
|
||||||
//SYNC_BODYPREFERENCE_MIME
|
|
||||||
ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." bodypreference 4 requested");
|
|
||||||
$output->asbody->type = SYNC_BODYPREFERENCE_MIME;//4;
|
|
||||||
// use Api\Mailer::convert to convert charset of all text parts to utf-8, which is a z-push or AS requirement!
|
|
||||||
// ToDo: check if above is true for mime-message, otherwise with could use a stream without conversion
|
|
||||||
$Body = Api\Mailer::convert($this->mail->getMessageRawBody($id, '', $_folderName));
|
|
||||||
if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." Setting Mailobjectcontent to output:".$Body);
|
|
||||||
if ((string)$Body === '') $Body = ' ';
|
|
||||||
$output->asbody->data = StringStreamWrapper::Open($Body);
|
|
||||||
$output->asbody->estimatedDataSize = strlen($Body);
|
|
||||||
}
|
|
||||||
else if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
|
|
||||||
{
|
{
|
||||||
if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
|
if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
|
||||||
// Send HTML if requested and native type was html
|
// Send HTML if requested and native type was html
|
||||||
@ -1027,6 +1030,7 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
|
|||||||
$output->asbody->estimatedDataSize = 1;
|
$output->asbody->estimatedDataSize = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// end AS12 Stuff
|
// end AS12 Stuff
|
||||||
ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Header info:'.$headers['SUBJECT'].' from:'.$headers['DATE']);
|
ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Header info:'.$headers['SUBJECT'].' from:'.$headers['DATE']);
|
||||||
$output->read = $stat["flags"];
|
$output->read = $stat["flags"];
|
||||||
|
Loading…
Reference in New Issue
Block a user