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