从JavaMail消息中预提取预览文本 [英] Prefetch preview text from JavaMail Message

查看:312
本文介绍了从JavaMail消息中预提取预览文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JavaMail 1.5.2从IMAP帐户读取消息.为了减少对主机的请求数量,我预取了一些消息数据,例如发件人",日期",消息ID"等:

I'm using JavaMail 1.5.2 to read messages from IMAP accounts. To reduce the number of requests to the host I prefetch some message data, like From, Date, Message-ID etc.:

Folder folder = store.getFolder("inbox");
folder.open(Folder.READ_ONLY);

FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.CONTENT_INFO);
fp.add("Message-ID");

Message msgs[] = folder.getMessages();
folder.fetch(msgs,fp);

但是,我还想预取内容的一些部分,以便为邮件创建预览文本,而不必加载包含所有附件的完整邮件.例如,我想预取内容的所有部分,这些部分的类型均为文本/纯文本",并且没有附件.有可能吗?

However, I want to also prefetch some parts of the content to create a preview text for the mail without having to load the full message with all attachments. For example, I would like to prefetch all parts of the content that have the type "text/plain" and are no attachments. Is that possible?

PS:我不是要搜索像fp.add(IMAPFolder.FetchProfileItem.MESSAGE)这样的解决方案,因为这将预取带有所有附件的全部消息.

PS: I'm not searching for a solution like fp.add(IMAPFolder.FetchProfileItem.MESSAGE) because this will prefetch the whole message with all attachments.

推荐答案

您必须

You have to retrieve the bodystructure first, then loop across the message structure, check the mime type of each part, and download the parts you want. IMAP lets you download all of the parts using one command, so if Javamail is a little smart, you should be able to do this with two IMAP commands, no matter how many bodyparts you end up wanting to download.

如果您是喜欢看电线流量的类型,则IMAP命令应该类似于a uid fetch 234789 bodystructure,然后是b uid fetch 234789 (body.peek[1.1] body.peek[2]).

The IMAP commands, if you're the type who likes to look at wire traffic, should be something like a uid fetch 234789 bodystructure followed by b uid fetch 234789 (body.peek[1.1] body.peek[2]).

这篇关于从JavaMail消息中预提取预览文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆