Hi All,

I am now trying to switch from JavaMail to Mime4j. I want to know what is
the best way (or any samples) to retrieve the message body of a multipart
message?

In Javamail:

MimeMessage message = new MimeMessage(null, inputstream);
Object content = message.getContent();
if (content instanceof Multipart) {
        Multipart multiPart = (Multipart)content;
        for (int i = 0 ; i < multiPart.getCount() ; i++) {
                BodyPart bodyPart = multiPart.getBodyPart(i);
                if 
(bodyPart.getContentType().startsWith("multipart/alternative")) {
                        Multipart subParts = (Multipart) bodypart.getContent();
                        for (int i = 0; i < subParts.getCount(); i++) {
                                // subParts here
                        }
                }
        }
}

In Mime4j, I know there is a MimeParser:

for (int state = stream.getState(); 
                state != MimeTokenStream.T_END_OF_STREAM; 
                state = stream.next()) {
        switch (state) {
                case MimeTokenStream.T_BODY:
                        if 
(stream.getBodyDescriptor().getMimeType().equals("text/html")) {
                                StringBuffer sb = new StringBuffer();
                                BufferedReader br = new BufferedReader(new
InputStreamReader(stream.getInputStream()));
                                String line = null;
                                while ((line = br.readLine()) != null) {
                                        sb.append(new 
String(DecoderUtil.decodeBaseQuotedPrintable(line)));
                                }
                        } else {
                        }
                        break;
        }
}

The codes above is working but I think there exist some better way get Html
body. Codes about created many temp 'line' objects which is not good in
performance.

Please advise.

Regards,
Ken

-- 
View this message in context: 
http://old.nabble.com/-mime4j--how-to-retrieve-multipart%27s-html-body-tp29130037p29130037.html
Sent from the James - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to