001 /** 002 * 003 * Copyright 2003-2006 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package javax.mail; 019 020 import java.util.ArrayList; 021 import java.util.List; 022 023 /** 024 * A FetchProfile defines a list of message attributes that a client wishes to prefetch 025 * from the server during a fetch operation. 026 * 027 * Clients can either specify individual headers, or can reference common profiles 028 * as defined by {@link FetchProfile.Item FetchProfile.Item}. 029 * 030 * @version $Rev: 421852 $ $Date: 2006-07-14 03:02:19 -0700 (Fri, 14 Jul 2006) $ 031 */ 032 public class FetchProfile { 033 /** 034 * Inner class that defines sets of headers that are commonly bundled together 035 * in a FetchProfile. 036 */ 037 public static class Item { 038 /** 039 * Item for fetching information about the content of the message. 040 * 041 * This includes all the headers about the content including but not limited to: 042 * Content-Type, Content-Disposition, Content-Description, Size and Line-Count 043 */ 044 public static final Item CONTENT_INFO = new Item("Content-Info"); 045 046 /** 047 * Item for fetching information about the envelope of the message. 048 * 049 * This includes all the headers comprising the envelope including but not limited to: 050 * From, To, Cc, Bcc, Reply-To, Subject and Date 051 * 052 * For IMAP4, this should also include the ENVELOPE data item. 053 * 054 */ 055 public static final Item ENVELOPE = new Item("Envelope"); 056 057 /** 058 * Item for fetching information about message flags. 059 * Generall corresponds to the X-Flags header. 060 */ 061 public static final Item FLAGS = new Item("Flags"); 062 063 protected Item(String name) { 064 // hmmm, name is passed in but we are not allowed to provide accessors 065 // or to override equals/hashCode so what use is it? 066 } 067 } 068 069 // use Lists as we don't expect contains to be called often and the number of elements should be small 070 private final List items = new ArrayList(); 071 private final List headers = new ArrayList(); 072 073 /** 074 * Add a predefined profile of headers. 075 * 076 * @param item the profile to add 077 */ 078 public void add(Item item) { 079 items.add(item); 080 } 081 082 /** 083 * Add a specific header. 084 * @param header the header whose value should be prefetched 085 */ 086 public void add(String header) { 087 headers.add(header); 088 } 089 090 /** 091 * Determine if the given profile item is already included. 092 * @param item the profile to check for 093 * @return true if the profile item is already included 094 */ 095 public boolean contains(Item item) { 096 return items.contains(item); 097 } 098 099 /** 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 }