tags:

views:

83

answers:

1

Hi,

I'm trying to delete the messages which is selected by user by clicking the checkbox and then clicking the delete button, but I don't understand why my code is not performing the desirable result. Here's the code in Javamail:

public static boolean deleteMessage(int j) throws Exception
 { 

 store = session.getStore("pop3");
store.connect("localhost", "red","red");



 inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);


    msgs[j].setFlag(Flags.Flag.DELETED, true); // set the DELETED flag

      if (msgs[j].isSet(Flags.Flag.DELETED))
    {
    inbox.close(true);
    return true; 
    }
    return false;
}

The above method is calling every time based on how many messages selected by user to delete. If there two messages selected by user to delete, then it will be called twice. Passing those numbers as a parameter in the deleteMessage method by calling method class. But it's not doing anything, nor it's throwing any exception. What's wrong I'm doing?

+2  A: 

Try

Message msg = inbox.getMessage(j);
msg.setFlag(Flags.Flag.DELETED, true);
if (msg.isSet(Flags.Flag.DELETED))
{
    inbox.close(true);
    return true;
}
reubensammut