Merge pull request #70 from skl/stream-save

Implement memory-efficient streaming save
This commit is contained in:
Robert Hafner 2014-06-29 10:56:10 -07:00
commit aa5d96033f

View File

@ -203,9 +203,29 @@ class Attachment
if (($filePointer = fopen($path, 'w')) == false) if (($filePointer = fopen($path, 'w')) == false)
return false; return false;
$results = fwrite($filePointer, $this->getData()); switch ($this->encoding) {
case 3:
case 'base64':
$streamFilter = stream_filter_append($filePointer, 'convert.base64-decode', STREAM_FILTER_WRITE);
break;
case 4:
case 'quoted-printable':
$streamFilter = stream_filter_append($handle, 'convert.quoted-printable', STREAM_FILTER_WRITE);
break;
default:
$streamFilter = null;
}
$result = imap_savebody($this->imapStream, $filePointer, $this->messageId, $this->partId ?: 1, FT_UID);
if ($streamFilter) {
stream_filter_remove($streamFilter);
}
fclose($filePointer); fclose($filePointer);
return is_numeric($results); return $result;
} }
} }