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; i < _sRecordsArray.length; i++) {
// 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;i< msgs.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)msgbp, true);
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