1 19 20 package org.apache.james.imapserver.util; 21 22 import java.util.HashSet ; 23 import java.util.Set ; 24 25 import javax.mail.MessagingException ; 26 import javax.mail.Flags.Flag; 27 import javax.mail.internet.MimeMessage ; 28 29 public class UnsolicitedResponseGenerator 30 { 31 Set responseSet = new HashSet (); 32 int recent=0; 33 34 public void addByMessages(MimeMessage [] msgs) throws MessagingException { 35 addExists(msgs.length); 36 int recent=0; 37 int firstUnseen=0; 38 for (int i=0; i<msgs.length; i++) { 39 if (msgs[i].isSet(Flag.RECENT)) { 40 recent++; 41 } 42 if (firstUnseen==0 && !msgs[i].isSet(Flag.SEEN)) { 43 firstUnseen=i+1; 44 } 45 46 } 47 addRecent(recent); 48 addFlags(); 49 addFirstUnseen(firstUnseen); 50 addPermanentFlags(); 51 } 52 53 public void addExists(int i) 54 { 55 responseSet.add("* " + i + " EXISTS"); 56 } 57 58 public void addRecent(int i) 59 { 60 recent=i; 61 responseSet.add("* " + i + " RECENT"); 62 } 63 64 public void addFlags() 65 { 66 responseSet 67 .add("* FLAGS (\\Answered \\Deleted \\Draft \\Flagged \\Seen)"); 68 } 69 70 public void addUidValidity(long uidv) 71 { 72 responseSet.add("* OK [UIDVALIDITY " + uidv + "]"); 73 } 74 75 public void addFirstUnseen(int firstUnseen) 76 { 77 if (firstUnseen > 0) { 78 responseSet.add("* OK [UNSEEN "+firstUnseen+"] Message "+firstUnseen+" is the first unseen"); 79 } else { 80 responseSet.add("* OK No messages unseen"); 81 } 82 } 83 84 public void addPermanentFlags() 85 { 86 responseSet 87 .add("* OK [PERMANENTFLAGS (\\Answered \\Deleted \\Draft \\Flagged \\Seen)]"); 88 } 89 90 public Set getResponseSet() 91 { 92 93 return responseSet; 94 } 95 96 public int getRecent() { 97 98 return recent; 99 } 100 101 } 102 | Popular Tags |