Skip to content
Snippets Groups Projects
Commit 6f866f14 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #2492 from ericLemanissier/patch-4


reduce memory usage when decoding files

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents 55338e58 ace26af6
No related branches found
No related tags found
No related merge requests found
......@@ -193,6 +193,30 @@ class MailFetcher {
$text=imap_binary($text);
break;
case 3:
if (strlen($text) > (1 << 20)) {
try {
if (!($temp = tempnam(sys_get_temp_dir(), 'attachments'))
|| !($f = fopen($temp, 'w'))
) {
throw new Exception();
}
$s_filter = stream_filter_append($f, 'convert.base64-decode',STREAM_FILTER_WRITE);
if (!fwrite($f, $text))
throw new Exception();
stream_filter_remove($s_filter);
fclose($f);
if (!($f = fopen($temp, 'r')) || !($text = fread($f, filesize($temp)))
throw new Exception();
fclose($f);
unlink($temp);
break;
}
catch (Exception $e) {
// Noop. Fall through to imap_base64 method below
@fclose($f);
@unlink($temp);
}
}
// imap_base64 implies strict mode. If it refuses to decode the
// data, then fallback to base64_decode in non-strict mode
$text = (($conv=imap_base64($text))) ? $conv : base64_decode($text);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment