if ($iSize < $iBufferSize) {
$iBufferSize = $iSize;
}
+
$iRetrieved = 0;
$results = '';
$sRead = $sReadRem = '';
$sRead = $sReadRem . $sRead;
$sReadRem = '';
}
- if (substr($sRead,-1) !== "\n") {
- $i = strrpos($sRead,"\n");
- if ($i !== false && $iRetrieved<$iSize) {
- ++$i;
- $sReadRem = substr($sRead,$i);
- $sRead = substr($sRead,0,$i);
- } else if ($iLength && $iRetrieved<$iSize) { // linelength > received buffer
- $sReadRem = $sRead;
- $sRead = '';
- }
- }
+
if ($filter && $sRead) {
- $filter($sRead);
+ // in case the filter is base64 decoding we return a remainder
+ $sReadRem = $filter($sRead);
}
if ($outputstream && $sRead) {
if (is_resource($outputstream)) {
return $results;
}
+
/**
* Obsolete function, inform plugins that use it
* @deprecated use sqimap_run_command or sqimap_run_command_list instead
}
function sqimap_base64_decode(&$string) {
- $string = str_replace("\r\n", "\n", $string);
+
+ // base64 enoded data goes in pairs of 4 bytes. To achieve on the
+ // fly decoding (to reduce memory usage) you have to check if the
+ // data has incomplete pairs
+
+ // remove the noise in order to check if the 4 bytes pairs are complete
+ $string = str_replace(array("\r\n","\n", "\r", " "),array('','','',''),$string);
+
+ $sStringRem = '';
+ $iMod = strlen($string) % 4;
+ if ($iMod) {
+ $sStringRem = substr($string,-$iMod);
+ // check if $sStringRem contains padding characters
+ if (substr($sStringRem,-1) != '=') {
+ $string = substr($string,0,-$iMod);
+ } else {
+ $sStringRem = '';
+ }
+ }
$string = base64_decode($string);
+ return $sStringRem;
}
+
/* This function decodes the body depending on the encoding type. */
function decodeBody($body, $encoding) {
global $show_html_default;