thunderbird / thunderbird/thunderbird-android

Sync fails when FETCH response contains an IMAP keyword containing `[`

Open
#7,589 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
14k
Forks
2.8k
Avg merge
3d 3h
Merged PRs (30d)
57

Description

Checklist
  • I have used the search function to see if someone else has already submitted the same bug report.
  • I will describe the problem with as much detail as possible.
App version

6.603

Where did you get the app from?

None

Android version

irrelevant

Device model

No response

Steps to reproduce
  1. Add an IMAP keyword that contains a [ character to a message
  2. Sync the folder containing that message

Test code to trigger the bug (add it to ImapResponseParserTest):

@Test
fun `FETCH response with keyword containing opening square bracket`() {
    val parser = createParserWithResponses(
        """* 1 FETCH (UID 23 FLAGS (\Seen [keyword))""",
    )

    val response = parser.readResponse()

    assertThat(response).hasSize(3)
    assertThat(response).index(0).isEqualTo("1")
    assertThat(response).index(1).isEqualTo("FETCH")
    assertThat(response).index(2).isInstanceOf<ImapList>().all {
        hasSize(4)
        index(0).isEqualTo("UID")
        index(1).isEqualTo("23")
        index(2).isEqualTo("FLAGS")
        index(3).isInstanceOf<ImapList>().containsExactly("""\Seen""", "[keyword")
    }
    assertThatAllInputWasConsumed()
}
Expected behavior

Sync doesn't abort with an error.

Actual behavior

Folder fails to sync.

Logs
01-26 20:23:04.343  8298  8382 D ImapSync: SYNC: Have 54 unsynced messages
01-26 20:23:04.343  8298  8382 D ImapSync: SYNC: About to fetch 54 unsynced messages for folder INBOX
01-26 20:23:04.344  8298  8382 V RealImapConnection: conn177890135>>> 19 UID FETCH 244093,244092,244091,244090,244089,244088,244087,244085,244084,244080,244079,244078,244077,244076,244075,244074,244072,244071,244069,244066,244065,244064,244062,244061,244060,244059,244057,244056,244055,244051,244049,244048,244047,244045,244044,244042,244041,244040,244039,244038,244037,244036,244035,244025,244021,244020,244019,244018,244017,244016,244014,244012,244008,244005 (UID FLAGS INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS (date subject from content-type to cc bcc reply-to message-id references in-reply-to list-unsubscribe sender X-K9mail-Identity Chat-Version)])
01-26 20:23:04.381  8298  8382 V RealImapConnection: conn177890135<<<#null# [5526, FETCH, [UID, 244005, FLAGS, [\Seen, NonJunk, [EXTERN]], INTERNALDATE, 25-Jan-2024 07:18:15 +0000, RFC822.SIZE, 71570, BODY, [HEADER.FIELDS, [date, subject, from, content-type, to, cc, bcc, reply-to, message-id, references, in-reply-to, list-unsubscribe, sender, X-K9mail-Identity, Chat-Version]], Date: Thu, 25 Jan 2024 08:17:42 +0100 (CET)
01-26 20:23:04.381  8298  8382 V RealImapConnection: From: xxxxxxxxxxxxxxxxxxxxxxx
01-26 20:23:04.381  8298  8382 V RealImapConnection: Sender: xxxxxxxxxxxxxxxxxxxxxxx
01-26 20:23:04.381  8298  8382 V RealImapConnection: Reply-To: xxxxxxxxxxxxxxxxxxxxxxx
01-26 20:23:04.381  8298  8382 V RealImapConnection: To: xxxxxxxxxxxxxxxxxxxxxxx
01-26 20:23:04.381  8298  8382 V RealImapConnection: Message-ID: xxxxxxxxxxxxxxxxxxxxxxx
01-26 20:23:04.381  8298  8382 V RealImapConnection: Subject: =xxxxxxxxxxxxxxxxxxxxxxx
01-26 20:23:04.381  8298  8382 V RealImapConnection:  =xxxxxxxxxxxxxxxxxxxxxxx
01-26 20:23:04.381  8298  8382 V RealImapConnection:  =xxxxxxxxxxxxxxxxxxxxxxx
01-26 20:23:04.381  8298  8382 V RealImapConnection:  =xxxxxxxxxxxxxxxxxxxxxxx
01-26 20:23:04.381  8298  8382 V RealImapConnection: Content-Type: text/html; charset="UTF-8"
01-26 20:23:04.381  8298  8382 V RealImapConnection: 
01-26 20:23:04.381  8298  8382 V RealImapConnection: ]]
01-26 20:23:04.382  8298  8382 E ImapSync: synchronizeMailbox
01-26 20:23:04.382  8298  8382 E ImapSync: java.lang.ClassCastException: com.fsck.k9.mail.store.imap.ImapList cannot be cast to java.lang.String
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.mail.store.imap.ImapList.getString(ImapList.java:38)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.mail.store.imap.RealImapFolder.handleFetchResponse(RealImapFolder.kt:711)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.mail.store.imap.RealImapFolder.fetch(RealImapFolder.kt:602)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.backend.imap.ImapSync.fetchUnsyncedMessages(ImapSync.kt:458)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.backend.imap.ImapSync.downloadMessages(ImapSync.kt:328)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.backend.imap.ImapSync.synchronizeMailboxSynchronous(ImapSync.kt:200)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.backend.imap.ImapSync.sync(ImapSync.kt:34)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.backend.imap.ImapBackend.sync(ImapBackend.kt:54)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.controller.MessagingController.syncFolder(MessagingController.java:616)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.controller.MessagingController.synchronizeMailboxSynchronous(MessagingController.java:556)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.controller.MessagingController.synchronizeFolderInBackground(MessagingController.java:2351)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.controller.MessagingController.lambda$synchronizeFolder$28(MessagingController.java:2323)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.controller.MessagingController.$r8$lambda$aDvPuf3fqQD52MZIdwGXU2EFGXE(MessagingController.java:0)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.controller.MessagingController$$ExternalSyntheticLambda31.run(R8$$SyntheticClass:0)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.controller.MessagingController.runInBackground(MessagingController.java:216)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.controller.MessagingController.-$$Nest$mrunInBackground(MessagingController.java:0)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at com.fsck.k9.controller.MessagingController$1.run(MessagingController.java:157)
01-26 20:23:04.382  8298  8382 E ImapSync: 	at java.lang.Thread.run(Thread.java:920)
01-26 20:23:04.387  8298  8382 E ImapSync: Failed synchronizing folder IMTEK:INBOX @ Fri Jan 26 20:23:04 GMT+01:00 2024

See https://forum.k9mail.app/t/k-9-does-not-retrieve-mail/7975

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ImapResponseParserTest and the supplied FETCH response case, then trace the failure from RealImapFolder.kt handleFetchResponse. Run the parser test and verify that a keyword containing [ is parsed as part of the keyword and that the folder sync no longer aborts.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.