Skip to content

Commit 613629f

Browse files
committed
Fix decoding mail parts with multiple base64-encoded text blocks (roundcube#9290)
1 parent bcaab87 commit 613629f

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
- Fix newmail_notifier notification focus in Chrome (#9467)
5858
- Fix fatal error when parsing some TNEF attachments (#9462)
5959
- Fix double scrollbar when composing a mail with many plain text lines (#7760)
60+
- Fix decoding mail parts with multiple base64-encoded text blocks (#9290)
6061

6162
## Release 1.6.7
6263

program/lib/Roundcube/rcube_imap_generic.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3015,7 +3015,14 @@ protected static function decodeContent($chunk, $mode, $is_last = false, &$prev
30153015
$prev = '';
30163016
}
30173017

3018-
return base64_decode($chunk);
3018+
// There might be multiple base64 blocks in a single message part,
3019+
// we have to pass them separately to base64_decode() (#9290)
3020+
$result = '';
3021+
foreach (preg_split('|=+|', $chunk, -1, \PREG_SPLIT_NO_EMPTY) as $_chunk) {
3022+
$result .= base64_decode($_chunk);
3023+
}
3024+
3025+
return $result;
30193026
}
30203027

30213028
// QUOTED-PRINTABLE

tests/Framework/ImapGenericTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,26 @@ public function test_decode_content_base64()
152152
$this->runDecodeContent($content, $encoded, 1, 6000);
153153
}
154154

155+
/**
156+
* Test for decodeContent() with base64 encoding (multiple bodies)
157+
*/
158+
public function test_decode_content_base64_multiple()
159+
{
160+
$expected = $content = str_repeat('a', 100);
161+
$encoded = chunk_split(base64_encode($content), 72, "\r\n");
162+
163+
$expected .= ($content = str_repeat('b', 101));
164+
$encoded .= chunk_split(base64_encode($content), 72, "\r\n");
165+
166+
$expected .= ($content = str_repeat('c', 102));
167+
$encoded .= chunk_split(base64_encode($content), 72, "\r\n");
168+
169+
$expected .= ($content = str_repeat('d', 103));
170+
$encoded .= chunk_split(base64_encode($content), 72, "\r\n");
171+
172+
$this->runDecodeContent($expected, $encoded, 1);
173+
}
174+
155175
/**
156176
* Test for decodeContent() with quoted-printable encoding
157177
*/

0 commit comments

Comments
 (0)