1 19 20 package org.apache.james.imapserver.client; 21 22 import java.util.Iterator ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 26 import javax.mail.Flags ; 27 import javax.mail.MessagingException ; 28 import javax.mail.internet.MimeMessage ; 29 30 public class StoreClientCommand extends AbstractCommand { 31 32 public static final int MODE_SET = 0; 33 34 public static final int MODE_ADD = 1; 35 36 public static final int MODE_REMOVE = 2; 37 38 private final int mode; 39 40 private final boolean silent; 41 42 private final Flags flags; 43 44 private MessageSet set; 45 46 public StoreClientCommand(int mode, boolean silent, Flags flags, 47 MessageSet set) { 48 this.mode = mode; 49 this.silent = silent; 50 this.flags = flags; 51 this.set = set; 52 this.statusResponse = "OK STORE completed."; 53 } 54 55 public String getCommand() { 56 command = ""; 57 if (set.isUid()) { 58 command = "UID "; 59 } 60 command += "STORE "; 61 command += set + " "; 62 63 if (mode == MODE_ADD) { 64 command += "+"; 65 } else if (mode == MODE_REMOVE) { 66 command += "-"; 67 } 68 command += "FLAGS"; 69 if (silent) { 70 command += ".SILENT"; 71 } 72 command += " ("; 73 command += FetchCommand.flagsToString(flags); 74 command += ")"; 75 76 return command; 77 78 } 79 80 public List getExpectedResponseList() throws MessagingException { 81 List responseList = new LinkedList (); 82 if (!silent) { 83 List selectedNumbers = set.getSelectedMessageNumbers(); 84 for (Iterator it = selectedNumbers.iterator(); it.hasNext();) { 85 final int no = ((Integer ) it.next()).intValue(); 86 final MimeMessage mm = set.getMessage(no); 87 String line = "* " + no + " FETCH ("; 88 line += "FLAGS (" + FetchCommand.flagsToString(mm.getFlags()) 89 + ")"; 90 if (set.isUid()) { 91 line += " UID " + set.getUid(no); 92 } 93 line += ")"; 94 responseList.add(line); 95 } 96 } 97 return responseList; 98 } 99 } 100 | Popular Tags |