开发者

javamail and gmail

  1. The following code throws IndexOutOfBoundsException. Any idea why?

     Folder folder = store.getDefaultFolder();
     folder = folder.getFolder("INBOX");
    
     int totalMessages = folder.getMessageCount();
     //totalMessages is 17000
    
      folder.getMessages(16900, 16999)   --- here I am trying to get the NEWEST 99                                                                                         messages.
    

This code throws the exception indexoutofbounds even though there are so many mails. What am I doing wrong?

  1. folder.getMessages() - get all the emails from 1st email to last. In my case 17000!! How do I get the emails开发者_高级运维 starting from newest to oldest? I only want to see the latest emails - around 100 of them. Is this possible?


Never us magic values in code, it will just cause you pain. Try:

int messagesToDisplay = 100;
folder.getMessages(totalMessages  - messagesToDisplay , totalMessages);

From the JavaDoc the messages are identified with a 1 based array not 0.

Can you also add the stack trace please.


please open the folder in read or read_write mode first.

folder.open(Folder.READ_WRITE);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜