* DEFAULT: No
* </pre>
*
- * @return mixed The text of the part, a stream resource if 'stream'
- * is true and 'mimeheaders' is false, or an array of
- * header text and a body stream resource if 'stream' is
- * true and 'mimeheaders' is true.
+ * @return mixed The text of the part or a stream resource if 'stream'
+ * is true.
*/
public function getBodyPart($id, $options = array())
{
$this->lastBodyPartDecode = $res[$this->_index]['bodypartdecode'][$id];
}
return $res[$this->_index]['bodypart'][$id];
+ } elseif (empty($options['stream'])) {
+ return $res[$this->_index]['mimeheader'][$id] . $res[$this->_index]['bodypart'][$id];
} else {
- return empty($options['stream'])
- ? $res[$this->_index]['mimeheader'][$id] . $res[$this->_index]['bodypart'][$id]
- : array($res[$this->_index]['mimeheader'][$id], $res[$this->_index]['bodypart'][$id]);
+ $swrapper = new Horde_Support_CombineStream(array($res[$this->_index]['mimeheader'][$id], $res[$this->_index]['bodypart'][$id]));
+ return $swrapper->fopen();
}
} catch (Horde_Imap_Client_Exception $e) {
return '';
* DEFAULT: No
* </pre>
*
- * @return mixed The full message text, or an array with a text entry
- * (header text) and a stream resource (body text) if
- * 'stream' is true.
+ * @return mixed The full message text or a stream resource if 'stream'
+ * is true.
*/
public function fullMessageText($options = array())
{
Horde_Imap_Client::FETCH_HEADERTEXT => array(array('peek' => true)),
Horde_Imap_Client::FETCH_BODYTEXT => array(array('peek' => true, 'stream' => !empty($options['stream'])))
), array('ids' => array($this->_index)));
- return empty($options['stream'])
- ? $res[$this->_index]['headertext'][0] . $res[$this->_index]['bodytext'][0]
- : array($res[$this->_index]['headertext'][0], $res[$this->_index]['bodytext'][0]);
+
+ if (empty($options['stream'])) {
+ return $res[$this->_index]['headertext'][0] . $res[$this->_index]['bodytext'][0];
+ }
+
+ $swrapper = new Horde_Support_CombineStream(array($res[$this->_index]['headertext'][0], $res[$this->_index]['bodytext'][0]));
+ return $swrapper->fopen();
} catch (Horde_Imap_Client_Exception $e) {
return empty($options['stream'])
? ''
/* If a (not)spam reporting program has been provided, use
* it. */
if (!empty($GLOBALS['conf'][$action]['program'])) {
- $raw_msg = $imp_contents->fullMessageText(true);
+ $raw_msg = $imp_contents->fullMessageText(array('stream' => true));
/* Use a pipe to write the message contents. This should
* be secure. */
Horde::logMessage('Cannot open process ' . $prog, __FILE__, __LINE__, PEAR_LOG_ERR);
return 0;
}
- fwrite($pipes[0], $raw_msg[0]);
- rewind($raw_msg[1]);
- stream_copy_to_stream($raw_msg[1], $pipes[0]);
+ stream_copy_to_stream($raw_msg, $pipes[0]);
fclose($pipes[0]);
$stderr = '';
while (!feof($pipes[2])) {
if ($to) {
if (!isset($raw_msg)) {
- $raw_msg = $imp_contents->fullMessageText(true);
+ $raw_msg = $imp_contents->fullMessageText(array('stream' => true));
}
if (!isset($imp_compose)) {
return Horde_String::convertCharset(trim(preg_replace('/[^\pL\pN-+_. ]/u', '_', $name), ' _'), 'UTF-8');
}
-function _fullMessageTextLength($ob)
-{
- if (!$ob[1]) {
- return strlen($ob[0]);
- }
- $stat = fseek($ob[1], 0, SEEK_END);
- $len = strlen($ob[0]) + ftell($ob[1]);
- rewind($ob[1]);
- return $len;
-}
-
require_once dirname(__FILE__) . '/lib/Application.php';
/* Don't compress if we are already sending in compressed format. */
case 'view_source':
$msg = $contents->fullMessageText(array('stream' => true));
- $browser->downloadHeaders('Message Source', 'text/plain', true, _fullMessageTextLength($msg));
- echo $msg[0];
- if ($msg[1]) {
- fpassthru($msg[1]);
- }
+ fseek($msg, 0, SEEK_END);
+ $browser->downloadHeaders('Message Source', 'text/plain', true, ftell($msg));
+ rewind($msg);
+ fpassthru($msg);
exit;
case 'save_message':
$hdr = 'From ' . $from . ' ' . $date->format('D M d H:i:s Y') . "\r\n";
$msg = $contents->fullMessageText(array('stream' => true));
- $browser->downloadHeaders($name . '.eml', 'message/rfc822', false, strlen($hdr) + _fullMessageTextLength($msg));
- echo $hdr . $msg[0];
- if ($msg[1]) {
- fpassthru($msg[1]);
- }
+ fseek($msg, 0, SEEK_END);
+ $browser->downloadHeaders($name . '.eml', 'message/rfc822', false, strlen($hdr) + ftell($msg));
+ echo $hdr;
+ rewind($msg);
+ fpassthru($msg);
exit;
}