Correct on the fly base64 decode algoritm in case the returned data does not
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 24 Jul 2003 18:08:10 +0000 (18:08 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 24 Jul 2003 18:08:10 +0000 (18:08 +0000)
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.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@5415 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/imap_general.php

index 63d37823df2aa529f07ccde08ab2cdb63dab2808..4ac6d3ea383e1450313b84b667c3827b0dcb8c97 100755 (executable)
@@ -201,6 +201,17 @@ function sqimap_fread($imap_stream,$iSize,$filter=false,
             break;
         }
         $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) {
            // in case line-endings do not appear at position 78 we adapt the buffersize so we can base64 decode on the fly
            if (!$bBufferSizeAdapted) {