Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalWriteException when trying to write flags in JavaMail IMAP

Currently I am trying to set the seen flag on an IMAP email like this:

messages[EmailNumber].setFlag(Flag.SEEN, true);
messages[EmailNumber].saveChanges();

Where messages[] is an array of Message object populated by loading all the emails in a folder (which is set to have Read/Write access) and EmailNumber is a specific email in the array computed by the user's choice of an Email in a JTable that I am populating with the emails themselves.

However this keeps giving me this on the second line:

javax.mail.IllegalWriteException: IMAPMessage is read-only

Even though I populate the messages array (in a different function) like this:

folder.open(Folder.READ_WRITE);
messages = folder.getMessages();

What's going on here?

like image 317
Phillip Macdonald Avatar asked Nov 25 '13 13:11

Phillip Macdonald


1 Answers

Remove the call to saveChanges, it's unnecessary here.

like image 192
Bill Shannon Avatar answered Sep 24 '22 17:09

Bill Shannon