|
@@ -56,7 +56,7 @@ public class CoreServiceImpl {
|
|
|
private static final long minWaitingTime = 1000 * 30;
|
|
|
// 初始化同步邮件天数
|
|
|
private static final int initDay = 7;
|
|
|
-
|
|
|
+ // 缓存错误次数
|
|
|
private static final Map<String, Integer> map = new ConcurrentHashMap<>();
|
|
|
|
|
|
@AllArgsConstructor
|
|
@@ -84,18 +84,21 @@ public class CoreServiceImpl {
|
|
|
new Thread(this::monitorMail).start();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 邮件同步
|
|
|
+ */
|
|
|
public void monitorMail() {
|
|
|
-
|
|
|
try {
|
|
|
doMonitorMail();
|
|
|
} catch (Exception e) {
|
|
|
log.error("未知异常", e);
|
|
|
}
|
|
|
-
|
|
|
new Thread(this::monitorMail).start();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 执行邮件同步逻辑
|
|
|
+ */
|
|
|
private void doMonitorMail() {
|
|
|
|
|
|
// 开始处理时间
|
|
@@ -213,13 +216,14 @@ public class CoreServiceImpl {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 删除错误次数
|
|
|
map.remove(mailboxId);
|
|
|
|
|
|
} catch (AuthenticationFailedException | MailConnectException exception) {
|
|
|
-
|
|
|
+ // 添加异常次数
|
|
|
map.merge(mailboxId, 1, Integer::sum);
|
|
|
-
|
|
|
Integer num = map.get(mailboxId);
|
|
|
+ // 异常次数连续超过3次,不再同步邮件
|
|
|
if (num >= 3) {
|
|
|
mailboxService.update(Wrappers.<Mailbox>lambdaUpdate()
|
|
|
.eq(Mailbox::getId, mailboxId)
|
|
@@ -247,6 +251,7 @@ public class CoreServiceImpl {
|
|
|
* 拉取邮件
|
|
|
*/
|
|
|
private List<MailInfo> getMailInfoList(MailFolder mailFolder, Message[] messages) throws MessagingException {
|
|
|
+
|
|
|
// 获取最后一次发件id
|
|
|
String lastMessageId = mailFolder.getLastMessageId();
|
|
|
|