|
40 | 40 | import com.google.api.services.gmail.Gmail; |
41 | 41 | import com.google.api.services.gmail.model.ListMessagesResponse; |
42 | 42 | import com.sun.mail.imap.IMAPFolder; |
| 43 | +import com.sun.mail.util.MailConnectException; |
43 | 44 |
|
44 | 45 | import org.apache.commons.io.IOUtils; |
45 | 46 |
|
|
68 | 69 | import javax.mail.internet.MimeBodyPart; |
69 | 70 | import javax.mail.internet.MimeMessage; |
70 | 71 | import javax.mail.internet.MimeMultipart; |
| 72 | +import javax.net.ssl.SSLException; |
71 | 73 |
|
72 | 74 | /** |
73 | 75 | * @author Denis Bondarenko |
@@ -275,21 +277,38 @@ private void sendQueuedMessages(Context context, AccountDao accountDao, MessageD |
275 | 277 | } |
276 | 278 | } catch (Exception e) { |
277 | 279 | 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); |
289 | 281 |
|
290 | 282 | if (!GeneralUtil.isInternetConnectionAvailable(context)) { |
| 283 | + messageDaoSource.updateMessageState(context, generalMessageDetails.getEmail(), |
| 284 | + generalMessageDetails.getLabel(), generalMessageDetails.getUid(), MessageState.QUEUED); |
| 285 | + |
291 | 286 | publishProgress(true); |
| 287 | + |
292 | 288 | 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); |
293 | 312 | } |
294 | 313 |
|
295 | 314 | Thread.sleep(5000); |
|
0 commit comments