diff --git a/CHANGELOG b/CHANGELOG index 2fda0357e..d356f89e6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ CHANGELOG Roundcube Webmail =========================== +- Fix broken long filenames when using imap4d server - workaround server bug (#6048) + RELEASE 1.3.3 ------------- - Fix decoding of mailto: links with + character in HTML messages (#6020) diff --git a/program/lib/Roundcube/rcube_mime.php b/program/lib/Roundcube/rcube_mime.php index a6c09c845..76e2e11c9 100644 --- a/program/lib/Roundcube/rcube_mime.php +++ b/program/lib/Roundcube/rcube_mime.php @@ -212,9 +212,21 @@ class rcube_mime // Decode and join encoded-word's chunks if ($encoding == 'B' || $encoding == 'b') { - // base64 must be decoded a segment at a time - for ($i=0; $i<$count; $i++) - $text .= base64_decode($tmp[$i]); + $rest = ''; + // base64 must be decoded a segment at a time. + // However, there are broken implementations that continue + // in the following word, we'll handle that (#6048) + for ($i=0; $i<$count; $i++) { + $chunk = $rest . $tmp[$i]; + $length = strlen($chunk); + if ($length % 4) { + $length = floor($length / 4) * 4; + $rest = substr($chunk, $length); + $chunk = substr($chunk, 0, $length); + } + + $text .= base64_decode($chunk); + } } else { //if ($encoding == 'Q' || $encoding == 'q') { // quoted printable can be combined and processed at once