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