在做javamail通过pop3解析邮件的时候,在解析邮件包含附件的时候,在测试服务器上出现了以下异常
Missing start boundary
javax.mail.MessagingException: Missing start boundary
at javax.mail.internet.MimeMultipart.parse(MimeMultipart.java:297)
at javax.mail.internet.MimeMultipart.getCount(MimeMultipart.java:159)
at com.gdcn.mail.util.Pop3Util.getAttachments(Pop3Util.java:1937)
at com.gdcn.mail.util.Pop3Util.analysisMessage(Pop3Util.java:1455)
at com.gdcn.mail.util.Pop3Util.getMessages3(Pop3Util.java:611)
at com.gdcn.mail.service.impl.MailServicePop3Impl.fetchMail(MailServicePop3Impl.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy6.fetchMail(Unknown Source)
at com.gdcn.mail.push.FetchMailTask.run(FetchMailTask.java:31)
at com.gdcn.mail.push.ThreadPool$PoolWorker.run(ThreadPool.java:223)
出现异常的邮件
HMM_SOURCE_IP: 10.27.101.6:46499.1351811048
HMM_ATTACHE_NUM: 0002
HMM_SOURCE_TYPE: SMTP
Received: from entas6-mta (unknown [10.27.101.6]) by corp.21cn.com (HERMES) with ESMTP id 79F701A4821 for <gdcm@gdccs.com.cn>; Tue, 1 Sep 2009 17:21:40 +0800 (CST)
Received: from m13-86.163.com([220.181.13.86]) by entas6-mta(Knowledge-based Antispam Gateway 2.127s34(2009-06-12),121.14.129.76) with ESMTP id mx28123.1251796900 for <gdcm@gdccs.com.cn>; Tue, 01 Sep 2009 17:21:40 +0800
X-Original-MailFrom: mdbjz@163.com
Received: from mdbjz ( [59.41.140.125] ) by ajax-webmail-wmsvr86 (Coremail) ; Tue, 1 Sep 2009 17:21:37 +0800 (CST)
Date: Tue, 1 Sep 2009 17:21:37 +0800 (CST)
From: =?GBK?B?sPy93NbQ?= <mdbjz@163.com>
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830
To: "gdcm" <gdcm@gdccs.com.cn>
Message-ID: <18639209.356941251796897159.JavaMail.coremail@bj163app86.163.com>
Subject: =?GBK?B?WyEhIFNQQU1dICA1MMz1suLK1Mr9vt28sNbcsagov6q3ormry74p?=
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_NextPart_000_F2CD_01CA2CBB.C11696B0"
X-Originating-IP: [59.41.140.125]
X-Priority: 1
X-Mailer: Coremail Webmail Server Version XT2_snapshot build 090721(8334.2507.2500) Copyright (c) 2002-2009 www.mailtech.cn 163com
X-CM-CTRLDATA: AojLYWZvb3Rlcl9odG09NTM6MTIy
X-CM-TRANSID: VsGowLB7TgKh55xK0OEWAQ--.13413W
X-CM-SenderInfo: hpgey6i6rwjhhfrp/1tbiSRjQp0iZZ8PSFwAAsW
X-Coremail-Antispam: 1Ur529EdanIXcx71UUUUU7IcSsGvfJTRUUUbk8YjxAI67I2x7xF5VA2z7Wlb7IF0VA0xI801c0E3s0DM7k042IE42xK82IY6r43WwAYjxAI6xAIw28IcVAK0I8IjxAxM7k042IE4IIF72xFxVCS07vE4c8EcI0En4kS14v7M7k042IE4IIF72xFxVCS07vE4c8EcI0Ec7CjxVAaw2AFwI1ln4vEc-sFP3VYkVCFn4kS6r1kJF4UZwAa7VASz4kS-IxE6c8GOVWUur1xGFWl57IF6s8CjcxG0xylFVAaXTZC67ZELSn0mTvEwaV2v3VFvVW8M4kE7xkE3sIEV2x5Mx0Yzs0v6IAIbVCF54CYxVAaw2AFwI1l7xkE3sIEV2xY6xAqzxv26xkF7I0En4kS14v7MxCIbVA2zIxYr2IEbsI20wCS07vEb7Iv0xC_Jr1lV2xY67kC6x804xWlV2xY67AvxsIEeIx0w2Cm54CxMIAIbVAFxVCF77xC64kEw24lV2xY67C26IkvcIIF6IxKo4kEV4ylV2xY62AExVA0xI801c8C04v7MIAIbVAqx4xG64xvF2IEw4CE5I8CrVC2j2WlV2xY6cIj6x8ErcxFaVAv8VWUMIAIbVAv7VC0I7IYx2IY67AKxVWUAVWUtwCS07vEYx0Ex4A2jsIE14v26F4j6r4UJwCS07vE7480Y4vEI4kI2Ix0rVAqx4xJMIAIbVCjxxvEw4WlV2xY6xkIecxEwVAFwVW8uwCS07vEc2IjII80xcxEwVWxJVW3JwCS07vE4c8EcI0En4kS14v26rWUJr0E3s0q3wCS07vE4c8EcI0Ec7CjxVAaw2AFwI0_Ar1UJVCq3s0DMIAIbVCF72vE77IF4wCS07vEx4CE17CEb7AF67AKxVWUJVWUXbIYCTnIWIevJa73U
This is a multi-part message in MIME format.
------=_NextPart_000_F2CD_01CA2CBB.C11696B0
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_F2CE_01CA2CBB.C11696B0"
------=_NextPart_001_F2CE_01CA2CBB.C11696B0
Content-Type: text/plain;
charset="gbk"
Content-Transfer-Encoding: base64
CgoKCgog
------=_NextPart_001_F2CE_01CA2CBB.C11696B0
Content-Type: text/html;
charset="gbk"
Content-Transfer-Encoding: base64
PERJVj48QlI+PEJSPjwvRElWPgo8RElWPjxCUj4KPERJVj4mbmJzcDs8L0RJVj48L0RJVj48YnI+
PGJyPjxzcGFuIHRpdGxlPSJuZXRlYXNlZm9vdGVyIi8+PGhyLz4KPGEgaHJlZj0iaHR0cDovL3d3
dy55ZWFoLm5ldC8/ZnJvbT1mb290ZXIiPsO709C547jmtcTW1cntw+K30dPKz+Qsd3d3LnllYWgu
bmV0PC9hPgo8L3NwYW4+
------=_NextPart_001_F2CE_01CA2CBB.C11696B0--
------=_NextPart_000_F2CD_01CA2CBB.C11696B0
Content-Type: application/vnd.ms-excel;
name="=?GBK?B?uL28/jctus/NrM/uxL/K/b7dytW8r7HtKL2ov6opLnhscw==?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="=?GBK?B?uL28/jctus/NrM/uxL/K/b7dytW8r7HtKL2ov6opLnhscw==?="
0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAADAAAAAQAAAAAAAAAA
EAAAMQEAAAEAAAD+AAAAAAAAAABiAAAA8QAAAP//
///9
NAEAAAMAAAAEAAAABQAAAAYAAAAHAAAACAAAAAkAAAAKAAAACwAAAAwAAAANAAAADgAAAA8A
AAAQAAAAEQAAABIAAAATAAAAFAAAABUAAAAWAAAAFwAAABgAAAAZAAAAGgAAABsAAAAcAAAAHQAA
AB4AAAAfAAAAIAAAACEAAAAiAAAAIwAAACQAAAAlAAAAJgAAACcAAAAoAAAAKQAAACoAAAArAAAA
LAAAAC0AAAAuAAAALwAAADAAAAAxAAAAMgAAADMAAAA0AAAANQAAADYAAAA3AAAAOAAAADkAAAA6
AAAAOwAAADwAAAA9AAAAPgAAAD8AAABAAAAAQQAAAEIAAABDAAAARAAAAEUAAABGAAAARwAAAEgA
AABJAAAASgAAAEsAAABMAAAATQAAAE4AAABPAAAAUAAAAFEAAABSAAAAUwAAAFQAAABVAAAAVgAA
AFcAAABYAAAAWQAAAFoAAABbAAAAXAAAAF0AAABeAAAAXwAAAGAAAABhAAAAYwAAAP3///9kAAAA
ZQAAAGYAAABnAAAAaAAAAGkAAABqAAAAawAAAGwAAABtAAAAbgAAAG8AAABwAAAAcQAAAHIAAABz
AAAAdAAAAHUAAAB2AAAAdwAAAHgAAAB5AAAAegAAAHsAAAB8AAAAfQAAAH4AAAB/AAAAgAAAAFIA
bwBv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1tTTzEAFADcAAAACACQAQAAAACGEgIBi1tTTzEAFAC0AAAA/3+QAQAAAACGEgIBi1tTTzEA
FAC0AAAA/3+QAQAAAACGEgIBi1tTTzEAFADcAAAACACQAQAAAACGEgIBi1tTTzEAFAC0AAAA/3+Q
AQAAAACGEgIBi1tTTzEAFADcAAEACAC8AgAAAACGEgIBi1tTTzEAFACQAQEACAC8AgAAAACGEgIB
i1tTTzEAFADcAAAACACQAQAAAACGEgIBi1tTTzEAFABAAQEACAC8AgAAAACGEgIBi1tTTzEAFADw
(中间部分太长了,省略)
DCgAA/wYJAgAAAAAAwAAAAAAAAEYjAAAATWljcm9zb2Z0IE9mZmljZSBXb3JkIDk3LTIwMDMgzsS1
tQAKAAAATVNXb3JkRG9jABAAAABXb3JkLkRvY3VtZW50LjgA9DmycQAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
------=_NextPart_000_F2CD_01CA2CBB.C11696B0--
但是这个在本机并没有这样的异常出现。网上查了不少帖子,真正能解决这个问题不多。
不过有个帖子给了我点提示
http://forums.sun.com/thread.jspa?forumID=43&threadID=5152319
后来部署到另外一台测试机器上发现能正常解析,于是停掉了原来测试机的杀毒软件,就能正常解析出来了
不过也在解析的时候首先判断了message是否继承与Part接口的
部分节选代码如下
try {
if (msg instanceof Part){
Part part = (Part) msg;
if (part.isMimeType("multipart/*")) {
Multipart mp = (Multipart) part.getContent();
System.out.println(mp);
int count = mp.getCount();
for (int i = 0; i < count; i++) {
Part p = mp.getBodyPart(i);
//某些处理
}
mp = null;
}
}
} catch (MessagingException e) {
...省略