Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JavaMail DecodingException: BASE64Decoder

Stanley.tanSep 12 2017 — edited Sep 17 2017

I searched for this topic before posting it here, but with no luck, all the related solutions can't solve my problem. Therefore, I am here to seek your help. Thanks!

I am new to JavaMail and get stuck on a strange Decoding Exception while fetching some emails (only several in thousands). Have tried to set partialfetch to false, but doesn’t help.  Below is the details:

Env: JavaMail 1.5.5, Jre1.8, Windows 10

Error: throws when call part.getContent():

  1. com.sun.mail.util.DecodingException: BASE64Decoder: Error in encoded stream: needed at least 2 valid base64 characters, but only got 0 before padding character (=), the 10 most recent characters were: "\n\r\n------="

       at com.sun.mail.util.BASE64DecoderStream.decode(BASE64DecoderStream.java:271)

       at com.sun.mail.util.BASE64DecoderStream.read(BASE64DecoderStream.java:144)

       at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)

       at sun.nio.cs.StreamDecoder.implRead(Unknown Source)

       at sun.nio.cs.StreamDecoder.read(Unknown Source)

       at java.io.InputStreamReader.read(Unknown Source)

       at java.io.BufferedReader.fill(Unknown Source)

       at java.io.BufferedReader.readLine(Unknown Source)

       at java.io.BufferedReader.readLine(Unknown Source)

       at com.hulsing.ftms.mail.RecvMail.recvBody(RecvMail.java:580)

I know the mail causing error is spam/ad, and can be ignored. But other email client can display the content so we need to support it as well. Could anyone please advise how to solve the problem? Really appreciate if anyone can shed me some light! Thanks in advance!

PS: below is the original email which causing error:

X-Alimail-AntiSpam:AC=SPAM;BC=0.8302265|0.8990061;BR=01201311R581b1;FP=15954177455743661246|1|1|1|0|-1|-1|-1;HT=e01f04452;MF=info@headstyle.se;NM=1;PH=DM;RN=1;RT=1;SC=80;SR=3;TI=MTA_---0SpwZtZd_1503630838;

Received: from nxcwd.inbox.com(mailfrom:Info@headstyle.se ip:220.197.206.78)

          by mx1.aliyun-inc.com(127.0.0.1);

          Fri, 25 Aug 2017 11:14:01 +0800

From: "Gloria Busby" <Info@headstyle.se>

Date: Fri, 25 Aug 2017 04:14:04 +0100

Content-Language: en

Message-ID: <0010b88357e0$8950a2c2$fb547c76$@headstyle.se>

Content-Type: multipart/alternative; boundary="----=_NextPart_000_0019_01D31D60.2FBEAF73"

Subject: =?utf-8?B?VGhlIFJlc2lzdGFuY2UgUmUtU2hhcGluZyBXb3Jrb3V0cw==?=

To: "hulsingcrm3" <hulsingcrm3@aliyun.com>

MIME-Version: 1.0

E

------=_NextPart_000_0019_01D31D60.2FBEAF73

Content-Transfer-Encoding: base64

Content-Type: text/plain; charset="utf-8"

R3JlZXRpbmdzLCANClJlbWVtYmVyaW5nIHlvdXIgIHdvcmtvdXQgd2lsbCBuZXZlciAgYmUgYSAg

cHJvYmxlbSB3aXRoIG15IE1lbW9yeS1Kb2dnZXIgdmlkZW8gY2xpcHMuDQpUaGVzZSBxdWljayBy

ZWZlcmVuY2UgY2xpcHMgd2lsbCBtYWtlIHN1cmUgeW91ciBmb3JtIGFuZCB0ZWNobmlxdWUgYXJl

IGFsd2F5cyBwZXJmZWN0LCBqdXN0IGxpa2UgIGhhdmluZyBtZSBhcyB5b3VyIG93biBwZXJzb25h

bCB0cmFpbmVyIQ0KbGVhcm5pbmcgbXVjaCBtb3JlIGhlcmUgaHR0cDovL2RhdmVuZXQubmwvc3Rh

ci5waHA/VkhkVVhVRnYNCg0K

------=_NextPart_000_0019_01D31D60.2FBEAF73

Content-Transfer-Encoding: base64

Content-Type: text/html; charset="utf-8"

PGh0bWw+PGJvZHkgbGFuZz0iRU4iPg0KPHAgY2xhc3M9TXNvTm9ybWFsPjxzcGFuIGxhbmc9RU4t

VVM+R3JlZXRpbmdzLCA8bzpwPjwvbzpwPjwvc3Bhbj48L3A+PHAgY2xhc3M9TXNvTm9ybWFsPjxz

cGFuIGxhbmc9RU4tVVM+UmVtZW1iZXJpbmcgeW91ciAgd29ya291dCB3aWxsIG5ldmVyICBiZSBh

ICBwcm9ibGVtIHdpdGggbXkgTWVtb3J5LUpvZ2dlciB2aWRlbyBjbGlwcy48bzpwPjwvbzpwPjwv

c3Bhbj48L3A+PHAgY2xhc3M9TXNvTm9ybWFsPjxzcGFuIGxhbmc9RU4tVVM+VGhlc2UgcXVpY2sg

cmVmZXJlbmNlIGNsaXBzIHdpbGwgbWFrZSBzdXJlIHlvdXIgZm9ybSBhbmQgdGVjaG5pcXVlIGFy

ZSBhbHdheXMgcGVyZmVjdCwganVzdCBsaWtlICBoYXZpbmcgbWUgYXMgeW91ciBvd24gcGVyc29u

YWwgdHJhaW5lciE8bzpwPjwvbzpwPjwvc3Bhbj48L3A+PHAgY2xhc3M9TXNvTm9ybWFsPjxzcGFu

IGxhbmc9RU4tVVM+cmVhZCBtb3JlIGhlcmUgPGEgaHJlZj0iaHR0cDovL2RhdmVuZXQubmwvc3Rh

ci5waHA/VkhkVVhVRnYiPnd3dyBzaXRlPC9hPjxvOnA+PC9vOnA+PC9zcGFuPjwvcD4NCjwvYm9k

eT48L2h0bWw+

  ------=_NextPart_000_0019_01D31D60.2FBEAF73--

This post has been answered by Bill Shannon-Oracle on Sep 12 2017
Jump to Answer

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 15 2017
Added on Sep 12 2017
4 comments
6,320 views