Skip to content

IMAP Server support is broken for iOS Mail.app and shorter messages #12345

@tomwardill

Description

@tomwardill

Describe the incorrect behavior you saw

Using the IMAPServer class with the latest (at least, I've not tested on older versions) Mail.app on iOS appears to be broken. The client can load the folder structure, but will never load the body of the message if the message is less than 393216 bytes.

This appears to be due to iOS using BODY.PEEK with a very large partial window. The IMAP RFC (RFC3501) states:

Any partial fetch that attempts to read beyond the end of the
text is truncated as appropriate. A partial fetch that starts
at octet 0 is returned as a partial fetch, even if this
truncation happened.

Note: This means that BODY[]<0.2048> of a 1500-octet message
will return BODY[]<0> with a literal of size 1500, not
BODY[].

Twisted does not respect this and returns the original partial window and the content of the message. This is then never displayed in mail.app and causes the app to go into a message retrieval loop.

iOS appears to always use the same partial range, with UID enabled:
UID BODY.PEEK[]<0.393216>
This taken from both debug output in twisted and a wireshark packet trace.

Describe how to cause this behavior

Create a test IMAP server using the IMAP4 support in Twisted and populate it with some messages. Attempt to connect to it using the iOS native mail.app.

This https://github.com/mistio/localmail/tree/master is an example of a server that exhibits the problem.

Describe the correct behavior you'd like to see

The mail should be viewable in mail.app, and the server should follow the RFC spec (as much as possible with the IMAP spec)

Testing environment

  • Operating System and Version; paste the output of these commands:
Linux SanctionedPartsOnly 6.11.0-8-generic #8-Ubuntu SMP PREEMPT_DYNAMIC Mon Sep 16 13:41:20 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.10
DISTRIB_CODENAME=oracular
DISTRIB_DESCRIPTION="Ubuntu 24.10"
  • Twisted version [e.g. 22.2.0]
attrs==24.2.0
Automat==24.8.1
constantly==23.10.4
hyperlink==21.0.0
idna==3.10
incremental==24.7.2
setuptools==75.2.0
Twisted==24.7.0
typing_extensions==4.12.2
zope.interface==7.1.1
  • Reactor [e.g. select, iocp]
    select

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions