1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.emailcommon.mail; 18 19 import java.util.ArrayList; 20 21 /** 22 * <pre> 23 * A FetchProfile is a list of items that should be downloaded in bulk for a set of messages. 24 * FetchProfile can contain the following objects: 25 * FetchProfile.Item: Described below. 26 * Message: Indicates that the body of the entire message should be fetched. 27 * Synonymous with FetchProfile.Item.BODY. 28 * Part: Indicates that the given Part should be fetched. The provider 29 * is expected have previously created the given BodyPart and stored 30 * any information it needs to download the content. 31 * </pre> 32 */ 33 public class FetchProfile extends ArrayList<Fetchable> { 34 /** 35 * Default items available for pre-fetching. It should be expected that any 36 * item fetched by using these items could potentially include all of the 37 * previous items. 38 */ 39 public enum Item implements Fetchable { 40 /** 41 * Download the flags of the message. 42 */ 43 FLAGS, 44 45 /** 46 * Download the envelope of the message. This should include at minimum 47 * the size and the following headers: date, subject, from, content-type, to, cc 48 */ 49 ENVELOPE, 50 51 /** 52 * Download the structure of the message. This maps directly to IMAP's BODYSTRUCTURE 53 * and may map to other providers. 54 * The provider should, if possible, fill in a properly formatted MIME structure in 55 * the message without actually downloading any message data. If the provider is not 56 * capable of this operation it should specifically set the body of the message to null 57 * so that upper levels can detect that a full body download is needed. 58 */ 59 STRUCTURE, 60 61 /** 62 * A sane portion of the entire message, cut off at a provider determined limit. 63 * This should generaly be around 50kB. 64 */ 65 BODY_SANE, 66 67 /** 68 * The entire message. 69 */ 70 BODY, 71 } 72 73 /** 74 * @return the first {@link Part} in this collection, or null if it doesn't contain 75 * {@link Part}. 76 */ getFirstPart()77 public Part getFirstPart() { 78 for (Fetchable o : this) { 79 if (o instanceof Part) { 80 return (Part) o; 81 } 82 } 83 return null; 84 } 85 } 86