Decoding a jpg picture in a text/plain message
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   julien_lamarre
Posted On:   Sunday, September 23, 2001 11:29 AM

Hi, i'm new to jguru. What a nice site! First i hope my bad english won't be a big problem... I'm trying to download jpg pictures from newsgroups with javamail. I use the Knife provider. All is ok when the pictures are attachments and the message type is "multipart/*". But when the picture is encoded in a "text/plain" message i have some problems saving it in a file. I've read a lot of articles on javamail and a lot of questions in this forum but i didn't find what i'm looking for! My problem is to know how to decode the rigth part of the message ( the image part). I've try with MimeUtility.decode(in ,"base64" ) and with MimeUtility.decode(in ,"uuencode   More>>

Hi,
i'm new to jguru. What a nice site!
First i hope my bad english won't be a big problem...



I'm trying to download jpg pictures from newsgroups with javamail.

I use the Knife provider. All is ok when the pictures are attachments and the message type is "multipart/*". But when the picture is encoded in a "text/plain" message i have some problems saving it in a file.


I've read a lot of articles on javamail and a lot of questions in this forum but i didn't find what i'm looking for!
My problem is to know how to decode the rigth part of the message ( the image part). I've try with MimeUtility.decode(in ,"base64" ) and with MimeUtility.decode(in ,"uuencode" ). The resulting file using "uuencode" decoding is a 0 K file. The resulting file with "base64" decoding has a realistic size but is not seen as a image file...


Any help will be really appreciated!

Thanks a lot...



Here's my code:


--------------------------


			
for (int i = 0, n = message.length; i < n ; i++) {
if (message[i].isMimeType("text/plain")) {

int pos1 = -1 ,pos2 = -1 ,posFin = -1 ;
String sautLigne = "
" ;
String contenuString = (String) message[i].getContent() ;

if((pos1 = contenuString.indexOf(sautLigne + "begin ")) == -1)
continue ;

pos2 = contenuString.indexOf(sautLigne,pos1 + 1) ;

if(contenuString.substring(pos1,pos2).indexOf(".jpg") == -1)
continue ;

if((posFin = contenuString.indexOf("`" + sautLigne + "end",pos2)) == -1)
continue ;

contenuString = contenuString.substring(pos2 + 1,posFin) ;

ByteArrayInputStream in= new ByteArrayInputStream( contenuString.getBytes() ) ;

InputStream StringDecoded = MimeUtility.decode(in ,"base64" ) ; //"uuencode");

File fichier = new File("D:\web\test" + i + ".jpg");
fichier.createNewFile();

FileOutputStream fichierOut = new FileOutputStream(fichier) ;

int size= StringDecoded.available() ;
byte[] buff = new byte[size] ;

while(StringDecoded.read(buff) != -1)
fichierOut.write(buff);

fichierOut.flush() ;
fichierOut.close() ;
}
}



----------------------    <<Less

Re: Decoding a jpg picture in a text/plain message

Posted By:   Simon_Ablett  
Posted On:   Wednesday, October 10, 2001 02:46 AM

Julien,

I'm confused. Why are you being sent jpegs as text/plain mail messages? Maybe I have misunderstood the Mime encoding but I would have expected only to find straight ascii text in a message marked in this way. A jpeg image should be marked as image/jpeg.

Regards.

Re: Decoding a jpg picture in a text/plain message

Posted By:   John_Zukowski  
Posted On:   Wednesday, September 26, 2001 08:35 PM

Not that this answers your question, but I've seen some utilities that do this for you already that happen to be written in Java. Wish I remember where I saw them....

Re: Decoding a jpg picture in a text/plain message

Posted By:   julien_lamarre  
Posted On:   Tuesday, September 25, 2001 03:39 PM

I found the beginning of the solution if someone if interrested:
You have to include the line "begin xxx myPicture.jpg" in the string you are trying to decode. Including the "end" line is a good thing too i think.



Instead of "MimeUtility" i use "sun.misc.UUDecoder" and it works...



But now i have new problems, it's WAY too slow... But this is another story!
About | Sitemap | Contact