|
@@ -96,12 +96,11 @@ public class AccountServiceImpl implements IAccountService, ServletContextAware
|
|
|
}
|
|
|
|
|
|
while (syncMessageContentList.size() > 0) {
|
|
|
- String remove = null;
|
|
|
+ synchronized (this) {
|
|
|
|
|
|
- try {
|
|
|
- synchronized (this) {
|
|
|
+ String remove = null;
|
|
|
+ try {
|
|
|
ThreadUtil.sleep(1000);
|
|
|
- log.info("下载正文");
|
|
|
remove = syncMessageContentList.remove(0);
|
|
|
if (ObjectUtils.isEmpty(remove)) {
|
|
|
continue;
|
|
@@ -127,12 +126,13 @@ public class AccountServiceImpl implements IAccountService, ServletContextAware
|
|
|
emailMessage.setMessageId(messageId);
|
|
|
emailMessage.setContentSync(true);
|
|
|
emailMessageService.updateById(emailMessage);
|
|
|
- log.info("下载正文成功");
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步正文发生异常:{}", remove, e);
|
|
|
+ ThreadUtil.sleep(3 * 60 * 1000);
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("同步正文发生异常:{}", remove, e);
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
ThreadUtil.sleep(60 * 1000);
|
|
@@ -156,12 +156,11 @@ public class AccountServiceImpl implements IAccountService, ServletContextAware
|
|
|
}
|
|
|
|
|
|
while (syncMessageAttachmentList.size() > 0) {
|
|
|
- String remove = null;
|
|
|
+ synchronized (this) {
|
|
|
|
|
|
- try {
|
|
|
- synchronized (this) {
|
|
|
+ String remove = null;
|
|
|
+ try {
|
|
|
ThreadUtil.sleep(3000);
|
|
|
- log.info("下载附件");
|
|
|
remove = syncMessageAttachmentList.remove(0);
|
|
|
if (ObjectUtil.isEmpty(remove)) {
|
|
|
continue;
|
|
@@ -181,12 +180,12 @@ public class AccountServiceImpl implements IAccountService, ServletContextAware
|
|
|
attachment.setIsDownload(true);
|
|
|
emailMessageAttachmentService.updateById(attachment);
|
|
|
|
|
|
- log.info("下载附件成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("下载附件发生异常:{}", remove, e);
|
|
|
+ ThreadUtil.sleep(3 * 60 * 1000);
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("下载附件发生异常:{}", remove, e);
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
ThreadUtil.sleep(60 * 1000);
|
|
@@ -198,18 +197,17 @@ public class AccountServiceImpl implements IAccountService, ServletContextAware
|
|
|
@Override
|
|
|
public EmailInfo binding(BindingVo bindingVo) {
|
|
|
String email = bindingVo.getEmail();
|
|
|
- EmailInfo emailInfo;
|
|
|
+ EmailInfo emailInfo = emailInfoService.getOne(q -> q.eq(EmailInfo::getEmail, email));
|
|
|
+ // 如果存在,直接返回邮箱信息
|
|
|
+ if (emailInfo != null) {
|
|
|
+ return emailInfo;
|
|
|
+ }
|
|
|
try {
|
|
|
- emailInfo = emailInfoService.getOne(Wrappers.<EmailInfo>lambdaQuery().eq(EmailInfo::getEmail, email));
|
|
|
- // 如果存在,直接返回邮箱信息
|
|
|
- if (emailInfo != null) {
|
|
|
- return emailInfo;
|
|
|
- }
|
|
|
// 保存账号信息到数据库
|
|
|
- emailInfo = this.saveEmailInfo(bindingVo);
|
|
|
+ emailInfo = BeanUtil.copyProperties(bindingVo, EmailInfo.class);
|
|
|
+ emailInfoService.save(emailInfo);
|
|
|
// 添加账号
|
|
|
RetryUtil.execute(() -> EmailEngineUtil.createAccount(bindingVo), 3, 1000L);
|
|
|
-
|
|
|
// redis添加同步进度
|
|
|
this.progressInitialization(bindingVo);
|
|
|
} catch (Exception e) {
|
|
@@ -250,15 +248,6 @@ public class AccountServiceImpl implements IAccountService, ServletContextAware
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 添加邮件信息
|
|
|
- */
|
|
|
- private EmailInfo saveEmailInfo(BindingVo bindingVo) {
|
|
|
- EmailInfo emailInfo = BeanUtil.copyProperties(bindingVo, EmailInfo.class);
|
|
|
- emailInfoService.save(emailInfo);
|
|
|
- return emailInfo;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 同步邮件进度初始化
|
|
|
*/
|
|
|
private void progressInitialization(BindingVo bindingVo) {
|
|
@@ -289,7 +278,7 @@ public class AccountServiceImpl implements IAccountService, ServletContextAware
|
|
|
while (page < pages) {
|
|
|
int itemPage = page;
|
|
|
// 分页获取文件夹邮件
|
|
|
- MessageVo result = RetryUtil.executeT(() -> EmailEngineUtil.getMessageList(email, mailbox, itemPage, SIZE), 5, 5000L);
|
|
|
+ MessageVo result = EmailEngineUtil.getMessageList(email, mailbox, itemPage, SIZE);
|
|
|
// 邮件信息
|
|
|
List<MessageVo.MessagesDTO> messagesDTOList = result.getMessages();
|
|
|
// 批量保存邮件信息
|
|
@@ -301,8 +290,8 @@ public class AccountServiceImpl implements IAccountService, ServletContextAware
|
|
|
ThreadUtil.sleep(1000L);
|
|
|
}
|
|
|
} catch (EmailEngineException e) {
|
|
|
- log.error("下载失败,等待10分钟");
|
|
|
- ThreadUtil.sleep(1000 * 60 * 10);
|
|
|
+ log.error("同步邮件列表失败,等待3分钟");
|
|
|
+ ThreadUtil.sleep(1000 * 60 * 3);
|
|
|
asyncReadEmail(emailInfoId, bindingVo, page);
|
|
|
} catch (Exception e) {
|
|
|
log.error("未知原因同步邮件失败:{}", email, e);
|