JavaMail decodes quoted printable incorrectly

Hi,

I have a MIME / Multipart message whose content has been encoded as Content-Type: application/ms-tnef;

name="winmail.dat"and

Content-Transfer-Encoding: quoted-printable

This message originated in a windows system.

This message is in a POP3 server.Now i am trying to retrieve this mail from the server into a Unix environment using folder.getMessages() . Now when i see this retrieved message, it is different from the original message that was in the server. can anyone please tell me why?

Further, if i print the original message (the one in the server) as an input stream in the VI editor(unix), it is the same as in seen in the windows environmen. However if i print it as a byteArray, i see ^M characters appended at the end of every sentence. The same is the case with the message which is retireved with folder.getMessages().

can anyone please give me an answer to these questions? is javm,ail tryng to decode the quoted printable and decoding it incorrectly because of the ^M characters?

[1049 byte] By [darchanaa] at [2007-10-3 2:54:28]
# 1
If the only difference in the message is the ^M (CR) characters at the ends of thelines, that's a result of the POP3 protocol requirements. See the JavaMail FAQfor more information about line termination conventions.
bshannona at 2007-7-14 20:43:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Hi No the only difference between the original message and the message retrieved with folder.getMessages() is not only the ^M character. The extracted message is completely different from the original message. It has been modified by the JavaMail API.
darchanaa at 2007-7-14 20:43:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

No, it has not been modified by the JavaMail API. It has most likely

been modified by the server, or possibly by some anti-virus software

running on your computer.

Turn on session debugging (see the JavaMail FAQ) and examine

the protocol trace and you'll see what JavaMail is getting from your

server.

bshannona at 2007-7-14 20:43:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
Hi,Thanks for the information. but how do i check the rotocol trace?
darchanaa at 2007-7-14 20:43:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
As I said, see the JavaMail FAQ for how to do that.
bshannona at 2007-7-14 20:43:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

Hi,

i am doing something like this

session = Session.getInstance(mailProps);

session.setDebug(true);

try {

store = session.getStore(strProtocol);

store.connect(strHost, intPort, strUsername, strPassword);

}

try {

folder = store.getDefaultFolder();

folder = store.getFolder(MAILBOX);

}

try {

totalmessage = folder.getMessageCount();

}

AllMessages =folder.getMessages(1, totalmessage);

This is the protocol trace that i get. it is not printing the message the JavaMail is retrieving from the server. It prints the number of bytes.

[2006-08-21 13:54:10.456] ALL DEBUG: setDebug: JavaMail version 1.3

[2006-08-21 13:54:10.467] ALL C: TOP 1 0

[2006-08-21 13:54:10.475] ALL S: +OK

[2006-08-21 13:54:10.624] ALL C: RETR 1

[2006-08-21 13:54:10.632] ALL S: +OK

[2006-08-21 13:54:11.629] ALL [JDBCOutputStream] baos_init_size: 16384

[2006-08-21 13:54:34.759] ALL C: DELE 1

[2006-08-21 13:54:34.76] ALL S: +OK

[2006-08-21 13:54:34.76] ALL C: QUIT

[2006-08-21 13:54:34.761] ALL S: +OK Microsoft Exchange Server 2003 POP3 server version 6.5.7638.1 signing off.

can you please tell me how to check the exact message that is retrieved? any help would be appreciated

darchanaa at 2007-7-14 20:43:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7
You haven't requested any content from any message so JavaMailhasn't fetched it from the server. The message content is fetchedon demand.Try using the msgshow.java demo program included with theJavaMail download bundle to debug problems such as this.
bshannona at 2007-7-14 20:43:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8
HiThanks a lot for your help. I have been able to print the message and its now obvioius that javamail is decoding the message incorrectly. My problem is now solved and i can answer the questions related to this issue, thnk you.
darchanaa at 2007-7-14 20:43:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9
In what way is JavaMail decoding the message incorrectly?
bshannona at 2007-7-14 20:43:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10

this is what i have done, well almost. its the same code in msghow.java.

Message m = null;

try {

m = folder.getMessage(1);

dumpPart(m);

} catch (IndexOutOfBoundsException iex) {

System.out.println("Message number out of range");

}

public void dumpPart(Part p) throws Exception {

if (p.isMimeType("multipart/*")) {

pr("This is a Multipart");

pr("");

Multipart mp = (Multipart)p.getContent();

int count = mp.getCount();

for (int i = 0; i < count; i++)

dumpPart(mp.getBodyPart(i));

PrintStream ps= session.getDebugOut();

System.out.println("dk6"+ps.toString());

}else{

Object o = p.getContent();

if (o instanceof String) {

pr("This is a string");

pr("");

//System.out.println((String)o);

} else if (o instanceof InputStream) {

pr("This is just an input stream");

pr("");

InputStream is = (InputStream)o;

int c;

while ((c = is.read()) != -1);

//System.out.write(c);

} else {

pr("This is an unknown type");

pr("");

pr(o.toString());

}

}

}

public static void pr(String s) {

System.out.println(s);

}

No this was what the original message was like:

MIME-Version: 1.0

Content-Type: application/ms-tnef;

name="winmail.dat"

Content-Transfer-Encoding: quoted-printable

Content-Disposition: attachment;

filename="winmail.dat"

X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0

Disposition-Notification-To: "xxxx" <xxx@yyy.COM>

X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200

X-MS-TNEF-Correlator: sthsth

Received-SPF: none (xxxx )

x=9F>"=1C=0D=01=06=90=08=00=04=00=00=00=00=00=01=00=01=00=01=07=90=06=00=08=

=00=00=00=E4=04=00=00=00=00=00=00=E8=00=01=08=80=07=00=18=00=00=00IPM.Mic=

rosoft =

Mail.Note=001=08=01=03=90=06=00D=01=00=00=0D=00=00=00=0B=00#=00=01=00=00=00=

=0B=00)=00=01=00=00=00=0B=00=08=0C=00=00=00=00=02=01=1D=0C=01=00=00=00!=00=

=00=00SMTP:GENADMIN@HAM.HAMBURGSUD.COM=00=00=00=00=0B=00=01=0E=01=00=00=00=

=0B=00=0C=0E=01=00=00=00=03=00=14=0E=01=00=00=00=02=01=F8=0F=01=00=00=00=10=

this is what javamail retrieves:

MIME-Version: 1.0^M

Content-Type: multipart/mixed;^M

boundary="-_=_NextPart_001_01C6BC72.EF204E37"^M

Content-class: urn:content-classes:message^M

Subject: .mai^M

Date: Thu, 10 Aug 2006 17:18:44 +0530^M

Message-ID: <xxxx@xxx>^M

X-MS-Has-Attach: yes^M

X-MS-TNEF-Correlator: ^M

Thread-Topic: .mai^M

Thread-Index: Aca5+BhmONr8an58SK2aXd+rCHghYQACzn2gAAXjZxAAizoLMAAEFobgAALHdqAAADpVEAACCmgQAACyC4AAAPQHsA==^M

From: "xxxx"<yyy@zzz.com>^M

To: "xxx" <yyy@zzz.com>^M

^M

This is a multi-part message in MIME format.^M

^M

_=_NextPart_001_01C6BC72.EF204E37^M

Content-Type: text/html;^M

charset="us-ascii"^M

Content-Transfer-Encoding: quoted-printable^M

^M

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =^M

xmlns:o=3D"urn:schemas-microsoft-com:office:office" =^M

xmlns:w=3D"urn:schemas-microsoft-com:office:word" =^M

xmlns=3D"http://www.w3.org/TR/REC-html40">^M

^M

<head>^M

<meta http-equiv=3DContent-Type content=3D"text/html; =^M

charset=3Dus-ascii">^M

<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">^M

<style>^M

<!--^M

/* Font Definitions */^M

@font-face^M

{font-family:Batang;^M

panose-1:2 3 6 0 0 1 1 1 1 1;}^M

@font-face^M

{font-family:"\@Batang";^M

panose-1:0 0 0 0 0 0 0 0 0 0;}^M

/* Style Definitions */^M

p.MsoNormal, li.MsoNormal, div.MsoNormal^M

{margin:0in;^M

margin-bottom:.0001pt;^M

font-size:12.0pt;^M

font-family:"Times New Roman";}^M

a:link, span.MsoHyperlink^M

{color:blue;^M

text-decoration:underline;}^M

a:visited, span.MsoHyperlinkFollowed^M

{color:purple;^M

text-decoration:underline;}^M

span.EmailStyle17^M

{mso-style-type:personal;^M

font-family:Arial;^M

color:windowtext;}^M

</style>^M

^M

</head>^M

^M

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>^M

^M

<div class=3DSection1>^M

^M

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =^M

style=3D'font-size:^M

10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font>

^M

^M

</div>^M

^M

</body>^M

^M

</html>^M

^M

_=_NextPart_001_01C6BC72.EF204E37^M

Content-Type: application/octet-stream;^M

name="388EBAA214474ACBA470D0FE42F5.MAI"^M

Content-Transfer-Encoding: base64^M

Content-Description: 388EBAA214474ACBA470D0FE42F5.MAI^M

Content-Disposition: attachment;^M

filename="388EBAA214474ACBA470D0FE42F5.MAI"^M

^M

UmVjZWl2ZWQ6IHdpdGggTWFpbEVuYWJsZSBQb3N0b2ZmaWNlIENvbm5lY3RvcjsgRnJpLCAyNCBG^M

ZWIgMjAwNiAwMDozOToyOCArMTEwMApSZWNlaXZlZDogZnJvbSBiZWRlbG1haWwwMi5wb3BiZWwu^M

cG9wb3J0cy5iZSAoWzE5NS4xMC4xOC4xMjldKSBieSA0U29sdXRpb25zLmNvbS5hdSB3aXRoIE1h^M

aWxFbmFibGUgRVNNVFA7IEZyaSwgMjQgRmViIDIwMDYgMDA6Mzk6MjAgKzExMDAKUmVjZWl2ZWQ6^M

darchanaa at 2007-7-14 20:43:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 11

The stuff you see JavaMail retrieving in the protocol trace is exactly

what your server is sending. It's not JavaMail that's changing the

message, it's your server. Most likely you're using Exchange, which

is trying to be helpful by converting the Microsoft-specific message

content to a form that other applications can more easily understand.

bshannona at 2007-7-14 20:43:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 12
Hi,It is the exchange server that is doingthe tnef decoding and everything. But id there a workaround this problem? can i somehow retrieve the original mail from the server?
darchanaa at 2007-7-14 20:43:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 13

(in case anyone picks up this thread from a search)

note the mail headers:

Content-Type: application/ms-tnef;

name="winmail.dat"

my understanding is that TNEF is a Microsoft-proprietary mail format.

see:http://www.freeutils.net/source/jtnef/for an API that claims to undertand this format. I haven't tried JTNEF api with javamail yet myself, but will be checking it out soon as I am having this same problem.

i_program_java_all_daya at 2007-7-14 20:43:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...