Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
GregSmith104
Posts: 20
Registered: ‎01-05-2009
My Device: Not Specified
Accepted Solution

Extract Plain Text from HTML Email

Is there a built-in, direct way of extracting the text of an HTML email as Plain Text?

 

I have read http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800698/How_To_... but I'm always getting the new String((byte[])obj) cast, which is the plain text equivalent of the complete HTML.

 

A quick thought would be cast the Message to a TextMessage and call msg.getPayloadText(), but this seems like more of a hack than an effective approach.

 

Any help would really be appreciated on this.

 

 

Thanks!

Greg

Please use plain text.
New Developer
GregSmith104
Posts: 20
Registered: ‎01-05-2009
My Device: Not Specified

Re: Extract Plain Text from HTML Email

Would it be possible to somehow "Forward" the email in the background and extract the plain text from the forwarded email?
Please use plain text.
Administrator
MSohm
Posts: 14,421
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Extract Plain Text from HTML Email

The text portion of the email message would be found in a different BodyPart.  You may need to perform a more request to instruct the BlackBerry handheld to download the plain text portion of the email message.

 

The BlackBerry handheld would not download both versions of the message on its own.  It needs to be requested by the user or an application.  A user can request this by opening an HTML message and picking Get Plain Text from the menu.  an application can use the Transport.more method to request the other BodyPart be downloaded.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
loswilloz
Posts: 10
Registered: ‎12-18-2008
My Device: Not Specified

Re: Extract Plain Text from HTML Email

I cannot figure out how to programmatically get the 'all text version' of an email with html body parts.

 

Mark, in the previous reply you say that Transport.more can be used for this. Can you or anyone who knows give more insight in how to do this?

Please use plain text.
Developer
baskaraninfo
Posts: 342
Registered: ‎02-04-2009
My Device: BB 8320

Re: Extract Plain Text from HTML Email

Refer the following Transport class api:

 

http://www.blackberry.com/developers/docs/4.7.0api/net/rim/blackberry/api/mail/Transport.html#more(net.rim.blackberry.api.mail.BodyPart, boolean)


Use Search. "Accept Solution" if the problem gets resolved.
Please use plain text.
New Developer
loswilloz
Posts: 10
Registered: ‎12-18-2008
My Device: Not Specified

Re: Extract Plain Text from HTML Email

Well, the thing is that the information given in the java docs indicates that Transport.more( BodyPart bp, boolean requestAll) is used for downloading data of an email's body part bp which has not been completely downloaded yet.

 

So if bp is a plain text body part a call to that method will download plain text, whereas if bp is an html body part it will download html code.

 

What i want is: when the body part bp is an html body part, I want to get it as a plain text (on the device this can be done by selecting menu item 'Get Plain Text' from within an html email screen). From the post in this thread by Mark Sohm, I understand that it is possible to do this in some way.

 

However, the api and other resources on the internet do not clearly show me how to do this.

Please use plain text.
Developer
baskaraninfo
Posts: 342
Registered: ‎02-04-2009
My Device: BB 8320

Re: Extract Plain Text from HTML Email

Please use plain text.
Administrator
MSohm
Posts: 14,421
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Extract Plain Text from HTML Email


loswilloz wrote:

 

 

What i want is: when the body part bp is an html body part, I want to get it as a plain text (on the device this can be done by selecting menu item 'Get Plain Text' from within an html email screen). From the post in this thread by Mark Sohm, I understand that it is possible to do this in some way.

 


There is no method to convert an HTML BodyParty into plain text.  However, if the email message contains both HTML and plain text formats, there will at least 2 BodyParts in the message.  One will be in HTML format, the other plain text.  The example in the KB in the first message shows how to work with both.

 

It is possible that only one BodyPart was delivered to the BlackBerry handheld.  In this case you can use the Transport.more method to request that a BodyPart be downloaded.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
prashantmishra
Posts: 2
Registered: ‎05-26-2009
My Device: Not Specified

Re: Extract Plain Text from HTML Email

I have an email message that contains both HTML and Plain text format and accordingly I am able to retrieve the MimeBodyPart and the TextBodyPart respectively. I am interested to to get the plaintext content in TextBodyPart but getContent() on the TextBodyPart instance returns an empty String. Following the example in KB (How to access HTML email messages) and previous posts I tried using the Transport.more() call. When I call hasMore() on the TextBodyPart instance it returns true but doing Transport.more() on that instance throws a ClassCastException. Hence I am stuck and can't proceed further...

 

Prashant Kumar Mishra
Associate Software Engineer
Geodesic Ltd
Mumbai
Please use plain text.
Developer
johnbibs
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: Extract Plain Text from HTML Email

i'm experiencing the same issue. anybody made this work?
Please use plain text.