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

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

Merge pull request #6283 from thundernest/outbox_logging

Fix error reporting for send failures
parents 5e977f3a c80254f3
Loading
Loading
Loading
Loading
+13 −16
Original line number Diff line number Diff line
@@ -1501,7 +1501,6 @@ public class MessagingController {
    @VisibleForTesting
    protected void sendPendingMessagesSynchronous(final Account account) {
        Exception lastFailure = null;
        boolean wasPermanentFailure = false;
        try {
            if (isAuthenticationProblem(account, false)) {
                Timber.d("Authentication will fail. Skip sending messages.");
@@ -1551,10 +1550,16 @@ public class MessagingController {
                    long messageId = message.getDatabaseId();
                    OutboxState outboxState = outboxStateRepository.getOutboxState(messageId);

                    if (outboxState.getSendState() != SendState.READY) {
                        Timber.v("Skipping sending message %s", message.getUid());
                        notificationController.showSendFailedNotification(account,
                                new MessagingException(message.getSubject()));
                    SendState sendState = outboxState.getSendState();
                    if (sendState != SendState.READY) {
                        Timber.v("Skipping sending message %s (reason: %s)", message.getUid(),
                                sendState.getDatabaseName());

                        if (sendState == SendState.RETRIES_EXCEEDED) {
                            lastFailure = new MessagingException("Retries exceeded", true);
                        } else {
                            lastFailure = new MessagingException(outboxState.getSendError(), true);
                        }
                        continue;
                    }

@@ -1587,22 +1592,19 @@ public class MessagingController {
                    } catch (AuthenticationFailedException e) {
                        outboxStateRepository.decrementSendAttempts(messageId);
                        lastFailure = e;
                        wasPermanentFailure = false;

                        handleAuthenticationFailure(account, false);
                        handleSendFailure(account, localFolder, message, e);
                    } catch (CertificateValidationException e) {
                        outboxStateRepository.decrementSendAttempts(messageId);
                        lastFailure = e;
                        wasPermanentFailure = false;

                        notifyUserIfCertificateProblem(account, e, false);
                        handleSendFailure(account, localFolder, message, e);
                    } catch (MessagingException e) {
                        lastFailure = e;
                        wasPermanentFailure = e.isPermanentFailure();

                        if (wasPermanentFailure) {
                        if (e.isPermanentFailure()) {
                            String errorMessage = e.getMessage();
                            outboxStateRepository.setSendAttemptError(messageId, errorMessage);
                        } else if (outboxState.getNumberOfSendAttempts() + 1 >= MAX_SEND_ATTEMPTS) {
@@ -1612,24 +1614,19 @@ public class MessagingController {
                        handleSendFailure(account, localFolder, message, e);
                    } catch (Exception e) {
                        lastFailure = e;
                        wasPermanentFailure = true;

                        handleSendFailure(account, localFolder, message, e);
                    }
                } catch (Exception e) {
                    lastFailure = e;
                    wasPermanentFailure = false;

                    Timber.e(e, "Failed to fetch message for sending");
                    notifySynchronizeMailboxFailed(account, localFolder, e);
                }
            }

            if (lastFailure != null) {
                if (wasPermanentFailure) {
                notificationController.showSendFailedNotification(account, lastFailure);
                } else {
                    notificationController.showSendFailedNotification(account, lastFailure);
                }
            }
        } catch (Exception e) {
            Timber.v(e, "Failed to send pending messages");