From 472733edcd53b73df0271c1520669d3671325603 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 22 Aug 2017 16:33:19 +0200 Subject: [PATCH] introduce constants for message projection column indexes --- .../com/fsck/k9/mailstore/LocalMessage.java | 52 +++++++++---------- .../com/fsck/k9/mailstore/LocalStore.java | 27 ++++++++++ 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMessage.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMessage.java index 85b14dd8c..e842c9adc 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMessage.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMessage.java @@ -54,16 +54,16 @@ public class LocalMessage extends MimeMessage { void populateFromGetMessageCursor(Cursor cursor) throws MessagingException { - final String subject = cursor.getString(0); + final String subject = cursor.getString(LocalStore.MSG_INDEX_SUBJECT); this.setSubject(subject == null ? "" : subject); - Address[] from = Address.unpack(cursor.getString(1)); + Address[] from = Address.unpack(cursor.getString(LocalStore.MSG_INDEX_SENDER_LIST)); if (from.length > 0) { this.setFrom(from[0]); } - this.setInternalSentDate(new Date(cursor.getLong(2))); - this.setUid(cursor.getString(3)); - String flagList = cursor.getString(4); + this.setInternalSentDate(new Date(cursor.getLong(LocalStore.MSG_INDEX_DATE))); + this.setUid(cursor.getString(LocalStore.MSG_INDEX_UID)); + String flagList = cursor.getString(LocalStore.MSG_INDEX_FLAGS); if (flagList != null && flagList.length() > 0) { String[] flags = flagList.split(","); @@ -79,39 +79,39 @@ public class LocalMessage extends MimeMessage { } } } - this.databaseId = cursor.getLong(5); - this.setRecipients(RecipientType.TO, Address.unpack(cursor.getString(6))); - this.setRecipients(RecipientType.CC, Address.unpack(cursor.getString(7))); - this.setRecipients(RecipientType.BCC, Address.unpack(cursor.getString(8))); - this.setReplyTo(Address.unpack(cursor.getString(9))); + this.databaseId = cursor.getLong(LocalStore.MSG_INDEX_ID); + this.setRecipients(RecipientType.TO, Address.unpack(cursor.getString(LocalStore.MSG_INDEX_TO))); + this.setRecipients(RecipientType.CC, Address.unpack(cursor.getString(LocalStore.MSG_INDEX_CC))); + this.setRecipients(RecipientType.BCC, Address.unpack(cursor.getString(LocalStore.MSG_INDEX_BCC))); + this.setReplyTo(Address.unpack(cursor.getString(LocalStore.MSG_INDEX_REPLY_TO))); - this.attachmentCount = cursor.getInt(10); - this.setInternalDate(new Date(cursor.getLong(11))); - this.setMessageId(cursor.getString(12)); + this.attachmentCount = cursor.getInt(LocalStore.MSG_INDEX_ATTACHMENT_COUNT); + this.setInternalDate(new Date(cursor.getLong(LocalStore.MSG_INDEX_INTERNAL_DATE))); + this.setMessageId(cursor.getString(LocalStore.MSG_INDEX_MESSAGE_ID_HEADER)); - String previewTypeString = cursor.getString(24); + String previewTypeString = cursor.getString(LocalStore.MSG_INDEX_PREVIEW_TYPE); DatabasePreviewType databasePreviewType = DatabasePreviewType.fromDatabaseValue(previewTypeString); previewType = databasePreviewType.getPreviewType(); if (previewType == PreviewType.TEXT) { - preview = cursor.getString(14); + preview = cursor.getString(LocalStore.MSG_INDEX_PREVIEW); } else { preview = ""; } if (this.mFolder == null) { - LocalFolder f = new LocalFolder(this.localStore, cursor.getInt(13)); + LocalFolder f = new LocalFolder(this.localStore, cursor.getInt(LocalStore.MSG_INDEX_FOLDER_ID)); f.open(LocalFolder.OPEN_MODE_RW); this.mFolder = f; } - threadId = (cursor.isNull(15)) ? -1 : cursor.getLong(15); - rootId = (cursor.isNull(16)) ? -1 : cursor.getLong(16); + threadId = (cursor.isNull(LocalStore.MSG_INDEX_THREAD_ID)) ? -1 : cursor.getLong(LocalStore.MSG_INDEX_THREAD_ID); + rootId = (cursor.isNull(LocalStore.MSG_INDEX_THREAD_ROOT_ID)) ? -1 : cursor.getLong(LocalStore.MSG_INDEX_THREAD_ROOT_ID); - boolean deleted = (cursor.getInt(17) == 1); - boolean read = (cursor.getInt(18) == 1); - boolean flagged = (cursor.getInt(19) == 1); - boolean answered = (cursor.getInt(20) == 1); - boolean forwarded = (cursor.getInt(21) == 1); + boolean deleted = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_DELETED) == 1); + boolean read = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_READ) == 1); + boolean flagged = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_FLAGGED) == 1); + boolean answered = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_ANSWERED) == 1); + boolean forwarded = (cursor.getInt(LocalStore.MSG_INDEX_FLAG_FORWARDED) == 1); setFlagInternal(Flag.DELETED, deleted); setFlagInternal(Flag.SEEN, read); @@ -119,10 +119,10 @@ public class LocalMessage extends MimeMessage { setFlagInternal(Flag.ANSWERED, answered); setFlagInternal(Flag.FORWARDED, forwarded); - setMessagePartId(cursor.getLong(22)); - mimeType = cursor.getString(23); + setMessagePartId(cursor.getLong(LocalStore.MSG_INDEX_MESSAGE_PART_ID)); + mimeType = cursor.getString(LocalStore.MSG_INDEX_MIME_TYPE); - byte[] header = cursor.getBlob(25); + byte[] header = cursor.getBlob(LocalStore.MSG_INDEX_HEADER_DATA); if (header != null) { MessageHeaderParser.parse(this, new ByteArrayInputStream(header)); } else { diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java index dafe98fd6..0f08aa443 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java @@ -103,6 +103,33 @@ public class LocalStore extends Store implements Serializable { "folder_id, preview, threads.id, threads.root, deleted, read, flagged, answered, " + "forwarded, message_part_id, messages.mime_type, preview_type, header "; + static final int MSG_INDEX_SUBJECT = 0; + static final int MSG_INDEX_SENDER_LIST = 1; + static final int MSG_INDEX_DATE = 2; + static final int MSG_INDEX_UID = 3; + static final int MSG_INDEX_FLAGS = 4; + static final int MSG_INDEX_ID = 5; + static final int MSG_INDEX_TO = 6; + static final int MSG_INDEX_CC = 7; + static final int MSG_INDEX_BCC = 8; + static final int MSG_INDEX_REPLY_TO = 9; + static final int MSG_INDEX_ATTACHMENT_COUNT = 10; + static final int MSG_INDEX_INTERNAL_DATE = 11; + static final int MSG_INDEX_MESSAGE_ID_HEADER = 12; + static final int MSG_INDEX_FOLDER_ID = 13; + static final int MSG_INDEX_PREVIEW = 14; + static final int MSG_INDEX_THREAD_ID = 15; + static final int MSG_INDEX_THREAD_ROOT_ID = 16; + static final int MSG_INDEX_FLAG_DELETED = 17; + static final int MSG_INDEX_FLAG_READ = 18; + static final int MSG_INDEX_FLAG_FLAGGED = 19; + static final int MSG_INDEX_FLAG_ANSWERED = 20; + static final int MSG_INDEX_FLAG_FORWARDED = 21; + static final int MSG_INDEX_MESSAGE_PART_ID = 22; + static final int MSG_INDEX_MIME_TYPE = 23; + static final int MSG_INDEX_PREVIEW_TYPE = 24; + static final int MSG_INDEX_HEADER_DATA = 25; + static final String GET_FOLDER_COLS = "folders.id, name, visible_limit, last_updated, status, push_state, last_pushed, " + "integrate, top_group, poll_class, push_class, display_class, notify_class, more_messages";