v5.0-git
--------
+[mms] Use PHP temporary streams when working with message body data to reduce
+ memory usage (Request #3359).
[mms] Add ability to expand/collapse all folders in DIMP.
[mms] Add Folder Options menu to DIMP.
[mms] Add save link to full message display in DIMP.
/**
* Returns the entire body of the message.
*
- * @return string The text of the body of the message.
+ * @param array $options Additional options:
+ * <pre>
+ * 'stream' - (boolean) If true, return a stream.
+ * DEFAULT: No
+ * </pre>
+ *
+ * @return mixed The text of the part, or a stream resource if 'stream'
+ * is true.
*/
- public function getBody()
+ public function getBody($options = array())
{
if (is_null($this->_mailbox)) {
- return $this->_message->toString();
+ return $this->_message->toString(true, !empty($options['stream']));
}
try {
$res = $GLOBALS['imp_imap']->ob->fetch($this->_mailbox, array(
- Horde_Imap_Client::FETCH_BODYTEXT => array(array('peek' => true))
+ Horde_Imap_Client::FETCH_BODYTEXT => array(array('peek' => true, 'stream' => !empty($options['stream'])))
), array('ids' => array($this->_index)));
return $res[$this->_index]['bodytext'][0];
} catch (Horde_Imap_Client_Exception $e) {
* DEFAULT: All data is retrieved.
* 'mimeheaders' - (boolean) Include the MIME headers also?
* DEFAULT: No
+ * 'stream' - (boolean) If true, return a stream.
+ * DEFAULT: No
* </pre>
*
- * @return string The text of the part.
+ * @return mixed The text of the part, or a stream resource if 'stream'
+ * is true.
*/
public function getBodyPart($id, $options = array())
{
}
$query = array(
- Horde_Imap_Client::FETCH_BODYPART => array(array('id' => $id, 'peek' => true))
+ Horde_Imap_Client::FETCH_BODYPART => array(array('id' => $id, 'peek' => true, 'stream' => !empty($options['stream'])))
);
if (!empty($options['length'])) {
$query[Horde_Imap_Client::FETCH_BODYPART][0]['start'] = 0;
public function fullMessageText()
{
if (is_null($this->_mailbox)) {
- return $this->_message->toString(true);
+ return $this->_message->toString();
}
try {
+ // TODO - use streams
$res = $GLOBALS['imp_imap']->ob->fetch($this->_mailbox, array(
Horde_Imap_Client::FETCH_HEADERTEXT => array(array('peek' => true)),
Horde_Imap_Client::FETCH_BODYTEXT => array(array('peek' => true))
empty($options['nocontents']) &&
!is_null($this->_mailbox) &&
!$part->getContents()) {
- $contents = $this->getBodyPart($id, array('length' => empty($options['length']) ? null : $options['length']));
+ $contents = $this->getBodyPart($id, array('length' => empty($options['length']) ? null : $options['length'], 'stream' => true));
if (($part->getPrimaryType() == 'text') &&
(Horde_String::upper($part->getCharset()) == 'US-ASCII') &&
Horde_Mime::is8bit($contents)) {
if ($val == $number) {
$parts[$number] = $this->_mimepart->getContents();
} else {
- $ic = &IMP_Contents::singleton($val . IMP::IDX_SEP . $mbox);
+ $ic = IMP_Contents::singleton($val . IMP::IDX_SEP . $mbox);
$parts[$ic->getMIMEMessage()->getContentTypeParameter('number')] = $ic->getBody();
}
}
* get the necessary Horde_Mime_Part. */
if ($actionID == 'compose_attach_preview') {
/* Initialize the IMP_Compose:: object. */
- $imp_compose = &IMP_Compose::singleton(Horde_Util::getFormData('composeCache'));
+ $imp_compose = IMP_Compose::singleton(Horde_Util::getFormData('composeCache'));
$mime = $imp_compose->buildAttachment($id);
/* Create a dummy IMP_Contents() object so we can use the view code below.
* Then use the 'view_attach' handler to output. */
- $contents = &IMP_Contents::singleton($mime);
+ $contents = IMP_Contents::singleton($mime);
$actionID = 'view_attach';
$id = $mime->getMimeId();
} else {
}
try {
- $contents = &IMP_Contents::singleton($uid . IMP::IDX_SEP . $mailbox);
+ $contents = IMP_Contents::singleton($uid . IMP::IDX_SEP . $mailbox);
} catch (Horde_Exception $e) {
Horde::fatal($e, __FILE__, __LINE__);
}
}
if (!empty($tosave)) {
- $horde_compress = &Horde_Compress::singleton('zip');
+ $horde_compress = Horde_Compress::singleton('zip');
$body = $horde_compress->compress($tosave);
$browser->downloadHeaders($zipfile, 'application/zip', false, strlen($body));
echo $body;
switch ($actionID) {
case 'download_attach':
$mime = $contents->getMIMEPart($id);
- $body = $mime->getContents();
- $type = $mime->getType(true);
- $name = $mime->getName(true);
+ if (!$name = $mime->getName(true)) {
+ $name = _("unnamed");
+ }
+
+ /* Compress output? */
+ if (Horde_Util::getFormData('zip')) {
+ $horde_compress = Horde_Compress::singleton('zip');
+ $body = $horde_compress->compress(array(array('data' => $mime->getContents(), 'name' => $name)));
+ $name .= '.zip';
+ $type = 'application/zip';
+ } else {
+ $body = $mime->getContentsAsStream();
+ $type = $mime->getType(true);
+ }
break;
case 'download_render':
$key = key($render);
$body = $render[$key]['data'];
$type = $render[$key]['type'];
- $name = $render[$key]['name'];
+ if (!$name = $render[$key]['name']) {
+ $name = _("unnamed");
+ }
break;
}
- if (empty($name)) {
- $name = _("unnamed");
- }
-
- /* Compress output? */
- if (($actionID == 'download_attach') && Horde_Util::getFormData('zip')) {
- $horde_compress = &Horde_Compress::singleton('zip');
- $body = $horde_compress->compress(array(array('data' => $body, 'name' => $name)));
- $name .= '.zip';
- $type = 'application/zip';
- }
$browser->downloadHeaders($name, $type, false, strlen($body));
- echo $body;
+ if (is_resource($body)) {
+ fpassthru($body);
+ } else {
+ echo $body;
+ }
exit;
case 'view_attach':