KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > imapserver > client > StoreClientCommand


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20 package org.apache.james.imapserver.client;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.LinkedList JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.mail.Flags JavaDoc;
27 import javax.mail.MessagingException JavaDoc;
28 import javax.mail.internet.MimeMessage JavaDoc;
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 JavaDoc flags;
43
44     private MessageSet set;
45
46     public StoreClientCommand(int mode, boolean silent, Flags JavaDoc 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 JavaDoc 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 JavaDoc getExpectedResponseList() throws MessagingException JavaDoc {
81         List JavaDoc responseList = new LinkedList JavaDoc();
82         if (!silent) {
83             List JavaDoc selectedNumbers = set.getSelectedMessageNumbers();
84             for (Iterator JavaDoc it = selectedNumbers.iterator(); it.hasNext();) {
85                 final int no = ((Integer JavaDoc) it.next()).intValue();
86                 final MimeMessage JavaDoc mm = set.getMessage(no);
87                 String JavaDoc 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