Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi There,

We are reading email content from Java servlet program and for the content types text/plain and text/html it is working fine while getting the content from this code for content type as text/html "
String html = (String) bodyPart.getContent();
"...and for text/plain "
result = (String) bodyPart.getContent();
" and converting it to html.

Now for the content type text/enriched wrote the below code to retrieve the content
"
InputStream is = (InputStream) bodyPart.getContent();
		      StringWriter writer = new StringWriter();
		      IOUtils.copy(is, writer);
		      result= writer.toString();
"
Here after getting the content it is formatting as paragraph,means complete content coming as one string.
Can you please help me to get this in proper html format instead of paragraph.

What I have tried:

private static String getTextFromBodyPart(BodyPart bodyPart) throws IOException, MessagingException {
		String result = "";
		if (bodyPart.isMimeType("text/plain")) {
			//result = (String) bodyPart.getContent();
			result = (String) bodyPart.getContent();
			result=txtToHtml(result);
		} else if (bodyPart.isMimeType("text/html")) {
			String html = (String) bodyPart.getContent();
			result = html;
		} 
		else if (bodyPart.isMimeType("text/enriched")) {
		      InputStream is = (InputStream) bodyPart.getContent();
		      StringWriter writer = new StringWriter();
		      IOUtils.copy(is, writer);
		      result= writer.toString();
		     
		
		    }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900