I think I've got this message encoded...but I get garbage decode.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Betsy_Zelinger
Posted On:   Friday, June 1, 2001 01:37 AM

I made a message and encoded the attachment as base64... (I think.) The beginning of the attachment comes out like this when I send the message output to a file: ------=_Part_0_4872882.991375222570 Content-Type: application/octet-stream; name=TestrptPublicActualProfiles20010417192350ActPrfl04112001.csv Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=TestrptPublicActualProfiles20010417192350ActPrfl04112001.csv OS8yNS8yMDAxIDM6MjA6MDUgQU0sOS8yNS8yMDAxLDQNCkJVU0hJTEZfQ09BU1QsNC8xMS8yMDAx LDExMy44LDExMy4xMSwxMTIuNDMsMTExLjc0LDExMC45OSwxMTAuMzMsMTA5Ljc3LDEwOS4yOSwx MDguODQsMTA4LjQzLDEwOC4xNCwxMDcuOTgsMTA3Ljg4LDEwNy43NywxMDcuNzMsMTA3Ljc1LDEw    More>>

I made a message and encoded the attachment as base64...
(I think.) The beginning of the attachment comes out like this
when I send the message output to a file:

------=_Part_0_4872882.991375222570
Content-Type: application/octet-stream;
name=TestrptPublicActualProfiles20010417192350ActPrfl04112001.csv
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=TestrptPublicActualProfiles20010417192350ActPrfl04112001.csv

OS8yNS8yMDAxIDM6MjA6MDUgQU0sOS8yNS8yMDAxLDQNCkJVU0hJTEZfQ09BU1QsNC8xMS8yMDAx
LDExMy44LDExMy4xMSwxMTIuNDMsMTExLjc0LDExMC45OSwxMTAuMzMsMTA5Ljc3LDEwOS4yOSwx
MDguODQsMTA4LjQzLDEwOC4xNCwxMDcuOTgsMTA3Ljg4LDEwNy43NywxMDcuNzMsMTA3Ljc1LDEw

But when I try to get it decoded, using this code:

if (message.isMimeType("multipart/*")) {
Multipart multi = (Multipart)message.getContent();
BodyPart firstPart = multi.getBodyPart(0);
BodyPart secondPart = multi.getBodyPart(1);
InputStream fisDecoded = secondPart.getInputStream();
String[] sEncoding = secondPart.getHeader("Content-Transfer-Encoding");
if (sEncoding != null && sEncoding.length > 0) {
fisDecoded = MimeUtility.decode(fisDecoded, sEncoding[0]);
}
String disposition = secondPart.getDisposition();
System.out.println("Am I an attachment??? - disposition is: "+disposition);
printDecoded(fisDecoded);
}

I get nasty looking result (beginning of it):
Am I an attachment??? - disposition is: attachment
????m4????O??? ???????_? D?

Since it should look like this (after the out.print line):
9/25/2001 3:20:05 AM,9/25/2001,4

I am tearing my hair out. Any help would be TOTALLY
appreciated. Thank you.

   <<Less

Re: I think I've got this message encoded...but I get garbage decode.

Posted By:   Betsy_Zelinger  
Posted On:   Friday, June 1, 2001 01:13 PM

Answering myself (Yea, it works now!!)

Finally stumbled on the fact that "secondPart.getInputStream()
has already decoded the data.

So once I dropped off this:
String[] sEncoding = secondPart.getHeader("Content-Transfer-Encoding");
if (sEncoding != null && sEncoding.length > 0) {
fisDecoded = MimeUtility.decode(fisDecoded, sEncoding[0]);
}

I got back what I wanted.
Just answering myself in case anyone else out there has the
same trouble understanding what the heck is being said in
the javadoc for JavaMail.
About | Sitemap | Contact