Save body mails in txt files : problem with multipart/alternative
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alfred_Sniff
Posted On:   Thursday, August 11, 2005 10:03 AM

Hi all, I've make a little program which get mails from a pop3 (or imap) adress. Then, for each mail, I save the mail into a txt file, and attachment in their format (pdf, doc, xls...). It works, but when there is no attachment, i've got two files instead of one... one correctly format with html code and an other written on one line.... Why do I get two files for a simple message? I've made a loop like that : NbFic=1; for (int u=0;u { if (content instanceof Multipart) { messagePart=((Multipart)content).getBodyPart(u); NbFic=((Multipart)content).getCount(); } if (contentType.startsWith("text/plain")|| contentType.startsWith("text/html&qu   More>>

Hi all,

I've make a little program which get mails from a pop3 (or imap) adress. Then, for each mail, I save the mail into a txt file, and attachment in their format (pdf, doc, xls...). It works, but when there is no attachment, i've got two files instead of one... one correctly format with html code and an other written on one line....


Why do I get two files for a simple message? I've made a loop like that :

			
NbFic=1;
for (int u=0;u
{
if (content instanceof Multipart)
{
messagePart=((Multipart)content).getBodyPart(u);
NbFic=((Multipart)content).getCount();
}
if (contentType.startsWith("text/plain")|| contentType.startsWith("text/html"))
{..}
else{..} //case of others files format



It means that for a mail without attachment I got an attachment html code file, isn't it? (NB : I test it with Outlook)


When I have a mail with 1 or more attachment, I can't get the body of my mail in a text/plain or text/html... It's always a multipart/alternative... I save my files in txt and I don't want the text of the multipart/alternative, I just want the body of the mail... How can I convert the multipart/alternative file in a txt file (with only the html part or text/plain part)...


I hope I will be understand (i will improve my english for next time I swear it:))
Thanks in advance for all your answers    <<Less

Re: Save body mails in txt files : problem with multipart/alternative

Posted By:   Almagest_FUTT  
Posted On:   Thursday, August 11, 2005 10:25 AM

First, mind you you're building a tool that'll work with Outlook's messages and those only (if i remember right, Outlook is kind of wayward concerning message formats).

Second, i believe looking at the message's code will provide some answers for your problems.

Third, i think it'd be a better idea to save the message code as a whole and extract parts of it on demand. I believe there are too much message variants depending on program/os to have a properly functioning/flexible tool using your approach.
About | Sitemap | Contact