fix: 解决获取邮件主题时 如果出错导致邮件被删除问题

This commit is contained in:
orgin 2024-02-26 11:08:47 +08:00
parent 5cfa3e62d3
commit 720a9e47ce

View File

@ -83,6 +83,7 @@ public class SpectrumParsingActuator implements Runnable{
@Override
public void run() {
String subject = null;
boolean downloadFlag = false;
try {
//获取邮件主题
subject = emailServiceManager.getMailSubject(message,this.batchesCounter);
@ -97,6 +98,8 @@ public class SpectrumParsingActuator implements Runnable{
//所有邮件都需以.eml格式存储到eml文件夹中
final File emlFile = emailServiceManager.downloadEmailToEmlDir(message, emailCounter.getCurrValue(),this.batchesCounter);
downloadFlag = true;
//保存邮件日志到PG数据库
this.spectrumServiceQuotes.getMailLogService().create(message,emailProperties);
@ -126,13 +129,14 @@ public class SpectrumParsingActuator implements Runnable{
final String emlErrorPath = spectrumServiceQuotes.getSpectrumPathProperties().getEmlErrorPath();
final String finalPath = rootPath+emlErrorPath;
FileOperation.moveFile(emlFile,finalPath,true);
// 删除 key防止下次线程执行删除邮件
spectrumServiceQuotes.getRedisUtil().del(key);
throw new DownloadEmailException("邮件移走后手动抛出DownloadEmailException");
}
}
} catch (Exception e) {
// 如果不是下载导致的失败则删除下载的邮件对象
if(!(e instanceof DownloadEmailException)){
// 如果不是下载导致的失败 并且 下载成功则删除下载的邮件对象
if(!(e instanceof DownloadEmailException) && downloadFlag){
try {
log.error("Remove Email"+ message.getSubject() + StringPool.UNDERSCORE + DateUtils.formatDate(message.getReceivedDate(), "yyyy-MM-dd HH:mm:ss") + StringPool.UNDERSCORE);
} catch (MessagingException ex) {
@ -141,7 +145,11 @@ public class SpectrumParsingActuator implements Runnable{
emailServiceManager.removeMail(message,batchesCounter);
}
//输出异常信息
log.error("邮件处理异常:",e);
try {
log.error("邮件处理异常{},邮件主题:{}", e, message.getSubject());
} catch (MessagingException ex) {
ex.printStackTrace();
}
}finally {
try {
EmailLogEvent expungeEvent = new EmailLogEvent(this.batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,EmailLogManager.DONE);