09-22-2005, 11:59 PM
|
#3 (permalink)
|
| New Member
Join Date: Aug 2005 Model: 7250
Posts: 4
Post Thanks: 0 Thanked 0 Times in 0 Posts
| Hi Phil,
The app is signed.
I tried another approach wherein I am polling the inbox every 30 seconds and checking the mails with a particular subject. The polling is happening fine (logs whenever the thread wakes up) but it does not seem to scan the inbox. No exceptions are thrown either.
It is being tested on 7750 Verizon
Platform 1.5.0.30
App/OS version: 4.0.0.171
You could try out the following piece of code -
import net.rim.blackberry.api.mail.Session;
import net.rim.blackberry.api.mail.Folder;
import net.rim.blackberry.api.mail.Store;
import net.rim.blackberry.api.mail.event.FolderEvent;
import net.rim.blackberry.api.mail.event.FolderListener;
import net.rim.blackberry.api.mail.Message;
import net.rim.device.api.system.EventLogger;
public class Example extends Thread
{
public static final String SUBJECT = "<SUBJECT>";
public static final int SLEEP_TIME = 10 * 1000;
/**
* Id required for Event logging.
* Key is: Example
*/
private long guid = 0x52ae3a156ed010fL;
public Example()
{
EventLogger.register(guid, "Example", EventLogger.VIEWER_STRING);
EventLogger.setMinimumLevel(EventLogger.INFORMATI ON);
EventLogger.logEvent(guid, "Example Poll Agent Started".getBytes(), EventLogger.INFORMATION);
}
public void run()
{
try{
Store store = Session.getDefaultInstance().getStore();
Folder[] folders = store.list(Folder.INBOX);
Folder inbox = folders[0];
String subject = null;
while (true)
{
//Remove the message from the sent items if stored:
Message [] msgs = inbox.getMessages();
StringBuffer sb = new StringBuffer("Deleted messages: ");
for(int i=0; i < msgs.length; i++)
{
subject = msgs<i>.getSubject();
EventLogger.logEvent(guid, ("Mail Subject: "+subject).getBytes(), EventLogger.INFORMATION);
if ((subject != null) && (!subject.equals("")) && (subject.startsWith(SUBJECT)))
{
sb.append(subject).append(";");
inbox.deleteMessage(msgs<i>);
}
}
EventLogger.logEvent(guid, sb.toString().getBytes(), EventLogger.INFORMATION);
sb = null;
try{
Thread.sleep(SLEEP_TIME);
}
catch (Exception e){
EventLogger.logEvent(guid, e.toString().getBytes(), EventLogger.ERROR);
}
}
}
catch (Exception e){
EventLogger.logEvent(guid, e.toString().getBytes(), EventLogger.ERROR);
}
EventLogger.logEvent(guid, "Example Poll Agent Stopped.".getBytes(), EventLogger.INFORMATION);
}
public static void main(String[] args)
{
Example Example = new Example();
Example.start();
}
} |
| Offline
| |