简体   繁体   English

备用Java客户端库到JavaMail?

[英]Alternate Java Client library to JavaMail?

I'm running into a very strange issue. 我遇到了一个非常奇怪的问题。 Basically what happens is that I'm using java mail to scan through a mailbox using IMAP, examining each email, looking for attachments and then reading the ones I'm interested in. The code works... Except on certain Windows 7 machines, but it works on most W7 machines. 基本上发生的事情是我使用java邮件使用IMAP扫描邮箱,检查每封电子邮件,查找附件然后阅读我感兴趣的邮件。代码可以工作......除了在某些Windows 7计算机上,但它适用于大多数W7机器。

What is strange is the exception (see below). 奇怪的是异常(见下文)。

com.sun.mail.util.DecodingException: BASE64Decoder: Error in encoded stream: found valid base64 character after a padding character (=), the 10 most recent characters were: "am; name=9"
        at com.sun.mail.util.BASE64DecoderStream.decode(BASE64DecoderStream.java
:305)
        at com.sun.mail.util.BASE64DecoderStream.read(BASE64DecoderStream.java:1
44)
        at java.io.FilterInputStream.read(Unknown Source)

It seems that the base64 decode stream is trying to decode the attachement, but starts to read the base64 block at the part's header: the "am; name=9" in the exception seems to be the part in the header where the name of the file (starting indeed with "9") is defined. 似乎base64解码流正在尝试解码附件,但是开始在部件的标题处读取base64块:异常中的“am; name = 9”似乎是标题中的部分名称文件(以“9”开头)定义。

Copied from the application's log: "Found attachement 90TXSJ.zip" 从应用程序的日志中复制: “Found attachement 90TXSJ.zip”

I've tried to find a hook into the mail code to get my hands on the InputStream to filter out the header some how, but that seems quite impossible. 我试图在邮件代码中找到一个钩子来获取InputStream来过滤掉标题的一些方法,但这似乎是不可能的。

So, is there another IMAP client implementation that does not use Java mail? 那么,是否有另一个不使用Java邮件的IMAP客户端实现? Or does anyone know how I can get between the raw stream and the Base64 decoder? 或者有谁知道如何在原始流和Base64解码器之间获得?

An alternative that you probably didn't know about is Apache JAMES . 您可能不知道的另一种选择是Apache JAMES Instead of polling an IMAP or POP3 email account, JAMES allows you to implement your own Mailet . JAMES不允许轮询IMAP或POP3电子邮件帐户,而是允许您实施自己的Mailet A Mailet is the SMTP equivalent of an HTTP Servlet. Mailet是HTTP Servlet的SMTP等价物。

About a decade ago, I worked on a project that needed to integrate into the corporate infrastructure and auto-publish email content to a searchable database (opt-in, to make it easier to comply with reporting requirements). 大约十年前,我参与了一个项目,该项目需要集成到企业基础架构中,并将电子邮件内容自动发布到可搜索的数据库(选择加入,以便更容易遵守报告要求)。 We initially attempted to go down the JavaMail path but we quickly ran into issues with scalability, security constraints, and robustness. 我们最初尝试沿着JavaMail路径走下去,但我们很快遇到了可伸缩性,安全性约束和健壮性问题。

Installing Apache JAMES wasn't too difficult, and we could easily deploy updates to our mailet on the fly. 安装Apache JAMES并不太困难,我们可以轻松地将更新部署到我们的mailet上。 In our case, we repackaged the incoming email into our own POJO and serialized that through a java message queue. 在我们的例子中,我们将传入的电子邮件重新打包到我们自己的POJO中,并通过java消息队列进行序列化。 We were able to distribute the actual processing load pretty well coming off of the queue. 我们能够很好地分配实际的处理负载。

The Mailet uses a Matcher which you define to determine if you want to process an incoming message or not. Mailet使用您定义的匹配器来确定是否要处理传入消息。 The Matcher makes its decision using the provided Mail object. Matcher使用提供的Mail对象做出决定。 If the matcher approves the message, it's sent to your mailet to process. 如果匹配器批准该消息,则将其发送给您的mailet进行处理。

The Mail object contains access to the standard javax.mail.internet.MimeMessage which in turn has a getInputStream() for the decoded message and a getRawInputStream() to get the message as it was sent to the server. Mail对象包含对标准javax.mail.internet.MimeMessage访问权限,该标准javax.mail.internet.MimeMessage具有解码消息的getInputStream()getRawInputStream()以获取发送到服务器的消息。 We maid use of these since we had to extract attachments, virus scan them, and then upload them to our searchable database associated with the right message. 我们使用这些,因为我们必须提取附件,病毒扫描它们,然后将它们上传到与正确消息相关联的可搜索数据库。

I think you'll find a bit more freedom with this approach, as JAMES is an SMTP server and you don't have to hold mail in an inbox that needs to be periodically cleaned. 我认为你会发现这种方法更加自由,因为JAMES是一个SMTP服务器,你不必在需要定期清理的收件箱中保存邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM