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 javax.mail;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 /**
26 * A FetchProfile defines a list of message attributes that a client wishes to prefetch
27 * from the server during a fetch operation.
28 *
29 * Clients can either specify individual headers, or can reference common profiles
30 * as defined by {@link FetchProfile.Item FetchProfile.Item}.
31 *
32 * @version $Rev: 582797 $ $Date: 2007-10-08 08:29:12 -0400 (Mon, 08 Oct 2007) $
33 */
34 public class FetchProfile {
35 /**
36 * Inner class that defines sets of headers that are commonly bundled together
37 * in a FetchProfile.
38 */
39 public static class Item {
40 /**
41 * Item for fetching information about the content of the message.
42 *
43 * This includes all the headers about the content including but not limited to:
44 * Content-Type, Content-Disposition, Content-Description, Size and Line-Count
45 */
46 public static final Item CONTENT_INFO = new Item("CONTENT_INFO");
47
48 /**
49 * Item for fetching information about the envelope of the message.
50 *
51 * This includes all the headers comprising the envelope including but not limited to:
52 * From, To, Cc, Bcc, Reply-To, Subject and Date
53 *
54 * For IMAP4, this should also include the ENVELOPE data item.
55 *
56 */
57 public static final Item ENVELOPE = new Item("ENVELOPE");
58
59 /**
60 * Item for fetching information about message flags.
61 * Generall corresponds to the X-Flags header.
62 */
63 public static final Item FLAGS = new Item("FLAGS");
64
65 protected Item(String name) {
66 // hmmm, name is passed in but we are not allowed to provide accessors
67 // or to override equals/hashCode so what use is it?
68 }
69 }
70
71 // use Lists as we don't expect contains to be called often and the number of elements should be small
72 private final List items = new ArrayList();
73 private final List headers = new ArrayList();
74
75 /**
76 * Add a predefined profile of headers.
77 *
78 * @param item the profile to add
79 */
80 public void add(Item item) {
81 items.add(item);
82 }
83
84 /**
85 * Add a specific header.
86 * @param header the header whose value should be prefetched
87 */
88 public void add(String header) {
89 headers.add(header);
90 }
91
92 /**
93 * Determine if the given profile item is already included.
94 * @param item the profile to check for
95 * @return true if the profile item is already included
96 */
97 public boolean contains(Item item) {
98 return items.contains(item);
99 }
100
101 /**
102 * Determine if the specified header is already included.
103 * @param header the header to check for
104 * @return true if the header is already included
105 */
106 public boolean contains(String header) {
107 return headers.contains(header);
108 }
109
110 /**
111 * Get the profile items already included.
112 * @return the items already added to this profile
113 */
114 public Item[] getItems() {
115 return (Item[]) items.toArray(new Item[items.size()]);
116 }
117
118 /** Get the headers that have already been included.
119 * @return the headers already added to this profile
120 */
121 public String[] getHeaderNames() {
122 return (String[]) headers.toArray(new String[headers.size()]);
123 }
124 }