01: package org.concern.library.mail;
02:
03: import org.concern.controller.AbstractCondition;
04:
05: import javax.mail.Flags;
06: import javax.mail.MessagingException;
07: import javax.mail.internet.MimeMessage;
08: import java.util.HashMap;
09: import java.util.Map;
10:
11: public class ContainsStandardFlag extends AbstractCondition {
12: static Map FLAGS = new HashMap();
13: private Flags.Flag flag;
14:
15: static {
16: FLAGS.put("answered", Flags.Flag.ANSWERED);
17: FLAGS.put("deleted", Flags.Flag.DELETED);
18: FLAGS.put("draft", Flags.Flag.DRAFT);
19: FLAGS.put("flagged", Flags.Flag.FLAGGED);
20: FLAGS.put("recent", Flags.Flag.RECENT);
21: FLAGS.put("seen", Flags.Flag.SEEN);
22: FLAGS.put("user", Flags.Flag.USER);
23: }
24:
25: public boolean eval(Object subject) {
26: boolean eval = eval((MimeMessage) subject);
27: return eval;
28: }
29:
30: public boolean eval(MimeMessage subject) {
31: try {
32: return subject.getFlags().contains(getFlag());
33: } catch (MessagingException e) {
34: e.printStackTrace();
35: return false;
36: }
37: }
38:
39: Flags.Flag getFlag() {
40: if (flag == null)
41: flag = (Flags.Flag) FLAGS.get(environment.get("flag"));
42: return flag;
43: }
44: }
|