Skip to content

Base64-encoded message displayed without decoding when MIME-Version header is missing (Courier-IMAP 6.x) #10417

Done

Description

@tsnr

Prerequisites

  • I have searched for duplicate or closed issues
  • I can recreate the issue with all plugins disabled

Describe the issue

Description

I'm using Roundcube 1.7.5 (FreeBSD package 1.7.5,1) with Courier-IMAP 6.0.8.

I encountered an issue where Roundcube displays the Base64-encoded body of an email without decoding it when the message lacks the MIME-Version: 1.0 header.

The affected message contains the following headers:

Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64

Adding MIME-Version: 1.0 makes Roundcube display the message correctly.

Investigation

I compared the IMAP BODYSTRUCTURE responses between Courier-IMAP 5.3.2 and 6.0.7/6.0.8.

For a message without MIME-Version, Courier-IMAP 5.3.2 returns:

("text" "plain" NIL NIL NIL "base64" 22 1 NIL NIL NIL)

However, Courier-IMAP 6.0.7 and 6.0.8 return:

("text" "plain" NIL NIL NIL "7bit" 22 1 NIL NIL NIL)

I also confirmed that Roundcube fetches BODYSTRUCTURE when displaying these messages.

Thunderbird displays both messages correctly.

I reported this behavior change to the Courier-IMAP mailing list. The developer explained that the MIME parser was rewritten in C++ in version 6.x and suggested asking Roundcube to address the issue first.
https://sourceforge.net/p/courier/mailman/courier-imap/thread/afebd48b-dc14-499c-afe5-9e1c8a531b9b%40tsnr.com/#msg59433833

Expected behavior

Roundcube displays the decoded UTF-8 text even when the MIME-Version header is missing, as it did when using Courier-IMAP 5.3.2.

Actual behavior

Roundcube displays the raw Base64-encoded text when using Courier-IMAP 6.0.7 or 6.0.8.

Question

I understand that the message is not MIME-compliant because it lacks the required MIME-Version header.

However, would it be possible for Roundcube to handle such messages for backward compatibility, even when the IMAP server reports 7bit in BODYSTRUCTURE?

I've attached two sample messages that differ only in the presence or absence of the MIME-Version: 1.0 header.

Thank you for your consideration.

What browser(s) are you seeing the problem on?

Safari, Chrome, Firefox

What version of PHP are you using?

v8.4

What version of Roundcube are you using?

v1.7.5

JavaScript errors

with-MIME-Version.eml

without-MIME-Version.eml

PHP errors

No response

Activity

  1. alecpl commented on Nov 17, 2026

    @alecpl
    Member

    Yes, Roundcube depends on BODYSTRUCTURE, unlike Thunderbird. However, there's a specialcase when we fallback to parsing the message.

    if ($headers->ctype && !is_array($structure[0]) && $headers->ctype != 'text/plain'

    So, investigate why it still does not work. Maybe our parser/decoder can't handle such messages, or maybe this code path is not used.

  2. tsnr commented on Nov 18, 2026

    @tsnr
    Author

    Thanks for pointing me to the fallback logic.

    I added debug logging to get_message() and confirmed that the fallback condition is false in both cases. I've attached the patch I used for debugging.
    rcupe_imap.php.patch

    with-MIME-Version.eml:

    header_ctype='text/plain'
    header_charset='utf-8'
    structure_type=text/plain
    structure_encoding='base64'
    fallback_condition=false
    bodystructure=["text","plain",["charset","utf-8"],null,null,"base64","22","1",null,null,null]
    

    without-MIME-Version.eml:

    header_ctype='text/plain'
    header_charset='utf-8'
    structure_type=text/plain
    structure_encoding='7bit'
    fallback_condition=false
    bodystructure=["text","plain",null,null,null,"7bit","22","1",null,null,null]
    

    The fallback condition is false because $headers->ctype is text/plain in both cases.

    The issue is not a mismatch in Content-Type, but a mismatch in Content-Transfer-Encoding between the message headers and the BODYSTRUCTURE returned by Courier-IMAP 6.x. The charset parameter is also missing from BODYSTRUCTURE when MIME-Version is absent.

    Also, even if the outer condition were modified to allow text/plain, the elseif (preg_match('/^(text|application)\/(.*)/', ...)) branch would be taken, so rcube_mime::parse_message() would still not be called.

    It appears that the existing fallback logic does not cover this case.

  3. MikeFTV commented on Nov 25, 2026

    @MikeFTV
    Contributor

    I can reproduce this from the BODYSTRUCTURE alone: get_message() already substitutes the Content-Type and charset from the message headers for single-part messages, but not the Content-Transfer-Encoding, so a '7bit' structure keeps the part from being decoded. I'll send a patch that takes the header's base64/quoted-printable encoding in that workaround.

  4. tsnr commented on Nov 26, 2026

    @tsnr
    Author

    Thank you for the patch!

    I replaced rcube_imap.php in my local Roundcube 1.7.7 installation with the version from PR #10442 and confirmed that both with-MIME-Version.eml and without-MIME-Version.eml are now correctly decoded and displayed with Courier-IMAP 6.0.8.

    This resolves the issue in my environment. Thank you for your help!

  5. MikeFTV commented on Nov 26, 2026

    @MikeFTV
    Contributor

    Thanks for testing the patch against Courier-IMAP 6.0.8 and for the detailed debug output, it made the cause easy to pin down. Good to know both files decode correctly now.

  6. added this to the 1.7.7 milestone on Nov 26, 2026
  7. alecpl commented on Nov 26, 2026

    @alecpl
    Member

    Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions