summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube/rcube_imap_generic.php
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2012-11-27 16:22:49 +0100
committerThomas Bruederli <thomas@roundcube.net>2012-11-27 16:22:49 +0100
commitdff2c713fbc5dd8a501a31f3c158b8be412f46d0 (patch)
treeda0e7fc83ee07c25858122669bbcd3d40c305b28 /program/lib/Roundcube/rcube_imap_generic.php
parent0a83971d3e6bc5dae958e304bea4bb1e7a33db59 (diff)
Add argument to fetch message parts only partially. Can be used for content mimetype detection without loading the entire file
Diffstat (limited to 'program/lib/Roundcube/rcube_imap_generic.php')
-rw-r--r--program/lib/Roundcube/rcube_imap_generic.php13
1 files changed, 8 insertions, 5 deletions
diff --git a/program/lib/Roundcube/rcube_imap_generic.php b/program/lib/Roundcube/rcube_imap_generic.php
index a0a8f3b77..70fd6eb2c 100644
--- a/program/lib/Roundcube/rcube_imap_generic.php
+++ b/program/lib/Roundcube/rcube_imap_generic.php
@@ -2379,7 +2379,7 @@ class rcube_imap_generic
return $this->handlePartBody($mailbox, $id, $is_uid, $part);
}
- function handlePartBody($mailbox, $id, $is_uid=false, $part='', $encoding=NULL, $print=NULL, $file=NULL, $formatted=false)
+ function handlePartBody($mailbox, $id, $is_uid=false, $part='', $encoding=NULL, $print=NULL, $file=NULL, $formatted=false, $max_bytes=0)
{
if (!$this->select($mailbox)) {
return false;
@@ -2405,10 +2405,11 @@ class rcube_imap_generic
// Use BINARY extension when possible (and safe)
$binary = $mode && preg_match('/^[0-9.]+$/', $part) && $this->hasCapability('BINARY');
$fetch_mode = $binary ? 'BINARY' : 'BODY';
+ $partial = $max_bytes ? sprintf('<0.%d>', $max_bytes) : '';
// format request
$key = $this->nextTag();
- $request = $key . ($is_uid ? ' UID' : '') . " FETCH $id ($fetch_mode.PEEK[$part])";
+ $request = $key . ($is_uid ? ' UID' : '') . " FETCH $id ($fetch_mode.PEEK[$part]$partial)";
// send request
if (!$this->putLine($request)) {
@@ -2508,8 +2509,10 @@ class rcube_imap_generic
$line = rtrim($line, "\t\r\n\0\x0B") . "\n";
}
- if ($file)
- fwrite($file, $line);
+ if ($file) {
+ if (fwrite($file, $line) === false)
+ break;
+ }
else if ($print)
echo $line;
else
@@ -2525,7 +2528,7 @@ class rcube_imap_generic
if ($result !== false) {
if ($file) {
- fwrite($file, $result);
+ return fwrite($file, $result);
} else if ($print) {
echo $result;
} else