java邮件解析库,Java电子邮件解析器?

Is anyone familiar with a Java library that helps with parsing the fields (date, subject, from, to) of the email below?

Message-ID: <19815303.1075861029555.JavaMail.ss@kk>

Date: Wed, 6 Mar 2010 12:32:20 -0800 (PST)

From: someone@someotherplace.com

To: someone@someplace.com

Subject: some subject

Mime-Version: 1.0

Content-Type: text/plain; charset=us-ascii

Content-Transfer-Encoding: 7bit

X-From: one, some

X-To: one

X-cc:

X-bcc:

X-Folder: Bob\Inbox

X-Origin: Bob-R

X-FileName: rbob (Non-Privileged).pst

some message

解决方案

JavaMail is an oracle library that provides mail services and mail related services (like parsing conventional & MIME messages) in the javax.mail package. Additionally Apache has a Commons Email library for mail handling.

In the JavaMail api, a simple way to parse a string containing an email message (which may or may not be explicitly MIME) would be as follows

String content = ...

Session s = Session.getDefaultInstance(new Properties());

InputStream is = new ByteArrayInputStream(content.getBytes());

MimeMessage message = new MimeMessage(s, is);

and parsing the headers could be done like this

message.getAllHeaderLines();

for (Enumeration e = message.getAllHeaders(); e.hasMoreElements();) {

Header h = e.nextElement();

h.getName();

h.getValue();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值