1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package javax.mail;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 /**
24 * A FetchProfile defines a list of message attributes that a client wishes to prefetch
25 * from the server during a fetch operation.
26 *
27 * Clients can either specify individual headers, or can reference common profiles
28 * as defined by {@link FetchProfile.Item FetchProfile.Item}.
29 *
30 * @version $Rev: 125583 $ $Date: 2005-01-18 19:44:27 -0800 (Tue, 18 Jan 2005) $
31 */
32 public class FetchProfile {
33 /**
34 * Inner class that defines sets of headers that are commonly bundled together
35 * in a FetchProfile.
36 */
37 public static class Item {
38 /**
39 * Item for fetching information about the content of the message.
40 *
41 * This includes all the headers about the content including but not limited to:
42 * Content-Type, Content-Disposition, Content-Description, Size and Line-Count
43 */
44 public static final Item CONTENT_INFO = new Item("Content-Info");
45
46 /**
47 * Item for fetching information about the envelope of the message.
48 *
49 * This includes all the headers comprising the envelope including but not limited to:
50 * From, To, Cc, Bcc, Reply-To, Subject and Date
51 *
52 * For IMAP4, this should also include the ENVELOPE data item.
53 *
54 */
55 public static final Item ENVELOPE = new Item("Envelope");
56
57 /**
58 * Item for fetching information about message flags.
59 * Generall corresponds to the X-Flags header.
60 */
61 public static final Item FLAGS = new Item("Flags");
62
63 protected Item(String name) {
64
65
66 }
67 }
68
69
70 private final List items = new ArrayList();
71 private final List headers = new ArrayList();
72
73 /**
74 * Add a predefined profile of headers.
75 *
76 * @param item the profile to add
77 */
78 public void add(Item item) {
79 items.add(item);
80 }
81
82 /**
83 * Add a specific header.
84 * @param header the header whose value should be prefetched
85 */
86 public void add(String header) {
87 headers.add(header);
88 }
89
90 /**
91 * Determine if the given profile item is already included.
92 * @param item the profile to check for
93 * @return true if the profile item is already included
94 */
95 public boolean contains(Item item) {
96 return items.contains(item);
97 }
98
99 /**
100 * Determine if the specified header is already included.
101 * @param header the header to check for
102 * @return true if the header is already included
103 */
104 public boolean contains(String header) {
105 return headers.contains(header);
106 }
107
108 /**
109 * Get the profile items already included.
110 * @return the items already added to this profile
111 */
112 public Item[] getItems() {
113 return (Item[]) items.toArray(new Item[items.size()]);
114 }
115
116 /** Get the headers that have already been included.
117 * @return the headers already added to this profile
118 */
119 public String[] getHeaderNames() {
120 return (String[]) headers.toArray(new String[headers.size()]);
121 }
122 }