Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit dfa939c5 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #5406 from k9mail/fix_push_crashes

Fix push crashes
parents 659937aa 03caacc1
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -82,8 +82,7 @@ internal class AccountPushController(
    private fun updatePushFolders(folderServerIds: List<String>) {
        Timber.v("AccountPushController(%s).updatePushFolders(): %s", account.uuid, folderServerIds)

        val backendPusher = this.backendPusher ?: error("BackendPusher not initialized")
        backendPusher.updateFolders(folderServerIds)
        backendPusher?.updateFolders(folderServerIds)
    }

    private fun syncFolders(folderServerId: String) {
+15 −11
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ class RealImapConnection implements ImapConnection {
    }

    @Override
    public void open() throws IOException, MessagingException {
    public synchronized void open() throws IOException, MessagingException {
        if (open) {
            return;
        } else if (stacktraceForClose != null) {
@@ -190,7 +190,7 @@ class RealImapConnection implements ImapConnection {
    }

    @Override
    public boolean isConnected() {
    public synchronized boolean isConnected() {
        return inputStream != null && outputStream != null && socket != null &&
                socket.isConnected() && !socket.isClosed();
    }
@@ -260,9 +260,11 @@ class RealImapConnection implements ImapConnection {
    }

    @Override
    public void setSocketReadTimeout(int timeout) throws SocketException {
    public synchronized void setSocketReadTimeout(int timeout) throws SocketException {
        if (socket != null) {
            socket.setSoTimeout(timeout);
        }
    }

    private void setUpStreamsAndParserFromSocket() throws IOException {
        setUpStreamsAndParser(socket.getInputStream(), socket.getOutputStream());
@@ -731,7 +733,7 @@ class RealImapConnection implements ImapConnection {
    }

    @Override
    public void close() {
    public synchronized void close() {
        if (!open) {
            return;
        }
@@ -750,7 +752,7 @@ class RealImapConnection implements ImapConnection {

    @Override
    @NotNull
    public OutputStream getOutputStream() {
    public synchronized OutputStream getOutputStream() {
        return outputStream;
    }

@@ -762,7 +764,8 @@ class RealImapConnection implements ImapConnection {

    @Override
    @NotNull
    public List<ImapResponse> executeSimpleCommand(@NotNull String command) throws IOException, MessagingException {
    public synchronized List<ImapResponse> executeSimpleCommand(@NotNull String command)
            throws IOException, MessagingException {
        return executeSimpleCommand(command, false);
    }

@@ -786,8 +789,8 @@ class RealImapConnection implements ImapConnection {

    @Override
    @NotNull
    public List<ImapResponse> executeCommandWithIdSet(@NotNull String commandPrefix, @NotNull String commandSuffix,
            @NotNull Set<Long> ids) throws IOException, MessagingException {
    public synchronized List<ImapResponse> executeCommandWithIdSet(@NotNull String commandPrefix,
            @NotNull String commandSuffix, @NotNull Set<Long> ids) throws IOException, MessagingException {

        GroupedIds groupedIds = IdGrouper.groupIds(ids);
        List<String> splitCommands = ImapCommandSplitter.splitCommand(
@@ -828,7 +831,8 @@ class RealImapConnection implements ImapConnection {

    @Override
    @NotNull
    public String sendCommand(@NotNull String command, boolean sensitive) throws MessagingException, IOException {
    public synchronized String sendCommand(@NotNull String command, boolean sensitive)
            throws MessagingException, IOException {
        try {
            open();

@@ -853,7 +857,7 @@ class RealImapConnection implements ImapConnection {
    }

    @Override
    public void sendContinuation(@NotNull String continuation) throws IOException {
    public synchronized void sendContinuation(@NotNull String continuation) throws IOException {
        outputStream.write(continuation.getBytes());
        outputStream.write('\r');
        outputStream.write('\n');
+19 −6
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package com.fsck.k9.mail.store.imap

import com.fsck.k9.mail.MessagingException
import com.fsck.k9.mail.power.WakeLock
import java.io.IOException
import timber.log.Timber

private const val SOCKET_EXTRA_TIMEOUT_MS = 2 * 60 * 1000L
@@ -59,7 +60,12 @@ internal class RealImapFolderIdler(
    private fun endIdle() {
        if (idleSent && !doneSent) {
            idleRefreshTimer?.cancel()

            try {
                sendDone()
            } catch (e: IOException) {
                Timber.v(e, "%s: IOException while sending DONE", logTag)
            }
        }
    }

@@ -136,19 +142,26 @@ internal class RealImapFolderIdler(
            return
        }

        try {
            sendDone()
        } catch (e: IOException) {
            Timber.v(e, "%s: IOException while sending DONE", logTag)
        }
    }

    @Synchronized
    private fun sendDone() {
        val folder = folder ?: return
        val connection = connectionProvider.getConnection(folder) ?: return

        synchronized(connection) {
            if (connection.isConnected) {
                doneSent = true
                connection.setSocketDefaultReadTimeout()
                connection.sendContinuation("DONE")
            }
        }
    }

    private fun ImapConnection.setSocketIdleReadTimeout() {
        setSocketReadTimeout((idleRefreshTimeoutProvider.idleRefreshTimeoutMs + SOCKET_EXTRA_TIMEOUT_MS).toInt())