Skip to content

Commit fb23ba1

Browse files
committed
Added handling connection errors during sending the outgoing messages.| #328
1 parent 396bc2b commit fb23ba1

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

FlowCrypt/src/main/java/com/flowcrypt/email/jobscheduler/MessagesSenderJobService.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.google.api.services.gmail.Gmail;
4141
import com.google.api.services.gmail.model.ListMessagesResponse;
4242
import com.sun.mail.imap.IMAPFolder;
43+
import com.sun.mail.util.MailConnectException;
4344

4445
import org.apache.commons.io.IOUtils;
4546

@@ -68,6 +69,7 @@
6869
import javax.mail.internet.MimeBodyPart;
6970
import javax.mail.internet.MimeMessage;
7071
import javax.mail.internet.MimeMultipart;
72+
import javax.net.ssl.SSLException;
7173

7274
/**
7375
* @author Denis Bondarenko
@@ -275,21 +277,38 @@ private void sendQueuedMessages(Context context, AccountDao accountDao, MessageD
275277
}
276278
} catch (Exception e) {
277279
e.printStackTrace();
278-
MessageState newMessageState = MessageState.ERROR_SENDING_FAILED;
279-
280-
if (e.getCause() != null) {
281-
if (e.getCause() instanceof FileNotFoundException) {
282-
newMessageState = MessageState.ERROR_CACHE_PROBLEM;
283-
}
284-
}
285-
286-
messageDaoSource.updateMessageState(context,
287-
generalMessageDetails.getEmail(), generalMessageDetails.getLabel(),
288-
generalMessageDetails.getUid(), newMessageState);
280+
ExceptionUtil.handleError(e);
289281

290282
if (!GeneralUtil.isInternetConnectionAvailable(context)) {
283+
messageDaoSource.updateMessageState(context, generalMessageDetails.getEmail(),
284+
generalMessageDetails.getLabel(), generalMessageDetails.getUid(), MessageState.QUEUED);
285+
291286
publishProgress(true);
287+
292288
break;
289+
} else {
290+
MessageState newMessageState = MessageState.ERROR_SENDING_FAILED;
291+
292+
if (e instanceof MailConnectException) {
293+
newMessageState = MessageState.QUEUED;
294+
}
295+
296+
if (e instanceof MessagingException) {
297+
if (e.getCause() != null) {
298+
if (e.getCause() instanceof SSLException) {
299+
newMessageState = MessageState.QUEUED;
300+
}
301+
}
302+
}
303+
304+
if (e.getCause() != null) {
305+
if (e.getCause() instanceof FileNotFoundException) {
306+
newMessageState = MessageState.ERROR_CACHE_PROBLEM;
307+
}
308+
}
309+
310+
messageDaoSource.updateMessageState(context, generalMessageDetails.getEmail(),
311+
generalMessageDetails.getLabel(), generalMessageDetails.getUid(), newMessageState);
293312
}
294313

295314
Thread.sleep(5000);

0 commit comments

Comments
 (0)