IMAP IDLE/PUSH doesn't work for Android 11

I’ve been trying to configure IMAP IDLE/PUSH on my Xiaomi Redmi 9 which runs Android 11. I’m currently using MIUI12, which has Google Play Services onboard. Before flashing the stock ROM I was using AOSP A11 based ROM with microG in place of Google Play Services. In both cases I experience the same issue with gmail accounts when I try to configure IMAP IDLE/PUSH.

The battery optimization is disabled for k-9 mail. The persistent notification is visible and it’s a regular one (not silent). K-9 mail autostarts at boot, and it can run without any restrictions (i.e. DND, or background data). But when I send an email to that account, which is configured in k-9 mail, I don’ get any notifications about new mail.

I have PUSH configured in k-9 mail fetching mail settings for only 1st Class folders and max folders to check with push is set to 10. Also the Refresh IDLE connection option is set to 24 minutes (I tried to lower the interval even to 2 minutes, but I still don’t get the notifications when the new mail arrives).

When I check for the active connections in the phone’s system, I can see that:

galahad:/ # netstat -napletu | grep -i k9
tcp6       0      0 ::ffff:192.168.1.:52850 ::ffff:173.194.222.:993 ESTABLISHED 10272      360413      14361/com.fsck.k9
tcp6       0      0 ::ffff:192.168.1.:52738 ::ffff:173.194.222.:993 ESTABLISHED 10272      335785      14361/com.fsck.k9

So there are 2 established connections, but no notifications were received. This happens not only when the phone unplugged, but also the issue exists when phone is being charged, or when the screen is on. Also when connecting to the net via LTE or WiFi.

When I access the K-9 mail app, it also doesn’t notify about the new mail – I have to refresh the inbox, and then I will see new mail and the notification is delivered.

When I left the phone for a while, the notification about new mail was ultimately delivered after aprox 24 minutes, which corresponds to the value set in the Refresh IDLE connection .

Should IMAP IDLE/PUSH work in the newer Androids?

Can you enable debug logging and record a debug log? See LoggingErrors · k9mail/k-9 Wiki · GitHub

This is basically what I get:

$ tail -f k9-log.txt
10-15 15:23:06.675 14361  7271 W BpBinder: Slow Binder: BpBinder transact took 335ms, interface=android.app.IActivityManager, code=22 oneway=false
10-15 15:23:18.825 14361 14361 I Timeline: Timeline: Activity_launch_request time:6912624
10-15 15:23:36.656 14361 14361 I Timeline: Timeline: Activity_launch_request time:6930455
10-15 15:23:55.757 14361 14361 I Timeline: Timeline: Activity_launch_request time:6949557
10-15 15:23:57.221 14361 14361 I Timeline: Timeline: Activity_launch_request time:6951020
--------- beginning of main
10-15 15:24:32.206 14361 14361 V PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@18854db, this = DecorView@fe9bbbf[MessageList]
10-15 15:24:33.286 14361 14361 V PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@18854db, this = DecorView@fe9bbbf[MessageList]
10-15 15:24:34.284 14361 14361 D View    : [Warning] assignParent to null: this = DecorView@fe9bbbf[MessageList]
10-15 15:24:34.287 14361 14361 I InputTransport: Destroy ARC handle: 0xb400007214c2ab60

This is after the massage was sent to the k9 mail account. So basically there’s no activity so far.

Should I wait 24 minutes to provide any logs?

I got some additional logs, but still no notification:

--------- beginning of main
10-15 15:33:57.245 14361 14389 V RealImapFolderIdler: ImapFolderIdler[INBOX].idleRefresh()
10-15 15:33:57.253 14361 14389 V RealImapConnection: conn229713838>>> DONE
10-15 15:33:57.675 14361  6362 V AndroidPowerManager$AndroidWakeLock: AndroidWakeLock for tag ImapFolderPusher-Morfik-INBOX / id 7: acquired with no timeout.
10-15 15:33:57.679 14361  6362 V ImapFolderPusher: Exception in ImapFolderPusher
10-15 15:33:57.679 14361  6362 V ImapFolderPusher: java.net.SocketException: Connection reset
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at java.net.SocketInputStream.read(SocketInputStream.java:215)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at java.net.SocketInputStream.read(SocketInputStream.java:144)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.readFromSocket(ConscryptEngineSocket.java:945)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.processDataFromSocket(ConscryptEngineSocket.java:909)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.readUntilDataAvailable(ConscryptEngineSocket.java:824)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.read(ConscryptEngineSocket.java:797)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:266)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:177)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at java.io.BufferedInputStream.fill(BufferedInputStream.java:248)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at java.io.BufferedInputStream.read(BufferedInputStream.java:267)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.fsck.k9.mail.filter.PeekableInputStream.peek(PeekableInputStream.java:36)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.fsck.k9.mail.store.imap.ImapResponseParser.readResponse(ImapResponseParser.java:36)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.fsck.k9.mail.store.imap.RealImapConnection.readResponse(RealImapConnection.java:881)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.fsck.k9.mail.store.imap.RealImapConnection.readResponse(RealImapConnection.java:874)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.fsck.k9.mail.store.imap.RealImapFolderIdler.idle(RealImapFolderIdler.kt:124)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.fsck.k9.mail.store.imap.RealImapFolderIdler.idle(RealImapFolderIdler.kt:39)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.fsck.k9.backend.imap.ImapFolderPusher.runPushLoop(ImapFolderPusher.kt:73)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.fsck.k9.backend.imap.ImapFolderPusher.access$runPushLoop(ImapFolderPusher.kt:15)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.fsck.k9.backend.imap.ImapFolderPusher$start$1.invoke(ImapFolderPusher.kt:36)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at com.fsck.k9.backend.imap.ImapFolderPusher$start$1.invoke(ImapFolderPusher.kt:33)
10-15 15:33:57.679 14361  6362 V ImapFolderPusher:      at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher: I/O error while trying to use IDLE
10-15 15:33:57.680 14361  6362 V ImapBackendPusher: java.net.SocketException: Connection reset
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at java.net.SocketInputStream.read(SocketInputStream.java:215)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at java.net.SocketInputStream.read(SocketInputStream.java:144)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.readFromSocket(ConscryptEngineSocket.java:945)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.processDataFromSocket(ConscryptEngineSocket.java:909)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.readUntilDataAvailable(ConscryptEngineSocket.java:824)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.read(ConscryptEngineSocket.java:797)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:266)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:177)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at java.io.BufferedInputStream.fill(BufferedInputStream.java:248)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at java.io.BufferedInputStream.read(BufferedInputStream.java:267)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.fsck.k9.mail.filter.PeekableInputStream.peek(PeekableInputStream.java:36)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.fsck.k9.mail.store.imap.ImapResponseParser.readResponse(ImapResponseParser.java:36)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.fsck.k9.mail.store.imap.RealImapConnection.readResponse(RealImapConnection.java:881)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.fsck.k9.mail.store.imap.RealImapConnection.readResponse(RealImapConnection.java:874)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.fsck.k9.mail.store.imap.RealImapFolderIdler.idle(RealImapFolderIdler.kt:124)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.fsck.k9.mail.store.imap.RealImapFolderIdler.idle(RealImapFolderIdler.kt:39)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.fsck.k9.backend.imap.ImapFolderPusher.runPushLoop(ImapFolderPusher.kt:73)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.fsck.k9.backend.imap.ImapFolderPusher.access$runPushLoop(ImapFolderPusher.kt:15)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.fsck.k9.backend.imap.ImapFolderPusher$start$1.invoke(ImapFolderPusher.kt:36)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at com.fsck.k9.backend.imap.ImapFolderPusher$start$1.invoke(ImapFolderPusher.kt:33)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher:     at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)
10-15 15:33:57.680 14361  6362 V ImapBackendPusher: ImapBackendPusher for folder INBOX sleeping for 300000 ms
10-15 15:33:57.685 14361  6362 V AndroidPowerManager$AndroidWakeLock: AndroidWakeLock for tag ImapFolderPusher-Morfik-INBOX / id 7: releasing after 9 ms, timeout = null ms
10-15 15:33:57.689 14361  6362 V ImapFolderPusher$start: Exiting ImapFolderPusher thread for Morfik / INBOX

And this is when the notification gets delivered:


10-15 15:38:57.686 14361 14389 V ImapBackendPusher: Refreshing ImapBackendPusher (at least one retry timer has expired)
10-15 15:38:57.690 14361 14389 V ImapBackendPusher: ImapBackendPusher.updateFolders(): [INBOX]
10-15 15:38:57.695 14361 14389 V ImapFolderPusher: Starting ImapFolderPusher for Morfik / INBOX
10-15 15:38:57.697 14361  8904 V ImapFolderPusher$start: Starting ImapFolderPusher thread for Morfik / INBOX
10-15 15:38:57.700 14361  8904 V AndroidPowerManager$AndroidWakeLock: AndroidWakeLock for tag ImapFolderPusher-Morfik-INBOX / id 8: Create
10-15 15:38:57.704 14361  8904 V AndroidPowerManager$AndroidWakeLock: AndroidWakeLock for tag ImapFolderPusher-Morfik-INBOX / id 8: acquired with no timeout.
10-15 15:38:57.711 14361 14384 I MessagingController: Running command 'synchronizeMailbox', seq = 56 (background priority)
10-15 15:38:57.722 14361 14384 D MessagingController: Last folder list refresh @ Fri Oct 15 15:17:34 GMT+02:00 2021. Not refreshing now.
10-15 15:38:57.732 14361 14384 I ImapSync: Synchronizing folder Morfik:INBOX
10-15 15:38:57.732 14361 14384 V ImapSync: SYNC: About to get local folder INBOX
10-15 15:38:57.738 14361 14384 V ImapSync: SYNC: About to get remote folder INBOX
10-15 15:38:57.738 14361 14384 V ImapSync: SYNC: About to open remote folder INBOX
10-15 15:38:57.741 14361 14384 V RealImapConnection: conn264785677>>> 5 NOOP
10-15 15:38:58.179 14361 14384 V ImapResponseParser: conn264785677<<<#5# [OK, Success]
10-15 15:38:58.181 14361 14384 V RealImapConnection: conn264785677>>> 6 EXAMINE "INBOX"
10-15 15:38:58.355 14361 14384 V ImapResponseParser: conn264785677<<<#null# [FLAGS, [\Answered, \Flagged, \Draft, \Deleted, \Seen, $NotPhishing, $Phishing]]
10-15 15:38:58.356 14361 14384 V ImapResponseParser: conn264785677<<<#null# [OK, [PERMANENTFLAGS, []], Flags permitted.]
10-15 15:38:58.357 14361 14384 V ImapResponseParser: conn264785677<<<#null# [OK, [UIDVALIDITY, 1], UIDs valid.]
10-15 15:38:58.359 14361 14384 V ImapResponseParser: conn264785677<<<#null# [2, EXISTS]
10-15 15:38:58.360 14361 14384 V ImapResponseParser: conn264785677<<<#null# [0, RECENT]
10-15 15:38:58.361 14361 14384 V ImapResponseParser: conn264785677<<<#null# [OK, [UIDNEXT, 757], Predicted next UID.]
10-15 15:38:58.362 14361 14384 V ImapResponseParser: conn264785677<<<#null# [OK, [HIGHESTMODSEQ, 228249]]
10-15 15:38:58.363 14361 14384 V ImapResponseParser: conn264785677<<<#6# [OK, [READ-ONLY], INBOX selected. (Success)]
10-15 15:38:58.364 14361 14384 D RealImapFolder: Got untagged EXISTS with value 2 for Morfik:INBOX/MessagingController/conn264785677
10-15 15:38:58.365 14361 14384 D RealImapFolder: Got UidNext = 757 for Morfik:INBOX/MessagingController/conn264785677
10-15 15:38:58.372 14361 14384 V ImapSync: SYNC: Remote message count for folder INBOX is 2
10-15 15:38:58.372 14361 14384 V ImapSync: SYNC: About to get messages 1 through 2 for folder INBOX
10-15 15:38:58.375 14361 14384 V RealImapConnection: conn264785677>>> 7 UID SEARCH 1:2 SINCE 15-Apr-2021 NOT DELETED
10-15 15:38:58.640 14361 14384 V ImapResponseParser: conn264785677<<<#null# [SEARCH, 755, 756]
10-15 15:38:58.641 14361 14384 V ImapResponseParser: conn264785677<<<#7# [OK, SEARCH completed (Success)]
10-15 15:38:58.645 14361 14384 V ImapSync: SYNC: Got 2 messages for folder INBOX
10-15 15:38:58.648 14361 14384 V ImapSync: Message with uid 756 has not yet been downloaded
10-15 15:38:58.652 14361 14384 V ImapSync: Message with uid 755 is present in the local store
10-15 15:38:58.654 14361 14384 D ImapSync: SYNC: Have 1 unsynced messages
10-15 15:38:58.658 14361 14384 D ImapSync: SYNC: About to fetch 1 unsynced messages for folder INBOX
10-15 15:38:58.661 14361 14384 V RealImapConnection: conn264785677>>> 8 UID FETCH 756 (UID FLAGS INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS (date subject from content-type to cc reply-to message-id references in-reply-to X-K9mail-Identity Chat-Version)])
10-15 15:38:58.856 14361 14384 V RealImapConnection: conn264785677<<<#null# [2, FETCH, [UID, 756, RFC822.SIZE, 5139, INTERNALDATE, 15-Oct-2021 13:25:48 +0000, FLAGS, [], BODY, [HEADER.FIELDS, [date, subject, from, content-type, to, cc, reply-to, message-id, references, in-reply-to, X-K9mail-Identity, Chat-Version]], To: Morfik <mail-sent-to@gmail.com>
10-15 15:38:58.856 14361 14384 V RealImapConnection: From: Mikhail Morfikov <mail-sent-from@gmail.com>
10-15 15:38:58.856 14361 14384 V RealImapConnection: Subject: test
10-15 15:38:58.856 14361 14384 V RealImapConnection: Message-ID: <a1439ea2-7118-ff8a-709c-c0f08649dd79@gmail.com>
10-15 15:38:58.856 14361 14384 V RealImapConnection: Date: Fri, 15 Oct 2021 15:25:47 +0200
10-15 15:38:58.856 14361 14384 V RealImapConnection: Content-Type: text/plain; charset=utf-8
10-15 15:38:58.856 14361 14384 V RealImapConnection:
10-15 15:38:58.856 14361 14384 V RealImapConnection: ]]
10-15 15:38:58.867 14361 14384 V RealImapConnection: conn264785677<<<#8# [OK, Success]
10-15 15:38:58.868 14361 14384 D ImapSync: SYNC: Synced unsynced messages for folder INBOX
10-15 15:38:58.869 14361 14384 D ImapSync: SYNC: Have 0 large messages and 1 small messages out of 1 unsynced messages
10-15 15:38:58.870 14361 14384 D ImapSync: SYNC: Fetching 1 small messages for folder INBOX
10-15 15:38:58.872 14361 14384 V RealImapConnection: conn264785677>>> 9 UID FETCH 756 (UID BODY.PEEK[])
10-15 15:38:59.475 14361 14384 V RealImapConnection: conn264785677<<<#null# [2, FETCH, [UID, 756, BODY, [], 1]]
10-15 15:38:59.509 14361 14384 D BinaryTempFileBody$BinaryTempFileBodyInputStream: Deleting temporary binary file: body4899007371212010983.tmp
10-15 15:38:59.532 14361 14384 V LockableDatabase: LockableDatabase: Transaction ended, took 4 ms / com.fsck.k9.storage.messages.SaveMessageOperations.saveMessage(SaveMessageOperations.kt:81)
10-15 15:38:59.535 14361 14384 V ImapSync$downloadSmallMessages: About to notify listeners that we got a new small message Morfik:INBOX:756
10-15 15:38:59.548 14361 14384 V MessagingController$ControllerSyncListener: Creating notification for message INBOX:756
10-15 15:38:59.591 14361 14384 V RealImapConnection: conn264785677<<<#9# [OK, Success]
10-15 15:38:59.592 14361 14384 D ImapSync: SYNC: Done fetching small messages for folder INBOX
10-15 15:38:59.593 14361 14384 D ImapSync: SYNC: Fetching large messages for folder INBOX
10-15 15:38:59.593 14361 14384 D ImapSync: SYNC: Done fetching large messages for folder INBOX
10-15 15:38:59.594 14361 14384 D ImapSync: SYNC: About to sync flags for 1 remote messages for folder INBOX
10-15 15:38:59.596 14361 14384 V RealImapConnection: conn264785677>>> 10 UID FETCH 755 (UID FLAGS)
10-15 15:39:00.097 14361 14384 V RealImapConnection: conn264785677<<<#null# [1, FETCH, [UID, 755, FLAGS, [\Seen]]]
10-15 15:39:00.098 14361 14384 V RealImapConnection: conn264785677<<<#10# [OK, Success]
10-15 15:39:00.102 14361 14384 D ImapSync: SYNC: Synced remote messages for folder INBOX, 1 new messages
10-15 15:39:00.115 14361 14384 D ImapSync: Done synchronizing folder Morfik:INBOX @ Fri Oct 15 15:39:00 GMT+02:00 2021 with 1 new messages
10-15 15:39:00.117 14361 14384 I ImapSync: Done synchronizing folder Morfik:INBOX
10-15 15:39:00.118 14361 14384 I MessagingController:  Command 'synchronizeMailbox' completed
10-15 15:39:00.119 14361  8904 V RealImapFolderIdler: ImapFolderIdler[INBOX].idle()
10-15 15:39:00.121 14361  8904 V RealImapConnection: conn264785677>>> 11 NOOP
10-15 15:39:00.227 14361  8904 V ImapResponseParser: conn264785677<<<#11# [OK, Success]
10-15 15:39:00.229 14361  8904 V RealImapConnection: conn264785677>>> 12 EXAMINE "INBOX"
10-15 15:39:00.795 14361  8904 V ImapResponseParser: conn264785677<<<#null# [FLAGS, [\Answered, \Flagged, \Draft, \Deleted, \Seen, $NotPhishing, $Phishing]]
10-15 15:39:00.796 14361  8904 V ImapResponseParser: conn264785677<<<#null# [OK, [PERMANENTFLAGS, []], Flags permitted.]
10-15 15:39:00.797 14361  8904 V ImapResponseParser: conn264785677<<<#null# [OK, [UIDVALIDITY, 1], UIDs valid.]
10-15 15:39:00.799 14361  8904 V ImapResponseParser: conn264785677<<<#null# [2, EXISTS]
10-15 15:39:00.807 14361  8904 V ImapResponseParser: conn264785677<<<#null# [0, RECENT]
10-15 15:39:00.808 14361  8904 V ImapResponseParser: conn264785677<<<#null# [OK, [UIDNEXT, 757], Predicted next UID.]
10-15 15:39:00.813 14361  8904 V ImapResponseParser: conn264785677<<<#null# [OK, [HIGHESTMODSEQ, 228249]]
10-15 15:39:00.814 14361  8904 V ImapResponseParser: conn264785677<<<#12# [OK, [READ-ONLY], INBOX selected. (Success)]
10-15 15:39:00.819 14361  8904 D RealImapFolder: Got untagged EXISTS with value 2 for Morfik:INBOX/ImapFolderPusher-Morfik-INBOX/conn264785677
10-15 15:39:00.819 14361  8904 D RealImapFolder: Got UidNext = 757 for Morfik:INBOX/ImapFolderPusher-Morfik-INBOX/conn264785677
10-15 15:39:00.822 14361  8904 V RealImapConnection: Connection conn264785677 has 21 capabilities
10-15 15:39:00.824 14361  8904 V RealImapConnection: conn264785677>>> 13 IDLE
10-15 15:39:01.017 14361  8904 V RealImapConnection: conn264785677<<<#+# [idling]
10-15 15:39:01.021 14361  8904 V AndroidPowerManager$AndroidWakeLock: AndroidWakeLock for tag ImapFolderPusher-Morfik-INBOX / id 8: releasing after 3316 ms, timeout = null ms

It looks like this happens all the time when the phone is not used.

From your description and the log showing an exception when trying to refresh the IDLE connection it looks like the connection to the IMAP server is not being kept alive. If this happens both on the mobile network and WiFi, it’s more likely to be caused by your phone than by your provider. It could be some power saving measure of MIUI. Maybe Xiaomi | Don’t kill my app! can help.

I thought it would, but as I mentioned, this happens even when the phone’s screen is on. The app isn’t killed (it has the lock icon toggled on just to be sure), the persistent notification is always showed even on the lock screen. I also have the battery optimization disabled in the developer settings (it’s a separate setting for MIUI alone). Basically all the settings from the link you’ve provided I already have set for K-9 Mail and the app have issues with PUSH.

I wanted to note that for AOSP based ROM I also had the same issue, so it’s not related only to MIUI.

BTW: I wanted to ask one thing. Should K-9 mail register for Google Cloud Messaging? I’m asking because when I was using AOSP with microG I haven’t seen K-9 mail on the app list.

K-9 Mail doesn’t use Google Cloud Messaging. Push is implemented in the app itself.

Ok, so I have no idea why it doesn’t work. :slight_smile:

I don’t know either. Have you tried using Push with a different email provider. It’s possible (though unlikely) that your Gmail account is not notifying the IDLE connection when a new message arrives.

I could try. I’ll see whether it works for a different provider than gmail.

I also wanted to add, that for instance, the conversations doesn’t have such issues. The same settings are set for the conversations app, and it works well.

It’s weird but after adding the second account, it looks like there’s no problem with PUSH in the case of both accounts. I need more testing though. But it looks like that it works well now – after 1 hour of phone disconnected from the power source with its screen turned off.

I assume the following lines should be logged all the time when K9 mail is working properly?

10-16 00:56:59.790 14476  2833 V RealImapConnection: conn260624438<<<#null# [OK, Still here]
10-16 00:56:59.796 14476  2833 V AndroidPowerManager$AndroidWakeLock: AndroidWakeLock for tag ImapFolderPusher-Morfik-2nd-INBOX / id 7: acquired with no timeout.
10-16 00:56:59.797 14476  2833 V RealImapFolderIdler: ImapFolderIdler[INBOX].idle(): Ignoring untagged response
10-16 00:56:59.797 14476  2833 V AndroidPowerManager$AndroidWakeLock: AndroidWakeLock for tag ImapFolderPusher-Morfik-2nd-INBOX / id 7: releasing after 1 ms, timeout = null ms

It looks like they appear in the log every 2 minutes.

If I’m right, there should be a copy of these messages for every account configures in K-9 mail, is that right? If so, only for the second account these messages are present in the log when the device is not used.

I tested this by sending the mail to the first account, and there’s no notification. But when I sent a mail to the second account, the notification is instantly delivered. Both of the accounts have the same settings set in K-9 mail. So apparently something is wrong with the fist account or its settings.

Ok, I verified this. The first account gets this ImapFolderPusher: java.net.SocketException: Connection reset , while for the other account, I get the log I posted above – at the same time (more or less).

The other account is not google.

I try to remove the first account and add it again.

Ok, readding the gmail account didn’t solve the issue. So apparently something is wrong either with gmail itself or with K-9 mail handling gmail. So the question is: does the K-9 Mail PUSH work with gmail accounts which have 2FA configured (the app password feature)?

2 Likes

The “OK Still here” message is sent by the server. It is used to keep the connection alive. Generally, this is unnecessary because clients have their own mechanism to keep the connection alive. Receiving data every two minutes will most likely lead to high battery usage. If you can, you should disable this mechanism on the server or at least increase the interval.

Since the device is now waking up every two minutes anyway, please try setting Settings > [Gmail account] > Fetching mail > Advanced > Refresh IDLE connection to Every 2 minutes again. If the connection is already dead, it’s possible that changing this setting doesn’t have immediate effect. Please “force stop” the app and start it again to see if changing this value to 2 minutes does fix Push for the Gmail account. If it does, try increasing the Refresh IDLE connection value until sending the “DONE” command fails with an exception. Then use the last value where sending “DONE” worked without an error.

It’s not my server. So I can’t increase the delay or disable it.

I removed the account already and now I have only gmail configured. I set the refresh to 2 minutes and forced restart K9-Mail. It looks like it works for gmail. I increased this to 6 minutes, but it fails. Apparently the max refresh time for gmail is 3 minutes. With that interval it works well.

Could you add also 4 and 5 minutes interval? Maybe gmail is set max to 5 minutes, but with the current K-9 Mail settings there’s only 3 and 6 to choose from.

I’ve had no problems with Fair Email using a foreground service on Android Apps 11. I believe that the changes that will be implemented in 12 can be worked around. This is compatible with Aqua Mail’s (another Android email client) IMAP Push implementation. — You received this message as a result of this project.