Sfoglia il codice sorgente

Correct on the fly base64 decode algoritm in case the returned data does not
have "proper" lines with the same length. With an old uw server I discovered
that lines were split in the middle by \n. This fix will correct it.

The rfc about base64 decoding does not mention anything about line length.
rfc2045 does mention that lines should not be longer then 78 characters but
does not say all the lines (excluding the last of course) must be of the same
size.
There for i could not ignore it and fixed it.

stekkel 22 anni fa
parent
commit
b3c5fc5794
1 ha cambiato i file con 11 aggiunte e 0 eliminazioni
  1. 11 0
      functions/imap_general.php

+ 11 - 0
functions/imap_general.php

@@ -201,6 +201,17 @@ function sqimap_fread($imap_stream,$iSize,$filter=false,
             break;
             break;
         }
         }
         $iRetrieved += $iBufferSize;
         $iRetrieved += $iBufferSize;
+        // if the returned lines are split, do not end with \n
+        // then we have a problem and need to adjust (happened with uw)
+        if ($bBufferSizeAdapted && substr($sRead,-1) !== "\n") {
+            // use fgets because it stops at \n.
+            // we can do it because it's for correction
+            $sRead .= fgets($imap_stream,$iBufferSize);
+            $iRetrieved += strlen($sRead);
+            if ($iRetrieved == $iSize) {
+                $bFinished = true;
+            }
+        }
         if ($filter) {
         if ($filter) {
            // in case line-endings do not appear at position 78 we adapt the buffersize so we can base64 decode on the fly
            // in case line-endings do not appear at position 78 we adapt the buffersize so we can base64 decode on the fly
            if (!$bBufferSizeAdapted) {
            if (!$bBufferSizeAdapted) {