JavaMail - 获取正文文本为第一部分返回null

时间:2013-01-28 15:38:11

标签: java null javamail multipart mime-message

我编写了一个方法,以递归方式将BodyPart消息的多个Multipart的内容添加到字符串中。我不知道为什么,但字符串中的第一个短语是null - 为什么?

代码:

protected void dumpPart(Part p, Email email) throws MessagingException, IOException
    {
        if (p.isMimeType("text/plain"))
        {
            if (!p.getContent().toString().equals(null))
                email.setBody((String)p.getContent());
        }
        else if (p.isMimeType("multipart/*"))
        {
            Multipart mp = (Multipart)p.getContent();

            for (int x = 0; x < mp.getCount(); x++)
            {
                dumpPart(mp.getBodyPart(x), email);
            }
        }
    }

输出:

nullWe did not answer protests to our Order 637 filing...

1 个答案:

答案 0 :(得分:0)

“p.getContent()。toString()。equals(null)”总是假的。

email.setBody做什么?