thunderbird / thunderbird-android

Thunderbird for Android – Open Source Email App for Android (fka K-9 Mail)
https://thunderbird.net/
Apache License 2.0
10.47k stars 2.49k forks source link

ClassCastException: com.fsck.k9.mail.store.imap.ImapList cannot be cast to java.lang.String #7056

Open farblos opened 1 year ago

farblos commented 1 year ago

Checklist

App version

6.602

Where did you get the app from?

Google Play

Android version

13

Device model

Samsung Galaxy Tab S7 (SM-T870)

Steps to reproduce

Receive a mail with broken content type in its MIME structure from provider vodafonemail.de.

Expected behavior

Mail is displayed in summary overview.

Actual behavior

Mail is not displayed in summary overview, log contains below error.

Thunderbird displays it properly.

Logs

Below is my educated guess of what happens here - if you need more specific information, please let me know.

The stack trace is as follows:

ImapSync: synchronizeMailbox
ImapSync: java.lang.ClassCastException: com.fsck.k9.mail.store.imap.ImapList cannot be cast to java.lang.String
ImapSync:   at com.fsck.k9.mail.store.imap.ImapList.getString(ImapList.java:38)
ImapSync:   at com.fsck.k9.mail.store.imap.RealImapFolder.parseBodyStructure(RealImapFolder.kt:873)
ImapSync:   at com.fsck.k9.mail.store.imap.RealImapFolder.parseBodyStructure(RealImapFolder.kt:833)
ImapSync:   at com.fsck.k9.mail.store.imap.RealImapFolder.handleFetchResponse(RealImapFolder.kt:751)
ImapSync:   at com.fsck.k9.mail.store.imap.RealImapFolder.fetch(RealImapFolder.kt:602)
ImapSync:   at com.fsck.k9.backend.imap.ImapSync.downloadLargeMessages(ImapSync.kt:571)
ImapSync:   at com.fsck.k9.backend.imap.ImapSync.downloadMessages(ImapSync.kt:373)
ImapSync:   at com.fsck.k9.backend.imap.ImapSync.synchronizeMailboxSynchronous(ImapSync.kt:200)
ImapSync:   at com.fsck.k9.backend.imap.ImapSync.sync(ImapSync.kt:34)
ImapSync:   at com.fsck.k9.backend.imap.ImapBackend.sync(ImapBackend.kt:54)
ImapSync:   at com.fsck.k9.controller.MessagingController.syncFolder(MessagingController.java:616)
ImapSync:   at com.fsck.k9.controller.MessagingController.synchronizeMailboxSynchronous(MessagingController.java:556)
ImapSync:   at com.fsck.k9.controller.MessagingController.lambda$synchronizeMailbox$4(MessagingController.java:528)
ImapSync:   at com.fsck.k9.controller.MessagingController.$r8$lambda$Nd8VAILpR3kPTlfPD9A8uxRDVsc(MessagingController.java:0)
ImapSync:   at com.fsck.k9.controller.MessagingController$$ExternalSyntheticLambda16.run(R8$$SyntheticClass:0)
ImapSync:   at com.fsck.k9.controller.MessagingController.runInBackground(MessagingController.java:216)
ImapSync:   at com.fsck.k9.controller.MessagingController.-$$Nest$mrunInBackground(MessagingController.java:0)
ImapSync:   at com.fsck.k9.controller.MessagingController$1.run(MessagingController.java:157)
ImapSync:   at java.lang.Thread.run(Thread.java:1012)
ImapSync: Failed synchronizing folder foo.bar@arcor.de:INBOX @ Mi. Juli 05 23:20:02 MESZ 2023

The mail causing this has the following content type declaration on one of its parts (note the double quotes around application/pdf!):

  Content-Type: "application/pdf"; name="19976893.pdf"
  Content-Disposition: attachment; filename="19976893.pdf"
  Content-Transfer-Encoding: base64

When fetching manually the body structure, this becomes (note ""APPLICATION" "PDF""!):

* OK [CAPABILITY IMAP4rev1 ID AUTH=PLAIN SASL-IR] vodafone ready
1 LOGIN foo.bar@arcor.de ******
1 OK [CAPABILITY IMAP4rev1 CHILDREN UNSELECT XLIST ID MOVE NAMESPACE UIDPLUS] LOGIN completed.
2 SELECT INBOX
* FLAGS (\Answered \Deleted \Draft \Flagged \Recent \Seen)
* 25 EXISTS
* 0 RECENT
* OK [UNSEEN 19] First unseen.
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)] Flags permitted.
* OK [UIDNEXT 3293] Predicted next UID
* OK [UIDVALIDITY 1488271715] UIDs valid
2 OK [READ-WRITE] SELECT completed.
6 UID FETCH 3289 (UID BODYSTRUCTURE)
* 23 FETCH (UID 3289 BODYSTRUCTURE ((("TEXT" "PLAIN" ("charset" "UTF-8") NIL NIL "7BIT" 1106 13 NIL NIL NIL NIL)("TEXT" "HTML" ("charset" "UTF-8") NIL NIL "7BIT" 10266 140 NIL NIL NIL NIL) "ALTERNATIVE" ("boundary" "PHP-alt-2906f36265a5ec8760edd1caaf0094f1") NIL NIL NIL)(""APPLICATION" "PDF"" ("name" "19976893.pdf") NIL NIL "BASE64" 111788 NIL ("attachment" ("filename" "19976893.pdf")) NIL NIL) "MIXED" ("boundary" "PHP-mixed-2906f36265a5ec8760edd1caaf0094f1") NIL NIL NIL))
6 OK FETCH completed.

K-9 parses out of that:

RealImapConnection: conn161313233>>> 6 UID FETCH 3289 (UID BODYSTRUCTURE)
RealImapConnection: conn161313233<<<#null# [23, FETCH, [UID, 3289, BODYSTRUCTURE, [[[TEXT, PLAIN, [charset, UTF-8], NIL, NIL, 7BIT, 1106, 13, NIL, NIL, NIL, NIL], [TEXT, HTML, [charset, UTF-8], NIL, NIL, 7BIT, 10266, 140, NIL, NIL, NIL, NIL], ALTERNATIVE, [boundary, PHP-alt-2906f36265a5ec8760edd1caaf0094f1], NIL, NIL, NIL], [, APPLICATION,  , PDF, , [name, 19976893.pdf], NIL, NIL, BASE64, 111788, NIL, [attachment, [filename, 19976893.pdf]], NIL, NIL], MIXED, [boundary, PHP-mixed-2906f36265a5ec8760edd1caaf0094f1], NIL, NIL, NIL]]]

Where the element corresponding to the application/pdf part

[, APPLICATION,  , PDF, , [name, 19976893.pdf], NIL, NIL, BASE64, 111788, NIL, [attachment, [filename, 19976893.pdf]], NIL, NIL]

is messed up most likely due to the double double quotes. In particular, where K-9 expects a string specifying the encoding, there is list [name, 19976893.pdf], causing the exception.

farblos commented 1 year ago

If my educated guess above is true, K-9 mail would not be the culprit here, of course ...

farblos commented 1 year ago

Note that this different from #6800: There the error is thrown by this line@version 6.400:

861:   val subType = bs.getString(1)

where in my case it is thrown here@version 6.602:

873:  val encoding = bs.getString(5)