Save This Page
Home » glassfish-v2ur2-b04-src » javax » mail » [javadoc | source]
    1   /*
    2    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    3    *
    4    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    5    *
    6    * The contents of this file are subject to the terms of either the GNU
    7    * General Public License Version 2 only ("GPL") or the Common Development
    8    * and Distribution License("CDDL") (collectively, the "License").  You
    9    * may not use this file except in compliance with the License. You can obtain
   10    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   11    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   12    * language governing permissions and limitations under the License.
   13    *
   14    * When distributing the software, include this License Header Notice in each
   15    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   16    * Sun designates this particular file as subject to the "Classpath" exception
   17    * as provided by Sun in the GPL Version 2 section of the License file that
   18    * accompanied this code.  If applicable, add the following below the License
   19    * Header, with the fields enclosed by brackets [] replaced by your own
   20    * identifying information: "Portions Copyrighted [year]
   21    * [name of copyright owner]"
   22    *
   23    * Contributor(s):
   24    *
   25    * If you wish your version of this file to be governed by only the CDDL or
   26    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   27    * elects to include this software in this distribution under the [CDDL or GPL
   28    * Version 2] license."  If you don't indicate a single choice of license, a
   29    * recipient has the option to distribute your version of this file under
   30    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   31    * its licensees as provided above.  However, if you add GPL Version 2 code
   32    * and therefore, elected the GPL Version 2 license, then the option applies
   33    * only if the new code is made subject to such option by the copyright
   34    * holder.
   35    */
   36   
   37   /*
   38    * @(#)FetchProfile.java	1.10 07/05/04
   39    */
   40   
   41   package javax.mail;
   42   
   43   import java.util.Vector;
   44   
   45   /**
   46    * Clients use a FetchProfile to list the Message attributes that 
   47    * it wishes to prefetch from the server for a range of messages.<p>
   48    *
   49    * Messages obtained from a Folder are light-weight objects that 
   50    * typically start off as empty references to the actual messages.
   51    * Such a Message object is filled in "on-demand" when the appropriate 
   52    * get*() methods are invoked on that particular Message. Certain
   53    * server-based message access protocols (Ex: IMAP) allow batch
   54    * fetching of message attributes for a range of messages in a single
   55    * request. Clients that want to use message attributes for a range of
   56    * Messages (Example: to display the top-level headers in a headerlist)
   57    * might want to use the optimization provided by such servers. The
   58    * <code>FetchProfile</code> allows the client to indicate this desire
   59    * to the server. <p>
   60    *
   61    * Note that implementations are not obligated to support
   62    * FetchProfiles, since there might be cases where the backend service 
   63    * does not allow easy, efficient fetching of such profiles. <p>
   64    *
   65    * Sample code that illustrates the use of a FetchProfile is given
   66    * below:  <p>
   67    * <blockquote>
   68    * <pre>
   69    *
   70    *  Message[] msgs = folder.getMessages();
   71    *
   72    *  FetchProfile fp = new FetchProfile();
   73    *  fp.add(FetchProfile.Item.ENVELOPE);
   74    *  fp.add("X-mailer");
   75    *  folder.fetch(msgs, fp);
   76    *
   77    * </pre></blockquote><p>
   78    *
   79    * @see javax.mail.Folder#fetch
   80    * @author John Mani
   81    * @author Bill Shannon
   82    */
   83   
   84   public class FetchProfile {
   85   
   86       private Vector specials; // specials
   87       private Vector headers; // vector of header names
   88   
   89       /**
   90        * This inner class is the base class of all items that
   91        * can be requested in a FetchProfile. The items currently
   92        * defined here are <code>ENVELOPE</code>, <code>CONTENT_INFO</code>
   93        * and <code>FLAGS</code>. The <code>UIDFolder</code> interface 
   94        * defines the <code>UID</code> Item as well. <p>
   95        *
   96        * Note that this class only has a protected constructor, therby
   97        * restricting new Item types to either this class or subclasses.
   98        * This effectively implements a enumeration of allowed Item types.
   99        *
  100        * @see UIDFolder
  101        */
  102   
  103       public static class Item {
  104   	/**
  105   	 * This is the Envelope item. <p>
  106   	 *
  107   	 * The Envelope is an aggregration of the common attributes
  108   	 * of a Message. Implementations should include the following
  109   	 * attributes: From, To, Cc, Bcc, ReplyTo, Subject and Date.
  110   	 * More items may be included as well. <p>
  111   	 *
  112   	 * For implementations of the IMAP4 protocol (RFC 2060), the 
  113   	 * Envelope should include the ENVELOPE data item. More items
  114   	 * may be included too.
  115   	 */
  116   	public static final Item ENVELOPE = new Item("ENVELOPE");
  117   
  118   	/**
  119   	 * This item is for fetching information about the 
  120   	 * content of the message. <p>
  121   	 *
  122   	 * This includes all the attributes that describe the content
  123   	 * of the message. Implementations should include the following
  124   	 * attributes: ContentType, ContentDisposition, 
  125   	 * ContentDescription, Size and LineCount. Other items may be
  126   	 * included as well.
  127   	 */
  128   	public static final Item CONTENT_INFO = new Item("CONTENT_INFO");
  129   
  130   	/**
  131   	 * This is the Flags item.
  132   	 */
  133   	public static final Item FLAGS = new Item("FLAGS");
  134   
  135   	private String name;
  136   
  137   	/**
  138   	 * Constructor for an item.  The name is used only for debugging.
  139   	 */
  140   	protected Item(String name) {
  141   	    this.name = name;
  142   	}
  143       }
  144   
  145       /**
  146        * Create an empty FetchProfile.
  147        */
  148       public FetchProfile() { 
  149   	specials = null;
  150   	headers = null;
  151       }
  152       
  153       /**
  154        * Add the given special item as one of the attributes to
  155        * be prefetched.
  156        *
  157        * @param	item		the special item to be fetched
  158        * @see	FetchProfile.Item#ENVELOPE
  159        * @see	FetchProfile.Item#CONTENT_INFO
  160        * @see	FetchProfile.Item#FLAGS
  161        */
  162       public void add(Item item) { 
  163   	if (specials == null)
  164   	    specials = new Vector();
  165   	specials.addElement(item);
  166       }
  167   
  168       /**
  169        * Add the specified header-field to the list of attributes
  170        * to be prefetched.
  171        *
  172        * @param	headerName	header to be prefetched
  173        */
  174       public void add(String headerName) { 
  175      	if (headers == null)
  176   	    headers = new Vector();
  177   	headers.addElement(headerName);
  178       }
  179   
  180       /**
  181        * Returns true if the fetch profile contains given special item.
  182        */
  183       public boolean contains(Item item) { 
  184      	return specials != null && specials.contains(item);
  185       }
  186   
  187       /**
  188        * Returns true if the fetch profile contains given header name.
  189        */
  190       public boolean contains(String headerName) { 
  191      	return headers != null && headers.contains(headerName);
  192       }
  193   
  194       /**
  195        * Get the items set in this profile. 
  196        *
  197        * @return		items set in this profile
  198        */
  199       public Item[] getItems() { 
  200   	if (specials == null)
  201   	    return new Item[0];
  202   
  203      	Item[] s = new Item[specials.size()];
  204   	specials.copyInto(s);
  205   	return s;
  206       }
  207   
  208       /**
  209        * Get the names of the header-fields set in this profile. 
  210        *
  211        * @return		headers set in this profile
  212        */
  213       public String[] getHeaderNames() { 
  214   	if (headers == null)
  215   	    return new String[0];
  216   
  217      	String[] s = new String[headers.size()];
  218   	headers.copyInto(s);
  219   	return s;
  220       }
  221   }

Save This Page
Home » glassfish-v2ur2-b04-src » javax » mail » [javadoc | source]