2012-06-28 19:16:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.email.provider;
|
|
|
|
|
|
|
|
import android.accounts.AccountManager;
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.ContentValues;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.SQLException;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
2014-05-12 18:33:43 +00:00
|
|
|
import android.database.sqlite.SQLiteDoneException;
|
2012-06-28 19:16:59 +00:00
|
|
|
import android.database.sqlite.SQLiteOpenHelper;
|
2014-05-12 18:33:43 +00:00
|
|
|
import android.database.sqlite.SQLiteStatement;
|
2014-04-11 21:42:28 +00:00
|
|
|
import android.provider.BaseColumns;
|
2012-06-28 19:16:59 +00:00
|
|
|
import android.provider.CalendarContract;
|
|
|
|
import android.provider.ContactsContract;
|
2013-03-05 17:45:10 +00:00
|
|
|
import android.text.TextUtils;
|
2012-06-28 19:16:59 +00:00
|
|
|
|
2014-08-28 18:00:08 +00:00
|
|
|
import com.android.email.DebugUtils;
|
2013-03-05 17:45:10 +00:00
|
|
|
import com.android.email.R;
|
2012-06-28 19:16:59 +00:00
|
|
|
import com.android.emailcommon.mail.Address;
|
|
|
|
import com.android.emailcommon.provider.Account;
|
2013-12-04 00:55:48 +00:00
|
|
|
import com.android.emailcommon.provider.Credential;
|
2012-06-28 19:16:59 +00:00
|
|
|
import com.android.emailcommon.provider.EmailContent;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.AccountColumns;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.Attachment;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.AttachmentColumns;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.Body;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.BodyColumns;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.HostAuthColumns;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.MailboxColumns;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.Message;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.MessageColumns;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.PolicyColumns;
|
|
|
|
import com.android.emailcommon.provider.EmailContent.QuickResponseColumns;
|
2015-03-01 21:02:40 +00:00
|
|
|
import com.android.emailcommon.provider.EmailContent.SuggestedContactColumns;
|
2012-06-28 19:16:59 +00:00
|
|
|
import com.android.emailcommon.provider.EmailContent.SyncColumns;
|
|
|
|
import com.android.emailcommon.provider.HostAuth;
|
|
|
|
import com.android.emailcommon.provider.Mailbox;
|
2013-09-05 20:52:03 +00:00
|
|
|
import com.android.emailcommon.provider.MessageChangeLogTable;
|
|
|
|
import com.android.emailcommon.provider.MessageMove;
|
|
|
|
import com.android.emailcommon.provider.MessageStateChange;
|
2012-06-28 19:16:59 +00:00
|
|
|
import com.android.emailcommon.provider.Policy;
|
|
|
|
import com.android.emailcommon.provider.QuickResponse;
|
2015-03-01 21:02:40 +00:00
|
|
|
import com.android.emailcommon.provider.SuggestedContact;
|
2015-05-01 19:35:23 +00:00
|
|
|
import com.android.emailcommon.service.EmailServiceProxy;
|
2012-06-28 19:16:59 +00:00
|
|
|
import com.android.emailcommon.service.LegacyPolicySet;
|
2013-06-14 01:03:06 +00:00
|
|
|
import com.android.emailcommon.service.SyncWindow;
|
2012-06-28 19:16:59 +00:00
|
|
|
import com.android.mail.providers.UIProvider;
|
2013-03-05 17:45:10 +00:00
|
|
|
import com.android.mail.utils.LogUtils;
|
2012-06-28 19:16:59 +00:00
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
2013-03-05 17:45:10 +00:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
|
2014-05-12 18:33:43 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
2013-03-05 17:45:10 +00:00
|
|
|
import java.util.Map;
|
2012-06-28 19:16:59 +00:00
|
|
|
|
|
|
|
public final class DBHelper {
|
|
|
|
private static final String TAG = "EmailProvider";
|
|
|
|
|
2012-09-22 00:49:26 +00:00
|
|
|
private static final String LEGACY_SCHEME_IMAP = "imap";
|
|
|
|
private static final String LEGACY_SCHEME_POP3 = "pop3";
|
|
|
|
private static final String LEGACY_SCHEME_EAS = "eas";
|
|
|
|
|
2013-11-06 21:51:01 +00:00
|
|
|
|
2014-04-11 21:42:28 +00:00
|
|
|
private static final String WHERE_ID = BaseColumns._ID + "=?";
|
2012-06-28 19:16:59 +00:00
|
|
|
|
|
|
|
private static final String TRIGGER_MAILBOX_DELETE =
|
|
|
|
"create trigger mailbox_delete before delete on " + Mailbox.TABLE_NAME +
|
|
|
|
" begin" +
|
|
|
|
" delete from " + Message.TABLE_NAME +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + MessageColumns.MAILBOX_KEY + "=old." + BaseColumns._ID +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; delete from " + Message.UPDATED_TABLE_NAME +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + MessageColumns.MAILBOX_KEY + "=old." + BaseColumns._ID +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; delete from " + Message.DELETED_TABLE_NAME +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + MessageColumns.MAILBOX_KEY + "=old." + BaseColumns._ID +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; end";
|
|
|
|
|
|
|
|
private static final String TRIGGER_ACCOUNT_DELETE =
|
|
|
|
"create trigger account_delete before delete on " + Account.TABLE_NAME +
|
|
|
|
" begin delete from " + Mailbox.TABLE_NAME +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + MailboxColumns.ACCOUNT_KEY + "=old." + BaseColumns._ID +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; delete from " + HostAuth.TABLE_NAME +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + BaseColumns._ID + "=old." + AccountColumns.HOST_AUTH_KEY_RECV +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; delete from " + HostAuth.TABLE_NAME +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + BaseColumns._ID + "=old." + AccountColumns.HOST_AUTH_KEY_SEND +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; delete from " + Policy.TABLE_NAME +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + BaseColumns._ID + "=old." + AccountColumns.POLICY_KEY +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; end";
|
|
|
|
|
2013-12-04 00:55:48 +00:00
|
|
|
private static final String TRIGGER_HOST_AUTH_DELETE =
|
|
|
|
"create trigger host_auth_delete after delete on " + HostAuth.TABLE_NAME +
|
|
|
|
" begin delete from " + Credential.TABLE_NAME +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + Credential._ID + "=old." + HostAuthColumns.CREDENTIAL_KEY +
|
2013-12-04 00:55:48 +00:00
|
|
|
" and (select count(*) from " + HostAuth.TABLE_NAME + " where " +
|
2014-04-11 21:42:28 +00:00
|
|
|
HostAuthColumns.CREDENTIAL_KEY + "=old." + HostAuthColumns.CREDENTIAL_KEY + ")=0" +
|
2013-12-04 00:55:48 +00:00
|
|
|
"; end";
|
|
|
|
|
|
|
|
|
2012-06-28 19:16:59 +00:00
|
|
|
// Any changes to the database format *must* include update-in-place code.
|
|
|
|
// Original version: 3
|
|
|
|
// Version 4: Database wipe required; changing AccountManager interface w/Exchange
|
|
|
|
// Version 5: Database wipe required; changing AccountManager interface w/Exchange
|
|
|
|
// Version 6: Adding Message.mServerTimeStamp column
|
|
|
|
// Version 7: Replace the mailbox_delete trigger with a version that removes orphaned messages
|
|
|
|
// from the Message_Deletes and Message_Updates tables
|
|
|
|
// Version 8: Add security flags column to accounts table
|
|
|
|
// Version 9: Add security sync key and signature to accounts table
|
|
|
|
// Version 10: Add meeting info to message table
|
|
|
|
// Version 11: Add content and flags to attachment table
|
|
|
|
// Version 12: Add content_bytes to attachment table. content is deprecated.
|
|
|
|
// Version 13: Add messageCount to Mailbox table.
|
|
|
|
// Version 14: Add snippet to Message table
|
|
|
|
// Version 15: Fix upgrade problem in version 14.
|
|
|
|
// Version 16: Add accountKey to Attachment table
|
|
|
|
// Version 17: Add parentKey to Mailbox table
|
|
|
|
// Version 18: Copy Mailbox.displayName to Mailbox.serverId for all IMAP & POP3 mailboxes.
|
|
|
|
// Column Mailbox.serverId is used for the server-side pathname of a mailbox.
|
|
|
|
// Version 19: Add Policy table; add policyKey to Account table and trigger to delete an
|
|
|
|
// Account's policy when the Account is deleted
|
|
|
|
// Version 20: Add new policies to Policy table
|
|
|
|
// Version 21: Add lastSeenMessageKey column to Mailbox table
|
|
|
|
// Version 22: Upgrade path for IMAP/POP accounts to integrate with AccountManager
|
|
|
|
// Version 23: Add column to mailbox table for time of last access
|
|
|
|
// Version 24: Add column to hostauth table for client cert alias
|
|
|
|
// Version 25: Added QuickResponse table
|
|
|
|
// Version 26: Update IMAP accounts to add FLAG_SUPPORTS_SEARCH flag
|
|
|
|
// Version 27: Add protocolSearchInfo to Message table
|
|
|
|
// Version 28: Add notifiedMessageId and notifiedMessageCount to Account
|
|
|
|
// Version 29: Add protocolPoliciesEnforced and protocolPoliciesUnsupported to Policy
|
|
|
|
// Version 30: Use CSV of RFC822 addresses instead of "packed" values
|
|
|
|
// Version 31: Add columns to mailbox for ui status/last result
|
|
|
|
// Version 32: Add columns to mailbox for last notified message key/count; insure not null
|
|
|
|
// for "notified" columns
|
|
|
|
// Version 33: Add columns to attachment for ui provider columns
|
|
|
|
// Version 34: Add total count to mailbox
|
|
|
|
// Version 35: Set up defaults for lastTouchedCount for drafts and sent
|
|
|
|
// Version 36: mblank intentionally left this space
|
|
|
|
// Version 37: Add flag for settings support in folders
|
|
|
|
// Version 38&39: Add threadTopic to message (for future support)
|
|
|
|
// Version 39 is last Email1 version
|
|
|
|
// Version 100 is first Email2 version
|
|
|
|
// Version 101 SHOULD NOT BE USED
|
|
|
|
// Version 102&103: Add hierarchicalName to Mailbox
|
2012-06-29 16:42:05 +00:00
|
|
|
// Version 104&105: add syncData to Message
|
2012-07-31 22:47:49 +00:00
|
|
|
// Version 106: Add certificate to HostAuth
|
2012-12-11 18:37:35 +00:00
|
|
|
// Version 107: Add a SEEN column to the message table
|
2013-02-23 03:42:40 +00:00
|
|
|
// Version 108: Add a cachedFile column to the attachments table
|
2013-03-05 17:45:10 +00:00
|
|
|
// Version 109: Migrate the account so they have the correct account manager types
|
2013-06-14 01:03:06 +00:00
|
|
|
// Version 110: Stop updating message_count, don't use auto lookback, and don't use
|
2013-07-31 03:10:36 +00:00
|
|
|
// ping/push_hold sync states. Note that message_count updating is restored in 113.
|
2013-06-18 02:45:17 +00:00
|
|
|
// Version 111: Delete Exchange account mailboxes.
|
2013-06-21 00:11:01 +00:00
|
|
|
// Version 112: Convert Mailbox syncInterval to a boolean (whether or not this mailbox
|
|
|
|
// syncs along with the account).
|
2013-07-31 03:10:36 +00:00
|
|
|
// Version 113: Restore message_count to being useful.
|
2013-08-06 23:50:11 +00:00
|
|
|
// Version 114: Add lastFullSyncTime column
|
2013-08-21 17:46:55 +00:00
|
|
|
// Version 115: Add pingDuration column
|
2013-09-05 20:52:03 +00:00
|
|
|
// Version 116: Add MessageMove & MessageStateChange tables.
|
2013-09-17 16:39:36 +00:00
|
|
|
// Version 117: Add trigger to delete duplicate messages on sync.
|
2013-09-23 22:55:23 +00:00
|
|
|
// Version 118: Set syncInterval to 0 for all IMAP mailboxes
|
2013-10-10 21:49:53 +00:00
|
|
|
// Version 119: Disable syncing of DRAFTS type folders.
|
Change trigger to allow duplicate messages in search folders
b/11294681
b/11325976
The problem is that when we get a message as part of a search
result, we'll end up deleting that message from the inbox (or
whatever folder it's currently in). This is because there is
a trigger that deletes messages if a new message is inserted
that has the same serverId and account.
Now, messages with duplicate serverId/account combinations are
allowed if one of the messages is in a SEARCH type folder.
Also, make a change so that when a message comes down in
a search result, we do also copy it into the primary mailbox
that message resides in, we only add it to the SEARCH folder.
Prior to this there was some code that intended to put
the search result message into the regular mailbox it's supposed
to be in, so that we'd have correct state in that message.
Unfortunately, there are several problems with this:
1. The code didn't work, it would make a copy in the regular
folder, and then unconditionally move it to the search folder.
2. If we leave this code in place, putting the message
temporarily into the regular folder still activates the duplicate
message deletion trigger, wiping out the original copy, even with
the update to the trigger.
3. It's unclear that it's even desirable to load the search
result message into the regular folder. It could be a very old
message that would not have been synced before, leaving a large
gap in your inbox, which is confusing and could interfere with
IMAP syncing.
Change-Id: I34671a3b677ab42a3efd0d170a6ebd9246ec493d
2013-10-22 00:48:47 +00:00
|
|
|
// Version 120: Changed duplicateMessage deletion trigger to ignore search mailboxes.
|
Add an additional mailbox key column to message table
b/11294681
The problem is that when we try to open an attachment for a
message in search results, it fails. The reason is that part of
loading the attachment, we need to open the remote folder the
message is in. For search results, the message's mailboxKey is
the special fake "search_results" folder, which doesn't actually
exist on the server.
For this change, I've added a new column called "mainMailboxKey".
For search results, this column will be populated with the real
mailbox the message is in. It will be blank for other messages.
This is a quick and low risk fix for this bug, but it's kind
of awkward. We would prefer to do one or both of the following
some time after MR1.
1. Make the "search_results" folder be a virtual folder, the same
way that unread, starred, and other virtual folders are. For these,
there is actually no mailbox row in the database, just some
queries that check various flags in the messages and behave
like folders in the UI. The messages actually still reside in the
real folders.
2. Remove the requirement to open the folder at all to load the
attachment.
Change-Id: I825ab846f78bf8b041a5d1d579260dc5d7b4c522
2013-10-23 18:18:54 +00:00
|
|
|
// Version 121: Add mainMailboxKey, which will be set for messages that are in the fake
|
|
|
|
// "search_results" folder to reflect the mailbox that the server considers
|
|
|
|
// the message to be in. Also, wipe out any stale search_result folders.
|
2013-10-25 02:28:35 +00:00
|
|
|
// Version 122: Need to update Message_Updates and Message_Deletes to match previous.
|
2013-11-06 21:51:01 +00:00
|
|
|
// Version 123: Changed the duplicateMesage deletion trigger to ignore accounts that aren't
|
|
|
|
// exchange accounts.
|
2014-03-06 23:27:54 +00:00
|
|
|
// Version 124: Added MAX_ATTACHMENT_SIZE to the account table
|
|
|
|
// Version 125: Add credentials table for OAuth.
|
2014-01-25 00:43:36 +00:00
|
|
|
// Version 126: Decode address lists for To, From, Cc, Bcc and Reply-To columns in Message.
|
2014-04-01 21:37:36 +00:00
|
|
|
// Version 127: Force mFlags to contain the correct flags for EAS accounts given a protocol
|
|
|
|
// version above 12.0
|
2015-04-04 18:42:30 +00:00
|
|
|
// Version 129: Update all IMAP INBOX mailboxes to force synchronization
|
2015-05-01 19:35:23 +00:00
|
|
|
// Version 130: Account capabilities (check EmailServiceProxy#CAPABILITY_*)
|
|
|
|
public static final int DATABASE_VERSION = 130;
|
2012-06-28 19:16:59 +00:00
|
|
|
|
|
|
|
// Any changes to the database format *must* include update-in-place code.
|
|
|
|
// Original version: 2
|
|
|
|
// Version 3: Add "sourceKey" column
|
|
|
|
// Version 4: Database wipe required; changing AccountManager interface w/Exchange
|
|
|
|
// Version 5: Database wipe required; changing AccountManager interface w/Exchange
|
|
|
|
// Version 6: Adding Body.mIntroText column
|
|
|
|
// Version 7/8: Adding quoted text start pos
|
|
|
|
// Version 8 is last Email1 version
|
2014-05-12 18:33:43 +00:00
|
|
|
// Version 100 is the first Email2 version
|
|
|
|
// Version 101: Move body contents to external files
|
|
|
|
public static final int BODY_DATABASE_VERSION = 101;
|
2012-06-28 19:16:59 +00:00
|
|
|
|
2015-03-01 21:02:40 +00:00
|
|
|
// Any changes to the database format *must* include update-in-place code.
|
|
|
|
// Original version: 1
|
|
|
|
// Version 1: Suggested contacts
|
|
|
|
public static final int EXTRAS_DATABASE_VERSION = 1;
|
|
|
|
|
2012-06-28 19:16:59 +00:00
|
|
|
/*
|
|
|
|
* Internal helper method for index creation.
|
|
|
|
* Example:
|
|
|
|
* "create index message_" + MessageColumns.FLAG_READ
|
|
|
|
* + " on " + Message.TABLE_NAME + " (" + MessageColumns.FLAG_READ + ");"
|
|
|
|
*/
|
|
|
|
/* package */
|
|
|
|
static String createIndex(String tableName, String columnName) {
|
|
|
|
return "create index " + tableName.toLowerCase() + '_' + columnName
|
|
|
|
+ " on " + tableName + " (" + columnName + ");";
|
|
|
|
}
|
|
|
|
|
2013-07-31 03:10:36 +00:00
|
|
|
static void createMessageCountTriggers(final SQLiteDatabase db) {
|
|
|
|
// Insert a message.
|
|
|
|
db.execSQL("create trigger message_count_message_insert after insert on " +
|
|
|
|
Message.TABLE_NAME +
|
|
|
|
" begin update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.MESSAGE_COUNT +
|
|
|
|
'=' + MailboxColumns.MESSAGE_COUNT + "+1" +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + BaseColumns._ID + "=NEW." + MessageColumns.MAILBOX_KEY +
|
2013-07-31 03:10:36 +00:00
|
|
|
"; end");
|
|
|
|
|
|
|
|
// Delete a message.
|
|
|
|
db.execSQL("create trigger message_count_message_delete after delete on " +
|
|
|
|
Message.TABLE_NAME +
|
|
|
|
" begin update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.MESSAGE_COUNT +
|
|
|
|
'=' + MailboxColumns.MESSAGE_COUNT + "-1" +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + BaseColumns._ID + "=OLD." + MessageColumns.MAILBOX_KEY +
|
2013-07-31 03:10:36 +00:00
|
|
|
"; end");
|
|
|
|
|
|
|
|
// Change a message's mailbox.
|
|
|
|
db.execSQL("create trigger message_count_message_move after update of " +
|
|
|
|
MessageColumns.MAILBOX_KEY + " on " + Message.TABLE_NAME +
|
|
|
|
" begin update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.MESSAGE_COUNT +
|
|
|
|
'=' + MailboxColumns.MESSAGE_COUNT + "-1" +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + BaseColumns._ID + "=OLD." + MessageColumns.MAILBOX_KEY +
|
2013-07-31 03:10:36 +00:00
|
|
|
"; update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.MESSAGE_COUNT +
|
|
|
|
'=' + MailboxColumns.MESSAGE_COUNT + "+1" +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + BaseColumns._ID + "=NEW." + MessageColumns.MAILBOX_KEY +
|
2013-07-31 03:10:36 +00:00
|
|
|
"; end");
|
|
|
|
}
|
|
|
|
|
2013-12-04 00:55:48 +00:00
|
|
|
static void createCredentialsTable(SQLiteDatabase db) {
|
2014-04-11 21:42:28 +00:00
|
|
|
String s = " (" + Credential._ID + " integer primary key autoincrement, "
|
2013-12-04 00:55:48 +00:00
|
|
|
+ Credential.PROVIDER_COLUMN + " text,"
|
|
|
|
+ Credential.ACCESS_TOKEN_COLUMN + " text,"
|
|
|
|
+ Credential.REFRESH_TOKEN_COLUMN + " text,"
|
|
|
|
+ Credential.EXPIRATION_COLUMN + " integer"
|
|
|
|
+ ");";
|
|
|
|
db.execSQL("create table " + Credential.TABLE_NAME + s);
|
|
|
|
db.execSQL(TRIGGER_HOST_AUTH_DELETE);
|
|
|
|
}
|
|
|
|
|
Change trigger to allow duplicate messages in search folders
b/11294681
b/11325976
The problem is that when we get a message as part of a search
result, we'll end up deleting that message from the inbox (or
whatever folder it's currently in). This is because there is
a trigger that deletes messages if a new message is inserted
that has the same serverId and account.
Now, messages with duplicate serverId/account combinations are
allowed if one of the messages is in a SEARCH type folder.
Also, make a change so that when a message comes down in
a search result, we do also copy it into the primary mailbox
that message resides in, we only add it to the SEARCH folder.
Prior to this there was some code that intended to put
the search result message into the regular mailbox it's supposed
to be in, so that we'd have correct state in that message.
Unfortunately, there are several problems with this:
1. The code didn't work, it would make a copy in the regular
folder, and then unconditionally move it to the search folder.
2. If we leave this code in place, putting the message
temporarily into the regular folder still activates the duplicate
message deletion trigger, wiping out the original copy, even with
the update to the trigger.
3. It's unclear that it's even desirable to load the search
result message into the regular folder. It could be a very old
message that would not have been synced before, leaving a large
gap in your inbox, which is confusing and could interfere with
IMAP syncing.
Change-Id: I34671a3b677ab42a3efd0d170a6ebd9246ec493d
2013-10-22 00:48:47 +00:00
|
|
|
static void dropDeleteDuplicateMessagesTrigger(final SQLiteDatabase db) {
|
|
|
|
db.execSQL("drop trigger message_delete_duplicates_on_insert");
|
|
|
|
}
|
|
|
|
|
2013-09-17 16:39:36 +00:00
|
|
|
/**
|
|
|
|
* Add a trigger to delete duplicate server side messages before insertion.
|
2013-11-06 21:51:01 +00:00
|
|
|
* This should delete any messages older messages that have the same serverId and account as
|
|
|
|
* the new message, if:
|
|
|
|
* Neither message is in a SEARCH type mailbox, and
|
|
|
|
* The new message's mailbox's account is an exchange account.
|
|
|
|
*
|
Change trigger to allow duplicate messages in search folders
b/11294681
b/11325976
The problem is that when we get a message as part of a search
result, we'll end up deleting that message from the inbox (or
whatever folder it's currently in). This is because there is
a trigger that deletes messages if a new message is inserted
that has the same serverId and account.
Now, messages with duplicate serverId/account combinations are
allowed if one of the messages is in a SEARCH type folder.
Also, make a change so that when a message comes down in
a search result, we do also copy it into the primary mailbox
that message resides in, we only add it to the SEARCH folder.
Prior to this there was some code that intended to put
the search result message into the regular mailbox it's supposed
to be in, so that we'd have correct state in that message.
Unfortunately, there are several problems with this:
1. The code didn't work, it would make a copy in the regular
folder, and then unconditionally move it to the search folder.
2. If we leave this code in place, putting the message
temporarily into the regular folder still activates the duplicate
message deletion trigger, wiping out the original copy, even with
the update to the trigger.
3. It's unclear that it's even desirable to load the search
result message into the regular folder. It could be a very old
message that would not have been synced before, leaving a large
gap in your inbox, which is confusing and could interfere with
IMAP syncing.
Change-Id: I34671a3b677ab42a3efd0d170a6ebd9246ec493d
2013-10-22 00:48:47 +00:00
|
|
|
* Here is the plain text of this sql:
|
|
|
|
* create trigger message_delete_duplicates_on_insert before insert on
|
2013-11-06 21:51:01 +00:00
|
|
|
* Message for each row when new.syncServerId is not null and
|
|
|
|
* (select type from Mailbox where _id=new.mailboxKey) != 8 and
|
|
|
|
* (select HostAuth.protocol from HostAuth, Account where
|
|
|
|
* new.accountKey=account._id and account.hostAuthKeyRecv=hostAuth._id) = 'gEas'
|
|
|
|
* begin delete from Message where new.syncServerId=syncSeverId and
|
Change trigger to allow duplicate messages in search folders
b/11294681
b/11325976
The problem is that when we get a message as part of a search
result, we'll end up deleting that message from the inbox (or
whatever folder it's currently in). This is because there is
a trigger that deletes messages if a new message is inserted
that has the same serverId and account.
Now, messages with duplicate serverId/account combinations are
allowed if one of the messages is in a SEARCH type folder.
Also, make a change so that when a message comes down in
a search result, we do also copy it into the primary mailbox
that message resides in, we only add it to the SEARCH folder.
Prior to this there was some code that intended to put
the search result message into the regular mailbox it's supposed
to be in, so that we'd have correct state in that message.
Unfortunately, there are several problems with this:
1. The code didn't work, it would make a copy in the regular
folder, and then unconditionally move it to the search folder.
2. If we leave this code in place, putting the message
temporarily into the regular folder still activates the duplicate
message deletion trigger, wiping out the original copy, even with
the update to the trigger.
3. It's unclear that it's even desirable to load the search
result message into the regular folder. It could be a very old
message that would not have been synced before, leaving a large
gap in your inbox, which is confusing and could interfere with
IMAP syncing.
Change-Id: I34671a3b677ab42a3efd0d170a6ebd9246ec493d
2013-10-22 00:48:47 +00:00
|
|
|
* new.accountKey=accountKey and
|
2013-11-06 21:51:01 +00:00
|
|
|
* (select Mailbox.type from Mailbox where _id=mailboxKey) != 8; end
|
2013-09-17 16:39:36 +00:00
|
|
|
*/
|
2013-11-06 21:51:01 +00:00
|
|
|
static void createDeleteDuplicateMessagesTrigger(final Context context,
|
|
|
|
final SQLiteDatabase db) {
|
2013-09-17 16:39:36 +00:00
|
|
|
db.execSQL("create trigger message_delete_duplicates_on_insert before insert on "
|
|
|
|
+ Message.TABLE_NAME + " for each row when new." + SyncColumns.SERVER_ID
|
Change trigger to allow duplicate messages in search folders
b/11294681
b/11325976
The problem is that when we get a message as part of a search
result, we'll end up deleting that message from the inbox (or
whatever folder it's currently in). This is because there is
a trigger that deletes messages if a new message is inserted
that has the same serverId and account.
Now, messages with duplicate serverId/account combinations are
allowed if one of the messages is in a SEARCH type folder.
Also, make a change so that when a message comes down in
a search result, we do also copy it into the primary mailbox
that message resides in, we only add it to the SEARCH folder.
Prior to this there was some code that intended to put
the search result message into the regular mailbox it's supposed
to be in, so that we'd have correct state in that message.
Unfortunately, there are several problems with this:
1. The code didn't work, it would make a copy in the regular
folder, and then unconditionally move it to the search folder.
2. If we leave this code in place, putting the message
temporarily into the regular folder still activates the duplicate
message deletion trigger, wiping out the original copy, even with
the update to the trigger.
3. It's unclear that it's even desirable to load the search
result message into the regular folder. It could be a very old
message that would not have been synced before, leaving a large
gap in your inbox, which is confusing and could interfere with
IMAP syncing.
Change-Id: I34671a3b677ab42a3efd0d170a6ebd9246ec493d
2013-10-22 00:48:47 +00:00
|
|
|
+ " is not null and "
|
2013-11-06 21:51:01 +00:00
|
|
|
+ "(select " + MailboxColumns.TYPE + " from " + Mailbox.TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " where " + MailboxColumns._ID + "=new."
|
Change trigger to allow duplicate messages in search folders
b/11294681
b/11325976
The problem is that when we get a message as part of a search
result, we'll end up deleting that message from the inbox (or
whatever folder it's currently in). This is because there is
a trigger that deletes messages if a new message is inserted
that has the same serverId and account.
Now, messages with duplicate serverId/account combinations are
allowed if one of the messages is in a SEARCH type folder.
Also, make a change so that when a message comes down in
a search result, we do also copy it into the primary mailbox
that message resides in, we only add it to the SEARCH folder.
Prior to this there was some code that intended to put
the search result message into the regular mailbox it's supposed
to be in, so that we'd have correct state in that message.
Unfortunately, there are several problems with this:
1. The code didn't work, it would make a copy in the regular
folder, and then unconditionally move it to the search folder.
2. If we leave this code in place, putting the message
temporarily into the regular folder still activates the duplicate
message deletion trigger, wiping out the original copy, even with
the update to the trigger.
3. It's unclear that it's even desirable to load the search
result message into the regular folder. It could be a very old
message that would not have been synced before, leaving a large
gap in your inbox, which is confusing and could interfere with
IMAP syncing.
Change-Id: I34671a3b677ab42a3efd0d170a6ebd9246ec493d
2013-10-22 00:48:47 +00:00
|
|
|
+ MessageColumns.MAILBOX_KEY + ")!=" + Mailbox.TYPE_SEARCH
|
2013-11-06 21:51:01 +00:00
|
|
|
+ " and (select "
|
|
|
|
+ HostAuth.TABLE_NAME + "." + HostAuthColumns.PROTOCOL + " from "
|
|
|
|
+ HostAuth.TABLE_NAME + "," + Account.TABLE_NAME
|
|
|
|
+ " where new." + MessageColumns.ACCOUNT_KEY
|
2014-04-11 21:42:28 +00:00
|
|
|
+ "=" + Account.TABLE_NAME + "." + AccountColumns._ID
|
2013-11-06 21:51:01 +00:00
|
|
|
+ " and " + Account.TABLE_NAME + "." + AccountColumns.HOST_AUTH_KEY_RECV
|
2014-04-11 21:42:28 +00:00
|
|
|
+ "=" + HostAuth.TABLE_NAME + "." + HostAuthColumns._ID
|
2013-11-06 21:51:01 +00:00
|
|
|
+ ")='" + context.getString(R.string.protocol_eas) + "'"
|
Change trigger to allow duplicate messages in search folders
b/11294681
b/11325976
The problem is that when we get a message as part of a search
result, we'll end up deleting that message from the inbox (or
whatever folder it's currently in). This is because there is
a trigger that deletes messages if a new message is inserted
that has the same serverId and account.
Now, messages with duplicate serverId/account combinations are
allowed if one of the messages is in a SEARCH type folder.
Also, make a change so that when a message comes down in
a search result, we do also copy it into the primary mailbox
that message resides in, we only add it to the SEARCH folder.
Prior to this there was some code that intended to put
the search result message into the regular mailbox it's supposed
to be in, so that we'd have correct state in that message.
Unfortunately, there are several problems with this:
1. The code didn't work, it would make a copy in the regular
folder, and then unconditionally move it to the search folder.
2. If we leave this code in place, putting the message
temporarily into the regular folder still activates the duplicate
message deletion trigger, wiping out the original copy, even with
the update to the trigger.
3. It's unclear that it's even desirable to load the search
result message into the regular folder. It could be a very old
message that would not have been synced before, leaving a large
gap in your inbox, which is confusing and could interfere with
IMAP syncing.
Change-Id: I34671a3b677ab42a3efd0d170a6ebd9246ec493d
2013-10-22 00:48:47 +00:00
|
|
|
+ " begin delete from " + Message.TABLE_NAME + " where new."
|
2013-09-17 16:39:36 +00:00
|
|
|
+ SyncColumns.SERVER_ID + "=" + SyncColumns.SERVER_ID + " and new."
|
Change trigger to allow duplicate messages in search folders
b/11294681
b/11325976
The problem is that when we get a message as part of a search
result, we'll end up deleting that message from the inbox (or
whatever folder it's currently in). This is because there is
a trigger that deletes messages if a new message is inserted
that has the same serverId and account.
Now, messages with duplicate serverId/account combinations are
allowed if one of the messages is in a SEARCH type folder.
Also, make a change so that when a message comes down in
a search result, we do also copy it into the primary mailbox
that message resides in, we only add it to the SEARCH folder.
Prior to this there was some code that intended to put
the search result message into the regular mailbox it's supposed
to be in, so that we'd have correct state in that message.
Unfortunately, there are several problems with this:
1. The code didn't work, it would make a copy in the regular
folder, and then unconditionally move it to the search folder.
2. If we leave this code in place, putting the message
temporarily into the regular folder still activates the duplicate
message deletion trigger, wiping out the original copy, even with
the update to the trigger.
3. It's unclear that it's even desirable to load the search
result message into the regular folder. It could be a very old
message that would not have been synced before, leaving a large
gap in your inbox, which is confusing and could interfere with
IMAP syncing.
Change-Id: I34671a3b677ab42a3efd0d170a6ebd9246ec493d
2013-10-22 00:48:47 +00:00
|
|
|
+ MessageColumns.ACCOUNT_KEY + "=" + MessageColumns.ACCOUNT_KEY
|
|
|
|
+ " and (select " + Mailbox.TABLE_NAME + "." + MailboxColumns.TYPE + " from "
|
2014-04-11 21:42:28 +00:00
|
|
|
+ Mailbox.TABLE_NAME + " where " + MailboxColumns._ID + "="
|
Change trigger to allow duplicate messages in search folders
b/11294681
b/11325976
The problem is that when we get a message as part of a search
result, we'll end up deleting that message from the inbox (or
whatever folder it's currently in). This is because there is
a trigger that deletes messages if a new message is inserted
that has the same serverId and account.
Now, messages with duplicate serverId/account combinations are
allowed if one of the messages is in a SEARCH type folder.
Also, make a change so that when a message comes down in
a search result, we do also copy it into the primary mailbox
that message resides in, we only add it to the SEARCH folder.
Prior to this there was some code that intended to put
the search result message into the regular mailbox it's supposed
to be in, so that we'd have correct state in that message.
Unfortunately, there are several problems with this:
1. The code didn't work, it would make a copy in the regular
folder, and then unconditionally move it to the search folder.
2. If we leave this code in place, putting the message
temporarily into the regular folder still activates the duplicate
message deletion trigger, wiping out the original copy, even with
the update to the trigger.
3. It's unclear that it's even desirable to load the search
result message into the regular folder. It could be a very old
message that would not have been synced before, leaving a large
gap in your inbox, which is confusing and could interfere with
IMAP syncing.
Change-Id: I34671a3b677ab42a3efd0d170a6ebd9246ec493d
2013-10-22 00:48:47 +00:00
|
|
|
+ MessageColumns.MAILBOX_KEY + ")!=" + Mailbox.TYPE_SEARCH +"; end");
|
2013-09-17 16:39:36 +00:00
|
|
|
}
|
|
|
|
|
2013-11-06 21:51:01 +00:00
|
|
|
static void createMessageTable(Context context, SQLiteDatabase db) {
|
2012-06-28 19:16:59 +00:00
|
|
|
String messageColumns = MessageColumns.DISPLAY_NAME + " text, "
|
|
|
|
+ MessageColumns.TIMESTAMP + " integer, "
|
|
|
|
+ MessageColumns.SUBJECT + " text, "
|
|
|
|
+ MessageColumns.FLAG_READ + " integer, "
|
|
|
|
+ MessageColumns.FLAG_LOADED + " integer, "
|
|
|
|
+ MessageColumns.FLAG_FAVORITE + " integer, "
|
|
|
|
+ MessageColumns.FLAG_ATTACHMENT + " integer, "
|
|
|
|
+ MessageColumns.FLAGS + " integer, "
|
|
|
|
+ MessageColumns.DRAFT_INFO + " integer, "
|
|
|
|
+ MessageColumns.MESSAGE_ID + " text, "
|
|
|
|
+ MessageColumns.MAILBOX_KEY + " integer, "
|
|
|
|
+ MessageColumns.ACCOUNT_KEY + " integer, "
|
|
|
|
+ MessageColumns.FROM_LIST + " text, "
|
|
|
|
+ MessageColumns.TO_LIST + " text, "
|
|
|
|
+ MessageColumns.CC_LIST + " text, "
|
|
|
|
+ MessageColumns.BCC_LIST + " text, "
|
|
|
|
+ MessageColumns.REPLY_TO_LIST + " text, "
|
|
|
|
+ MessageColumns.MEETING_INFO + " text, "
|
|
|
|
+ MessageColumns.SNIPPET + " text, "
|
|
|
|
+ MessageColumns.PROTOCOL_SEARCH_INFO + " text, "
|
2012-06-29 16:42:05 +00:00
|
|
|
+ MessageColumns.THREAD_TOPIC + " text, "
|
2012-12-11 18:37:35 +00:00
|
|
|
+ MessageColumns.SYNC_DATA + " text, "
|
Add an additional mailbox key column to message table
b/11294681
The problem is that when we try to open an attachment for a
message in search results, it fails. The reason is that part of
loading the attachment, we need to open the remote folder the
message is in. For search results, the message's mailboxKey is
the special fake "search_results" folder, which doesn't actually
exist on the server.
For this change, I've added a new column called "mainMailboxKey".
For search results, this column will be populated with the real
mailbox the message is in. It will be blank for other messages.
This is a quick and low risk fix for this bug, but it's kind
of awkward. We would prefer to do one or both of the following
some time after MR1.
1. Make the "search_results" folder be a virtual folder, the same
way that unread, starred, and other virtual folders are. For these,
there is actually no mailbox row in the database, just some
queries that check various flags in the messages and behave
like folders in the UI. The messages actually still reside in the
real folders.
2. Remove the requirement to open the folder at all to load the
attachment.
Change-Id: I825ab846f78bf8b041a5d1d579260dc5d7b4c522
2013-10-23 18:18:54 +00:00
|
|
|
+ MessageColumns.FLAG_SEEN + " integer, "
|
|
|
|
+ MessageColumns.MAIN_MAILBOX_KEY + " integer"
|
2012-06-28 19:16:59 +00:00
|
|
|
+ ");";
|
|
|
|
|
|
|
|
// This String and the following String MUST have the same columns, except for the type
|
|
|
|
// of those columns!
|
2014-04-11 21:42:28 +00:00
|
|
|
String createString = " (" + BaseColumns._ID + " integer primary key autoincrement, "
|
2012-06-28 19:16:59 +00:00
|
|
|
+ SyncColumns.SERVER_ID + " text, "
|
|
|
|
+ SyncColumns.SERVER_TIMESTAMP + " integer, "
|
|
|
|
+ messageColumns;
|
|
|
|
|
|
|
|
// For the updated and deleted tables, the id is assigned, but we do want to keep track
|
|
|
|
// of the ORDER of updates using an autoincrement primary key. We use the DATA column
|
|
|
|
// at this point; it has no other function
|
2014-04-11 21:42:28 +00:00
|
|
|
String altCreateString = " (" + BaseColumns._ID + " integer unique, "
|
2012-06-28 19:16:59 +00:00
|
|
|
+ SyncColumns.SERVER_ID + " text, "
|
|
|
|
+ SyncColumns.SERVER_TIMESTAMP + " integer, "
|
|
|
|
+ messageColumns;
|
|
|
|
|
|
|
|
// The three tables have the same schema
|
|
|
|
db.execSQL("create table " + Message.TABLE_NAME + createString);
|
|
|
|
db.execSQL("create table " + Message.UPDATED_TABLE_NAME + altCreateString);
|
|
|
|
db.execSQL("create table " + Message.DELETED_TABLE_NAME + altCreateString);
|
|
|
|
|
|
|
|
String indexColumns[] = {
|
|
|
|
MessageColumns.TIMESTAMP,
|
|
|
|
MessageColumns.FLAG_READ,
|
|
|
|
MessageColumns.FLAG_LOADED,
|
|
|
|
MessageColumns.MAILBOX_KEY,
|
|
|
|
SyncColumns.SERVER_ID
|
|
|
|
};
|
|
|
|
|
|
|
|
for (String columnName : indexColumns) {
|
|
|
|
db.execSQL(createIndex(Message.TABLE_NAME, columnName));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deleting a Message deletes all associated Attachments
|
|
|
|
// Deleting the associated Body cannot be done in a trigger, because the Body is stored
|
|
|
|
// in a separate database, and trigger cannot operate on attached databases.
|
|
|
|
db.execSQL("create trigger message_delete before delete on " + Message.TABLE_NAME +
|
|
|
|
" begin delete from " + Attachment.TABLE_NAME +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + AttachmentColumns.MESSAGE_KEY + "=old." + BaseColumns._ID +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; end");
|
|
|
|
|
|
|
|
// Add triggers to keep unread count accurate per mailbox
|
|
|
|
|
|
|
|
// NOTE: SQLite's before triggers are not safe when recursive triggers are involved.
|
|
|
|
// Use caution when changing them.
|
|
|
|
|
|
|
|
// Insert a message; if flagRead is zero, add to the unread count of the message's mailbox
|
|
|
|
db.execSQL("create trigger unread_message_insert before insert on " + Message.TABLE_NAME +
|
|
|
|
" when NEW." + MessageColumns.FLAG_READ + "=0" +
|
|
|
|
" begin update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.UNREAD_COUNT +
|
|
|
|
'=' + MailboxColumns.UNREAD_COUNT + "+1" +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + BaseColumns._ID + "=NEW." + MessageColumns.MAILBOX_KEY +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; end");
|
|
|
|
|
|
|
|
// Delete a message; if flagRead is zero, decrement the unread count of the msg's mailbox
|
|
|
|
db.execSQL("create trigger unread_message_delete before delete on " + Message.TABLE_NAME +
|
|
|
|
" when OLD." + MessageColumns.FLAG_READ + "=0" +
|
|
|
|
" begin update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.UNREAD_COUNT +
|
|
|
|
'=' + MailboxColumns.UNREAD_COUNT + "-1" +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + BaseColumns._ID + "=OLD." + MessageColumns.MAILBOX_KEY +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; end");
|
|
|
|
|
|
|
|
// Change a message's mailbox
|
|
|
|
db.execSQL("create trigger unread_message_move before update of " +
|
|
|
|
MessageColumns.MAILBOX_KEY + " on " + Message.TABLE_NAME +
|
|
|
|
" when OLD." + MessageColumns.FLAG_READ + "=0" +
|
|
|
|
" begin update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.UNREAD_COUNT +
|
|
|
|
'=' + MailboxColumns.UNREAD_COUNT + "-1" +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + BaseColumns._ID + "=OLD." + MessageColumns.MAILBOX_KEY +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.UNREAD_COUNT +
|
|
|
|
'=' + MailboxColumns.UNREAD_COUNT + "+1" +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + BaseColumns._ID + "=NEW." + MessageColumns.MAILBOX_KEY +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; end");
|
|
|
|
|
|
|
|
// Change a message's read state
|
|
|
|
db.execSQL("create trigger unread_message_read before update of " +
|
|
|
|
MessageColumns.FLAG_READ + " on " + Message.TABLE_NAME +
|
|
|
|
" when OLD." + MessageColumns.FLAG_READ + "!=NEW." + MessageColumns.FLAG_READ +
|
|
|
|
" begin update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.UNREAD_COUNT +
|
|
|
|
'=' + MailboxColumns.UNREAD_COUNT + "+ case OLD." + MessageColumns.FLAG_READ +
|
|
|
|
" when 0 then -1 else 1 end" +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + BaseColumns._ID + "=OLD." + MessageColumns.MAILBOX_KEY +
|
2012-06-28 19:16:59 +00:00
|
|
|
"; end");
|
2013-07-31 03:10:36 +00:00
|
|
|
|
|
|
|
// Add triggers to maintain message_count.
|
|
|
|
createMessageCountTriggers(db);
|
2013-11-06 21:51:01 +00:00
|
|
|
createDeleteDuplicateMessagesTrigger(context, db);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
|
2013-11-06 21:51:01 +00:00
|
|
|
static void resetMessageTable(Context context, SQLiteDatabase db,
|
|
|
|
int oldVersion, int newVersion) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("drop table " + Message.TABLE_NAME);
|
|
|
|
db.execSQL("drop table " + Message.UPDATED_TABLE_NAME);
|
|
|
|
db.execSQL("drop table " + Message.DELETED_TABLE_NAME);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
}
|
2013-11-06 21:51:01 +00:00
|
|
|
createMessageTable(context, db);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
|
2013-09-05 20:52:03 +00:00
|
|
|
/**
|
|
|
|
* Common columns for all {@link MessageChangeLogTable} tables.
|
|
|
|
*/
|
|
|
|
private static String MESSAGE_CHANGE_LOG_COLUMNS =
|
|
|
|
MessageChangeLogTable.ID + " integer primary key autoincrement, "
|
|
|
|
+ MessageChangeLogTable.MESSAGE_KEY + " integer, "
|
|
|
|
+ MessageChangeLogTable.SERVER_ID + " text, "
|
|
|
|
+ MessageChangeLogTable.ACCOUNT_KEY + " integer, "
|
|
|
|
+ MessageChangeLogTable.STATUS + " integer, ";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create indices common to all {@link MessageChangeLogTable} tables.
|
|
|
|
* @param db The {@link SQLiteDatabase}.
|
|
|
|
* @param tableName The name of this particular table.
|
|
|
|
*/
|
|
|
|
private static void createMessageChangeLogTableIndices(final SQLiteDatabase db,
|
|
|
|
final String tableName) {
|
|
|
|
db.execSQL(createIndex(tableName, MessageChangeLogTable.MESSAGE_KEY));
|
|
|
|
db.execSQL(createIndex(tableName, MessageChangeLogTable.ACCOUNT_KEY));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create triggers common to all {@link MessageChangeLogTable} tables.
|
|
|
|
* @param db The {@link SQLiteDatabase}.
|
|
|
|
* @param tableName The name of this particular table.
|
|
|
|
*/
|
|
|
|
private static void createMessageChangeLogTableTriggers(final SQLiteDatabase db,
|
|
|
|
final String tableName) {
|
|
|
|
// Trigger to delete from the change log when a message is deleted.
|
|
|
|
db.execSQL("create trigger " + tableName + "_delete_message before delete on "
|
|
|
|
+ Message.TABLE_NAME + " for each row begin delete from " + tableName
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " where " + MessageChangeLogTable.MESSAGE_KEY + "=old." + MessageColumns._ID
|
2013-09-05 20:52:03 +00:00
|
|
|
+ "; end");
|
|
|
|
|
|
|
|
// Trigger to delete from the change log when an account is deleted.
|
|
|
|
db.execSQL("create trigger " + tableName + "_delete_account before delete on "
|
|
|
|
+ Account.TABLE_NAME + " for each row begin delete from " + tableName
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " where " + MessageChangeLogTable.ACCOUNT_KEY + "=old." + AccountColumns._ID
|
2013-09-05 20:52:03 +00:00
|
|
|
+ "; end");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the MessageMove table.
|
|
|
|
* @param db The {@link SQLiteDatabase}.
|
|
|
|
*/
|
|
|
|
private static void createMessageMoveTable(final SQLiteDatabase db) {
|
|
|
|
db.execSQL("create table " + MessageMove.TABLE_NAME + " ("
|
|
|
|
+ MESSAGE_CHANGE_LOG_COLUMNS
|
|
|
|
+ MessageMove.SRC_FOLDER_KEY + " integer, "
|
|
|
|
+ MessageMove.DST_FOLDER_KEY + " integer, "
|
|
|
|
+ MessageMove.SRC_FOLDER_SERVER_ID + " text, "
|
|
|
|
+ MessageMove.DST_FOLDER_SERVER_ID + " text);");
|
|
|
|
|
|
|
|
createMessageChangeLogTableIndices(db, MessageMove.TABLE_NAME);
|
|
|
|
createMessageChangeLogTableTriggers(db, MessageMove.TABLE_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the MessageStateChange table.
|
|
|
|
* @param db The {@link SQLiteDatabase}.
|
|
|
|
*/
|
|
|
|
private static void createMessageStateChangeTable(final SQLiteDatabase db) {
|
|
|
|
db.execSQL("create table " + MessageStateChange.TABLE_NAME + " ("
|
|
|
|
+ MESSAGE_CHANGE_LOG_COLUMNS
|
|
|
|
+ MessageStateChange.OLD_FLAG_READ + " integer, "
|
|
|
|
+ MessageStateChange.NEW_FLAG_READ + " integer, "
|
|
|
|
+ MessageStateChange.OLD_FLAG_FAVORITE + " integer, "
|
|
|
|
+ MessageStateChange.NEW_FLAG_FAVORITE + " integer);");
|
|
|
|
|
|
|
|
createMessageChangeLogTableIndices(db, MessageStateChange.TABLE_NAME);
|
|
|
|
createMessageChangeLogTableTriggers(db, MessageStateChange.TABLE_NAME);
|
|
|
|
}
|
|
|
|
|
2012-06-28 19:16:59 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
static void createAccountTable(SQLiteDatabase db) {
|
2014-04-11 21:42:28 +00:00
|
|
|
String s = " (" + AccountColumns._ID + " integer primary key autoincrement, "
|
2012-06-28 19:16:59 +00:00
|
|
|
+ AccountColumns.DISPLAY_NAME + " text, "
|
|
|
|
+ AccountColumns.EMAIL_ADDRESS + " text, "
|
|
|
|
+ AccountColumns.SYNC_KEY + " text, "
|
|
|
|
+ AccountColumns.SYNC_LOOKBACK + " integer, "
|
|
|
|
+ AccountColumns.SYNC_INTERVAL + " text, "
|
|
|
|
+ AccountColumns.HOST_AUTH_KEY_RECV + " integer, "
|
|
|
|
+ AccountColumns.HOST_AUTH_KEY_SEND + " integer, "
|
|
|
|
+ AccountColumns.FLAGS + " integer, "
|
|
|
|
+ AccountColumns.IS_DEFAULT + " integer, "
|
|
|
|
+ AccountColumns.COMPATIBILITY_UUID + " text, "
|
|
|
|
+ AccountColumns.SENDER_NAME + " text, "
|
|
|
|
+ AccountColumns.RINGTONE_URI + " text, "
|
|
|
|
+ AccountColumns.PROTOCOL_VERSION + " text, "
|
|
|
|
+ AccountColumns.NEW_MESSAGE_COUNT + " integer, "
|
|
|
|
+ AccountColumns.SECURITY_FLAGS + " integer, "
|
|
|
|
+ AccountColumns.SECURITY_SYNC_KEY + " text, "
|
|
|
|
+ AccountColumns.SIGNATURE + " text, "
|
2013-08-21 17:46:55 +00:00
|
|
|
+ AccountColumns.POLICY_KEY + " integer, "
|
2014-03-06 23:27:54 +00:00
|
|
|
+ AccountColumns.MAX_ATTACHMENT_SIZE + " integer, "
|
2015-05-01 20:05:03 +00:00
|
|
|
+ AccountColumns.PING_DURATION + " integer, "
|
2015-05-01 19:35:23 +00:00
|
|
|
+ AccountColumns.AUTO_FETCH_ATTACHMENTS + " integer, "
|
|
|
|
+ AccountColumns.CAPABILITIES + " integer default 0"
|
2012-06-28 19:16:59 +00:00
|
|
|
+ ");";
|
|
|
|
db.execSQL("create table " + Account.TABLE_NAME + s);
|
|
|
|
// Deleting an account deletes associated Mailboxes and HostAuth's
|
|
|
|
db.execSQL(TRIGGER_ACCOUNT_DELETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void resetAccountTable(SQLiteDatabase db, int oldVersion, int newVersion) {
|
|
|
|
try {
|
|
|
|
db.execSQL("drop table " + Account.TABLE_NAME);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
}
|
|
|
|
createAccountTable(db);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void createPolicyTable(SQLiteDatabase db) {
|
2014-04-11 21:42:28 +00:00
|
|
|
String s = " (" + PolicyColumns._ID + " integer primary key autoincrement, "
|
2012-06-28 19:16:59 +00:00
|
|
|
+ PolicyColumns.PASSWORD_MODE + " integer, "
|
|
|
|
+ PolicyColumns.PASSWORD_MIN_LENGTH + " integer, "
|
|
|
|
+ PolicyColumns.PASSWORD_EXPIRATION_DAYS + " integer, "
|
|
|
|
+ PolicyColumns.PASSWORD_HISTORY + " integer, "
|
|
|
|
+ PolicyColumns.PASSWORD_COMPLEX_CHARS + " integer, "
|
|
|
|
+ PolicyColumns.PASSWORD_MAX_FAILS + " integer, "
|
|
|
|
+ PolicyColumns.MAX_SCREEN_LOCK_TIME + " integer, "
|
|
|
|
+ PolicyColumns.REQUIRE_REMOTE_WIPE + " integer, "
|
|
|
|
+ PolicyColumns.REQUIRE_ENCRYPTION + " integer, "
|
|
|
|
+ PolicyColumns.REQUIRE_ENCRYPTION_EXTERNAL + " integer, "
|
|
|
|
+ PolicyColumns.REQUIRE_MANUAL_SYNC_WHEN_ROAMING + " integer, "
|
|
|
|
+ PolicyColumns.DONT_ALLOW_CAMERA + " integer, "
|
|
|
|
+ PolicyColumns.DONT_ALLOW_ATTACHMENTS + " integer, "
|
|
|
|
+ PolicyColumns.DONT_ALLOW_HTML + " integer, "
|
|
|
|
+ PolicyColumns.MAX_ATTACHMENT_SIZE + " integer, "
|
|
|
|
+ PolicyColumns.MAX_TEXT_TRUNCATION_SIZE + " integer, "
|
|
|
|
+ PolicyColumns.MAX_HTML_TRUNCATION_SIZE + " integer, "
|
|
|
|
+ PolicyColumns.MAX_EMAIL_LOOKBACK + " integer, "
|
|
|
|
+ PolicyColumns.MAX_CALENDAR_LOOKBACK + " integer, "
|
|
|
|
+ PolicyColumns.PASSWORD_RECOVERY_ENABLED + " integer, "
|
|
|
|
+ PolicyColumns.PROTOCOL_POLICIES_ENFORCED + " text, "
|
|
|
|
+ PolicyColumns.PROTOCOL_POLICIES_UNSUPPORTED + " text"
|
|
|
|
+ ");";
|
|
|
|
db.execSQL("create table " + Policy.TABLE_NAME + s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void createHostAuthTable(SQLiteDatabase db) {
|
2014-04-11 21:42:28 +00:00
|
|
|
String s = " (" + HostAuthColumns._ID + " integer primary key autoincrement, "
|
2012-06-28 19:16:59 +00:00
|
|
|
+ HostAuthColumns.PROTOCOL + " text, "
|
|
|
|
+ HostAuthColumns.ADDRESS + " text, "
|
|
|
|
+ HostAuthColumns.PORT + " integer, "
|
|
|
|
+ HostAuthColumns.FLAGS + " integer, "
|
|
|
|
+ HostAuthColumns.LOGIN + " text, "
|
|
|
|
+ HostAuthColumns.PASSWORD + " text, "
|
|
|
|
+ HostAuthColumns.DOMAIN + " text, "
|
|
|
|
+ HostAuthColumns.ACCOUNT_KEY + " integer,"
|
2012-07-31 22:47:49 +00:00
|
|
|
+ HostAuthColumns.CLIENT_CERT_ALIAS + " text,"
|
2013-12-04 00:55:48 +00:00
|
|
|
+ HostAuthColumns.SERVER_CERT + " blob,"
|
|
|
|
+ HostAuthColumns.CREDENTIAL_KEY + " integer"
|
2012-06-28 19:16:59 +00:00
|
|
|
+ ");";
|
|
|
|
db.execSQL("create table " + HostAuth.TABLE_NAME + s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void resetHostAuthTable(SQLiteDatabase db, int oldVersion, int newVersion) {
|
|
|
|
try {
|
|
|
|
db.execSQL("drop table " + HostAuth.TABLE_NAME);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
}
|
|
|
|
createHostAuthTable(db);
|
|
|
|
}
|
|
|
|
|
2014-05-12 18:33:43 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2012-06-28 19:16:59 +00:00
|
|
|
static void createMailboxTable(SQLiteDatabase db) {
|
2014-04-11 21:42:28 +00:00
|
|
|
String s = " (" + MailboxColumns._ID + " integer primary key autoincrement, "
|
2012-06-28 19:16:59 +00:00
|
|
|
+ MailboxColumns.DISPLAY_NAME + " text, "
|
|
|
|
+ MailboxColumns.SERVER_ID + " text, "
|
|
|
|
+ MailboxColumns.PARENT_SERVER_ID + " text, "
|
|
|
|
+ MailboxColumns.PARENT_KEY + " integer, "
|
|
|
|
+ MailboxColumns.ACCOUNT_KEY + " integer, "
|
|
|
|
+ MailboxColumns.TYPE + " integer, "
|
|
|
|
+ MailboxColumns.DELIMITER + " integer, "
|
|
|
|
+ MailboxColumns.SYNC_KEY + " text, "
|
|
|
|
+ MailboxColumns.SYNC_LOOKBACK + " integer, "
|
|
|
|
+ MailboxColumns.SYNC_INTERVAL + " integer, "
|
|
|
|
+ MailboxColumns.SYNC_TIME + " integer, "
|
|
|
|
+ MailboxColumns.UNREAD_COUNT + " integer, "
|
|
|
|
+ MailboxColumns.FLAG_VISIBLE + " integer, "
|
|
|
|
+ MailboxColumns.FLAGS + " integer, "
|
|
|
|
+ MailboxColumns.VISIBLE_LIMIT + " integer, "
|
|
|
|
+ MailboxColumns.SYNC_STATUS + " text, "
|
|
|
|
+ MailboxColumns.MESSAGE_COUNT + " integer not null default 0, "
|
|
|
|
+ MailboxColumns.LAST_TOUCHED_TIME + " integer default 0, "
|
|
|
|
+ MailboxColumns.UI_SYNC_STATUS + " integer default 0, "
|
|
|
|
+ MailboxColumns.UI_LAST_SYNC_RESULT + " integer default 0, "
|
|
|
|
+ MailboxColumns.LAST_NOTIFIED_MESSAGE_KEY + " integer not null default 0, "
|
|
|
|
+ MailboxColumns.LAST_NOTIFIED_MESSAGE_COUNT + " integer not null default 0, "
|
|
|
|
+ MailboxColumns.TOTAL_COUNT + " integer, "
|
2013-08-06 23:50:11 +00:00
|
|
|
+ MailboxColumns.HIERARCHICAL_NAME + " text, "
|
|
|
|
+ MailboxColumns.LAST_FULL_SYNC_TIME + " integer"
|
2012-06-28 19:16:59 +00:00
|
|
|
+ ");";
|
|
|
|
db.execSQL("create table " + Mailbox.TABLE_NAME + s);
|
|
|
|
db.execSQL("create index mailbox_" + MailboxColumns.SERVER_ID
|
|
|
|
+ " on " + Mailbox.TABLE_NAME + " (" + MailboxColumns.SERVER_ID + ")");
|
|
|
|
db.execSQL("create index mailbox_" + MailboxColumns.ACCOUNT_KEY
|
|
|
|
+ " on " + Mailbox.TABLE_NAME + " (" + MailboxColumns.ACCOUNT_KEY + ")");
|
|
|
|
// Deleting a Mailbox deletes associated Messages in all three tables
|
|
|
|
db.execSQL(TRIGGER_MAILBOX_DELETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void resetMailboxTable(SQLiteDatabase db, int oldVersion, int newVersion) {
|
|
|
|
try {
|
|
|
|
db.execSQL("drop table " + Mailbox.TABLE_NAME);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
}
|
|
|
|
createMailboxTable(db);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void createAttachmentTable(SQLiteDatabase db) {
|
2014-04-11 21:42:28 +00:00
|
|
|
String s = " (" + AttachmentColumns._ID + " integer primary key autoincrement, "
|
2012-06-28 19:16:59 +00:00
|
|
|
+ AttachmentColumns.FILENAME + " text, "
|
|
|
|
+ AttachmentColumns.MIME_TYPE + " text, "
|
|
|
|
+ AttachmentColumns.SIZE + " integer, "
|
|
|
|
+ AttachmentColumns.CONTENT_ID + " text, "
|
|
|
|
+ AttachmentColumns.CONTENT_URI + " text, "
|
|
|
|
+ AttachmentColumns.MESSAGE_KEY + " integer, "
|
|
|
|
+ AttachmentColumns.LOCATION + " text, "
|
|
|
|
+ AttachmentColumns.ENCODING + " text, "
|
|
|
|
+ AttachmentColumns.CONTENT + " text, "
|
|
|
|
+ AttachmentColumns.FLAGS + " integer, "
|
|
|
|
+ AttachmentColumns.CONTENT_BYTES + " blob, "
|
|
|
|
+ AttachmentColumns.ACCOUNT_KEY + " integer, "
|
|
|
|
+ AttachmentColumns.UI_STATE + " integer, "
|
|
|
|
+ AttachmentColumns.UI_DESTINATION + " integer, "
|
2013-02-23 03:42:40 +00:00
|
|
|
+ AttachmentColumns.UI_DOWNLOADED_SIZE + " integer, "
|
|
|
|
+ AttachmentColumns.CACHED_FILE + " text"
|
2012-06-28 19:16:59 +00:00
|
|
|
+ ");";
|
|
|
|
db.execSQL("create table " + Attachment.TABLE_NAME + s);
|
|
|
|
db.execSQL(createIndex(Attachment.TABLE_NAME, AttachmentColumns.MESSAGE_KEY));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void resetAttachmentTable(SQLiteDatabase db, int oldVersion, int newVersion) {
|
|
|
|
try {
|
|
|
|
db.execSQL("drop table " + Attachment.TABLE_NAME);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
}
|
|
|
|
createAttachmentTable(db);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void createQuickResponseTable(SQLiteDatabase db) {
|
2014-04-11 21:42:28 +00:00
|
|
|
String s = " (" + QuickResponseColumns._ID + " integer primary key autoincrement, "
|
2012-06-28 19:16:59 +00:00
|
|
|
+ QuickResponseColumns.TEXT + " text, "
|
|
|
|
+ QuickResponseColumns.ACCOUNT_KEY + " integer"
|
|
|
|
+ ");";
|
|
|
|
db.execSQL("create table " + QuickResponse.TABLE_NAME + s);
|
|
|
|
}
|
|
|
|
|
2014-05-12 18:33:43 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2012-06-28 19:16:59 +00:00
|
|
|
static void createBodyTable(SQLiteDatabase db) {
|
2014-04-11 21:42:28 +00:00
|
|
|
String s = " (" + BodyColumns._ID + " integer primary key autoincrement, "
|
2012-06-28 19:16:59 +00:00
|
|
|
+ BodyColumns.MESSAGE_KEY + " integer, "
|
|
|
|
+ BodyColumns.HTML_CONTENT + " text, "
|
|
|
|
+ BodyColumns.TEXT_CONTENT + " text, "
|
|
|
|
+ BodyColumns.HTML_REPLY + " text, "
|
|
|
|
+ BodyColumns.TEXT_REPLY + " text, "
|
|
|
|
+ BodyColumns.SOURCE_MESSAGE_KEY + " text, "
|
|
|
|
+ BodyColumns.INTRO_TEXT + " text, "
|
|
|
|
+ BodyColumns.QUOTED_TEXT_START_POS + " integer"
|
|
|
|
+ ");";
|
|
|
|
db.execSQL("create table " + Body.TABLE_NAME + s);
|
|
|
|
db.execSQL(createIndex(Body.TABLE_NAME, BodyColumns.MESSAGE_KEY));
|
|
|
|
}
|
|
|
|
|
2015-03-01 21:02:40 +00:00
|
|
|
private static void createSuggestedContactTable(SQLiteDatabase db) {
|
|
|
|
String s = " (" + SuggestedContactColumns._ID + " integer primary key autoincrement, "
|
|
|
|
+ SuggestedContactColumns.ACCOUNT_KEY + " integer, "
|
|
|
|
+ SuggestedContactColumns.ADDRESS + " text, "
|
|
|
|
+ SuggestedContactColumns.NAME + " text, "
|
|
|
|
+ SuggestedContactColumns.DISPLAY_NAME + " text, "
|
|
|
|
+ SuggestedContactColumns.LAST_SEEN + " integer"
|
|
|
|
+ ");";
|
|
|
|
db.execSQL("create table " + SuggestedContact.TABLE_NAME + s);
|
|
|
|
|
|
|
|
// Create a unique index for account-address
|
|
|
|
String indexDDL = "create unique index " + SuggestedContact.TABLE_NAME.toLowerCase()
|
|
|
|
+ "_account_address" + " on " + SuggestedContact.TABLE_NAME
|
|
|
|
+ " (" + SuggestedContactColumns.ACCOUNT_KEY + ", "
|
|
|
|
+ SuggestedContactColumns.ADDRESS + ");";
|
|
|
|
db.execSQL(indexDDL);
|
|
|
|
}
|
|
|
|
|
2014-05-12 18:33:43 +00:00
|
|
|
private static void upgradeBodyToVersion5(final SQLiteDatabase db) {
|
|
|
|
try {
|
|
|
|
db.execSQL("drop table " + Body.TABLE_NAME);
|
|
|
|
createBodyTable(db);
|
|
|
|
} catch (final SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
|
|
|
LogUtils.w(TAG, e, "Exception upgrading EmailProviderBody.db from <v5");
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
2014-05-12 18:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
private static void upgradeBodyFromVersion5ToVersion6(final SQLiteDatabase db) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Body.TABLE_NAME
|
|
|
|
+ " add " + BodyColumns.INTRO_TEXT + " text");
|
|
|
|
} catch (final SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
|
|
|
LogUtils.w(TAG, e, "Exception upgrading EmailProviderBody.db from v5 to v6");
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
2014-05-12 18:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void upgradeBodyFromVersion6ToVersion8(final SQLiteDatabase db) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Body.TABLE_NAME
|
|
|
|
+ " add " + BodyColumns.QUOTED_TEXT_START_POS + " integer");
|
|
|
|
} catch (final SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
|
|
|
LogUtils.w(TAG, e, "Exception upgrading EmailProviderBody.db from v6 to v8");
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
2014-05-12 18:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This upgrade migrates email bodies out of the database and into individual files.
|
|
|
|
*/
|
|
|
|
private static void upgradeBodyFromVersion100ToVersion101(final Context context,
|
|
|
|
final SQLiteDatabase db) {
|
|
|
|
try {
|
|
|
|
// We can't read the body parts through the cursor because they might be over 2MB
|
|
|
|
final String projection[] = { BodyColumns.MESSAGE_KEY };
|
|
|
|
final Cursor cursor = db.query(Body.TABLE_NAME, projection,
|
|
|
|
null, null, null, null, null);
|
|
|
|
if (cursor == null) {
|
|
|
|
throw new IllegalStateException("Could not read body table for upgrade");
|
|
|
|
}
|
|
|
|
|
|
|
|
final SQLiteStatement htmlSql = db.compileStatement(
|
|
|
|
"SELECT " + BodyColumns.HTML_CONTENT +
|
|
|
|
" FROM " + Body.TABLE_NAME +
|
|
|
|
" WHERE " + BodyColumns.MESSAGE_KEY + "=?"
|
|
|
|
);
|
|
|
|
|
|
|
|
final SQLiteStatement textSql = db.compileStatement(
|
|
|
|
"SELECT " + BodyColumns.TEXT_CONTENT +
|
|
|
|
" FROM " + Body.TABLE_NAME +
|
|
|
|
" WHERE " + BodyColumns.MESSAGE_KEY + "=?"
|
|
|
|
);
|
|
|
|
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
final long messageId = cursor.getLong(0);
|
|
|
|
htmlSql.bindLong(1, messageId);
|
|
|
|
try {
|
|
|
|
final String htmlString = htmlSql.simpleQueryForString();
|
|
|
|
if (!TextUtils.isEmpty(htmlString)) {
|
|
|
|
final File htmlFile = EmailProvider.getBodyFile(context, messageId, "html");
|
|
|
|
final FileWriter w = new FileWriter(htmlFile);
|
|
|
|
try {
|
|
|
|
w.write(htmlString);
|
|
|
|
} finally {
|
|
|
|
w.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (final SQLiteDoneException e) {
|
|
|
|
LogUtils.v(LogUtils.TAG, e, "Done with the HTML column");
|
|
|
|
}
|
|
|
|
textSql.bindLong(1, messageId);
|
|
|
|
try {
|
|
|
|
final String textString = textSql.simpleQueryForString();
|
|
|
|
if (!TextUtils.isEmpty(textString)) {
|
|
|
|
final File textFile = EmailProvider.getBodyFile(context, messageId, "txt");
|
|
|
|
final FileWriter w = new FileWriter(textFile);
|
|
|
|
try {
|
|
|
|
w.write(textString);
|
|
|
|
} finally {
|
|
|
|
w.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (final SQLiteDoneException e) {
|
|
|
|
LogUtils.v(LogUtils.TAG, e, "Done with the text column");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
db.execSQL("update " + Body.TABLE_NAME +
|
|
|
|
" set " + BodyColumns.HTML_CONTENT + "=NULL,"
|
|
|
|
+ BodyColumns.TEXT_CONTENT + "=NULL");
|
|
|
|
} catch (final SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
|
|
|
LogUtils.w(TAG, e, "Exception upgrading EmailProviderBody.db from v100 to v101");
|
|
|
|
} catch (final IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-12 18:33:43 +00:00
|
|
|
|
2012-06-28 19:16:59 +00:00
|
|
|
protected static class BodyDatabaseHelper extends SQLiteOpenHelper {
|
2014-05-12 18:33:43 +00:00
|
|
|
final Context mContext;
|
|
|
|
|
2012-06-28 19:16:59 +00:00
|
|
|
BodyDatabaseHelper(Context context, String name) {
|
|
|
|
super(context, name, null, BODY_DATABASE_VERSION);
|
2014-05-12 18:33:43 +00:00
|
|
|
mContext = context;
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(SQLiteDatabase db) {
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.d(TAG, "Creating EmailProviderBody database");
|
2012-06-28 19:16:59 +00:00
|
|
|
createBodyTable(db);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-05-12 18:33:43 +00:00
|
|
|
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
|
|
|
if (oldVersion < 5) {
|
|
|
|
upgradeBodyToVersion5(db);
|
|
|
|
}
|
|
|
|
if (oldVersion < 6) {
|
|
|
|
upgradeBodyFromVersion5ToVersion6(db);
|
|
|
|
}
|
|
|
|
if (oldVersion < 8) {
|
|
|
|
upgradeBodyFromVersion6ToVersion8(db);
|
|
|
|
}
|
|
|
|
if (oldVersion < 101) {
|
|
|
|
upgradeBodyFromVersion100ToVersion101(mContext, db);
|
|
|
|
}
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onOpen(SQLiteDatabase db) {
|
2015-03-01 21:02:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static class ExtrasDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
final Context mContext;
|
|
|
|
|
|
|
|
ExtrasDatabaseHelper(Context context, String name) {
|
|
|
|
super(context, name, null, EXTRAS_DATABASE_VERSION);
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(SQLiteDatabase db) {
|
|
|
|
LogUtils.d(TAG, "Creating EmailProviderExtras database");
|
|
|
|
createSuggestedContactTable(db);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onOpen(SQLiteDatabase db) {
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Counts the number of messages in each mailbox, and updates the message count column. */
|
|
|
|
@VisibleForTesting
|
|
|
|
static void recalculateMessageCount(SQLiteDatabase db) {
|
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.MESSAGE_COUNT +
|
|
|
|
"= (select count(*) from " + Message.TABLE_NAME +
|
2014-04-11 21:42:28 +00:00
|
|
|
" where " + MessageColumns.MAILBOX_KEY + " = " +
|
|
|
|
Mailbox.TABLE_NAME + "." + MailboxColumns._ID + ")");
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected static class DatabaseHelper extends SQLiteOpenHelper {
|
2014-05-12 18:33:43 +00:00
|
|
|
final Context mContext;
|
2012-06-28 19:16:59 +00:00
|
|
|
|
|
|
|
DatabaseHelper(Context context, String name) {
|
|
|
|
super(context, name, null, DATABASE_VERSION);
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(SQLiteDatabase db) {
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.d(TAG, "Creating EmailProvider database");
|
2012-06-28 19:16:59 +00:00
|
|
|
// Create all tables here; each class has its own method
|
2013-11-06 21:51:01 +00:00
|
|
|
createMessageTable(mContext, db);
|
2012-06-28 19:16:59 +00:00
|
|
|
createAttachmentTable(db);
|
|
|
|
createMailboxTable(db);
|
|
|
|
createHostAuthTable(db);
|
|
|
|
createAccountTable(db);
|
2013-09-05 20:52:03 +00:00
|
|
|
createMessageMoveTable(db);
|
|
|
|
createMessageStateChangeTable(db);
|
2012-06-28 19:16:59 +00:00
|
|
|
createPolicyTable(db);
|
|
|
|
createQuickResponseTable(db);
|
2013-12-04 00:55:48 +00:00
|
|
|
createCredentialsTable(db);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
|
2012-09-22 00:49:26 +00:00
|
|
|
@Override
|
2012-06-28 19:16:59 +00:00
|
|
|
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
|
|
|
if (oldVersion == 101 && newVersion == 100) {
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.d(TAG, "Downgrade from v101 to v100");
|
2012-06-28 19:16:59 +00:00
|
|
|
} else {
|
|
|
|
super.onDowngrade(db, oldVersion, newVersion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
2014-11-10 02:45:50 +00:00
|
|
|
|
|
|
|
boolean fromCM11 = false;
|
|
|
|
|
2012-06-28 19:16:59 +00:00
|
|
|
// For versions prior to 5, delete all data
|
|
|
|
// Versions >= 5 require that data be preserved!
|
|
|
|
if (oldVersion < 5) {
|
|
|
|
android.accounts.Account[] accounts = AccountManager.get(mContext)
|
2013-11-06 21:51:01 +00:00
|
|
|
.getAccountsByType(LEGACY_SCHEME_EAS);
|
2012-06-28 19:16:59 +00:00
|
|
|
for (android.accounts.Account account: accounts) {
|
|
|
|
AccountManager.get(mContext).removeAccount(account, null, null);
|
|
|
|
}
|
2013-11-06 21:51:01 +00:00
|
|
|
resetMessageTable(mContext, db, oldVersion, newVersion);
|
2012-06-28 19:16:59 +00:00
|
|
|
resetAttachmentTable(db, oldVersion, newVersion);
|
|
|
|
resetMailboxTable(db, oldVersion, newVersion);
|
|
|
|
resetHostAuthTable(db, oldVersion, newVersion);
|
|
|
|
resetAccountTable(db, oldVersion, newVersion);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (oldVersion == 5) {
|
|
|
|
// Message Tables: Add SyncColumns.SERVER_TIMESTAMP
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Message.TABLE_NAME
|
|
|
|
+ " add column " + SyncColumns.SERVER_TIMESTAMP + " integer" + ";");
|
|
|
|
db.execSQL("alter table " + Message.UPDATED_TABLE_NAME
|
|
|
|
+ " add column " + SyncColumns.SERVER_TIMESTAMP + " integer" + ";");
|
|
|
|
db.execSQL("alter table " + Message.DELETED_TABLE_NAME
|
|
|
|
+ " add column " + SyncColumns.SERVER_TIMESTAMP + " integer" + ";");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v5 to v6", e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-23 22:55:23 +00:00
|
|
|
// TODO: Change all these to strict inequalities
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 6) {
|
2012-06-28 19:16:59 +00:00
|
|
|
// Use the newer mailbox_delete trigger
|
|
|
|
db.execSQL("drop trigger mailbox_delete;");
|
|
|
|
db.execSQL(TRIGGER_MAILBOX_DELETE);
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 7) {
|
2012-06-28 19:16:59 +00:00
|
|
|
// add the security (provisioning) column
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Account.TABLE_NAME
|
|
|
|
+ " add column " + AccountColumns.SECURITY_FLAGS + " integer" + ";");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 7 to 8 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 8) {
|
2012-06-28 19:16:59 +00:00
|
|
|
// accounts: add security sync key & user signature columns
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Account.TABLE_NAME
|
|
|
|
+ " add column " + AccountColumns.SECURITY_SYNC_KEY + " text" + ";");
|
|
|
|
db.execSQL("alter table " + Account.TABLE_NAME
|
|
|
|
+ " add column " + AccountColumns.SIGNATURE + " text" + ";");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 8 to 9 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 9) {
|
2012-06-28 19:16:59 +00:00
|
|
|
// Message: add meeting info column into Message tables
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Message.TABLE_NAME
|
|
|
|
+ " add column " + MessageColumns.MEETING_INFO + " text" + ";");
|
|
|
|
db.execSQL("alter table " + Message.UPDATED_TABLE_NAME
|
|
|
|
+ " add column " + MessageColumns.MEETING_INFO + " text" + ";");
|
|
|
|
db.execSQL("alter table " + Message.DELETED_TABLE_NAME
|
|
|
|
+ " add column " + MessageColumns.MEETING_INFO + " text" + ";");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 9 to 10 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 10) {
|
2012-06-28 19:16:59 +00:00
|
|
|
// Attachment: add content and flags columns
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Attachment.TABLE_NAME
|
|
|
|
+ " add column " + AttachmentColumns.CONTENT + " text" + ";");
|
|
|
|
db.execSQL("alter table " + Attachment.TABLE_NAME
|
|
|
|
+ " add column " + AttachmentColumns.FLAGS + " integer" + ";");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 10 to 11 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 11) {
|
2012-06-28 19:16:59 +00:00
|
|
|
// Attachment: add content_bytes
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Attachment.TABLE_NAME
|
|
|
|
+ " add column " + AttachmentColumns.CONTENT_BYTES + " blob" + ";");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 11 to 12 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 12) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Mailbox.TABLE_NAME
|
|
|
|
+ " add column " + Mailbox.MESSAGE_COUNT
|
|
|
|
+" integer not null default 0" + ";");
|
|
|
|
recalculateMessageCount(db);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 12 to 13 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 13) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Message.TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + MessageColumns.SNIPPET
|
2012-06-28 19:16:59 +00:00
|
|
|
+" text" + ";");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 13 to 14 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 14) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Message.DELETED_TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + MessageColumns.SNIPPET +" text" + ";");
|
2012-06-28 19:16:59 +00:00
|
|
|
db.execSQL("alter table " + Message.UPDATED_TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + MessageColumns.SNIPPET +" text" + ";");
|
2012-06-28 19:16:59 +00:00
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 14 to 15 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 15) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Attachment.TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + AttachmentColumns.ACCOUNT_KEY +" integer" + ";");
|
2012-06-28 19:16:59 +00:00
|
|
|
// Update all existing attachments to add the accountKey data
|
|
|
|
db.execSQL("update " + Attachment.TABLE_NAME + " set " +
|
2014-04-11 21:42:28 +00:00
|
|
|
AttachmentColumns.ACCOUNT_KEY + "= (SELECT " + Message.TABLE_NAME +
|
|
|
|
"." + MessageColumns.ACCOUNT_KEY + " from " + Message.TABLE_NAME +
|
|
|
|
" where " + Message.TABLE_NAME + "." + MessageColumns._ID + " = " +
|
|
|
|
Attachment.TABLE_NAME + "." + AttachmentColumns.MESSAGE_KEY + ")");
|
2012-06-28 19:16:59 +00:00
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 15 to 16 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 16) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Mailbox.TABLE_NAME
|
|
|
|
+ " add column " + Mailbox.PARENT_KEY + " integer;");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 16 to 17 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 17) {
|
2012-06-28 19:16:59 +00:00
|
|
|
upgradeFromVersion17ToVersion18(db);
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 18) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Account.TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + AccountColumns.POLICY_KEY + " integer;");
|
2012-06-28 19:16:59 +00:00
|
|
|
db.execSQL("drop trigger account_delete;");
|
|
|
|
db.execSQL(TRIGGER_ACCOUNT_DELETE);
|
|
|
|
createPolicyTable(db);
|
|
|
|
convertPolicyFlagsToPolicyTable(db);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 18 to 19 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 19) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Policy.TABLE_NAME
|
|
|
|
+ " add column " + PolicyColumns.REQUIRE_MANUAL_SYNC_WHEN_ROAMING +
|
|
|
|
" integer;");
|
|
|
|
db.execSQL("alter table " + Policy.TABLE_NAME
|
|
|
|
+ " add column " + PolicyColumns.DONT_ALLOW_CAMERA + " integer;");
|
|
|
|
db.execSQL("alter table " + Policy.TABLE_NAME
|
|
|
|
+ " add column " + PolicyColumns.DONT_ALLOW_ATTACHMENTS + " integer;");
|
|
|
|
db.execSQL("alter table " + Policy.TABLE_NAME
|
|
|
|
+ " add column " + PolicyColumns.DONT_ALLOW_HTML + " integer;");
|
|
|
|
db.execSQL("alter table " + Policy.TABLE_NAME
|
|
|
|
+ " add column " + PolicyColumns.MAX_ATTACHMENT_SIZE + " integer;");
|
|
|
|
db.execSQL("alter table " + Policy.TABLE_NAME
|
|
|
|
+ " add column " + PolicyColumns.MAX_TEXT_TRUNCATION_SIZE +
|
|
|
|
" integer;");
|
|
|
|
db.execSQL("alter table " + Policy.TABLE_NAME
|
|
|
|
+ " add column " + PolicyColumns.MAX_HTML_TRUNCATION_SIZE +
|
|
|
|
" integer;");
|
|
|
|
db.execSQL("alter table " + Policy.TABLE_NAME
|
|
|
|
+ " add column " + PolicyColumns.MAX_EMAIL_LOOKBACK + " integer;");
|
|
|
|
db.execSQL("alter table " + Policy.TABLE_NAME
|
|
|
|
+ " add column " + PolicyColumns.MAX_CALENDAR_LOOKBACK + " integer;");
|
|
|
|
db.execSQL("alter table " + Policy.TABLE_NAME
|
|
|
|
+ " add column " + PolicyColumns.PASSWORD_RECOVERY_ENABLED +
|
|
|
|
" integer;");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 19 to 20 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 21) {
|
2012-06-28 19:16:59 +00:00
|
|
|
upgradeFromVersion21ToVersion22(db, mContext);
|
|
|
|
oldVersion = 22;
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 22) {
|
2012-06-28 19:16:59 +00:00
|
|
|
upgradeFromVersion22ToVersion23(db);
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 23) {
|
2012-06-28 19:16:59 +00:00
|
|
|
upgradeFromVersion23ToVersion24(db);
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 24) {
|
2012-06-28 19:16:59 +00:00
|
|
|
upgradeFromVersion24ToVersion25(db);
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 25) {
|
2012-06-28 19:16:59 +00:00
|
|
|
upgradeFromVersion25ToVersion26(db);
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 26) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Message.TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + MessageColumns.PROTOCOL_SEARCH_INFO + " text;");
|
2012-06-28 19:16:59 +00:00
|
|
|
db.execSQL("alter table " + Message.DELETED_TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + MessageColumns.PROTOCOL_SEARCH_INFO +" text" + ";");
|
2012-06-28 19:16:59 +00:00
|
|
|
db.execSQL("alter table " + Message.UPDATED_TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + MessageColumns.PROTOCOL_SEARCH_INFO +" text" + ";");
|
2012-06-28 19:16:59 +00:00
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 26 to 27 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 28) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Policy.TABLE_NAME
|
|
|
|
+ " add column " + Policy.PROTOCOL_POLICIES_ENFORCED + " text;");
|
|
|
|
db.execSQL("alter table " + Policy.TABLE_NAME
|
|
|
|
+ " add column " + Policy.PROTOCOL_POLICIES_UNSUPPORTED + " text;");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 28 to 29 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 29) {
|
2012-06-28 19:16:59 +00:00
|
|
|
upgradeFromVersion29ToVersion30(db);
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 30) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Mailbox.TABLE_NAME
|
|
|
|
+ " add column " + Mailbox.UI_SYNC_STATUS + " integer;");
|
|
|
|
db.execSQL("alter table " + Mailbox.TABLE_NAME
|
|
|
|
+ " add column " + Mailbox.UI_LAST_SYNC_RESULT + " integer;");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 30 to 31 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 31) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Mailbox.TABLE_NAME
|
|
|
|
+ " add column " + Mailbox.LAST_NOTIFIED_MESSAGE_KEY + " integer;");
|
|
|
|
db.execSQL("alter table " + Mailbox.TABLE_NAME
|
|
|
|
+ " add column " + Mailbox.LAST_NOTIFIED_MESSAGE_COUNT + " integer;");
|
|
|
|
db.execSQL("update Mailbox set " + Mailbox.LAST_NOTIFIED_MESSAGE_KEY +
|
|
|
|
"=0 where " + Mailbox.LAST_NOTIFIED_MESSAGE_KEY + " IS NULL");
|
|
|
|
db.execSQL("update Mailbox set " + Mailbox.LAST_NOTIFIED_MESSAGE_COUNT +
|
|
|
|
"=0 where " + Mailbox.LAST_NOTIFIED_MESSAGE_COUNT + " IS NULL");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 31 to 32 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 32) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Attachment.TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + AttachmentColumns.UI_STATE + " integer;");
|
2012-06-28 19:16:59 +00:00
|
|
|
db.execSQL("alter table " + Attachment.TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + AttachmentColumns.UI_DESTINATION + " integer;");
|
2012-06-28 19:16:59 +00:00
|
|
|
db.execSQL("alter table " + Attachment.TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + AttachmentColumns.UI_DOWNLOADED_SIZE + " integer;");
|
2012-06-28 19:16:59 +00:00
|
|
|
// If we have a contentUri then the attachment is saved
|
|
|
|
// uiDestination of 0 = "cache", so we don't have to set this
|
2014-04-11 21:42:28 +00:00
|
|
|
db.execSQL("update " + Attachment.TABLE_NAME + " set " +
|
|
|
|
AttachmentColumns.UI_STATE + "=" + UIProvider.AttachmentState.SAVED +
|
|
|
|
" where " + AttachmentColumns.CONTENT_URI + " is not null;");
|
2012-06-28 19:16:59 +00:00
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 32 to 33 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 33) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Mailbox.TABLE_NAME
|
|
|
|
+ " add column " + MailboxColumns.TOTAL_COUNT + " integer;");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 33 to 34 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 34) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set " +
|
|
|
|
MailboxColumns.LAST_TOUCHED_TIME + " = " +
|
|
|
|
Mailbox.DRAFTS_DEFAULT_TOUCH_TIME + " WHERE " + MailboxColumns.TYPE +
|
|
|
|
" = " + Mailbox.TYPE_DRAFTS);
|
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set " +
|
|
|
|
MailboxColumns.LAST_TOUCHED_TIME + " = " +
|
|
|
|
Mailbox.SENT_DEFAULT_TOUCH_TIME + " WHERE " + MailboxColumns.TYPE +
|
|
|
|
" = " + Mailbox.TYPE_SENT);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 34 to 35 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 36) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
// Set "supports settings" for EAS mailboxes
|
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set " +
|
|
|
|
MailboxColumns.FLAGS + "=" + MailboxColumns.FLAGS + "|" +
|
|
|
|
Mailbox.FLAG_SUPPORTS_SETTINGS + " where (" +
|
|
|
|
MailboxColumns.FLAGS + "&" + Mailbox.FLAG_HOLDS_MAIL + ")!=0 and " +
|
|
|
|
MailboxColumns.ACCOUNT_KEY + " IN (SELECT " + Account.TABLE_NAME +
|
2014-04-11 21:42:28 +00:00
|
|
|
"." + AccountColumns._ID + " from " + Account.TABLE_NAME + "," +
|
2012-06-28 19:16:59 +00:00
|
|
|
HostAuth.TABLE_NAME + " where " + Account.TABLE_NAME + "." +
|
|
|
|
AccountColumns.HOST_AUTH_KEY_RECV + "=" + HostAuth.TABLE_NAME + "." +
|
2014-04-11 21:42:28 +00:00
|
|
|
HostAuthColumns._ID + " and " + HostAuthColumns.PROTOCOL + "='" +
|
2012-09-22 00:49:26 +00:00
|
|
|
LEGACY_SCHEME_EAS + "')");
|
2012-06-28 19:16:59 +00:00
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 35 to 36 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 37) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Message.TABLE_NAME
|
|
|
|
+ " add column " + MessageColumns.THREAD_TOPIC + " text;");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 37 to 38 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 38) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Message.DELETED_TABLE_NAME
|
|
|
|
+ " add column " + MessageColumns.THREAD_TOPIC + " text;");
|
|
|
|
db.execSQL("alter table " + Message.UPDATED_TABLE_NAME
|
|
|
|
+ " add column " + MessageColumns.THREAD_TOPIC + " text;");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 38 to 39 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 39) {
|
2012-06-28 19:16:59 +00:00
|
|
|
upgradeToEmail2(db);
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 102) {
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Mailbox.TABLE_NAME
|
|
|
|
+ " add " + MailboxColumns.HIERARCHICAL_NAME + " text");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v10x to v103", e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 103) {
|
2012-06-29 16:42:05 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Message.TABLE_NAME
|
|
|
|
+ " add " + MessageColumns.SYNC_DATA + " text");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v103 to v104", e);
|
2012-06-29 16:42:05 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 104) {
|
2012-06-29 16:42:05 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Message.UPDATED_TABLE_NAME
|
|
|
|
+ " add " + MessageColumns.SYNC_DATA + " text");
|
|
|
|
db.execSQL("alter table " + Message.DELETED_TABLE_NAME
|
|
|
|
+ " add " + MessageColumns.SYNC_DATA + " text");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v104 to v105", e);
|
2012-06-29 16:42:05 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 105) {
|
2012-07-31 22:47:49 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + HostAuth.TABLE_NAME
|
|
|
|
+ " add " + HostAuthColumns.SERVER_CERT + " blob");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v105 to v106", e);
|
2012-07-31 22:47:49 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 106) {
|
2012-12-11 18:37:35 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Message.TABLE_NAME
|
|
|
|
+ " add " + MessageColumns.FLAG_SEEN + " integer");
|
|
|
|
db.execSQL("alter table " + Message.UPDATED_TABLE_NAME
|
|
|
|
+ " add " + MessageColumns.FLAG_SEEN + " integer");
|
|
|
|
db.execSQL("alter table " + Message.DELETED_TABLE_NAME
|
|
|
|
+ " add " + MessageColumns.FLAG_SEEN + " integer");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v106 to v107", e);
|
2012-12-11 18:37:35 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 107) {
|
2013-02-23 03:42:40 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Attachment.TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + AttachmentColumns.CACHED_FILE +" text" + ";");
|
2013-02-23 03:42:40 +00:00
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v107 to v108", e);
|
2013-02-23 03:42:40 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 108) {
|
2013-03-05 17:45:10 +00:00
|
|
|
// Migrate the accounts with the correct account type
|
|
|
|
migrateLegacyAccounts(db, mContext);
|
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 109) {
|
2013-06-14 01:03:06 +00:00
|
|
|
// Fix any mailboxes that have ping or push_hold states.
|
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.SYNC_INTERVAL
|
|
|
|
+ "=" + Mailbox.CHECK_INTERVAL_PUSH + " where "
|
|
|
|
+ MailboxColumns.SYNC_INTERVAL + "<" + Mailbox.CHECK_INTERVAL_PUSH);
|
|
|
|
|
|
|
|
// Fix invalid syncLookback values.
|
|
|
|
db.execSQL("update " + Account.TABLE_NAME + " set " + AccountColumns.SYNC_LOOKBACK
|
2013-07-24 04:00:09 +00:00
|
|
|
+ "=" + SyncWindow.SYNC_WINDOW_1_WEEK + " where "
|
|
|
|
+ AccountColumns.SYNC_LOOKBACK + " is null or "
|
|
|
|
+ AccountColumns.SYNC_LOOKBACK + "<" + SyncWindow.SYNC_WINDOW_1_DAY + " or "
|
|
|
|
+ AccountColumns.SYNC_LOOKBACK + ">" + SyncWindow.SYNC_WINDOW_ALL);
|
|
|
|
|
2013-06-14 01:03:06 +00:00
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.SYNC_LOOKBACK
|
2013-07-24 04:00:09 +00:00
|
|
|
+ "=" + SyncWindow.SYNC_WINDOW_ACCOUNT + " where "
|
|
|
|
+ MailboxColumns.SYNC_LOOKBACK + " is null or "
|
|
|
|
+ MailboxColumns.SYNC_LOOKBACK + "<" + SyncWindow.SYNC_WINDOW_1_DAY + " or "
|
|
|
|
+ MailboxColumns.SYNC_LOOKBACK + ">" + SyncWindow.SYNC_WINDOW_ALL);
|
2013-06-18 02:45:17 +00:00
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 110) {
|
2013-06-21 00:11:01 +00:00
|
|
|
// Delete account mailboxes.
|
2013-06-18 02:45:17 +00:00
|
|
|
db.execSQL("delete from " + Mailbox.TABLE_NAME + " where " + MailboxColumns.TYPE
|
|
|
|
+ "=" +Mailbox.TYPE_EAS_ACCOUNT_MAILBOX);
|
2013-06-21 00:11:01 +00:00
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion <= 111) {
|
2013-06-21 00:11:01 +00:00
|
|
|
// Mailbox sync interval now indicates whether this mailbox syncs with the rest
|
|
|
|
// of the account. Anyone who was syncing at all, plus outboxes, are set to 1,
|
|
|
|
// everyone else is 0.
|
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.SYNC_INTERVAL
|
|
|
|
+ "=case when " + MailboxColumns.SYNC_INTERVAL + "="
|
|
|
|
+ Mailbox.CHECK_INTERVAL_NEVER + " then 0 else 1 end");
|
2013-06-14 01:03:06 +00:00
|
|
|
}
|
2013-07-31 03:10:36 +00:00
|
|
|
if (oldVersion >= 110 && oldVersion <= 112) {
|
|
|
|
// v110 had dropped these triggers, but starting with v113 we restored them
|
|
|
|
// (and altered the 109 -> 110 upgrade code to stop dropping them).
|
|
|
|
// We therefore only add them back for the versions in between. We also need to
|
|
|
|
// compute the correct value at this point as well.
|
|
|
|
recalculateMessageCount(db);
|
|
|
|
createMessageCountTriggers(db);
|
|
|
|
}
|
2013-08-06 23:50:11 +00:00
|
|
|
|
|
|
|
if (oldVersion <= 113) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Mailbox.TABLE_NAME
|
|
|
|
+ " add column " + MailboxColumns.LAST_FULL_SYNC_TIME +" integer" + ";");
|
2013-08-21 17:46:55 +00:00
|
|
|
final ContentValues cv = new ContentValues(1);
|
2013-08-06 23:50:11 +00:00
|
|
|
cv.put(MailboxColumns.LAST_FULL_SYNC_TIME, 0);
|
|
|
|
db.update(Mailbox.TABLE_NAME, cv, null, null);
|
2013-08-21 17:46:55 +00:00
|
|
|
} catch (final SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v113 to v114", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldVersion <= 114) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Account.TABLE_NAME
|
|
|
|
+ " add column " + AccountColumns.PING_DURATION +" integer" + ";");
|
|
|
|
final ContentValues cv = new ContentValues(1);
|
|
|
|
cv.put(AccountColumns.PING_DURATION, 0);
|
|
|
|
db.update(Account.TABLE_NAME, cv, null, null);
|
|
|
|
} catch (final SQLException e) {
|
2013-08-06 23:50:11 +00:00
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v113 to v114", e);
|
|
|
|
}
|
|
|
|
}
|
2013-09-05 20:52:03 +00:00
|
|
|
|
|
|
|
if (oldVersion <= 115) {
|
|
|
|
createMessageMoveTable(db);
|
|
|
|
createMessageStateChangeTable(db);
|
|
|
|
}
|
2013-09-17 16:39:36 +00:00
|
|
|
|
Change trigger to allow duplicate messages in search folders
b/11294681
b/11325976
The problem is that when we get a message as part of a search
result, we'll end up deleting that message from the inbox (or
whatever folder it's currently in). This is because there is
a trigger that deletes messages if a new message is inserted
that has the same serverId and account.
Now, messages with duplicate serverId/account combinations are
allowed if one of the messages is in a SEARCH type folder.
Also, make a change so that when a message comes down in
a search result, we do also copy it into the primary mailbox
that message resides in, we only add it to the SEARCH folder.
Prior to this there was some code that intended to put
the search result message into the regular mailbox it's supposed
to be in, so that we'd have correct state in that message.
Unfortunately, there are several problems with this:
1. The code didn't work, it would make a copy in the regular
folder, and then unconditionally move it to the search folder.
2. If we leave this code in place, putting the message
temporarily into the regular folder still activates the duplicate
message deletion trigger, wiping out the original copy, even with
the update to the trigger.
3. It's unclear that it's even desirable to load the search
result message into the regular folder. It could be a very old
message that would not have been synced before, leaving a large
gap in your inbox, which is confusing and could interfere with
IMAP syncing.
Change-Id: I34671a3b677ab42a3efd0d170a6ebd9246ec493d
2013-10-22 00:48:47 +00:00
|
|
|
/**
|
|
|
|
* Originally, at 116, we added a trigger to delete duplicate messages.
|
|
|
|
* But we needed to change that trigger for version 120, so when we get
|
|
|
|
* there, we'll drop the trigger if it exists and create a new version.
|
|
|
|
*/
|
2013-09-23 22:55:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This statement changes the syncInterval column to 0 for all IMAP mailboxes.
|
|
|
|
* It does this by matching mailboxes against all account IDs whose receive auth is
|
|
|
|
* either R.string.protocol_legacy_imap, R.string.protocol_imap or "imap"
|
|
|
|
*/
|
|
|
|
if (oldVersion <= 117) {
|
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.SYNC_INTERVAL
|
|
|
|
+ "=0 where " + MailboxColumns.ACCOUNT_KEY + " in (select "
|
2014-04-11 21:42:28 +00:00
|
|
|
+ Account.TABLE_NAME + "." + AccountColumns._ID + " from "
|
2013-09-23 22:55:23 +00:00
|
|
|
+ Account.TABLE_NAME + " join " + HostAuth.TABLE_NAME + " where "
|
2014-04-11 21:42:28 +00:00
|
|
|
+ HostAuth.TABLE_NAME + "." + HostAuthColumns._ID + "="
|
|
|
|
+ Account.TABLE_NAME + "." + AccountColumns.HOST_AUTH_KEY_RECV
|
|
|
|
+ " and (" + HostAuth.TABLE_NAME + "."
|
2013-09-23 22:55:23 +00:00
|
|
|
+ HostAuthColumns.PROTOCOL + "='"
|
|
|
|
+ mContext.getString(R.string.protocol_legacy_imap) + "' or "
|
|
|
|
+ HostAuth.TABLE_NAME + "." + HostAuthColumns.PROTOCOL + "='"
|
|
|
|
+ mContext.getString(R.string.protocol_imap) + "' or "
|
|
|
|
+ HostAuth.TABLE_NAME + "." + HostAuthColumns.PROTOCOL + "='imap'));");
|
|
|
|
}
|
2013-10-10 21:49:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This statement changes the sync interval column to 0 for all DRAFTS type mailboxes,
|
|
|
|
* and deletes any messages that are:
|
|
|
|
* * synced from the server, and
|
|
|
|
* * in an exchange account draft folder
|
|
|
|
*
|
|
|
|
* This is primary for Exchange (b/11158759) but we don't sync draft folders for any
|
|
|
|
* other account type anyway.
|
|
|
|
* This will only affect people who used intermediate builds between email1 and email2,
|
|
|
|
* it should be a no-op for most users.
|
|
|
|
*/
|
|
|
|
if (oldVersion <= 118) {
|
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.SYNC_INTERVAL
|
|
|
|
+ "=0 where " + MailboxColumns.TYPE + "=" + Mailbox.TYPE_DRAFTS);
|
|
|
|
|
|
|
|
db.execSQL("delete from " + Message.TABLE_NAME + " where "
|
|
|
|
+ "(" + SyncColumns.SERVER_ID + " not null and "
|
|
|
|
+ SyncColumns.SERVER_ID + "!='') and "
|
|
|
|
+ MessageColumns.MAILBOX_KEY + " in (select "
|
2014-04-11 21:42:28 +00:00
|
|
|
+ MailboxColumns._ID + " from " + Mailbox.TABLE_NAME + " where "
|
2013-10-10 21:49:53 +00:00
|
|
|
+ MailboxColumns.TYPE + "=" + Mailbox.TYPE_DRAFTS + ")");
|
|
|
|
}
|
Change trigger to allow duplicate messages in search folders
b/11294681
b/11325976
The problem is that when we get a message as part of a search
result, we'll end up deleting that message from the inbox (or
whatever folder it's currently in). This is because there is
a trigger that deletes messages if a new message is inserted
that has the same serverId and account.
Now, messages with duplicate serverId/account combinations are
allowed if one of the messages is in a SEARCH type folder.
Also, make a change so that when a message comes down in
a search result, we do also copy it into the primary mailbox
that message resides in, we only add it to the SEARCH folder.
Prior to this there was some code that intended to put
the search result message into the regular mailbox it's supposed
to be in, so that we'd have correct state in that message.
Unfortunately, there are several problems with this:
1. The code didn't work, it would make a copy in the regular
folder, and then unconditionally move it to the search folder.
2. If we leave this code in place, putting the message
temporarily into the regular folder still activates the duplicate
message deletion trigger, wiping out the original copy, even with
the update to the trigger.
3. It's unclear that it's even desirable to load the search
result message into the regular folder. It could be a very old
message that would not have been synced before, leaving a large
gap in your inbox, which is confusing and could interfere with
IMAP syncing.
Change-Id: I34671a3b677ab42a3efd0d170a6ebd9246ec493d
2013-10-22 00:48:47 +00:00
|
|
|
|
2013-11-06 21:51:01 +00:00
|
|
|
// We originally dropped and recreated the deleteDuplicateMessagesTrigger here at
|
|
|
|
// version 120. We needed to update it again at version 123, so there's no reason
|
|
|
|
// to do it twice.
|
Add an additional mailbox key column to message table
b/11294681
The problem is that when we try to open an attachment for a
message in search results, it fails. The reason is that part of
loading the attachment, we need to open the remote folder the
message is in. For search results, the message's mailboxKey is
the special fake "search_results" folder, which doesn't actually
exist on the server.
For this change, I've added a new column called "mainMailboxKey".
For search results, this column will be populated with the real
mailbox the message is in. It will be blank for other messages.
This is a quick and low risk fix for this bug, but it's kind
of awkward. We would prefer to do one or both of the following
some time after MR1.
1. Make the "search_results" folder be a virtual folder, the same
way that unread, starred, and other virtual folders are. For these,
there is actually no mailbox row in the database, just some
queries that check various flags in the messages and behave
like folders in the UI. The messages actually still reside in the
real folders.
2. Remove the requirement to open the folder at all to load the
attachment.
Change-Id: I825ab846f78bf8b041a5d1d579260dc5d7b4c522
2013-10-23 18:18:54 +00:00
|
|
|
|
|
|
|
// Add the mainMailboxKey column, and get rid of any messages in the search_results
|
|
|
|
// folder.
|
|
|
|
if (oldVersion <= 120) {
|
|
|
|
db.execSQL("alter table " + Message.TABLE_NAME
|
|
|
|
+ " add " + MessageColumns.MAIN_MAILBOX_KEY + " integer");
|
|
|
|
|
|
|
|
// Delete all TYPE_SEARCH mailboxes. These will be for stale queries anyway, and
|
|
|
|
// the messages in them will not have the mainMailboxKey column correctly populated.
|
|
|
|
// We have a trigger (See TRIGGER_MAILBOX_DELETE) that will delete any messages
|
|
|
|
// in the deleted mailboxes.
|
|
|
|
db.execSQL("delete from " + Mailbox.TABLE_NAME + " where "
|
|
|
|
+ Mailbox.TYPE + "=" + Mailbox.TYPE_SEARCH);
|
|
|
|
}
|
2013-10-25 02:28:35 +00:00
|
|
|
|
|
|
|
if (oldVersion <= 121) {
|
|
|
|
// The previous update omitted making these changes to the Message_Updates and
|
|
|
|
// Message_Deletes tables. The app will actually crash in between these versions!
|
|
|
|
db.execSQL("alter table " + Message.UPDATED_TABLE_NAME
|
|
|
|
+ " add " + MessageColumns.MAIN_MAILBOX_KEY + " integer");
|
|
|
|
db.execSQL("alter table " + Message.DELETED_TABLE_NAME
|
|
|
|
+ " add " + MessageColumns.MAIN_MAILBOX_KEY + " integer");
|
|
|
|
}
|
2013-11-06 21:51:01 +00:00
|
|
|
|
|
|
|
if (oldVersion <= 122) {
|
|
|
|
if (oldVersion >= 117) {
|
|
|
|
/**
|
|
|
|
* This trigger was originally created at version 117, but we needed to change
|
|
|
|
* it for version 122. So if our oldVersion is 117 or more, we know we have that
|
|
|
|
* trigger and must drop it before re creating it.
|
|
|
|
*/
|
|
|
|
dropDeleteDuplicateMessagesTrigger(db);
|
|
|
|
}
|
|
|
|
createDeleteDuplicateMessagesTrigger(mContext, db);
|
|
|
|
}
|
2013-12-04 00:55:48 +00:00
|
|
|
|
|
|
|
if (oldVersion <= 123) {
|
2014-03-06 23:27:54 +00:00
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Account.TABLE_NAME
|
|
|
|
+ " add column " + AccountColumns.MAX_ATTACHMENT_SIZE +" integer" + ";");
|
|
|
|
final ContentValues cv = new ContentValues(1);
|
|
|
|
cv.put(AccountColumns.MAX_ATTACHMENT_SIZE, 0);
|
|
|
|
db.update(Account.TABLE_NAME, cv, null, null);
|
|
|
|
} catch (final SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v123 to v124", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 02:45:50 +00:00
|
|
|
if (oldVersion == 126) {
|
|
|
|
fromCM11 = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldVersion <= 124 || fromCM11) {
|
2013-12-04 00:55:48 +00:00
|
|
|
createCredentialsTable(db);
|
|
|
|
// Add the credentialKey column, and set it to -1 for all pre-existing hostAuths.
|
|
|
|
db.execSQL("alter table " + HostAuth.TABLE_NAME
|
|
|
|
+ " add " + HostAuthColumns.CREDENTIAL_KEY + " integer");
|
2013-12-11 00:46:45 +00:00
|
|
|
db.execSQL("update " + HostAuth.TABLE_NAME + " set "
|
2013-12-04 00:55:48 +00:00
|
|
|
+ HostAuthColumns.CREDENTIAL_KEY + "=-1");
|
|
|
|
}
|
2014-01-25 00:43:36 +00:00
|
|
|
|
2014-11-10 02:45:50 +00:00
|
|
|
if (oldVersion <= 125 || fromCM11) {
|
2014-01-25 00:43:36 +00:00
|
|
|
upgradeFromVersion125ToVersion126(db);
|
|
|
|
}
|
2014-04-01 21:37:36 +00:00
|
|
|
|
2014-11-10 02:45:50 +00:00
|
|
|
if (oldVersion <= 126 || fromCM11) {
|
2014-04-01 21:37:36 +00:00
|
|
|
upgradeFromVersion126ToVersion127(mContext, db);
|
|
|
|
}
|
2014-11-10 02:45:50 +00:00
|
|
|
if (oldVersion <= 127 && !fromCM11) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Account.TABLE_NAME
|
|
|
|
+ " add column " + AccountColumns.AUTO_FETCH_ATTACHMENTS
|
|
|
|
+ " integer" + ";");
|
|
|
|
final ContentValues cv = new ContentValues(1);
|
|
|
|
cv.put(AccountColumns.AUTO_FETCH_ATTACHMENTS, 0);
|
|
|
|
db.update(Account.TABLE_NAME, cv, null, null);
|
|
|
|
} catch (final SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v127 to v128", e);
|
|
|
|
}
|
|
|
|
}
|
2015-04-04 18:42:30 +00:00
|
|
|
|
|
|
|
// This statement changes the syncInterval column to 1 for all IMAP INBOX mailboxes.
|
|
|
|
// It does this by matching mailboxes against all account IDs whose receive auth is
|
|
|
|
// either R.string.protocol_legacy_imap, R.string.protocol_imap or "imap"
|
|
|
|
// It needed in order to mark
|
|
|
|
// We do it here to avoid the minor collisions with aosp main db
|
|
|
|
if (oldVersion <= 129) {
|
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set "
|
|
|
|
+ MailboxColumns.SYNC_INTERVAL + "= 1 where "
|
|
|
|
+ MailboxColumns.TYPE + "= " + Mailbox.TYPE_INBOX + " and "
|
|
|
|
+ MailboxColumns.ACCOUNT_KEY + " in (select "
|
|
|
|
+ Account.TABLE_NAME + "." + AccountColumns._ID + " from "
|
|
|
|
+ Account.TABLE_NAME + " join " + HostAuth.TABLE_NAME + " where "
|
|
|
|
+ HostAuth.TABLE_NAME + "." + HostAuthColumns._ID + "="
|
|
|
|
+ Account.TABLE_NAME + "." + AccountColumns.HOST_AUTH_KEY_RECV
|
|
|
|
+ " and (" + HostAuth.TABLE_NAME + "."
|
|
|
|
+ HostAuthColumns.PROTOCOL + "='"
|
|
|
|
+ mContext.getString(R.string.protocol_legacy_imap) + "' or "
|
|
|
|
+ HostAuth.TABLE_NAME + "." + HostAuthColumns.PROTOCOL + "='"
|
|
|
|
+ mContext.getString(R.string.protocol_imap) + "' or "
|
|
|
|
+ HostAuth.TABLE_NAME + "." + HostAuthColumns.PROTOCOL + "='imap'));");
|
|
|
|
}
|
2015-05-01 20:05:03 +00:00
|
|
|
|
2015-05-01 19:35:23 +00:00
|
|
|
if (oldVersion <= 130) {
|
|
|
|
//Account capabilities (check EmailServiceProxy#CAPABILITY_*)
|
|
|
|
try {
|
|
|
|
// Create capabilities field
|
|
|
|
db.execSQL("alter table " + Account.TABLE_NAME
|
|
|
|
+ " add column " + AccountColumns.CAPABILITIES
|
|
|
|
+ " integer" + " default 0;");
|
|
|
|
|
|
|
|
// Update all accounts with the appropriate capabilities
|
|
|
|
Cursor c = db.rawQuery("select " + Account.TABLE_NAME + "."
|
|
|
|
+ AccountColumns._ID + ", " + HostAuth.TABLE_NAME + "."
|
|
|
|
+ HostAuthColumns.PROTOCOL + " from " + Account.TABLE_NAME + ", "
|
|
|
|
+ HostAuth.TABLE_NAME + " where " + Account.TABLE_NAME + "."
|
|
|
|
+ AccountColumns.HOST_AUTH_KEY_RECV + " = " + HostAuth.TABLE_NAME
|
|
|
|
+ "." + HostAuthColumns._ID + ";", null);
|
|
|
|
if (c != null) {
|
|
|
|
try {
|
|
|
|
while(c.moveToNext()) {
|
|
|
|
long id = c.getLong(c.getColumnIndexOrThrow(AccountColumns._ID));
|
|
|
|
String protocol = c.getString(c.getColumnIndexOrThrow(
|
|
|
|
HostAuthColumns.PROTOCOL));
|
|
|
|
|
|
|
|
int capabilities = 0;
|
|
|
|
if (protocol.equals(LEGACY_SCHEME_IMAP)
|
|
|
|
|| protocol.equals(LEGACY_SCHEME_EAS)) {
|
|
|
|
// Don't know yet if the imap server supports the IDLE
|
|
|
|
// capability, but since this is upgrading the account,
|
|
|
|
// just assume that all imap servers supports the push
|
|
|
|
// capability and let disable it by the IMAP service
|
|
|
|
capabilities |= EmailServiceProxy.CAPABILITY_PUSH;
|
|
|
|
}
|
|
|
|
final ContentValues cv = new ContentValues(1);
|
|
|
|
cv.put(AccountColumns.CAPABILITIES, capabilities);
|
|
|
|
db.update(Account.TABLE_NAME, cv, AccountColumns._ID + " = ?",
|
|
|
|
new String[]{String.valueOf(id)});
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (final SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v129 to v130", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-01 20:05:03 +00:00
|
|
|
// Due to a bug in commit 44a064e5f16ddaac25f2acfc03c118f65bc48aec,
|
|
|
|
// AUTO_FETCH_ATTACHMENTS column could not be available in the Account table.
|
|
|
|
// Since cm12 and up doesn't use this column, we are leave as is it. In case
|
|
|
|
// the feature were added, then we need to create a new exception to ensure
|
|
|
|
// that the columns is re-added.
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onOpen(SQLiteDatabase db) {
|
2013-04-10 07:34:04 +00:00
|
|
|
try {
|
|
|
|
// Cleanup some nasty records
|
|
|
|
db.execSQL("DELETE FROM " + Account.TABLE_NAME
|
|
|
|
+ " WHERE " + AccountColumns.DISPLAY_NAME + " ISNULL;");
|
|
|
|
db.execSQL("DELETE FROM " + HostAuth.TABLE_NAME
|
|
|
|
+ " WHERE " + HostAuthColumns.PROTOCOL + " ISNULL;");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
|
|
|
LogUtils.e(TAG, e, "Exception cleaning EmailProvider.db");
|
|
|
|
}
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
static void convertPolicyFlagsToPolicyTable(SQLiteDatabase db) {
|
|
|
|
Cursor c = db.query(Account.TABLE_NAME,
|
2014-04-11 21:42:28 +00:00
|
|
|
new String[] {BaseColumns._ID /*0*/, AccountColumns.SECURITY_FLAGS /*1*/},
|
2012-06-28 19:16:59 +00:00
|
|
|
AccountColumns.SECURITY_FLAGS + ">0", null, null, null, null);
|
2013-03-06 01:08:58 +00:00
|
|
|
try {
|
|
|
|
ContentValues cv = new ContentValues();
|
|
|
|
String[] args = new String[1];
|
|
|
|
while (c.moveToNext()) {
|
|
|
|
long securityFlags = c.getLong(1 /*SECURITY_FLAGS*/);
|
|
|
|
Policy policy = LegacyPolicySet.flagsToPolicy(securityFlags);
|
|
|
|
long policyId = db.insert(Policy.TABLE_NAME, null, policy.toContentValues());
|
|
|
|
cv.put(AccountColumns.POLICY_KEY, policyId);
|
|
|
|
cv.putNull(AccountColumns.SECURITY_FLAGS);
|
2014-04-11 21:42:28 +00:00
|
|
|
args[0] = Long.toString(c.getLong(0 /*_ID*/));
|
|
|
|
db.update(Account.TABLE_NAME, cv, BaseColumns._ID + "=?", args);
|
2013-03-06 01:08:58 +00:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
c.close();
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Upgrades the database from v17 to v18 */
|
|
|
|
@VisibleForTesting
|
|
|
|
static void upgradeFromVersion17ToVersion18(SQLiteDatabase db) {
|
|
|
|
// Copy the displayName column to the serverId column. In v18 of the database,
|
|
|
|
// we use the serverId for IMAP/POP3 mailboxes instead of overloading the
|
|
|
|
// display name.
|
|
|
|
//
|
|
|
|
// For posterity; this is the command we're executing:
|
|
|
|
//sqlite> UPDATE mailbox SET serverid=displayname WHERE mailbox._id in (
|
|
|
|
// ...> SELECT mailbox._id FROM mailbox,account,hostauth WHERE
|
|
|
|
// ...> (mailbox.parentkey isnull OR mailbox.parentkey=0) AND
|
|
|
|
// ...> mailbox.accountkey=account._id AND
|
|
|
|
// ...> account.hostauthkeyrecv=hostauth._id AND
|
|
|
|
// ...> (hostauth.protocol='imap' OR hostauth.protocol='pop3'));
|
|
|
|
try {
|
|
|
|
db.execSQL(
|
|
|
|
"UPDATE " + Mailbox.TABLE_NAME + " SET "
|
|
|
|
+ MailboxColumns.SERVER_ID + "=" + MailboxColumns.DISPLAY_NAME
|
|
|
|
+ " WHERE "
|
2014-04-11 21:42:28 +00:00
|
|
|
+ Mailbox.TABLE_NAME + "." + MailboxColumns._ID + " IN ( SELECT "
|
|
|
|
+ Mailbox.TABLE_NAME + "." + MailboxColumns._ID + " FROM "
|
2012-06-28 19:16:59 +00:00
|
|
|
+ Mailbox.TABLE_NAME + "," + Account.TABLE_NAME + ","
|
|
|
|
+ HostAuth.TABLE_NAME + " WHERE "
|
|
|
|
+ "("
|
|
|
|
+ Mailbox.TABLE_NAME + "." + MailboxColumns.PARENT_KEY + " isnull OR "
|
|
|
|
+ Mailbox.TABLE_NAME + "." + MailboxColumns.PARENT_KEY + "=0 "
|
|
|
|
+ ") AND "
|
|
|
|
+ Mailbox.TABLE_NAME + "." + MailboxColumns.ACCOUNT_KEY + "="
|
2014-04-11 21:42:28 +00:00
|
|
|
+ Account.TABLE_NAME + "." + AccountColumns._ID + " AND "
|
2012-06-28 19:16:59 +00:00
|
|
|
+ Account.TABLE_NAME + "." + AccountColumns.HOST_AUTH_KEY_RECV + "="
|
2014-04-11 21:42:28 +00:00
|
|
|
+ HostAuth.TABLE_NAME + "." + HostAuthColumns._ID + " AND ( "
|
2012-06-28 19:16:59 +00:00
|
|
|
+ HostAuth.TABLE_NAME + "." + HostAuthColumns.PROTOCOL + "='imap' OR "
|
|
|
|
+ HostAuth.TABLE_NAME + "." + HostAuthColumns.PROTOCOL + "='pop3' ) )");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 17 to 18 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
ContentCache.invalidateAllCaches();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upgrade the database from v21 to v22
|
|
|
|
* This entails creating AccountManager accounts for all pop3 and imap accounts
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static final String[] V21_ACCOUNT_PROJECTION =
|
|
|
|
new String[] {AccountColumns.HOST_AUTH_KEY_RECV, AccountColumns.EMAIL_ADDRESS};
|
|
|
|
private static final int V21_ACCOUNT_RECV = 0;
|
|
|
|
private static final int V21_ACCOUNT_EMAIL = 1;
|
|
|
|
|
|
|
|
private static final String[] V21_HOSTAUTH_PROJECTION =
|
|
|
|
new String[] {HostAuthColumns.PROTOCOL, HostAuthColumns.PASSWORD};
|
|
|
|
private static final int V21_HOSTAUTH_PROTOCOL = 0;
|
|
|
|
private static final int V21_HOSTAUTH_PASSWORD = 1;
|
|
|
|
|
2013-03-05 17:45:10 +00:00
|
|
|
private static void createAccountManagerAccount(Context context, String login, String type,
|
2012-06-28 19:16:59 +00:00
|
|
|
String password) {
|
2013-03-05 17:45:10 +00:00
|
|
|
final AccountManager accountManager = AccountManager.get(context);
|
|
|
|
|
|
|
|
if (isAccountPresent(accountManager, login, type)) {
|
|
|
|
// The account already exists,just return
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LogUtils.v("Email", "Creating account %s %s", login, type);
|
|
|
|
final android.accounts.Account amAccount = new android.accounts.Account(login, type);
|
2012-06-28 19:16:59 +00:00
|
|
|
accountManager.addAccountExplicitly(amAccount, password, null);
|
|
|
|
ContentResolver.setIsSyncable(amAccount, EmailContent.AUTHORITY, 1);
|
|
|
|
ContentResolver.setSyncAutomatically(amAccount, EmailContent.AUTHORITY, true);
|
|
|
|
ContentResolver.setIsSyncable(amAccount, ContactsContract.AUTHORITY, 0);
|
|
|
|
ContentResolver.setIsSyncable(amAccount, CalendarContract.AUTHORITY, 0);
|
|
|
|
}
|
|
|
|
|
2013-03-05 17:45:10 +00:00
|
|
|
private static boolean isAccountPresent(AccountManager accountManager, String name,
|
|
|
|
String type) {
|
|
|
|
final android.accounts.Account[] amAccounts = accountManager.getAccountsByType(type);
|
|
|
|
if (amAccounts != null) {
|
|
|
|
for (android.accounts.Account account : amAccounts) {
|
|
|
|
if (TextUtils.equals(account.name, name) && TextUtils.equals(account.type, type)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-28 19:16:59 +00:00
|
|
|
@VisibleForTesting
|
|
|
|
static void upgradeFromVersion21ToVersion22(SQLiteDatabase db, Context accountManagerContext) {
|
2013-03-05 17:45:10 +00:00
|
|
|
migrateLegacyAccounts(db, accountManagerContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void migrateLegacyAccounts(SQLiteDatabase db, Context accountManagerContext) {
|
|
|
|
final Map<String, String> legacyToNewTypeMap = new ImmutableMap.Builder<String, String>()
|
|
|
|
.put(LEGACY_SCHEME_POP3,
|
|
|
|
accountManagerContext.getString(R.string.account_manager_type_pop3))
|
|
|
|
.put(LEGACY_SCHEME_IMAP,
|
|
|
|
accountManagerContext.getString(R.string.account_manager_type_legacy_imap))
|
|
|
|
.put(LEGACY_SCHEME_EAS,
|
|
|
|
accountManagerContext.getString(R.string.account_manager_type_exchange))
|
|
|
|
.build();
|
2012-06-28 19:16:59 +00:00
|
|
|
try {
|
|
|
|
// Loop through accounts, looking for pop/imap accounts
|
2013-03-05 17:45:10 +00:00
|
|
|
final Cursor accountCursor = db.query(Account.TABLE_NAME, V21_ACCOUNT_PROJECTION, null,
|
2012-06-28 19:16:59 +00:00
|
|
|
null, null, null, null);
|
|
|
|
try {
|
2013-03-05 17:45:10 +00:00
|
|
|
final String[] hostAuthArgs = new String[1];
|
2012-06-28 19:16:59 +00:00
|
|
|
while (accountCursor.moveToNext()) {
|
|
|
|
hostAuthArgs[0] = accountCursor.getString(V21_ACCOUNT_RECV);
|
|
|
|
// Get the "receive" HostAuth for this account
|
2013-03-05 17:45:10 +00:00
|
|
|
final Cursor hostAuthCursor = db.query(HostAuth.TABLE_NAME,
|
2014-04-11 21:42:28 +00:00
|
|
|
V21_HOSTAUTH_PROJECTION, HostAuthColumns._ID + "=?", hostAuthArgs,
|
2012-06-28 19:16:59 +00:00
|
|
|
null, null, null);
|
|
|
|
try {
|
|
|
|
if (hostAuthCursor.moveToFirst()) {
|
2013-03-05 17:45:10 +00:00
|
|
|
final String protocol = hostAuthCursor.getString(V21_HOSTAUTH_PROTOCOL);
|
2012-06-28 19:16:59 +00:00
|
|
|
// If this is a pop3 or imap account, create the account manager account
|
2012-09-22 00:49:26 +00:00
|
|
|
if (LEGACY_SCHEME_IMAP.equals(protocol) ||
|
2013-03-05 17:45:10 +00:00
|
|
|
LEGACY_SCHEME_POP3.equals(protocol)) {
|
|
|
|
// If this is a pop3 or imap account, create the account manager
|
|
|
|
// account
|
2014-08-28 18:00:08 +00:00
|
|
|
if (DebugUtils.DEBUG) {
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.d(TAG, "Create AccountManager account for " + protocol
|
|
|
|
+ "account: "
|
|
|
|
+ accountCursor.getString(V21_ACCOUNT_EMAIL));
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
createAccountManagerAccount(accountManagerContext,
|
|
|
|
accountCursor.getString(V21_ACCOUNT_EMAIL),
|
2013-03-05 17:45:10 +00:00
|
|
|
legacyToNewTypeMap.get(protocol),
|
2012-06-28 19:16:59 +00:00
|
|
|
hostAuthCursor.getString(V21_HOSTAUTH_PASSWORD));
|
2012-09-22 00:49:26 +00:00
|
|
|
} else if (LEGACY_SCHEME_EAS.equals(protocol)) {
|
2013-03-05 17:45:10 +00:00
|
|
|
// If an EAS account, make Email sync automatically (equivalent of
|
|
|
|
// checking the "Sync Email" box in settings
|
|
|
|
|
|
|
|
android.accounts.Account amAccount = new android.accounts.Account(
|
|
|
|
accountCursor.getString(V21_ACCOUNT_EMAIL),
|
|
|
|
legacyToNewTypeMap.get(protocol));
|
2012-06-28 19:16:59 +00:00
|
|
|
ContentResolver.setIsSyncable(amAccount, EmailContent.AUTHORITY, 1);
|
|
|
|
ContentResolver.setSyncAutomatically(amAccount,
|
|
|
|
EmailContent.AUTHORITY, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
hostAuthCursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
accountCursor.close();
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception while migrating accounts " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Upgrades the database from v22 to v23 */
|
|
|
|
private static void upgradeFromVersion22ToVersion23(SQLiteDatabase db) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + Mailbox.TABLE_NAME
|
|
|
|
+ " add column " + Mailbox.LAST_TOUCHED_TIME + " integer default 0;");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 22 to 23 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Adds in a column for information about a client certificate to use. */
|
|
|
|
private static void upgradeFromVersion23ToVersion24(SQLiteDatabase db) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table " + HostAuth.TABLE_NAME
|
2014-04-11 21:42:28 +00:00
|
|
|
+ " add column " + HostAuthColumns.CLIENT_CERT_ALIAS + " text;");
|
2012-06-28 19:16:59 +00:00
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 23 to 24 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Upgrades the database from v24 to v25 by creating table for quick responses */
|
|
|
|
private static void upgradeFromVersion24ToVersion25(SQLiteDatabase db) {
|
|
|
|
try {
|
|
|
|
createQuickResponseTable(db);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 24 to 25 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final String[] V25_ACCOUNT_PROJECTION =
|
2014-04-11 21:42:28 +00:00
|
|
|
new String[] {AccountColumns._ID, AccountColumns.FLAGS, AccountColumns.HOST_AUTH_KEY_RECV};
|
2012-06-28 19:16:59 +00:00
|
|
|
private static final int V25_ACCOUNT_ID = 0;
|
|
|
|
private static final int V25_ACCOUNT_FLAGS = 1;
|
|
|
|
private static final int V25_ACCOUNT_RECV = 2;
|
|
|
|
|
|
|
|
private static final String[] V25_HOSTAUTH_PROJECTION = new String[] {HostAuthColumns.PROTOCOL};
|
|
|
|
private static final int V25_HOSTAUTH_PROTOCOL = 0;
|
|
|
|
|
|
|
|
/** Upgrades the database from v25 to v26 by adding FLAG_SUPPORTS_SEARCH to IMAP accounts */
|
|
|
|
private static void upgradeFromVersion25ToVersion26(SQLiteDatabase db) {
|
|
|
|
try {
|
|
|
|
// Loop through accounts, looking for imap accounts
|
|
|
|
Cursor accountCursor = db.query(Account.TABLE_NAME, V25_ACCOUNT_PROJECTION, null,
|
|
|
|
null, null, null, null);
|
|
|
|
ContentValues cv = new ContentValues();
|
|
|
|
try {
|
|
|
|
String[] hostAuthArgs = new String[1];
|
|
|
|
while (accountCursor.moveToNext()) {
|
|
|
|
hostAuthArgs[0] = accountCursor.getString(V25_ACCOUNT_RECV);
|
|
|
|
// Get the "receive" HostAuth for this account
|
|
|
|
Cursor hostAuthCursor = db.query(HostAuth.TABLE_NAME,
|
2014-04-11 21:42:28 +00:00
|
|
|
V25_HOSTAUTH_PROJECTION, HostAuthColumns._ID + "=?", hostAuthArgs,
|
2012-06-28 19:16:59 +00:00
|
|
|
null, null, null);
|
|
|
|
try {
|
|
|
|
if (hostAuthCursor.moveToFirst()) {
|
|
|
|
String protocol = hostAuthCursor.getString(V25_HOSTAUTH_PROTOCOL);
|
|
|
|
// If this is an imap account, add the search flag
|
2012-09-22 00:49:26 +00:00
|
|
|
if (LEGACY_SCHEME_IMAP.equals(protocol)) {
|
2012-06-28 19:16:59 +00:00
|
|
|
String id = accountCursor.getString(V25_ACCOUNT_ID);
|
|
|
|
int flags = accountCursor.getInt(V25_ACCOUNT_FLAGS);
|
|
|
|
cv.put(AccountColumns.FLAGS, flags | Account.FLAGS_SUPPORTS_SEARCH);
|
2014-04-11 21:42:28 +00:00
|
|
|
db.update(Account.TABLE_NAME, cv, AccountColumns._ID + "=?",
|
2012-06-28 19:16:59 +00:00
|
|
|
new String[] {id});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
hostAuthCursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
accountCursor.close();
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 25 to 26 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Upgrades the database from v29 to v30 by updating all address fields in Message */
|
2014-04-11 21:42:28 +00:00
|
|
|
private static final int[] ADDRESS_COLUMN_INDICES = {
|
|
|
|
Message.CONTENT_BCC_LIST_COLUMN,
|
|
|
|
Message.CONTENT_CC_LIST_COLUMN,
|
|
|
|
Message.CONTENT_FROM_LIST_COLUMN,
|
|
|
|
Message.CONTENT_REPLY_TO_COLUMN,
|
|
|
|
Message.CONTENT_TO_LIST_COLUMN
|
2012-06-28 19:16:59 +00:00
|
|
|
};
|
2014-04-11 21:42:28 +00:00
|
|
|
private static final String[] ADDRESS_COLUMN_NAMES = {
|
|
|
|
MessageColumns.BCC_LIST,
|
|
|
|
MessageColumns.CC_LIST,
|
|
|
|
MessageColumns.FROM_LIST,
|
|
|
|
MessageColumns.REPLY_TO_LIST,
|
|
|
|
MessageColumns.TO_LIST
|
2012-06-28 19:16:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private static void upgradeFromVersion29ToVersion30(SQLiteDatabase db) {
|
|
|
|
try {
|
|
|
|
// Loop through all messages, updating address columns to new format (CSV, RFC822)
|
|
|
|
Cursor messageCursor = db.query(Message.TABLE_NAME, Message.CONTENT_PROJECTION, null,
|
|
|
|
null, null, null, null);
|
|
|
|
ContentValues cv = new ContentValues();
|
|
|
|
String[] whereArgs = new String[1];
|
|
|
|
try {
|
|
|
|
while (messageCursor.moveToNext()) {
|
|
|
|
for (int i = 0; i < ADDRESS_COLUMN_INDICES.length; i++) {
|
|
|
|
Address[] addrs =
|
2014-01-22 23:34:41 +00:00
|
|
|
Address.fromHeader(messageCursor.getString(ADDRESS_COLUMN_INDICES[i]));
|
|
|
|
cv.put(ADDRESS_COLUMN_NAMES[i], Address.toHeader(addrs));
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
whereArgs[0] = messageCursor.getString(Message.CONTENT_ID_COLUMN);
|
|
|
|
db.update(Message.TABLE_NAME, cv, WHERE_ID, whereArgs);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
messageCursor.close();
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 29 to 30 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-25 00:43:36 +00:00
|
|
|
private static void upgradeFromVersion125ToVersion126(SQLiteDatabase db) {
|
|
|
|
try {
|
|
|
|
// Loop through all messages, updating address columns to their decoded form
|
|
|
|
Cursor messageCursor = db.query(Message.TABLE_NAME, Message.CONTENT_PROJECTION, null,
|
|
|
|
null, null, null, null);
|
|
|
|
ContentValues cv = new ContentValues();
|
|
|
|
String[] whereArgs = new String[1];
|
|
|
|
try {
|
|
|
|
while (messageCursor.moveToNext()) {
|
|
|
|
for (int i = 0; i < ADDRESS_COLUMN_INDICES.length; i++) {
|
|
|
|
Address[] addrs =
|
|
|
|
Address.fromHeader(messageCursor.getString(ADDRESS_COLUMN_INDICES[i]));
|
|
|
|
cv.put(ADDRESS_COLUMN_NAMES[i], Address.toString(addrs));
|
|
|
|
}
|
|
|
|
whereArgs[0] = messageCursor.getString(Message.CONTENT_ID_COLUMN);
|
|
|
|
db.update(Message.TABLE_NAME, cv, WHERE_ID, whereArgs);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
messageCursor.close();
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
// Shouldn't be needed unless we're debugging and interrupt the process
|
2014-04-01 21:37:36 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 125 to 126 " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update all accounts that are EAS v12.0 or greater with SmartForward and search flags
|
|
|
|
*/
|
|
|
|
private static void upgradeFromVersion126ToVersion127(final Context context,
|
|
|
|
final SQLiteDatabase db) {
|
|
|
|
try {
|
|
|
|
// These are the flags that we want to add to the Account table for the
|
|
|
|
// appropriate rows.
|
|
|
|
final long newFlags = Account.FLAGS_SUPPORTS_GLOBAL_SEARCH +
|
|
|
|
Account.FLAGS_SUPPORTS_SEARCH + Account.FLAGS_SUPPORTS_SMART_FORWARD;
|
|
|
|
|
|
|
|
// For posterity; this is the command we're executing:
|
|
|
|
// UPDATE Account SET flags=flags|[new flags] WHERE _id IN (SELECT t1._id FROM Account
|
|
|
|
// t1 INNER JOIN HostAuth t2 ON t1.hostAuthKeyRecv=t2._id WHERE t2.protocol='gEas' AND
|
|
|
|
// CAST(t1.protocolVersion AS REAL)>=12.0)
|
|
|
|
db.execSQL(
|
|
|
|
"UPDATE " + Account.TABLE_NAME + " SET " + AccountColumns.FLAGS + "=" +
|
|
|
|
AccountColumns.FLAGS + "|" + Long.toString(newFlags) + " WHERE " +
|
2014-04-11 21:42:28 +00:00
|
|
|
AccountColumns._ID + " IN (SELECT t1." + AccountColumns._ID + " FROM " +
|
2014-04-01 21:37:36 +00:00
|
|
|
Account.TABLE_NAME + " t1 INNER JOIN " + HostAuth.TABLE_NAME +
|
|
|
|
" t2 ON t1." + AccountColumns.HOST_AUTH_KEY_RECV + "=t2._id WHERE t2." +
|
|
|
|
HostAuthColumns.PROTOCOL + "='" +
|
|
|
|
context.getString(R.string.protocol_eas) + "' AND CAST(t1." +
|
|
|
|
AccountColumns.PROTOCOL_VERSION + " AS REAL)>=12.0)");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 126 to 127 " + e);
|
2014-01-25 00:43:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-28 19:16:59 +00:00
|
|
|
private static void upgradeToEmail2(SQLiteDatabase db) {
|
|
|
|
// Perform cleanup operations from Email1 to Email2; Email1 will have added new
|
|
|
|
// data that won't conform to what's expected in Email2
|
|
|
|
|
|
|
|
// From 31->32 upgrade
|
|
|
|
try {
|
|
|
|
db.execSQL("update Mailbox set " + Mailbox.LAST_NOTIFIED_MESSAGE_KEY +
|
|
|
|
"=0 where " + Mailbox.LAST_NOTIFIED_MESSAGE_KEY + " IS NULL");
|
|
|
|
db.execSQL("update Mailbox set " + Mailbox.LAST_NOTIFIED_MESSAGE_COUNT +
|
|
|
|
"=0 where " + Mailbox.LAST_NOTIFIED_MESSAGE_COUNT + " IS NULL");
|
|
|
|
} catch (SQLException e) {
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 31 to 32/100 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// From 32->33 upgrade
|
|
|
|
try {
|
2014-04-11 21:42:28 +00:00
|
|
|
db.execSQL("update " + Attachment.TABLE_NAME + " set " + AttachmentColumns.UI_STATE +
|
2012-06-28 19:16:59 +00:00
|
|
|
"=" + UIProvider.AttachmentState.SAVED + " where " +
|
|
|
|
AttachmentColumns.CONTENT_URI + " is not null;");
|
|
|
|
} catch (SQLException e) {
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 32 to 33/100 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// From 34->35 upgrade
|
|
|
|
try {
|
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set " +
|
|
|
|
MailboxColumns.LAST_TOUCHED_TIME + " = " +
|
|
|
|
Mailbox.DRAFTS_DEFAULT_TOUCH_TIME + " WHERE " + MailboxColumns.TYPE +
|
|
|
|
" = " + Mailbox.TYPE_DRAFTS);
|
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set " +
|
|
|
|
MailboxColumns.LAST_TOUCHED_TIME + " = " +
|
|
|
|
Mailbox.SENT_DEFAULT_TOUCH_TIME + " WHERE " + MailboxColumns.TYPE +
|
|
|
|
" = " + Mailbox.TYPE_SENT);
|
|
|
|
} catch (SQLException e) {
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 34 to 35/100 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// From 35/36->37
|
|
|
|
try {
|
|
|
|
db.execSQL("update " + Mailbox.TABLE_NAME + " set " +
|
|
|
|
MailboxColumns.FLAGS + "=" + MailboxColumns.FLAGS + "|" +
|
|
|
|
Mailbox.FLAG_SUPPORTS_SETTINGS + " where (" +
|
|
|
|
MailboxColumns.FLAGS + "&" + Mailbox.FLAG_HOLDS_MAIL + ")!=0 and " +
|
|
|
|
MailboxColumns.ACCOUNT_KEY + " IN (SELECT " + Account.TABLE_NAME +
|
2014-04-11 21:42:28 +00:00
|
|
|
"." + AccountColumns._ID + " from " + Account.TABLE_NAME + "," +
|
2012-06-28 19:16:59 +00:00
|
|
|
HostAuth.TABLE_NAME + " where " + Account.TABLE_NAME + "." +
|
|
|
|
AccountColumns.HOST_AUTH_KEY_RECV + "=" + HostAuth.TABLE_NAME + "." +
|
2014-04-11 21:42:28 +00:00
|
|
|
HostAuthColumns._ID + " and " + HostAuthColumns.PROTOCOL + "='" +
|
2012-09-22 00:49:26 +00:00
|
|
|
LEGACY_SCHEME_EAS + "')");
|
2012-06-28 19:16:59 +00:00
|
|
|
} catch (SQLException e) {
|
2013-05-26 04:32:32 +00:00
|
|
|
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from 35/36 to 37/100 " + e);
|
2012-06-28 19:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|