org.apache.commons.mail.util.mimemessageparser永无止境

发布于 2025-01-21 11:47:29 字数 1446 浏览 4 评论 0原文

我有一些代码来解析传入的邮件。我使用org.apache.commons.mail.util.mimemessageparser为此。问题出现在以下方法中:

private String getActionDescription(Message message) throws Exception {
    MimeMessage mimeMessage = (MimeMessage)message;
    MimeMessageParser mmp = new MimeMessageParser(mimeMessage);
    mmp.parse(); // !!! sometimes my code hangs here; inside this parse method
    String description = mmp.getHtmlContent();
    if(Utils.isNullOrEmpty(description)) {
        description = mmp.getPlainContent();
        if(description != null) {
            description = description.replace("\r\n", "<br>");
        }
    }
    return description;
}

大多数时候它可以正常工作,但是每隔几天我的代码就会粘在mmp.parse()中。我没有任何例外或超时。它只是停止。

任何人都可以阐明这一点吗?

亲切的问候。

PS:如果您需要更多信息,请询问,我将在此处添加。

Apache Jar版本:Commons-Email-1.5.jar

JDK版本:11

我的导入:

import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;

import org.apache.commons.mail.util.MimeMessageParser;

I have some code to parse incoming mails. I use org.apache.commons.mail.util.MimeMessageParser for this.The problem occurs in the following method:

private String getActionDescription(Message message) throws Exception {
    MimeMessage mimeMessage = (MimeMessage)message;
    MimeMessageParser mmp = new MimeMessageParser(mimeMessage);
    mmp.parse(); // !!! sometimes my code hangs here; inside this parse method
    String description = mmp.getHtmlContent();
    if(Utils.isNullOrEmpty(description)) {
        description = mmp.getPlainContent();
        if(description != null) {
            description = description.replace("\r\n", "<br>");
        }
    }
    return description;
}

Most of the time it works fine, but every few days my code gets stuck inside mmp.parse(). I don't get any exception or timeout. It just stops.

Anyone can shed any light on this?

Kind regards.

P.S.: if you need more info, just ask and I'll add it here.

apache jar version: commons-email-1.5.jar

jdk version: 11

my imports:

import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;

import org.apache.commons.mail.util.MimeMessageParser;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他夏了夏天 2025-01-28 11:47:29

在获得邮件会话时添加以下属性解决了问题:

mail.imap.partialfetch false
mail.imap.fetchsize 1048576

带有大附件的邮件极大地减慢了解析。这些设置大大改进了邮件服务器的网络IO,以获得大型附件。

adding following properties when getting a mail session solved the problem:

mail.imap.partialfetch false
mail.imap.fetchsize 1048576

Mails with big attachments slowed parsing down extremely. These settings greatly improved network IO to the mail server for big attachments.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文