Home | History | Annotate | Download | only in exchange
      1 /*
      2  * Copyright (C) 2008-2009 Marc Blank
      3  * Licensed to The Android Open Source Project.
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.exchange;
     19 
     20 import com.android.emailcommon.provider.Mailbox;
     21 import com.android.emailcommon.service.EmailServiceProxy;
     22 import com.android.mail.utils.LogUtils;
     23 
     24 import java.text.SimpleDateFormat;
     25 import java.util.Locale;
     26 import java.util.TimeZone;
     27 
     28 /**
     29  * Constants used throughout the EAS implementation are stored here.
     30  *
     31  */
     32 public class Eas {
     33 
     34     // For logging.
     35     public static final String LOG_TAG = "Exchange";
     36 
     37     // For debugging
     38     public static boolean WAIT_DEBUG = false;   // DO NOT CHECK IN WITH THIS SET TO TRUE
     39     public static boolean DEBUG = false;         // DO NOT CHECK IN WITH THIS SET TO TRUE
     40 
     41     // The following two are for user logging (the second providing more detail)
     42     public static boolean USER_LOG = false;     // DO NOT CHECK IN WITH THIS SET TO TRUE
     43     public static boolean PARSER_LOG = false;   // DO NOT CHECK IN WITH THIS SET TO TRUE
     44     public static boolean FILE_LOG = false;     // DO NOT CHECK IN WITH THIS SET TO TRUE
     45 
     46     public static final String CLIENT_VERSION = "EAS-1.3";
     47     public static final String ACCOUNT_MAILBOX_PREFIX = "__eas";
     48 
     49     // Define our default protocol version as 2.5 (Exchange 2003)
     50     public static final String SUPPORTED_PROTOCOL_EX2003 = "2.5";
     51     public static final double SUPPORTED_PROTOCOL_EX2003_DOUBLE = 2.5;
     52     public static final String SUPPORTED_PROTOCOL_EX2007 = "12.0";
     53     public static final double SUPPORTED_PROTOCOL_EX2007_DOUBLE = 12.0;
     54     public static final String SUPPORTED_PROTOCOL_EX2007_SP1 = "12.1";
     55     public static final double SUPPORTED_PROTOCOL_EX2007_SP1_DOUBLE = 12.1;
     56     public static final String SUPPORTED_PROTOCOL_EX2010 = "14.0";
     57     public static final double SUPPORTED_PROTOCOL_EX2010_DOUBLE = 14.0;
     58     public static final String SUPPORTED_PROTOCOL_EX2010_SP1 = "14.1";
     59     public static final double SUPPORTED_PROTOCOL_EX2010_SP1_DOUBLE = 14.1;
     60     public static final String DEFAULT_PROTOCOL_VERSION = SUPPORTED_PROTOCOL_EX2003;
     61 
     62     public static final String EXCHANGE_ACCOUNT_MANAGER_TYPE =
     63             com.android.exchange.Configuration.EXCHANGE_ACCOUNT_MANAGER_TYPE;
     64     public static final String PROTOCOL = com.android.exchange.Configuration.EXCHANGE_PROTOCOL;
     65     public static final String EXCHANGE_SERVICE_INTENT_ACTION =
     66             com.android.exchange.Configuration.EXCHANGE_SERVICE_INTENT_ACTION;
     67 
     68     // From EAS spec
     69     //                Mail Cal
     70     // 0 No filter    Yes  Yes
     71     // 1 1 day ago    Yes  No
     72     // 2 3 days ago   Yes  No
     73     // 3 1 week ago   Yes  No
     74     // 4 2 weeks ago  Yes  Yes
     75     // 5 1 month ago  Yes  Yes
     76     // 6 3 months ago No   Yes
     77     // 7 6 months ago No   Yes
     78 
     79     // TODO Rationalize this with SYNC_WINDOW_ALL
     80     public static final String FILTER_ALL = "0";
     81     public static final String FILTER_1_DAY = "1";
     82     public static final String FILTER_3_DAYS =  "2";
     83     public static final String FILTER_1_WEEK =  "3";
     84     public static final String FILTER_2_WEEKS =  "4";
     85     public static final String FILTER_1_MONTH =  "5";
     86     public static final String FILTER_3_MONTHS = "6";
     87     public static final String FILTER_6_MONTHS = "7";
     88 
     89     public static final String BODY_PREFERENCE_TEXT = "1";
     90     public static final String BODY_PREFERENCE_HTML = "2";
     91 
     92     public static final String MIME_BODY_PREFERENCE_TEXT = "0";
     93     public static final String MIME_BODY_PREFERENCE_MIME = "2";
     94 
     95     // Mailbox Types
     96     // Section 2.2.3.170.3 Type (FolderSync)
     97     // http://msdn.microsoft.com/en-us/library/gg650877(v=exchg.80).aspx
     98     public static final int MAILBOX_TYPE_USER_GENERIC = 1;
     99     public static final int MAILBOX_TYPE_INBOX = 2;
    100     public static final int MAILBOX_TYPE_DRAFTS = 3;
    101     public static final int MAILBOX_TYPE_DELETED = 4;
    102     public static final int MAILBOX_TYPE_SENT = 5;
    103     public static final int MAILBOX_TYPE_OUTBOX = 6;
    104 //    public static final int MAILBOX_TYPE_TASKS = 7;
    105     public static final int MAILBOX_TYPE_CALENDAR = 8;
    106     public static final int MAILBOX_TYPE_CONTACTS = 9;
    107 //    public static final int MAILBOX_TYPE_NOTES = 10;
    108 //    public static final int MAILBOX_TYPE_JOURNAL = 11;
    109     public static final int MAILBOX_TYPE_USER_MAIL = 12;
    110     public static final int MAILBOX_TYPE_USER_CALENDAR = 13;
    111     public static final int MAILBOX_TYPE_USER_CONTACTS = 14;
    112 //    public static final int MAILBOX_TYPE_USER_TASKS = 15;
    113 //    public static final int MAILBOX_TYPE_USER_JOURNAL = 16;
    114 //    public static final int MAILBOX_TYPE_USER_NOTES = 17;
    115 //    public static final int MAILBOX_TYPE_UNKNOWN = 18;
    116 //    public static final int MAILBOX_TYPE_RECIPIENT_INFORMATION_CACHE = 19;
    117 
    118 
    119     // These limits must never exceed about 500k which is half the max size of a Binder IPC buffer.
    120 
    121     // For EAS 12, we use HTML, so we want a larger size than in EAS 2.5
    122     public static final String EAS12_TRUNCATION_SIZE = "200000";
    123     // For EAS 2.5, truncation is a code; the largest is "7", which is 100k
    124     public static final String EAS2_5_TRUNCATION_SIZE = "7";
    125 
    126     public static final int FOLDER_STATUS_OK = 1;
    127     public static final int FOLDER_STATUS_INVALID_KEY = 9;
    128 
    129     public static final int EXCHANGE_ERROR_NOTIFICATION = 0x10;
    130 
    131     public static void setUserDebug(int state) {
    132         // DEBUG takes precedence and is never true in a user build
    133         if (!DEBUG) {
    134             USER_LOG = (state & EmailServiceProxy.DEBUG_BIT) != 0;
    135             PARSER_LOG = (state & EmailServiceProxy.DEBUG_VERBOSE_BIT) != 0;
    136             FILE_LOG = (state & EmailServiceProxy.DEBUG_FILE_BIT) != 0;
    137             if (FILE_LOG || PARSER_LOG) {
    138                 USER_LOG = true;
    139             }
    140             LogUtils.d("Eas Debug", "Logging: " + (USER_LOG ? "User " : "") +
    141                     (PARSER_LOG ? "Parser " : "") + (FILE_LOG ? "File" : ""));
    142         }
    143     }
    144 
    145     static public Double getProtocolVersionDouble(String version) {
    146         if (SUPPORTED_PROTOCOL_EX2003.equals(version)) {
    147             return SUPPORTED_PROTOCOL_EX2003_DOUBLE;
    148         } else if (SUPPORTED_PROTOCOL_EX2007.equals(version)) {
    149             return SUPPORTED_PROTOCOL_EX2007_DOUBLE;
    150         } if (SUPPORTED_PROTOCOL_EX2007_SP1.equals(version)) {
    151             return SUPPORTED_PROTOCOL_EX2007_SP1_DOUBLE;
    152         } if (SUPPORTED_PROTOCOL_EX2010.equals(version)) {
    153             return SUPPORTED_PROTOCOL_EX2010_DOUBLE;
    154         } if (SUPPORTED_PROTOCOL_EX2010_SP1.equals(version)) {
    155             return SUPPORTED_PROTOCOL_EX2010_SP1_DOUBLE;
    156         }
    157         throw new IllegalArgumentException("illegal protocol version");
    158     }
    159 
    160     /**
    161      * Gets the Exchange folder class for a mailbox type (PIM collections have different values
    162      * from email), needed when forming the request.
    163      * @param mailboxType The type of the mailbox we're interested in, from {@link Mailbox}.
    164      * @return The folder class for the mailbox we're interested in.
    165      */
    166     public static String getFolderClass(final int mailboxType) {
    167         switch (mailboxType) {
    168             case Mailbox.TYPE_CALENDAR:
    169                 return "Calendar";
    170             case Mailbox.TYPE_CONTACTS:
    171                 return "Contacts";
    172             default:
    173                 return "Email";
    174         }
    175     }
    176 
    177     // Time format documented at http://msdn.microsoft.com/en-us/library/ee201818(v=exchg.80).aspx
    178     public static final SimpleDateFormat DATE_FORMAT;
    179     static {
    180         DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'", Locale.US);
    181         DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
    182     }
    183 }
    184