1 /* 2 * Copyright (C) 2015 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 package com.android.voicemail.impl.mail; 17 18 import java.util.ArrayList; 19 20 /** 21 * 22 * 23 * <pre> 24 * A FetchProfile is a list of items that should be downloaded in bulk for a set of messages. 25 * FetchProfile can contain the following objects: 26 * FetchProfile.Item: Described below. 27 * Message: Indicates that the body of the entire message should be fetched. 28 * Synonymous with FetchProfile.Item.BODY. 29 * Part: Indicates that the given Part should be fetched. The provider 30 * is expected have previously created the given BodyPart and stored 31 * any information it needs to download the content. 32 * </pre> 33 */ 34 public class FetchProfile extends ArrayList<Fetchable> { 35 /** 36 * Default items available for pre-fetching. It should be expected that any item fetched by using 37 * these items could potentially include all of the previous items. 38 */ 39 public enum Item implements Fetchable { 40 /** Download the flags of the message. */ 41 FLAGS, 42 43 /** 44 * Download the envelope of the message. This should include at minimum the size and the 45 * following headers: date, subject, from, content-type, to, cc 46 */ 47 ENVELOPE, 48 49 /** 50 * Download the structure of the message. This maps directly to IMAP's BODYSTRUCTURE and may map 51 * to other providers. The provider should, if possible, fill in a properly formatted MIME 52 * structure in the message without actually downloading any message data. If the provider is 53 * not capable of this operation it should specifically set the body of the message to null so 54 * that upper levels can detect that a full body download is needed. 55 */ 56 STRUCTURE, 57 58 /** 59 * A sane portion of the entire message, cut off at a provider determined limit. This should 60 * generally be around 50kB. 61 */ 62 BODY_SANE, 63 64 /** The entire message. */ 65 BODY, 66 } 67 68 /** 69 * @return the first {@link Part} in this collection, or null if it doesn't contain {@link Part}. 70 */ getFirstPart()71 public Part getFirstPart() { 72 for (Fetchable o : this) { 73 if (o instanceof Part) { 74 return (Part) o; 75 } 76 } 77 return null; 78 } 79 } 80