Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Extract parts from a Multipart/Related email using Java Mail API
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Edwinah63, post: 3064007"] Hi everyone, Thanks for everyone's replies. I should have included a code snippet - I do know how to pull apart emails according to their mime body part, but my question is how to further extract the various headers (thanks to Derek above for this suggestion) a body part that is coded multipart/related - the email body contains both Text and an embedded Image code snippet (apologies how it pasted): BTW what is that post with all the links in it by arabzwaj50?) //logon to pop3 server //connect to store //open inbox folder Message messages[] = inboxFolder.getMessages(); for (int i=0, n=messages.length; i<n; i++) { Object content = messagePart.getContent(); if (content instanceof Multipart) { processMultipartContent(content, myNote); //myNote is object to hold parts/subject etc } else { //not multipart email String contentType = messagePart.getContentType(); if (contentType.startsWith("text/plain") || contentType.startsWith("text/html")) { myNote.setMsgBody((String) messagePart.getContent()); } } //save myNote to database etc //process the multipart - works for everything except text with inline object eg company email with text and company logo in body of email private static void processMultipartContent(Object content, Note nt) { Part[] pa = null; int i = 0; Part p = null; try { //loop through body parts Multipart mp = (Multipart) content; pa = new Part[mp.getCount()]; for(int j = 0; j< mp.getCount(); j++ ) { p = mp.getBodyPart(j); System.out.println(p.getContentType()); // this code works fine except for emails with inline attachements and messages if (p.getContentType().startsWith("text/plain") || p.getContentType().startsWith("text/html")) { nt.setMsgBody(nt.getMsgBody() + " " + (String) p.getContent()); } else //save all other mime content types to directory { //this is where the body of multipart/related email is getting put together into a single part at the moment. This is where I need help on how to loop thru multipart/related headers(?) pa[i] = p; i++; } } //end for } catch(Exception e){e.printStackTrace();} finally { //add array attachments nt.attachments = pa; //clean up p = null; pa = null; } } //processMultipartContent }[/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Extract parts from a Multipart/Related email using Java Mail API
Top