Skip to content

Commit

Permalink
[backend] Add retry on imap connexion (#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomuDeuxfois authored Sep 25, 2024
1 parent 7142c8b commit 209fddc
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ private void synchronizeBox(Folder inbox, Boolean isSent) throws Exception {
}

private void syncFolders() throws Exception {
try {
// Sync sent
Folder sentBox = imapStore.getFolder(sentFolder);
sentBox.open(Folder.READ_ONLY);
Expand All @@ -307,6 +308,23 @@ private void syncFolders() throws Exception {
inbox.open(Folder.READ_ONLY);
synchronizeBox(inbox, false);
}
} catch (MessagingException e) {
log.warning("Connection failure: " + e.getMessage());
// Retry logic or rethrow the exception
retrySyncFolders();
}
}

private void retrySyncFolders() throws Exception {
for (int i = 0; i < 3; i++) {
try {
syncFolders();
break;
} catch (MessagingException e) {
log.warning("Retrying connection..." + e.getMessage());
Thread.sleep(2000);
}
}
}

// Sync folders every 10 sec
Expand Down

0 comments on commit 209fddc

Please sign in to comment.