Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javamail: Setting custom flags on imap mail and searching for mails with custom flags

Is it possible to set custom flags on IMAP mail messages using java mail without overwriting existing flags? Eg, I need to set a flag "processed" on processed messages without changing its state to SEEN / DELETED or without mail clients interfering with this "processed" flag.

Then I need to find all mail that doesn't have the "processed" flag and process them after which they are also flagged as "processed".

Thanks!

like image 633
Jan Vladimir Mostert Avatar asked Feb 14 '12 14:02

Jan Vladimir Mostert


1 Answers

Flags processedFlag = new Flags("processed");
folder.setFlags(msgs, processedFlag, true);
// or
msg.setFlags(processedFlag, true);

Not all IMAP servers will support these "user flags", but most will. To find messages without this flag:

Message[] msgs = folder.search(new FlagTerm(processedFlag, false));
like image 84
Bill Shannon Avatar answered Oct 16 '22 02:10

Bill Shannon