You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by "Ken--@newsgroupstats.hk" <dr...@gmail.com> on 2010/07/11 09:35:36 UTC
[mime4j] how to retrieve multipart's html body
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: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org