Skip to main content

Unable to get javamail POP3Folder to delete any messages

1 reply [Last post]
casadelgato
Offline
Joined: 2010-05-17
Points: 0

I'm trying to setup some email processing using javamail, but have been completely unable to get it to even delete a message.

	Properties props = System.getProperties();
props.setProperty("mail.pop3.rsetbeforequit", "0");
Session session = Session.getInstance(props, null);
Store store = session.getStore("pop3");
store.connect(account.getHost(), account.getUserid(), account.getPassword());
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
int msgCnt = folder.getMessageCount();

for (int idx = 1; (idx <= msgCnt); idx++) {
Message msg = folder.getMessage(idx);
// Do Stuff here...

// doesn't work
msg.setFlag(Flags.Flag.DELETED, true);

                // doesn't work
// Flags flags = new Flags( Flags.Flag.DELETED);
// folder.setFlags(idx, idx, flags, true);

// doesn't work
// Flags flags = new Flags(Flags.Flag.DELETED);
// Message[] msgs = new Message[1];
// msgs[0] = msg;
// folder.setFlags(msgs, flags, true);
}

folder.close(true);

It doesn't seem to matter what I do, the message never gets deleted.

What am I doing wrong?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
casadelgato
Offline
Joined: 2010-05-17
Points: 0

And of course, minutes after posting this, I see the obvious problem.

I was opening the folder READ_ONLY. Changed it to READ_WRITE, and now it works!