BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-19-2007, 11:46 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default messages to body parts...

Please Login to Remove!

Hello there,

Ok. I am reading messages and processing them successfully. I have a problem whereby not all the data in a message comes into the mail box. I am dealing happily with folders and messages, but am not sure how to go from messages to bodyparts so I can use bp.hasMore(), and then Transport.more(bp, true) to retrieve the rest of it.

My application uses email to send data to the bbery which is being stored and used throughout the application.

I create an instance of the inbox folder, open a messages array with folder.getMessages(); and then use the methods of the message.

Essentially I go from :

net.rim.blackberry.api.mail.Message[] msgs = folder.getMessages();

to looping through the messagesto determine if msgs[i] is meant for the application (as opposed to being a regular email).

My question is this, how can I go from msgs[i] to creating a bodypart that I can use Transport.more for to retrieve the full message?

Thanks in advance!
Offline  
Old 04-20-2007, 01:12 PM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Please help!

Hi folks,

If anybody could explain this to me I'd very much appreciate it!
Offline  
Old 05-14-2007, 07:39 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Folks,

Ok, I figure I've asked the question the wrong way...

I need to read a message and then use the Transport.more method to make sure I get all of it (all the messages the app is interested in will require "more"...).

At the moment I'm using net.rim.blackberry.api.mail.Message[] msgs = folder.getMessages(); to get the emails into an array which I check through and when I find a message I'm "interested" in I read it and parse it.

Instead of a message object though I'd like to have a part message so I can get more before parsing it in my app.

Please, anybody make sense of this?

Thanks in advance...
Offline  
Old 05-24-2007, 09:41 AM   #4 (permalink)
New Member
 
Join Date: Jul 2006
Model: 8700
Carrier: o2 Germany
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Solution?

Hello seekay,

I think I was facing the same problem.

I have registered a FolderListener to the store, to process New Messages, but long mails have been incomplete. Using hasMore() and Transport.more() is the way to go. Here a complete Example how to receive the complete Content of a message

PHP Code:

public class Listener implements FolderListenerMessageListener {

    private 
Store store;

    public 
Listener() {
        
        try {
            
Session session Session.waitForDefaultSession();
            
store session.getStore();
            
store.addFolderListener(this);
        } catch (
Exception e) {
            
// TODO: Errorhandling
        
}
    }

    public 
void destroyInboxListener() {
        if (
store != null) {
            
store.removeFolderListener(this);
        }
    }

    private 
void processEvent(Message message) {
        
Object content message.getContent();
        if (
content instanceof BodyPart) {
            
BodyPart bodyPart = (BodyPartcontent;
            if (
bodyPart.hasMore()) {
                
// message has more parts, wait for them

                
if (!bodyPart.moreRequestSent()) {
                    
// no request for other parts yet

                    // add listener to this message
                    
message.addMessageListener(this);
                    
                    
// request other parts
                    
try {
                        
Transport.more(bodyParttrue);
                    } catch (
Exception e) {
                    }
                }
            } else {
                
// message complete, remove listener
                
message.removeMessageListener(this);
                
                
String complete Content message.getBodyText();

                
//process content here

                //delete the message
                
try {
                    
Folder folder message.getFolder();
                    
folder.deleteMessage(message);
                } catch (
Exception e) {
                    
// TODO: Errorhandling
                
}
            }
        }
    }

    public 
void messagesAdded(FolderEvent event) {
        
processEvent(event.getMessage());
    }

    public 
void changed(MessageEvent event) {
        
processEvent(event.getMessage());
    }

    public 
void messagesRemoved(FolderEvent arg0) {
        
// nothing todo
    
}

Hope this is what you were looking for.

Greetz Matoz
Offline  
Old 06-06-2007, 11:52 AM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a million for replying Matoz, I actually managed to figure it out while In was away on holiday hence why I didn't post the update!

I actually just did a BodyPart msgbp = (BodyPart)msg.getContent(); and took it from there. Simple when you know how, unfortunately I seem to be made to run before I ought to be walking with Java!!!

Many thanks again!
Offline  
Old 06-19-2007, 08:51 AM   #6 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Matoz,

I still have a little problem with this. I'm able to check to see if there's more to the message, and I'm able to get the rest of the message. However when I do A msg.getBodyText(); I still have the original 'short version'.

Just a bit of background. Before I perform the 'hasmore' test I am setting the subject and BodyText of the msg object to variables as I need to test to make sure this message is one of the specially formatted messages I'm 'interested' in.

I have tried creating a new folder and message, but still I'm only getting the same part of the message.

Going into the email application after my application shows that the rest of the message did download, but I don't seem to be able to read it from the application. Is there any way to 'refresh' an object that has already been created, the message object is supposed to be a reference to the actual objec so I thought by downloading the rest of the message I should simply be able to issue getBodyText() and reset my string variable, but its just not working.

Any ideas?

This has been driving me round the bend for days!!!!!!!

Thanks in advance...
Offline  
Old 06-20-2007, 10:38 AM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8700
PIN: N/A
Carrier: O2
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm going to keep posting here in case I write something that makes sense to someone!!!!

I have at this stage tried everything :

1. Recreating the whole path from the folder downwards (in steps) after retrieving the rest of the message in an effort to 'refresh' the message object.

2. I have hardcoded my test of the message's contents so I didn't have to call getBodyText() until I had retrieved the rest of the message.

3. I've used a bunch of new variables and objects and set them equal to various (from the original msg.getBodyText() to a completely seperate (TextBodyPart) set equal to (String)updbp.getContents().

... and nothing works.

I'm posting the code I have here :

PHP Code:
System.out.println("Inside MailCheck Method   @@@@@@@@@@@@@@@@@");     
          try{
                
// R & D
                 // Returns a reference to the service book from the factory.
                
_servicebook ServiceBook.getSB();

                
// Returns an array of all registered service records.
                
_sRecordsArray _servicebook.getRecords(); 

                
// Loops through the service record array
                // and obtains specific information relating
                // to each item and prints it to the debugging output.
                
for(int i 0_sRecordsArray.lengthi++) {
                    
// Obtains the Service Book CID
                    
cidValue _sRecordsArrayxxx91;ixxx93;.getCid();
                    
                    
// Obtains the Name of the Service Book
                    
sbName _sRecordsArrayxxx91;ixxx93;.getName();
                
System.out.println("got here 1 : name :" sbName "cid :" cidValue);
                if(
cidValue.equals("CMIME")&& sbName.startsWith("Email")) {
                
// Obtains the Service Book's APN
                // (Associated Access Point Name)
                
String sbAPN _sRecordsArrayxxx91;ixxx93;.getAPN();
            }
        }
           
                
// R & D 
                 
_service  =Session.waitForDefaultSession().getStore();
                 
_service.setConnected(true);
                 
Store store =(Store)_service;
             
               
               
Folderxxx91;xxx93; fldArray store.list();
               
               
net.rim.blackberry.api.mail.Folder folder null;
               
               
folder store.getFolder("Inbox");
               
net.rim.blackberry.api.mail.Messagexxx91;xxx93; msgs folder.getMessages();
               
               
int count =0;
              if( 
msgs.length >0){
               for(
int i=0;imsgs.length;i++){
                   
                    
//System.out.println("MESSAGE STATUS :::"+msgsxxx91;ixxx93;.getStatus()); 
                    
net.rim.blackberry.api.mail.Message msg msgsxxx91;ixxx93;; // Retrieve the first message.
                    
Addressxxx91;xxx93; recipients msg.getRecipients(Message.RecipientType.TO);
                    
Date sent msg.getSentDate();
                    
Address from msg.getFrom();
                    
String subject msg.getSubject();
                    
String mail msg.getBodyText() ;
                    
System.out.println("mail "mail);
                
                
                      
                    if(
subject.startsWith("INFO_SYNC") &&  !msg.isSet(Message.Flag.DELETED)){
                        
                        
String strDeviceID subject.substring(subject.lastIndexOf('_')+1,subject.length());
                        if(!(
strDeviceID.equals("")||strDeviceID==null)){
                        
String strResult =Common.checkDeviceID(strDeviceID);
                        
                       if(!
strResult.equals("No Record Found")){
                        
                        
count++;
                        
String strPrefix;
                        
//String mail = "SNXXS~";
                        
if(mail.indexOf("SNXXS")>=0){
                            
strPrefix mail.substring(mail.indexOf("SNXXS"),mail.indexOf("SNXXS")+5);
                        }
                        else{
                            
strPrefix ="";
                        }
                        
System.out.println("strprefix:" strPrefix);
                       if(
strPrefix.equals("SNXXS")){
                           
// For new and delete All  
                            //deleteAllTableRecord();
                            //System.out.println("deleted data!");
                            //get MORE
                            //Object msgo = msg.getContent();
                            
BodyPart msgbp = (BodyPart)msg.getContent();
                            if (
msgbp.hasMore()){
                                
System.out.println("Msg has more - fetching...");
                                
net.rim.blackberry.api.mail.Transport.more((BodyPart)msgbptrue);
                                
System.out.println("Updating body text container...");
                                
//net.rim.blackberry.api.mail.Folder updfolder = store.getFolder("Inbox");
                                //net.rim.blackberry.api.mail.Messagexxx91;xxx93; updmsgs = updfolder.getMessages();
                                //net.rim.blackberry.api.mail.Message updmsg = new Message();
                                //updmsg = msgsxxx91;ixxx93;;
                                
String complete_mail msg.getBodyText();
                                
mail null;
                                
//mail = updmsg.getBodyText() ;
                                
mail complete_mail;
                                
System.out.println("Mail body now : "+mail);
                            } 
Now what happens is this. I'm looking for an email with a specific subject (INFO_SYNC_x) where 'x' is the device id the email was intended for and then I check the beginning of the contents for a specific string ("SNXXS" to make sure it is one I am 'interested' in. I KNOW the code above retrieves the rest of the message, because if I run this twice it skips the part where it needs to retrieve and works fine, but I want it to do it first time...

The string printed to the debug output after the "Mail body now..." is exactly the same as the first one i.e. the first part of the message contents before the rest of the message was retrieved.

Please, anybody, any ideas?

I have tried creating

Last edited by seekay : 06-20-2007 at 10:40 AM. Reason: clarity
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.