Skip to content

Commit

Permalink
Fix decoding mail parts with multiple base64-encoded text blocks (rou…
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Jun 16, 2024
1 parent bcaab87 commit 613629f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
- Fix newmail_notifier notification focus in Chrome (#9467)
- Fix fatal error when parsing some TNEF attachments (#9462)
- Fix double scrollbar when composing a mail with many plain text lines (#7760)
- Fix decoding mail parts with multiple base64-encoded text blocks (#9290)

## Release 1.6.7

Expand Down
9 changes: 8 additions & 1 deletion program/lib/Roundcube/rcube_imap_generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -3015,7 +3015,14 @@ protected static function decodeContent($chunk, $mode, $is_last = false, &$prev
$prev = '';
}

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

return $result;
}

// QUOTED-PRINTABLE
Expand Down
20 changes: 20 additions & 0 deletions tests/Framework/ImapGenericTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ public function test_decode_content_base64()
$this->runDecodeContent($content, $encoded, 1, 6000);
}

/**
* Test for decodeContent() with base64 encoding (multiple bodies)
*/
public function test_decode_content_base64_multiple()
{
$expected = $content = str_repeat('a', 100);
$encoded = chunk_split(base64_encode($content), 72, "\r\n");

$expected .= ($content = str_repeat('b', 101));
$encoded .= chunk_split(base64_encode($content), 72, "\r\n");

$expected .= ($content = str_repeat('c', 102));
$encoded .= chunk_split(base64_encode($content), 72, "\r\n");

$expected .= ($content = str_repeat('d', 103));
$encoded .= chunk_split(base64_encode($content), 72, "\r\n");

$this->runDecodeContent($expected, $encoded, 1);
}

/**
* Test for decodeContent() with quoted-printable encoding
*/
Expand Down

0 comments on commit 613629f

Please sign in to comment.