Javamail appendMessages throws IOException No Content

放肆的年华 提交于 2021-01-27 16:05:06

问题


I'm trying to copy messages from one IMAP store to another.

The line of code that does the actual copying is:

folder.appendMessages(new Message[] { m });

Most messages are copied with no problem, but some fail with:

javax.mail.MessagingException: IOException while appending messages;
  nested exception is:
    java.io.IOException: No content

The stacktrace points to IMAPFolder.java:1767

Some of the messages that were copied successfully were as large as 6MB, while some of the ones that failed were as small as 16KB in my test case, so it is not a size issue.

I'm not certain, but it's possible that the messages that fail has an attachment. The content type multipart/ALTERNATIVE was found in both in the group of messages that failed and the group that succeeded.

Opening the failed messages in a mail client like Thunderbird works properly, so the messages are not corrupted.

UPDATE:

mail.imap.fetchsize plays a role with this problem. When it is the default of 16,384b, running over a sample of 1000 messages the smallest failed message is 16,432b -- slightly over the fetchsize.

When I increased it to 65,536b -- the smallest failed message of that same sample is 65,787b -- slightly over the fetchsize again.

The message with size 16,432b that consistently failed with the default fetchsize, copied successfully with the higher fetchsize, so this is definitely an issue here.


Any idea what causes this problem?

How can I copy the messages with having this issue?

TIA!

p.s. I'm using Java 1.7u71 and Javamail 1.5.2


回答1:


Based on our offline discussion, setting the mail.imap.partialfetch property to false causes it to work. When that happens, it's almost always because the server is broken in some way.

See also:

Javamail Notes under "A list of the known limitations, bugs, issues" sections 4 and 5.

Javamail FAQ, Fetch




回答2:


The bug was fixed in Java Mail 1.6

https://javaee.github.io/javamail/



来源:https://stackoverflow.com/questions/28133124/javamail-appendmessages-throws-ioexception-no-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!