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 DEBUG = false; // DO NOT CHECK IN WITH THIS SET TO TRUE 39 40 // The following two are for user logging (the second providing more detail) 41 public static boolean USER_LOG = false; // DO NOT CHECK IN WITH THIS SET TO TRUE 42 43 public static final String CLIENT_VERSION = "EAS-2.0"; 44 public static final String ACCOUNT_MAILBOX_PREFIX = "__eas"; 45 46 // Define our default protocol version as 2.5 (Exchange 2003) 47 public static final String SUPPORTED_PROTOCOL_EX2003 = "2.5"; 48 public static final double SUPPORTED_PROTOCOL_EX2003_DOUBLE = 2.5; 49 public static final String SUPPORTED_PROTOCOL_EX2007 = "12.0"; 50 public static final double SUPPORTED_PROTOCOL_EX2007_DOUBLE = 12.0; 51 public static final String SUPPORTED_PROTOCOL_EX2007_SP1 = "12.1"; 52 public static final double SUPPORTED_PROTOCOL_EX2007_SP1_DOUBLE = 12.1; 53 public static final String SUPPORTED_PROTOCOL_EX2010 = "14.0"; 54 public static final double SUPPORTED_PROTOCOL_EX2010_DOUBLE = 14.0; 55 public static final String SUPPORTED_PROTOCOL_EX2010_SP1 = "14.1"; 56 public static final double SUPPORTED_PROTOCOL_EX2010_SP1_DOUBLE = 14.1; 57 public static final String DEFAULT_PROTOCOL_VERSION = SUPPORTED_PROTOCOL_EX2003; 58 public static final boolean DEFAULT_PROTOCOL_IS_EAS14 = false; 59 60 public static final String EXCHANGE_ACCOUNT_MANAGER_TYPE = 61 com.android.exchange.Configuration.EXCHANGE_ACCOUNT_MANAGER_TYPE; 62 public static final String PROTOCOL = com.android.exchange.Configuration.EXCHANGE_PROTOCOL; 63 public static final String EXCHANGE_SERVICE_INTENT_ACTION = 64 com.android.exchange.Configuration.EXCHANGE_SERVICE_INTENT_ACTION; 65 66 // From EAS spec 67 // Mail Cal 68 // 0 No filter Yes Yes 69 // 1 1 day ago Yes No 70 // 2 3 days ago Yes No 71 // 3 1 week ago Yes No 72 // 4 2 weeks ago Yes Yes 73 // 5 1 month ago Yes Yes 74 // 6 3 months ago No Yes 75 // 7 6 months ago No Yes 76 77 // TODO Rationalize this with SYNC_WINDOW_ALL 78 public static final String FILTER_ALL = "0"; 79 public static final String FILTER_1_DAY = "1"; 80 public static final String FILTER_3_DAYS = "2"; 81 public static final String FILTER_1_WEEK = "3"; 82 public static final String FILTER_2_WEEKS = "4"; 83 public static final String FILTER_1_MONTH = "5"; 84 public static final String FILTER_3_MONTHS = "6"; 85 public static final String FILTER_6_MONTHS = "7"; 86 87 public static final String BODY_PREFERENCE_TEXT = "1"; 88 public static final String BODY_PREFERENCE_HTML = "2"; 89 90 public static final String MIME_BODY_PREFERENCE_TEXT = "0"; 91 public static final String MIME_BODY_PREFERENCE_MIME = "2"; 92 93 // Mailbox Types 94 // Section 2.2.3.170.3 Type (FolderSync) 95 // http://msdn.microsoft.com/en-us/library/gg650877(v=exchg.80).aspx 96 public static final int MAILBOX_TYPE_USER_GENERIC = 1; 97 public static final int MAILBOX_TYPE_INBOX = 2; 98 public static final int MAILBOX_TYPE_DRAFTS = 3; 99 public static final int MAILBOX_TYPE_DELETED = 4; 100 public static final int MAILBOX_TYPE_SENT = 5; 101 public static final int MAILBOX_TYPE_OUTBOX = 6; 102 // public static final int MAILBOX_TYPE_TASKS = 7; 103 public static final int MAILBOX_TYPE_CALENDAR = 8; 104 public static final int MAILBOX_TYPE_CONTACTS = 9; 105 // public static final int MAILBOX_TYPE_NOTES = 10; 106 // public static final int MAILBOX_TYPE_JOURNAL = 11; 107 public static final int MAILBOX_TYPE_USER_MAIL = 12; 108 public static final int MAILBOX_TYPE_USER_CALENDAR = 13; 109 public static final int MAILBOX_TYPE_USER_CONTACTS = 14; 110 // public static final int MAILBOX_TYPE_USER_TASKS = 15; 111 // public static final int MAILBOX_TYPE_USER_JOURNAL = 16; 112 // public static final int MAILBOX_TYPE_USER_NOTES = 17; 113 // public static final int MAILBOX_TYPE_UNKNOWN = 18; 114 // public static final int MAILBOX_TYPE_RECIPIENT_INFORMATION_CACHE = 19; 115 116 117 // These limits must never exceed about 500k which is half the max size of a Binder IPC buffer. 118 119 // For EAS 12, we use HTML, so we want a larger size than in EAS 2.5 120 public static final String EAS12_TRUNCATION_SIZE = "200000"; 121 // For EAS 2.5, truncation is a code; the largest is "7", which is 100k 122 public static final String EAS2_5_TRUNCATION_SIZE = "7"; 123 124 public static final int FOLDER_STATUS_OK = 1; 125 public static final int FOLDER_STATUS_INVALID_KEY = 9; 126 127 public static final int EXCHANGE_ERROR_NOTIFICATION = 0x10; 128 129 static public Double getProtocolVersionDouble(String version) { 130 if (SUPPORTED_PROTOCOL_EX2003.equals(version)) { 131 return SUPPORTED_PROTOCOL_EX2003_DOUBLE; 132 } else if (SUPPORTED_PROTOCOL_EX2007.equals(version)) { 133 return SUPPORTED_PROTOCOL_EX2007_DOUBLE; 134 } if (SUPPORTED_PROTOCOL_EX2007_SP1.equals(version)) { 135 return SUPPORTED_PROTOCOL_EX2007_SP1_DOUBLE; 136 } if (SUPPORTED_PROTOCOL_EX2010.equals(version)) { 137 return SUPPORTED_PROTOCOL_EX2010_DOUBLE; 138 } if (SUPPORTED_PROTOCOL_EX2010_SP1.equals(version)) { 139 return SUPPORTED_PROTOCOL_EX2010_SP1_DOUBLE; 140 } 141 throw new IllegalArgumentException("illegal protocol version"); 142 } 143 144 static public boolean isProtocolEas14(String version) { 145 if (version == null) { 146 return DEFAULT_PROTOCOL_IS_EAS14; 147 } 148 return getProtocolVersionDouble(version) >= SUPPORTED_PROTOCOL_EX2010_DOUBLE; 149 } 150 151 /** 152 * Gets the Exchange folder class for a mailbox type (PIM collections have different values 153 * from email), needed when forming the request. 154 * @param mailboxType The type of the mailbox we're interested in, from {@link Mailbox}. 155 * @return The folder class for the mailbox we're interested in. 156 */ 157 public static String getFolderClass(final int mailboxType) { 158 switch (mailboxType) { 159 case Mailbox.TYPE_CALENDAR: 160 return "Calendar"; 161 case Mailbox.TYPE_CONTACTS: 162 return "Contacts"; 163 default: 164 return "Email"; 165 } 166 } 167 168 // Time format documented at http://msdn.microsoft.com/en-us/library/ee201818(v=exchg.80).aspx 169 public static final SimpleDateFormat DATE_FORMAT; 170 static { 171 DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'", Locale.US); 172 DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC")); 173 } 174 } 175