Skip to content

Commit

Permalink
Fix decoding mail parts with multiple base64-encoded text blocks (#9290)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Jun 16, 2024
1 parent 6139544 commit e8e0c68
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 @@ -5,6 +5,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 @@ -3049,7 +3049,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/ImapGeneric.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ 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 e8e0c68

Please sign in to comment.