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
Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

message access from custom app works on 8800, 8100 but not on 8330

I'm using this piece of sample code found on the developer knowledge site or was it from the JED samples for viewing messages.

 

 

//add a field describing the source service ServiceConfiguration sc = message.getFolder().getStore().getServiceConfiguration(); EditField service = new EditField("Service: ", sc.getName(), 128, EditField.READONLY); add(service); //add the folder field EditField folder = new EditField("Folder: ", message.getFolder().getName(), 128, EditField.READONLY); add(folder); //Status Field String statusString = getStatusString(message); //we're looking for the read status here EditField status = new EditField("Status:", statusString, 128, EditField.READONLY); add(status); //The date field - when was it sent? String sent = Util.getDateAsString(message.getSentDate(), DateFormat.DATETIME_DEFAULT); if ( sent != null ) { EditField sentDate = new EditField("Date: ", sent, EditField.DEFAULT_MAXCHARS, style); add(sentDate); } //To fields try { Address[] toAddresses = message.getRecipients(Message.RecipientType.TO); int length = toAddresses.length; for (int i = 0; i < length; ++i) { String name = toAddresses[i].getName(); if ( name == null || name.length() == 0 ) name = toAddresses[i].getAddr(); EditField to = new EditField("To: ", name, EditField.DEFAULT_MAXCHARS, style); //add the address to this field for later use to.setCookie(toAddresses[i]); add(to); } } catch (MessagingException e) { System.err.println(e); } if ( message.isInbound() ) { try { //received message, who's it from? Address from = message.getFrom(); String name = from.getName(); if ( name == null || name.length() == 0 ) name = from.getAddr(); EditField fromField = new EditField("From: ", name, EditField.DEFAULT_MAXCHARS, style); fromField.setCookie(from); add(fromField); } catch (MessagingException e) { System.err.println(e); } } String subject = message.getSubject(); //always display the subject field even if blank EditField subjectField = new EditField("Subject: ", subject == null ? "" : subject, EditField.DEFAULT_MAXCHARS, style); add(subjectField); //add a separator to separate headers from the body add(new SeparatorField()); //now extract the body and any attachments Object o = message.getContent(); if ( o instanceof String ) { add(new RichTextField((String)o)); } else if ( o instanceof TextBodyPart ) { TextBodyPart tbp = (TextBodyPart)o; String body = (String)tbp.getContent(); add(new RichTextField(body)); } else if ( o instanceof Multipart ) { Multipart mp = (Multipart)o; int count = mp.getCount(); Vector otherfields = new Vector(count); //at most count fields, (possibly) one text part for (int i = 0; i < count; ++i) { BodyPart p = mp.getBodyPart(i); if ( p instanceof TextBodyPart ) { //make sure we always add the text part first! String s = (String)p.getContent(); add(new RichTextField(s)); } else if ( p instanceof UnsupportedAttachmentPart || p instanceof SupportedAttachmentPart ) { //don't add these parts yet, we want the text body part to show up first String name = null; String ctype = null; if ( p instanceof UnsupportedAttachmentPart ) { UnsupportedAttachmentPart uap = (UnsupportedAttachmentPart)p; name = uap.getName(); ctype = uap.getContentType(); } else if ( p instanceof SupportedAttachmentPart ) { SupportedAttachmentPart sap = (SupportedAttachmentPart)p; name = sap.getName(); ctype = sap.getContentType(); } otherfields.addElement(new SeparatorField()); StringBuffer sb = new StringBuffer(ctype); sb.append('['); sb.append(name); sb.append(']'); otherfields.addElement(new RichTextField(sb.toString())); } else if ( p instanceof ContactAttachmentPart) { otherfields.addElement(new SeparatorField()); Contact c = (Contact)p.getContent(); StringBuffer sb = new StringBuffer("LABEL"); String[] name = c.getStringArray(Contact.NAME, 0); boolean found = false; String nameseg; if ((nameseg = name[Contact.NAME_PREFIX]) != null) { sb.append(nameseg); found = true; } if ((nameseg = name[Contact.NAME_GIVEN]) != null) { if (found) { sb.append(' '); } sb.append(nameseg); found = true; } if ((nameseg = name[Contact.NAME_FAMILY]) != null) { if (found) { sb.append(' '); } sb.append(nameseg); } RichTextField contactAttachment = new RichTextField(sb.toString()); contactAttachment.setCookie(c); otherfields.addElement(contactAttachment); } } //add the list of fields just extracted, we do this so that the body part is first int size = otherfields.size(); for (int i = 0; i < size; ++i) { add((Field)otherfields.elementAt(i)); } }

 

The code works fine on my 8800 Cingular and 8100 TMobile device but for some reason the body part of the message is missing when run on 8330. I can't run it through the debugger connected with the 8330 as the user is on the other side of the planet. I did run it in the 8330 simulator and it seems to be working.

 

 

 

Does anyone know if the type of mail service BES/Exchange vs Internet mails service will affect the code above? or what might i try to figure out where the problem is.

 

thanks

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: message access from custom app works on 8800, 8100 but not on 8330

Just a guess, but is the 8330 running OS 4.5?

 

The way that text body parts are handled changed in 4.5. The text in most email messages is now an HTML attachment.

 

Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

Re: message access from custom app works on 8800, 8100 but not on 8330

I was afraid it was something like that. Thanks for the info RexDoug.
I saw an example that handled both regular and html messages.
I’ll try to find it.

Thanks.
Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

Re: message access from custom app works on 8800, 8100 but not on 8330

[ Edited ]

One question...

 

Is there a way to connect devices to JDE or ESS to simulate message receive on the device?

 

I have a couple of devices ranging from OS 4.5 - 4.7 that i want to test my message reading app on but these units are not live and not connected to a bes.

 

 

thanks.

 

 

Message Edited by ipcTony on 11-26-2008 02:31 PM
Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

Re: message access from custom app works on 8800, 8100 but not on 8330

With the information about html message I updated my demo application to accomidate html and plain text messages. Running in the JDE 4.5 8330 simultor i can see that html message in the simulator mail application looks the same as when viewing from my demo application. However my associate that has a real 8330 in the UK is saying that html messages are not being displayed correctly and is being displayed as html code. 

 

anyone run in to similar problems with displaying html messages?

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: message access from custom app works on 8800, 8100 but not on 8330

Here is the problem: you cannot activate HTML messages on the simulator, but you can on the actual device. Consequently, there is no way for you to duplicate his isssue on your simulator.

 

What you need to do is parse out the HTML and extract the "text" nodes.

 

You can use the SAX parser, or a quicker way is to use the DOM API and just walk the DOM tree looking for the text nodes.

 

Check the API docs for Document, DocumentBuilder, DocumentBuilderFactory, etc.

 

Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

Re: message access from custom app works on 8800, 8100 but not on 8330

Thanks for the eplanation RexDoug. I thought the example using MimeBodyPart was the answer to the html parsing. I'll take a look at both SAX and DOM methods.
Highlighted
Developer
Posts: 107
Registered: ‎08-08-2008
My Device: Not Specified

Re: message access from custom app works on 8800, 8100 but not on 8330

[ Edited ]

I was wondering if someone can past an example of the bodypart for an HTML message for OS 4.5 here.

 

I'm trying to debug my demo app that reads an email message and sends it to one of our bluetooth printers using a Blackberry 8300 OS 4.5 but I don't have a live device to work with. I'm currently using an 8800 OS 4.2

 

I'm thinking of replacing the XMLDemo xml file with this HTML bodypart sample but I don't know what the message bodypart look like with html codes.

 

I tried pasting an html message from my outlook but that does not seem to work.

 

thanks.

 

 

Message Edited by ipcTony on 12-03-2008 02:22 PM