From dae1ca201b80c960bc98e048805a6ca4ab25af77 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 22 Aug 2017 16:02:15 +0200 Subject: [PATCH 1/9] clean up LocalFolder --- .../com/fsck/k9/mailstore/LocalFolder.java | 233 +++++++++--------- 1 file changed, 119 insertions(+), 114 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java index f6d26b5a5..feb515e80 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java @@ -70,52 +70,57 @@ import timber.log.Timber; public class LocalFolder extends Folder implements Serializable { - private static final long serialVersionUID = -1973296520918624767L; private static final int MAX_BODY_SIZE_FOR_DATABASE = 16 * 1024; - static final long INVALID_MESSAGE_PART_ID = -1; + private static final long INVALID_MESSAGE_PART_ID = -1; + private final LocalStore localStore; private final AttachmentInfoExtractor attachmentInfoExtractor; - private String mName = null; - private long mFolderId = -1; - private int mVisibleLimit = -1; + + private String folderName = null; + private long folderId = -1; + private int visibleLimit = -1; private String prefId = null; - private FolderClass mDisplayClass = FolderClass.NO_CLASS; - private FolderClass mSyncClass = FolderClass.INHERITED; - private FolderClass mPushClass = FolderClass.SECOND_CLASS; - private FolderClass mNotifyClass = FolderClass.INHERITED; - private boolean mInTopGroup = false; - private String mPushState = null; - private boolean mIntegrate = false; + + private FolderClass displayClass = FolderClass.NO_CLASS; + private FolderClass syncClass = FolderClass.INHERITED; + private FolderClass pushClass = FolderClass.SECOND_CLASS; + private FolderClass notifyClass = FolderClass.INHERITED; + + private String pushState = null; + private boolean isInTopGroup = false; + private boolean isIntegrate = false; + // mLastUid is used during syncs. It holds the highest UID within the local folder so we // know whether or not an unread message added to the local folder is actually "new" or not. - private Integer mLastUid = null; + private Integer lastUid = null; private MoreMessages moreMessages = MoreMessages.UNKNOWN; + public LocalFolder(LocalStore localStore, String name) { super(); this.localStore = localStore; - this.mName = name; + this.folderName = name; attachmentInfoExtractor = localStore.attachmentInfoExtractor; if (getAccount().getInboxFolderName().equals(getName())) { - mSyncClass = FolderClass.FIRST_CLASS; - mPushClass = FolderClass.FIRST_CLASS; - mInTopGroup = true; + syncClass = FolderClass.FIRST_CLASS; + pushClass = FolderClass.FIRST_CLASS; + isInTopGroup = true; } } public LocalFolder(LocalStore localStore, long id) { super(); this.localStore = localStore; - this.mFolderId = id; + this.folderId = id; attachmentInfoExtractor = localStore.attachmentInfoExtractor; } public long getId() { - return mFolderId; + return folderId; } public String getAccountUuid() @@ -154,10 +159,11 @@ public class LocalFolder extends Folder implements Serializable { try { String baseQuery = "SELECT " + LocalStore.GET_FOLDER_COLS + " FROM folders "; - if (mName != null) { - cursor = db.rawQuery(baseQuery + "where folders.name = ?", new String[] { mName }); + if (folderName != null) { + cursor = db.rawQuery(baseQuery + "where folders.name = ?", new String[] { folderName }); } else { - cursor = db.rawQuery(baseQuery + "where folders.id = ?", new String[] { Long.toString(mFolderId) }); + cursor = db.rawQuery(baseQuery + "where folders.id = ?", new String[] { Long.toString( + folderId) }); } if (cursor.moveToFirst() && !cursor.isNull(LocalStore.FOLDER_ID_INDEX)) { @@ -184,33 +190,33 @@ public class LocalFolder extends Folder implements Serializable { } void open(Cursor cursor) throws MessagingException { - mFolderId = cursor.getInt(LocalStore.FOLDER_ID_INDEX); - mName = cursor.getString(LocalStore.FOLDER_NAME_INDEX); - mVisibleLimit = cursor.getInt(LocalStore.FOLDER_VISIBLE_LIMIT_INDEX); - mPushState = cursor.getString(LocalStore.FOLDER_PUSH_STATE_INDEX); + folderId = cursor.getInt(LocalStore.FOLDER_ID_INDEX); + folderName = cursor.getString(LocalStore.FOLDER_NAME_INDEX); + visibleLimit = cursor.getInt(LocalStore.FOLDER_VISIBLE_LIMIT_INDEX); + pushState = cursor.getString(LocalStore.FOLDER_PUSH_STATE_INDEX); super.setStatus(cursor.getString(LocalStore.FOLDER_STATUS_INDEX)); // Only want to set the local variable stored in the super class. This class // does a DB update on setLastChecked super.setLastChecked(cursor.getLong(LocalStore.FOLDER_LAST_CHECKED_INDEX)); super.setLastPush(cursor.getLong(LocalStore.FOLDER_LAST_PUSHED_INDEX)); - mInTopGroup = cursor.getInt(LocalStore.FOLDER_TOP_GROUP_INDEX) == 1; - mIntegrate = cursor.getInt(LocalStore.FOLDER_INTEGRATE_INDEX) == 1; + isInTopGroup = cursor.getInt(LocalStore.FOLDER_TOP_GROUP_INDEX) == 1; + isIntegrate = cursor.getInt(LocalStore.FOLDER_INTEGRATE_INDEX) == 1; String noClass = FolderClass.NO_CLASS.toString(); String displayClass = cursor.getString(LocalStore.FOLDER_DISPLAY_CLASS_INDEX); - mDisplayClass = Folder.FolderClass.valueOf((displayClass == null) ? noClass : displayClass); + this.displayClass = Folder.FolderClass.valueOf((displayClass == null) ? noClass : displayClass); String notifyClass = cursor.getString(LocalStore.FOLDER_NOTIFY_CLASS_INDEX); - mNotifyClass = Folder.FolderClass.valueOf((notifyClass == null) ? noClass : notifyClass); + this.notifyClass = Folder.FolderClass.valueOf((notifyClass == null) ? noClass : notifyClass); String pushClass = cursor.getString(LocalStore.FOLDER_PUSH_CLASS_INDEX); - mPushClass = Folder.FolderClass.valueOf((pushClass == null) ? noClass : pushClass); + this.pushClass = Folder.FolderClass.valueOf((pushClass == null) ? noClass : pushClass); String syncClass = cursor.getString(LocalStore.FOLDER_SYNC_CLASS_INDEX); - mSyncClass = Folder.FolderClass.valueOf((syncClass == null) ? noClass : syncClass); + this.syncClass = Folder.FolderClass.valueOf((syncClass == null) ? noClass : syncClass); String moreMessagesValue = cursor.getString(LocalStore.MORE_MESSAGES_INDEX); moreMessages = MoreMessages.fromDatabaseName(moreMessagesValue); } @Override public boolean isOpen() { - return (mFolderId != -1 && mName != null); + return (folderId != -1 && folderName != null); } @Override @@ -220,7 +226,7 @@ public class LocalFolder extends Folder implements Serializable { @Override public String getName() { - return mName; + return folderName; } @Override @@ -253,7 +259,7 @@ public class LocalFolder extends Folder implements Serializable { @Override public boolean create(FolderType type, final int visibleLimit) throws MessagingException { if (exists()) { - throw new MessagingException("Folder " + mName + " already exists."); + throw new MessagingException("Folder " + folderName + " already exists."); } List foldersToCreate = new ArrayList<>(1); foldersToCreate.add(this); @@ -263,17 +269,17 @@ public class LocalFolder extends Folder implements Serializable { } class PreferencesHolder { - FolderClass displayClass = mDisplayClass; - FolderClass syncClass = mSyncClass; - FolderClass notifyClass = mNotifyClass; - FolderClass pushClass = mPushClass; - boolean inTopGroup = mInTopGroup; - boolean integrate = mIntegrate; + FolderClass displayClass = LocalFolder.this.displayClass; + FolderClass syncClass = LocalFolder.this.syncClass; + FolderClass notifyClass = LocalFolder.this.notifyClass; + FolderClass pushClass = LocalFolder.this.pushClass; + boolean inTopGroup = isInTopGroup; + boolean integrate = isIntegrate; } @Override public void close() { - mFolderId = -1; + folderId = -1; } @Override @@ -292,7 +298,7 @@ public class LocalFolder extends Folder implements Serializable { cursor = db.rawQuery( "SELECT COUNT(id) FROM messages " + "WHERE empty = 0 AND deleted = 0 and folder_id = ?", - new String[] { Long.toString(mFolderId) }); + new String[] { Long.toString(folderId) }); cursor.moveToFirst(); return cursor.getInt(0); //messagecount } finally { @@ -307,7 +313,7 @@ public class LocalFolder extends Folder implements Serializable { @Override public int getUnreadMessageCount() throws MessagingException { - if (mFolderId == -1) { + if (folderId == -1) { open(OPEN_MODE_RW); } @@ -318,7 +324,7 @@ public class LocalFolder extends Folder implements Serializable { int unreadMessageCount = 0; Cursor cursor = db.query("messages", new String[] { "COUNT(id)" }, "folder_id = ? AND empty = 0 AND deleted = 0 AND read=0", - new String[] { Long.toString(mFolderId) }, null, null, null); + new String[] { Long.toString(folderId) }, null, null, null); try { if (cursor.moveToFirst()) { @@ -338,7 +344,7 @@ public class LocalFolder extends Folder implements Serializable { @Override public int getFlaggedMessageCount() throws MessagingException { - if (mFolderId == -1) { + if (folderId == -1) { open(OPEN_MODE_RW); } @@ -349,7 +355,7 @@ public class LocalFolder extends Folder implements Serializable { int flaggedMessageCount = 0; Cursor cursor = db.query("messages", new String[] { "COUNT(id)" }, "folder_id = ? AND empty = 0 AND deleted = 0 AND flagged = 1", - new String[] { Long.toString(mFolderId) }, null, null, null); + new String[] { Long.toString(folderId) }, null, null, null); try { if (cursor.moveToFirst()) { @@ -391,18 +397,18 @@ public class LocalFolder extends Folder implements Serializable { public int getVisibleLimit() throws MessagingException { open(OPEN_MODE_RW); - return mVisibleLimit; + return visibleLimit; } public void purgeToVisibleLimit(MessageRemovalListener listener) throws MessagingException { //don't purge messages while a Search is active since it might throw away search results if (!Search.isActive()) { - if (mVisibleLimit == 0) { + if (visibleLimit == 0) { return ; } open(OPEN_MODE_RW); List messages = getMessages(null, false); - for (int i = mVisibleLimit; i < messages.size(); i++) { + for (int i = visibleLimit; i < messages.size(); i++) { if (listener != null) { listener.messageRemoved(messages.get(i)); } @@ -413,10 +419,10 @@ public class LocalFolder extends Folder implements Serializable { public void setVisibleLimit(final int visibleLimit) throws MessagingException { - updateMoreMessagesOnVisibleLimitChange(visibleLimit, mVisibleLimit); + updateMoreMessagesOnVisibleLimitChange(visibleLimit, this.visibleLimit); - mVisibleLimit = visibleLimit; - updateFolderColumn("visible_limit", mVisibleLimit); + this.visibleLimit = visibleLimit; + updateFolderColumn("visible_limit", this.visibleLimit); } private void updateMoreMessagesOnVisibleLimitChange(int newVisibleLimit, int oldVisibleLimit) @@ -437,7 +443,7 @@ public class LocalFolder extends Folder implements Serializable { } public void setPushState(final String pushState) throws MessagingException { - mPushState = pushState; + this.pushState = pushState; updateFolderColumn("push_state", pushState); } @@ -451,7 +457,7 @@ public class LocalFolder extends Folder implements Serializable { } catch (MessagingException e) { throw new WrappedException(e); } - db.execSQL("UPDATE folders SET " + column + " = ? WHERE id = ?", new Object[] { value, mFolderId }); + db.execSQL("UPDATE folders SET " + column + " = ? WHERE id = ?", new Object[] { value, folderId }); return null; } }); @@ -461,67 +467,67 @@ public class LocalFolder extends Folder implements Serializable { } public String getPushState() { - return mPushState; + return pushState; } @Override public FolderClass getDisplayClass() { - return mDisplayClass; + return displayClass; } @Override public FolderClass getSyncClass() { - return (FolderClass.INHERITED == mSyncClass) ? getDisplayClass() : mSyncClass; + return (FolderClass.INHERITED == syncClass) ? getDisplayClass() : syncClass; } public FolderClass getRawSyncClass() { - return mSyncClass; + return syncClass; } public FolderClass getNotifyClass() { - return (FolderClass.INHERITED == mNotifyClass) ? getPushClass() : mNotifyClass; + return (FolderClass.INHERITED == notifyClass) ? getPushClass() : notifyClass; } public FolderClass getRawNotifyClass() { - return mNotifyClass; + return notifyClass; } @Override public FolderClass getPushClass() { - return (FolderClass.INHERITED == mPushClass) ? getSyncClass() : mPushClass; + return (FolderClass.INHERITED == pushClass) ? getSyncClass() : pushClass; } public FolderClass getRawPushClass() { - return mPushClass; + return pushClass; } public void setDisplayClass(FolderClass displayClass) throws MessagingException { - mDisplayClass = displayClass; - updateFolderColumn("display_class", mDisplayClass.name()); + this.displayClass = displayClass; + updateFolderColumn("display_class", this.displayClass.name()); } public void setSyncClass(FolderClass syncClass) throws MessagingException { - mSyncClass = syncClass; - updateFolderColumn("poll_class", mSyncClass.name()); + this.syncClass = syncClass; + updateFolderColumn("poll_class", this.syncClass.name()); } public void setPushClass(FolderClass pushClass) throws MessagingException { - mPushClass = pushClass; - updateFolderColumn("push_class", mPushClass.name()); + this.pushClass = pushClass; + updateFolderColumn("push_class", this.pushClass.name()); } public void setNotifyClass(FolderClass notifyClass) throws MessagingException { - mNotifyClass = notifyClass; - updateFolderColumn("notify_class", mNotifyClass.name()); + this.notifyClass = notifyClass; + updateFolderColumn("notify_class", this.notifyClass.name()); } public boolean isIntegrate() { - return mIntegrate; + return isIntegrate; } public void setIntegrate(boolean integrate) throws MessagingException { - mIntegrate = integrate; - updateFolderColumn("integrate", mIntegrate ? 1 : 0); + isIntegrate = integrate; + updateFolderColumn("integrate", isIntegrate ? 1 : 0); } public boolean hasMoreMessages() { @@ -547,7 +553,7 @@ public class LocalFolder extends Folder implements Serializable { private String getPrefId() throws MessagingException { open(OPEN_MODE_RW); - return getPrefId(mName); + return getPrefId(folderName); } public void delete() throws MessagingException { @@ -574,32 +580,32 @@ public class LocalFolder extends Folder implements Serializable { String id = getPrefId(); // there can be a lot of folders. For the defaults, let's not save prefs, saving space, except for INBOX - if (mDisplayClass == FolderClass.NO_CLASS && !getAccount().getInboxFolderName().equals(getName())) { + if (displayClass == FolderClass.NO_CLASS && !getAccount().getInboxFolderName().equals(getName())) { editor.remove(id + ".displayMode"); } else { - editor.putString(id + ".displayMode", mDisplayClass.name()); + editor.putString(id + ".displayMode", displayClass.name()); } - if (mSyncClass == FolderClass.INHERITED && !getAccount().getInboxFolderName().equals(getName())) { + if (syncClass == FolderClass.INHERITED && !getAccount().getInboxFolderName().equals(getName())) { editor.remove(id + ".syncMode"); } else { - editor.putString(id + ".syncMode", mSyncClass.name()); + editor.putString(id + ".syncMode", syncClass.name()); } - if (mNotifyClass == FolderClass.INHERITED && !getAccount().getInboxFolderName().equals(getName())) { + if (notifyClass == FolderClass.INHERITED && !getAccount().getInboxFolderName().equals(getName())) { editor.remove(id + ".notifyMode"); } else { - editor.putString(id + ".notifyMode", mNotifyClass.name()); + editor.putString(id + ".notifyMode", notifyClass.name()); } - if (mPushClass == FolderClass.SECOND_CLASS && !getAccount().getInboxFolderName().equals(getName())) { + if (pushClass == FolderClass.SECOND_CLASS && !getAccount().getInboxFolderName().equals(getName())) { editor.remove(id + ".pushMode"); } else { - editor.putString(id + ".pushMode", mPushClass.name()); + editor.putString(id + ".pushMode", pushClass.name()); } - editor.putBoolean(id + ".inTopGroup", mInTopGroup); + editor.putBoolean(id + ".inTopGroup", isInTopGroup); - editor.putBoolean(id + ".integrate", mIntegrate); + editor.putBoolean(id + ".integrate", isIntegrate); } @@ -810,7 +816,7 @@ public class LocalFolder extends Folder implements Serializable { try { cursor = db.rawQuery( "SELECT uid FROM messages WHERE id = ? AND folder_id = ?", - new String[] { Long.toString(id), Long.toString(mFolderId) }); + new String[] { Long.toString(id), Long.toString(folderId) }); if (!cursor.moveToNext()) { return null; } @@ -847,7 +853,7 @@ public class LocalFolder extends Folder implements Serializable { "LEFT JOIN message_parts ON (message_parts.id = messages.message_part_id) " + "LEFT JOIN threads ON (threads.message_id = messages.id) " + "WHERE uid = ? AND folder_id = ?", - new String[] { message.getUid(), Long.toString(mFolderId) }); + new String[] { message.getUid(), Long.toString(folderId) }); if (!cursor.moveToNext()) { return null; @@ -883,7 +889,7 @@ public class LocalFolder extends Folder implements Serializable { "FROM messages " + "WHERE empty = 0 AND deleted = 0 AND " + "folder_id = ? ORDER BY date DESC", - new String[] { Long.toString(mFolderId) }); + new String[] { Long.toString(folderId) }); while (cursor.moveToNext()) { String uid = cursor.getString(0); @@ -924,7 +930,7 @@ public class LocalFolder extends Folder implements Serializable { "WHERE empty = 0 AND " + (includeDeleted ? "" : "deleted = 0 AND ") + "folder_id = ? ORDER BY date DESC", - new String[] { Long.toString(mFolderId) }); + new String[] { Long.toString(folderId) }); } catch (MessagingException e) { throw new WrappedException(e); } @@ -951,7 +957,7 @@ public class LocalFolder extends Folder implements Serializable { "FROM messages " + "WHERE empty = 0 AND deleted = 0 AND " + "folder_id = ? ORDER BY date DESC", - new String[] { Long.toString(mFolderId) }); + new String[] { Long.toString(folderId) }); while (cursor.moveToNext()) { String uid = cursor.getString(0); @@ -1096,7 +1102,7 @@ public class LocalFolder extends Folder implements Serializable { cv.putNull("flags"); cv.put("read", 1); cv.put("deleted", 1); - cv.put("folder_id", mFolderId); + cv.put("folder_id", folderId); cv.put("empty", 0); String messageId = message.getMessageId(); @@ -1149,7 +1155,6 @@ public class LocalFolder extends Folder implements Serializable { * @param message Message to store. Never null. * @param runnable What to do before setting {@link Flag#X_DOWNLOADED_FULL}. Never null. * @return The local version of the message. Never null. - * @throws MessagingException */ public LocalMessage storeSmallMessage(final Message message, final Runnable runnable) throws MessagingException { return this.localStore.database.execute(true, new DbCallback() { @@ -1217,7 +1222,7 @@ public class LocalFolder extends Folder implements Serializable { "WHERE m.folder_id = ? AND m.message_id = ? " + ((onlyEmpty) ? "AND m.empty = 1 " : "") + "ORDER BY m.id LIMIT 1"; - String[] selectionArgs = { Long.toString(mFolderId), messageId }; + String[] selectionArgs = { Long.toString(folderId), messageId }; Cursor cursor = db.rawQuery(sql, selectionArgs); if (cursor != null) { @@ -1278,7 +1283,7 @@ public class LocalFolder extends Folder implements Serializable { } } - protected void saveMessage(SQLiteDatabase db, Message message, boolean copy, Map uidMap) + private void saveMessage(SQLiteDatabase db, Message message, boolean copy, Map uidMap) throws MessagingException { if (!(message instanceof MimeMessage)) { throw new Error("LocalStore can only store Messages that extend MimeMessage"); @@ -1344,13 +1349,13 @@ public class LocalFolder extends Folder implements Serializable { cv.put("sender_list", Address.pack(message.getFrom())); cv.put("date", message.getSentDate() == null ? System.currentTimeMillis() : message.getSentDate().getTime()); - cv.put("flags", this.localStore.serializeFlags(message.getFlags())); + cv.put("flags", LocalStore.serializeFlags(message.getFlags())); cv.put("deleted", message.isSet(Flag.DELETED) ? 1 : 0); cv.put("read", message.isSet(Flag.SEEN) ? 1 : 0); cv.put("flagged", message.isSet(Flag.FLAGGED) ? 1 : 0); cv.put("answered", message.isSet(Flag.ANSWERED) ? 1 : 0); cv.put("forwarded", message.isSet(Flag.FORWARDED) ? 1 : 0); - cv.put("folder_id", mFolderId); + cv.put("folder_id", folderId); cv.put("to_list", Address.pack(message.getRecipients(RecipientType.TO))); cv.put("cc_list", Address.pack(message.getRecipients(RecipientType.CC))); cv.put("bcc_list", Address.pack(message.getRecipients(RecipientType.BCC))); @@ -1675,7 +1680,6 @@ public class LocalFolder extends Folder implements Serializable { /** * Changes the stored uid of the given message (using it's internal id as a key) to * the uid in the message. - * @throws com.fsck.k9.mail.MessagingException */ public void changeUid(final LocalMessage message) throws MessagingException { open(OPEN_MODE_RW); @@ -1745,7 +1749,7 @@ public class LocalFolder extends Folder implements Serializable { "LEFT JOIN message_parts ON (message_parts.id = messages.message_part_id) " + "LEFT JOIN threads ON (threads.message_id = messages.id) " + "WHERE empty = 0 AND (folder_id = ? and date < ?)", - new String[] { Long.toString(mFolderId), Long.toString(cutoff) }); + new String[] { Long.toString(folderId), Long.toString(cutoff) }); for (Message message : messages) { message.destroy(); @@ -1755,7 +1759,7 @@ public class LocalFolder extends Folder implements Serializable { } public void clearAllMessages() throws MessagingException { - final String[] folderIdArg = new String[] { Long.toString(mFolderId) }; + final String[] folderIdArg = new String[] { Long.toString(folderId) }; open(OPEN_MODE_RO); @@ -1817,7 +1821,7 @@ public class LocalFolder extends Folder implements Serializable { throw new WrappedException(e); } db.execSQL("DELETE FROM folders WHERE id = ?", new Object[] - { Long.toString(mFolderId), }); + { Long.toString(folderId), }); return null; } }); @@ -1829,14 +1833,14 @@ public class LocalFolder extends Folder implements Serializable { @Override public boolean equals(Object o) { if (o instanceof LocalFolder) { - return ((LocalFolder)o).mName.equals(mName); + return ((LocalFolder)o).folderName.equals(folderName); } return super.equals(o); } @Override public int hashCode() { - return mName.hashCode(); + return folderName.hashCode(); } void destroyMessage(LocalMessage localMessage) throws MessagingException { @@ -2031,16 +2035,16 @@ public class LocalFolder extends Folder implements Serializable { @Override public boolean isInTopGroup() { - return mInTopGroup; + return isInTopGroup; } public void setInTopGroup(boolean inTopGroup) throws MessagingException { - mInTopGroup = inTopGroup; - updateFolderColumn("top_group", mInTopGroup ? 1 : 0); + isInTopGroup = inTopGroup; + updateFolderColumn("top_group", isInTopGroup ? 1 : 0); } public Integer getLastUid() { - return mLastUid; + return lastUid; } /** @@ -2057,7 +2061,6 @@ public class LocalFolder extends Folder implements Serializable { * updated to use internal dates rather than UIDs to determine new-ness. While this doesn't * solve things for POP (which doesn't have internal dates), we can likely use this as a * framework to examine send date in lieu of internal date.

- * @throws MessagingException */ public void updateLastUid() throws MessagingException { Integer lastUid = this.localStore.database.execute(false, new DbCallback() { @@ -2066,7 +2069,8 @@ public class LocalFolder extends Folder implements Serializable { Cursor cursor = null; try { open(OPEN_MODE_RO); - cursor = db.rawQuery("SELECT MAX(uid) FROM messages WHERE folder_id=?", new String[] { Long.toString(mFolderId) }); + cursor = db.rawQuery("SELECT MAX(uid) FROM messages WHERE folder_id=?", new String[] { Long.toString( + folderId) }); if (cursor.getCount() > 0) { cursor.moveToFirst(); return cursor.getInt(0); @@ -2080,8 +2084,8 @@ public class LocalFolder extends Folder implements Serializable { } }); - Timber.d("Updated last UID for folder %s to %s", mName, lastUid); - mLastUid = lastUid; + Timber.d("Updated last UID for folder %s to %s", folderName, lastUid); + this.lastUid = lastUid; } public Long getOldestMessageDate() throws MessagingException { @@ -2091,7 +2095,8 @@ public class LocalFolder extends Folder implements Serializable { Cursor cursor = null; try { open(OPEN_MODE_RO); - cursor = db.rawQuery("SELECT MIN(date) FROM messages WHERE folder_id=?", new String[] { Long.toString(mFolderId) }); + cursor = db.rawQuery("SELECT MIN(date) FROM messages WHERE folder_id=?", new String[] { Long.toString( + folderId) }); if (cursor.getCount() > 0) { cursor.moveToFirst(); return cursor.getLong(0); @@ -2151,7 +2156,7 @@ public class LocalFolder extends Folder implements Serializable { // Create placeholder message in 'messages' table ContentValues cv = new ContentValues(); cv.put("message_id", reference); - cv.put("folder_id", mFolderId); + cv.put("folder_id", folderId); cv.put("empty", 1); long newMsgId = db.insert("messages", null, cv); @@ -2232,7 +2237,7 @@ public class LocalFolder extends Folder implements Serializable { StringBuilder selection = new StringBuilder(); selection.append("folder_id = ? AND UID IN ("); - selectionArgs.add(Long.toString(mFolderId)); + selectionArgs.add(Long.toString(folderId)); int count = Math.min(messages.size() - start, LocalStore.UID_CHECK_BATCH_SIZE); @@ -2287,7 +2292,7 @@ public class LocalFolder extends Folder implements Serializable { // Note: The contents of the 'message_parts' table depend on these values. // TODO currently unused, might be for caching at a later point - static class MessagePartType { + private static class MessagePartType { static final int UNKNOWN = 0; static final int ALTERNATIVE_PLAIN = 1; static final int ALTERNATIVE_HTML = 2; From b768d2fb6fe1a8df2855050dc2d77a8c43366c67 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 22 Aug 2017 16:08:59 +0200 Subject: [PATCH 2/9] clean up LocalStore --- .../com/fsck/k9/mailstore/LocalFolder.java | 60 +++++----- .../com/fsck/k9/mailstore/LocalMessage.java | 6 +- .../com/fsck/k9/mailstore/LocalStore.java | 112 +++++++++--------- .../mailstore/StoreSchemaDefinitionTest.java | 2 +- 4 files changed, 89 insertions(+), 91 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java index feb515e80..2086c228d 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java @@ -103,7 +103,7 @@ public class LocalFolder extends Folder implements Serializable { super(); this.localStore = localStore; this.folderName = name; - attachmentInfoExtractor = localStore.attachmentInfoExtractor; + attachmentInfoExtractor = localStore.getAttachmentInfoExtractor(); if (getAccount().getInboxFolderName().equals(getName())) { syncClass = FolderClass.FIRST_CLASS; @@ -116,7 +116,7 @@ public class LocalFolder extends Folder implements Serializable { super(); this.localStore = localStore; this.folderId = id; - attachmentInfoExtractor = localStore.attachmentInfoExtractor; + attachmentInfoExtractor = localStore.getAttachmentInfoExtractor(); } public long getId() { @@ -152,7 +152,7 @@ public class LocalFolder extends Folder implements Serializable { } try { - this.localStore.database.execute(false, new DbCallback() { + this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException { Cursor cursor = null; @@ -231,7 +231,7 @@ public class LocalFolder extends Folder implements Serializable { @Override public boolean exists() throws MessagingException { - return this.localStore.database.execute(false, new DbCallback() { + return this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Boolean doDbWork(final SQLiteDatabase db) throws WrappedException { Cursor cursor = null; @@ -285,7 +285,7 @@ public class LocalFolder extends Folder implements Serializable { @Override public int getMessageCount() throws MessagingException { try { - return this.localStore.database.execute(false, new DbCallback() { + return this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Integer doDbWork(final SQLiteDatabase db) throws WrappedException { try { @@ -318,7 +318,7 @@ public class LocalFolder extends Folder implements Serializable { } try { - return this.localStore.database.execute(false, new DbCallback() { + return this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Integer doDbWork(final SQLiteDatabase db) throws WrappedException { int unreadMessageCount = 0; @@ -349,7 +349,7 @@ public class LocalFolder extends Folder implements Serializable { } try { - return this.localStore.database.execute(false, new DbCallback() { + return this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Integer doDbWork(final SQLiteDatabase db) throws WrappedException { int flaggedMessageCount = 0; @@ -449,7 +449,7 @@ public class LocalFolder extends Folder implements Serializable { private void updateFolderColumn(final String column, final Object value) throws MessagingException { try { - this.localStore.database.execute(false, new DbCallback() { + this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException { try { @@ -545,7 +545,7 @@ public class LocalFolder extends Folder implements Serializable { private String getPrefId(String name) { if (prefId == null) { - prefId = this.localStore.uUid + "." + name; + prefId = this.localStore.getUUid() + "." + name; } return prefId; @@ -662,7 +662,7 @@ public class LocalFolder extends Folder implements Serializable { public void fetch(final List messages, final FetchProfile fp, final MessageRetrievalListener listener) throws MessagingException { try { - this.localStore.database.execute(false, new DbCallback() { + this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException { try { @@ -806,7 +806,7 @@ public class LocalFolder extends Folder implements Serializable { public String getMessageUidById(final long id) throws MessagingException { try { - return this.localStore.database.execute(false, new DbCallback() { + return this.localStore.getDatabase().execute(false, new DbCallback() { @Override public String doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { try { @@ -837,7 +837,7 @@ public class LocalFolder extends Folder implements Serializable { @Override public LocalMessage getMessage(final String uid) throws MessagingException { try { - return this.localStore.database.execute(false, new DbCallback() { + return this.localStore.getDatabase().execute(false, new DbCallback() { @Override public LocalMessage doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { try { @@ -875,7 +875,7 @@ public class LocalFolder extends Folder implements Serializable { public Map getAllMessagesAndEffectiveDates() throws MessagingException { try { - return localStore.database.execute(false, new DbCallback>() { + return localStore.getDatabase().execute(false, new DbCallback>() { @Override public Map doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { Cursor cursor = null; @@ -917,7 +917,7 @@ public class LocalFolder extends Folder implements Serializable { public List getMessages(final MessageRetrievalListener listener, final boolean includeDeleted) throws MessagingException { try { - return localStore.database.execute(false, new DbCallback>() { + return localStore.getDatabase().execute(false, new DbCallback>() { @Override public List doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { try { @@ -943,7 +943,7 @@ public class LocalFolder extends Folder implements Serializable { public List getAllMessageUids() throws MessagingException { try { - return localStore.database.execute(false, new DbCallback>() { + return localStore.getDatabase().execute(false, new DbCallback>() { @Override public List doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { Cursor cursor = null; @@ -1032,7 +1032,7 @@ public class LocalFolder extends Folder implements Serializable { final Map uidMap = new HashMap<>(); try { - this.localStore.database.execute(false, new DbCallback() { + this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { try { @@ -1157,7 +1157,7 @@ public class LocalFolder extends Folder implements Serializable { * @return The local version of the message. Never null. */ public LocalMessage storeSmallMessage(final Message message, final Runnable runnable) throws MessagingException { - return this.localStore.database.execute(true, new DbCallback() { + return this.localStore.getDatabase().execute(true, new DbCallback() { @Override public LocalMessage doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { try { @@ -1193,7 +1193,7 @@ public class LocalFolder extends Folder implements Serializable { public void destroyMessages(final List messages) { try { - this.localStore.database.execute(true, new DbCallback() { + this.localStore.getDatabase().execute(true, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { for (Message message : messages) { @@ -1261,7 +1261,7 @@ public class LocalFolder extends Folder implements Serializable { open(OPEN_MODE_RW); try { final Map uidMap = new HashMap<>(); - this.localStore.database.execute(true, new DbCallback() { + this.localStore.getDatabase().execute(true, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { try { @@ -1646,7 +1646,7 @@ public class LocalFolder extends Folder implements Serializable { public void addPartToMessage(final LocalMessage message, final Part part) throws MessagingException { open(OPEN_MODE_RW); - localStore.database.execute(false, new DbCallback() { + localStore.getDatabase().execute(false, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { long messagePartId; @@ -1685,7 +1685,7 @@ public class LocalFolder extends Folder implements Serializable { open(OPEN_MODE_RW); final ContentValues cv = new ContentValues(); cv.put("uid", message.getUid()); - this.localStore.database.execute(false, new DbCallback() { + this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { db.update("messages", cv, "id = ?", new String[] @@ -1705,7 +1705,7 @@ public class LocalFolder extends Folder implements Serializable { // Use one transaction to set all flags try { - this.localStore.database.execute(true, new DbCallback() { + this.localStore.getDatabase().execute(true, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { @@ -1764,7 +1764,7 @@ public class LocalFolder extends Folder implements Serializable { open(OPEN_MODE_RO); try { - this.localStore.database.execute(false, new DbCallback() { + this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException { try { @@ -1807,7 +1807,7 @@ public class LocalFolder extends Folder implements Serializable { @Override public void delete(final boolean recurse) throws MessagingException { try { - this.localStore.database.execute(false, new DbCallback() { + this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { try { @@ -1850,7 +1850,7 @@ public class LocalFolder extends Folder implements Serializable { private void destroyMessage(final long messageId, final long messagePartId, final String messageIdHeader) throws MessagingException { try { - localStore.database.execute(true, new DbCallback() { + localStore.getDatabase().execute(true, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { @@ -1995,7 +1995,7 @@ public class LocalFolder extends Folder implements Serializable { } private void deleteMessageParts(final long rootMessagePartId) throws MessagingException { - localStore.database.execute(false, new DbCallback() { + localStore.getDatabase().execute(false, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { db.delete("message_parts", "root = ?", new String[] { Long.toString(rootMessagePartId) }); @@ -2005,7 +2005,7 @@ public class LocalFolder extends Folder implements Serializable { } private void deleteMessageDataFromDisk(final long rootMessagePartId) throws MessagingException { - localStore.database.execute(false, new DbCallback() { + localStore.getDatabase().execute(false, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { deleteMessagePartsFromDisk(db, rootMessagePartId); @@ -2063,7 +2063,7 @@ public class LocalFolder extends Folder implements Serializable { * framework to examine send date in lieu of internal date.

*/ public void updateLastUid() throws MessagingException { - Integer lastUid = this.localStore.database.execute(false, new DbCallback() { + Integer lastUid = this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Integer doDbWork(final SQLiteDatabase db) { Cursor cursor = null; @@ -2089,7 +2089,7 @@ public class LocalFolder extends Folder implements Serializable { } public Long getOldestMessageDate() throws MessagingException { - return this.localStore.database.execute(false, new DbCallback() { + return this.localStore.getDatabase().execute(false, new DbCallback() { @Override public Long doDbWork(final SQLiteDatabase db) { Cursor cursor = null; @@ -2218,7 +2218,7 @@ public class LocalFolder extends Folder implements Serializable { throws MessagingException { try { - return this.localStore.database.execute(false, new DbCallback>() { + return this.localStore.getDatabase().execute(false, new DbCallback>() { @Override public List doDbWork(final SQLiteDatabase db) throws WrappedException { try { 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 cbf69fbca..be7ae4ce6 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMessage.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMessage.java @@ -257,7 +257,7 @@ public class LocalMessage extends MimeMessage { public void setFlag(final Flag flag, final boolean set) throws MessagingException { try { - this.localStore.database.execute(true, new DbCallback() { + this.localStore.getDatabase().execute(true, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { try { @@ -297,7 +297,7 @@ public class LocalMessage extends MimeMessage { */ private void delete() throws MessagingException { try { - localStore.database.execute(true, new DbCallback() { + localStore.getDatabase().execute(true, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { ContentValues cv = new ContentValues(); @@ -339,7 +339,7 @@ public class LocalMessage extends MimeMessage { } try { - localStore.database.execute(true, new DbCallback() { + localStore.getDatabase().execute(true, new DbCallback() { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, MessagingException { ContentValues cv = new ContentValues(); 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 c1aa977e9..dc8302082 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java @@ -155,41 +155,17 @@ public class LocalStore extends Store implements Serializable { public static final int DB_VERSION = 60; - - public static String getColumnNameForFlag(Flag flag) { - switch (flag) { - case SEEN: { - return MessageColumns.READ; - } - case FLAGGED: { - return MessageColumns.FLAGGED; - } - case ANSWERED: { - return MessageColumns.ANSWERED; - } - case FORWARDED: { - return MessageColumns.FORWARDED; - } - default: { - throw new IllegalArgumentException("Flag must be a special column flag"); - } - } - } - - - protected String uUid = null; - - final Context context; - - LockableDatabase database; - - private ContentResolver mContentResolver; - private final Account mAccount; + private final Context context; + private final ContentResolver contentResolver; private final MessagePreviewCreator messagePreviewCreator; private final MessageFulltextCreator messageFulltextCreator; private final AttachmentCounter attachmentCounter; private final PendingCommandSerializer pendingCommandSerializer; - final AttachmentInfoExtractor attachmentInfoExtractor; + private final AttachmentInfoExtractor attachmentInfoExtractor; + + private final Account account; + private final String uUid; + private final LockableDatabase database; /** * local://localhost/path/to/database/uuid.db @@ -197,13 +173,8 @@ public class LocalStore extends Store implements Serializable { * @throws UnavailableStorageException if not {@link StorageProvider#isReady(Context)} */ private LocalStore(final Account account, final Context context) throws MessagingException { - mAccount = account; - database = new LockableDatabase(context, account.getUuid(), new StoreSchemaDefinition(this)); - this.context = context; - mContentResolver = context.getContentResolver(); - database.setStorageProviderId(account.getLocalStorageProviderId()); - uUid = account.getUuid(); + this.contentResolver = context.getContentResolver(); messagePreviewCreator = MessagePreviewCreator.newInstance(); messageFulltextCreator = MessageFulltextCreator.newInstance(); @@ -211,6 +182,11 @@ public class LocalStore extends Store implements Serializable { pendingCommandSerializer = PendingCommandSerializer.getInstance(); attachmentInfoExtractor = AttachmentInfoExtractor.getInstance(); + this.account = account; + this.uUid = account.getUuid(); + + database = new LockableDatabase(context, account.getUuid(), new StoreSchemaDefinition(this)); + database.setStorageProviderId(account.getLocalStorageProviderId()); database.open(); } @@ -266,8 +242,12 @@ public class LocalStore extends Store implements Serializable { return context; } - protected Account getAccount() { - return mAccount; + Account getAccount() { + return account; + } + + String getUUid() { + return uUid; } protected Storage getStorage() { @@ -358,7 +338,7 @@ public class LocalStore extends Store implements Serializable { } } - public int getMessageCount() throws MessagingException { + private int getMessageCount() throws MessagingException { return database.execute(false, new DbCallback() { @Override public Integer doDbWork(final SQLiteDatabase db) { @@ -374,7 +354,7 @@ public class LocalStore extends Store implements Serializable { }); } - public int getFolderCount() throws MessagingException { + private int getFolderCount() throws MessagingException { return database.execute(false, new DbCallback() { @Override public Integer doDbWork(final SQLiteDatabase db) { @@ -568,7 +548,7 @@ public class LocalStore extends Store implements Serializable { StringBuilder query = new StringBuilder(); List queryArgs = new ArrayList<>(); - SqlQueryBuilder.buildWhereClause(mAccount, search.getConditions(), query, queryArgs); + SqlQueryBuilder.buildWhereClause(account, search.getConditions(), query, queryArgs); // Avoid "ambiguous column name" error by prefixing "id" with the message table name String where = SqlQueryBuilder.addPrefixToSelection(new String[] { "id" }, @@ -914,10 +894,10 @@ public class LocalStore extends Store implements Serializable { // When created, special folders should always be displayed // inbox should be integrated // and the inbox and drafts folders should be syncced by default - if (mAccount.isSpecialFolder(name)) { + if (account.isSpecialFolder(name)) { prefHolder.inTopGroup = true; prefHolder.displayClass = LocalFolder.FolderClass.FIRST_CLASS; - if (name.equalsIgnoreCase(mAccount.getInboxFolderName())) { + if (name.equalsIgnoreCase(account.getInboxFolderName())) { prefHolder.integrate = true; prefHolder.notifyClass = LocalFolder.FolderClass.FIRST_CLASS; prefHolder.pushClass = LocalFolder.FolderClass.FIRST_CLASS; @@ -925,8 +905,8 @@ public class LocalStore extends Store implements Serializable { prefHolder.pushClass = LocalFolder.FolderClass.INHERITED; } - if (name.equalsIgnoreCase(mAccount.getInboxFolderName()) || - name.equalsIgnoreCase(mAccount.getDraftsFolderName())) { + if (name.equalsIgnoreCase(account.getInboxFolderName()) || + name.equalsIgnoreCase(account.getDraftsFolderName())) { prefHolder.syncClass = LocalFolder.FolderClass.FIRST_CLASS; } else { prefHolder.syncClass = LocalFolder.FolderClass.NO_CLASS; @@ -978,7 +958,7 @@ public class LocalStore extends Store implements Serializable { return database; } - public MessagePreviewCreator getMessagePreviewCreator() { + MessagePreviewCreator getMessagePreviewCreator() { return messagePreviewCreator; } @@ -986,13 +966,17 @@ public class LocalStore extends Store implements Serializable { return messageFulltextCreator; } - public AttachmentCounter getAttachmentCounter() { + AttachmentCounter getAttachmentCounter() { return attachmentCounter; } + AttachmentInfoExtractor getAttachmentInfoExtractor() { + return attachmentInfoExtractor; + } + void notifyChange() { Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + uUid + "/messages"); - mContentResolver.notifyChange(uri, null); + contentResolver.notifyChange(uri, null); } /** @@ -1008,10 +992,8 @@ public class LocalStore extends Store implements Serializable { * Supplies the argument set and the code to query/update the database. * @param batchSize * The maximum size of the selection set in each SQL statement. - * - * @throws MessagingException */ - public void doBatchSetSelection(final BatchSetSelection selectionCallback, final int batchSize) + private void doBatchSetSelection(final BatchSetSelection selectionCallback, final int batchSize) throws MessagingException { final List selectionArgs = new ArrayList<>(); @@ -1063,7 +1045,7 @@ public class LocalStore extends Store implements Serializable { /** * Defines the behavior of {@link LocalStore#doBatchSetSelection(BatchSetSelection, int)}. */ - public interface BatchSetSelection { + interface BatchSetSelection { /** * @return The size of the argument list. */ @@ -1089,7 +1071,6 @@ public class LocalStore extends Store implements Serializable { * {@code " IN (?,?,?)"} (starts with a space). * @param selectionArgs * The current subset of the argument list. - * @throws UnavailableStorageException */ void doDbWork(SQLiteDatabase db, String selectionSet, String[] selectionArgs) throws UnavailableStorageException; @@ -1116,7 +1097,6 @@ public class LocalStore extends Store implements Serializable { * @param newState * {@code true}, if the flag should be set. {@code false}, otherwise. * - * @throws MessagingException */ public void setFlag(final List messageIds, final Flag flag, final boolean newState) throws MessagingException { @@ -1165,7 +1145,6 @@ public class LocalStore extends Store implements Serializable { * @param newState * {@code true}, if the flag should be set. {@code false}, otherwise. * - * @throws MessagingException */ public void setFlagForThreads(final List threadRootIds, Flag flag, final boolean newState) throws MessagingException { @@ -1217,7 +1196,6 @@ public class LocalStore extends Store implements Serializable { * * @return The list of UIDs for the messages grouped by folder name. * - * @throws MessagingException */ public Map> getFoldersAndUids(final List messageIds, final boolean threadedList) throws MessagingException { @@ -1289,4 +1267,24 @@ public class LocalStore extends Store implements Serializable { return folderMap; } + + public static String getColumnNameForFlag(Flag flag) { + switch (flag) { + case SEEN: { + return MessageColumns.READ; + } + case FLAGGED: { + return MessageColumns.FLAGGED; + } + case ANSWERED: { + return MessageColumns.ANSWERED; + } + case FORWARDED: { + return MessageColumns.FORWARDED; + } + default: { + throw new IllegalArgumentException("Flag must be a special column flag"); + } + } + } } diff --git a/k9mail/src/test/java/com/fsck/k9/mailstore/StoreSchemaDefinitionTest.java b/k9mail/src/test/java/com/fsck/k9/mailstore/StoreSchemaDefinitionTest.java index 384809f21..1fd519671 100644 --- a/k9mail/src/test/java/com/fsck/k9/mailstore/StoreSchemaDefinitionTest.java +++ b/k9mail/src/test/java/com/fsck/k9/mailstore/StoreSchemaDefinitionTest.java @@ -336,7 +336,7 @@ public class StoreSchemaDefinitionTest { LockableDatabase lockableDatabase = createLockableDatabase(); LocalStore localStore = mock(LocalStore.class); - localStore.database = lockableDatabase; + when(localStore.getDatabase()).thenReturn(lockableDatabase); when(localStore.getContext()).thenReturn(context); when(localStore.getAccount()).thenReturn(account); From 52d76cad71ea74bdb1143fc40872aed944911a5e Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 22 Aug 2017 16:16:52 +0200 Subject: [PATCH 3/9] clean up LocalMessage --- .../com/fsck/k9/mailstore/LocalMessage.java | 84 +++++++++---------- 1 file changed, 39 insertions(+), 45 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 be7ae4ce6..e4db34de3 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMessage.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMessage.java @@ -27,18 +27,16 @@ import timber.log.Timber; public class LocalMessage extends MimeMessage { - protected MessageReference mReference; private final LocalStore localStore; - private long mId; - private int mAttachmentCount; - private String mSubject; - - private String mPreview = ""; - - private long mThreadId; - private long mRootId; + private long id; + private long rootId; + private long threadId; private long messagePartId; + private MessageReference messageReference; + private int attachmentCount; + private String subject; + private String preview = ""; private String mimeType; private PreviewType previewType; private boolean headerNeedsUpdating = false; @@ -81,13 +79,13 @@ public class LocalMessage extends MimeMessage { } } } - this.mId = cursor.getLong(5); + this.id = 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.mAttachmentCount = cursor.getInt(10); + this.attachmentCount = cursor.getInt(10); this.setInternalDate(new Date(cursor.getLong(11))); this.setMessageId(cursor.getString(12)); @@ -95,9 +93,9 @@ public class LocalMessage extends MimeMessage { DatabasePreviewType databasePreviewType = DatabasePreviewType.fromDatabaseValue(previewTypeString); previewType = databasePreviewType.getPreviewType(); if (previewType == PreviewType.TEXT) { - mPreview = cursor.getString(14); + preview = cursor.getString(14); } else { - mPreview = ""; + preview = ""; } if (this.mFolder == null) { @@ -106,8 +104,8 @@ public class LocalMessage extends MimeMessage { this.mFolder = f; } - mThreadId = (cursor.isNull(15)) ? -1 : cursor.getLong(15); - mRootId = (cursor.isNull(16)) ? -1 : cursor.getLong(16); + threadId = (cursor.isNull(15)) ? -1 : cursor.getLong(15); + rootId = (cursor.isNull(16)) ? -1 : cursor.getLong(16); boolean deleted = (cursor.getInt(17) == 1); boolean read = (cursor.getInt(18) == 1); @@ -157,18 +155,18 @@ public class LocalMessage extends MimeMessage { } public String getPreview() { - return mPreview; + return preview; } @Override public String getSubject() { - return mSubject; + return subject; } @Override public void setSubject(String subject) { - mSubject = subject; + this.subject = subject; headerNeedsUpdating = true; } @@ -182,16 +180,16 @@ public class LocalMessage extends MimeMessage { @Override public void setUid(String uid) { super.setUid(uid); - this.mReference = null; + this.messageReference = null; } @Override public boolean hasAttachments() { - return (mAttachmentCount > 0); + return (attachmentCount > 0); } - public int getAttachmentCount() { - return mAttachmentCount; + int getAttachmentCount() { + return attachmentCount; } @Override @@ -250,7 +248,7 @@ public class LocalMessage extends MimeMessage { @Override public long getId() { - return mId; + return id; } @Override @@ -273,13 +271,13 @@ public class LocalMessage extends MimeMessage { * Set the flags on the message. */ ContentValues cv = new ContentValues(); - cv.put("flags", LocalMessage.this.localStore.serializeFlags(getFlags())); + cv.put("flags", LocalStore.serializeFlags(getFlags())); cv.put("read", isSet(Flag.SEEN) ? 1 : 0); cv.put("flagged", isSet(Flag.FLAGGED) ? 1 : 0); cv.put("answered", isSet(Flag.ANSWERED) ? 1 : 0); cv.put("forwarded", isSet(Flag.FORWARDED) ? 1 : 0); - db.update("messages", cv, "id = ?", new String[] { Long.toString(mId) }); + db.update("messages", cv, "id = ?", new String[] { Long.toString(id) }); return null; } @@ -313,7 +311,7 @@ public class LocalMessage extends MimeMessage { cv.putNull("reply_to_list"); cv.putNull("message_part_id"); - db.update("messages", cv, "id = ?", new String[] { Long.toString(mId) }); + db.update("messages", cv, "id = ?", new String[] { Long.toString(id) }); try { ((LocalFolder) mFolder).deleteMessagePartsAndDataFromDisk(messagePartId); @@ -321,7 +319,7 @@ public class LocalMessage extends MimeMessage { throw new WrappedException(e); } - getFolder().deleteFulltextIndexEntry(db, mId); + getFolder().deleteFulltextIndexEntry(db, id); return null; } @@ -345,7 +343,7 @@ public class LocalMessage extends MimeMessage { ContentValues cv = new ContentValues(); cv.putNull("message_part_id"); - db.update("messages", cv, "id = ?", new String[] { Long.toString(mId) }); + db.update("messages", cv, "id = ?", new String[] { Long.toString(id) }); try { ((LocalFolder) mFolder).deleteMessagePartsAndDataFromDisk(messagePartId); @@ -381,13 +379,13 @@ public class LocalMessage extends MimeMessage { LocalMessage message = new LocalMessage(localStore); super.copy(message); - message.mReference = mReference; - message.mId = mId; - message.mAttachmentCount = mAttachmentCount; - message.mSubject = mSubject; - message.mPreview = mPreview; - message.mThreadId = mThreadId; - message.mRootId = mRootId; + message.messageReference = messageReference; + message.id = id; + message.attachmentCount = attachmentCount; + message.subject = subject; + message.preview = preview; + message.threadId = threadId; + message.rootId = rootId; message.messagePartId = messagePartId; message.mimeType = mimeType; message.previewType = previewType; @@ -397,11 +395,11 @@ public class LocalMessage extends MimeMessage { } public long getThreadId() { - return mThreadId; + return threadId; } public long getRootId() { - return mRootId; + return rootId; } public Account getAccount() { @@ -409,10 +407,10 @@ public class LocalMessage extends MimeMessage { } public MessageReference makeMessageReference() { - if (mReference == null) { - mReference = new MessageReference(getFolder().getAccountUuid(), getFolder().getName(), mUid, null); + if (messageReference == null) { + messageReference = new MessageReference(getFolder().getAccountUuid(), getFolder().getName(), mUid, null); } - return mReference; + return messageReference; } @Override @@ -434,7 +432,7 @@ public class LocalMessage extends MimeMessage { } private void updateHeader() { - super.setSubject(mSubject); + super.setSubject(subject); super.setReplyTo(mReplyTo); super.setRecipients(RecipientType.TO, mTo); super.setRecipients(RecipientType.CC, mCc); @@ -479,8 +477,4 @@ public class LocalMessage extends MimeMessage { private String getAccountUuid() { return getAccount().getUuid(); } - - public boolean isBodyMissing() { - return getBody() == null; - } } From 2fbd6f61a886a822f6953ab8cc374c8e0ca2db59 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 22 Aug 2017 16:27:09 +0200 Subject: [PATCH 4/9] rename LocalMessage id field to databaseId --- .../main/java/com/fsck/k9/mail/Message.java | 2 -- .../fsck/k9/mail/internet/MimeMessage.java | 5 ----- .../com/fsck/k9/cache/EmailProviderCache.java | 4 ++-- .../k9/controller/MessagingController.java | 8 ++++---- .../com/fsck/k9/mailstore/LocalBodyPart.java | 2 +- .../com/fsck/k9/mailstore/LocalFolder.java | 10 +++++----- .../com/fsck/k9/mailstore/LocalMessage.java | 19 +++++++++---------- .../fsck/k9/mailstore/LocalMimeMessage.java | 2 +- .../java/com/fsck/k9/mailstore/LocalPart.java | 2 +- .../com/fsck/k9/mailstore/LocalStore.java | 2 +- .../mailstore/migrations/MigrationTo55.java | 7 +++---- .../extractors/AttachmentInfoExtractor.java | 3 +-- .../com/fsck/k9/provider/MessageProvider.java | 4 ++-- .../java/com/fsck/k9/view/MessageHeader.java | 2 +- .../fsck/k9/cache/EmailProviderCacheTest.java | 2 +- .../com/fsck/k9/mailstore/MigrationTest.java | 16 ++++++++-------- 16 files changed, 40 insertions(+), 50 deletions(-) diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/Message.java b/k9mail-library/src/main/java/com/fsck/k9/mail/Message.java index 051127f2b..4254559d5 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/Message.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/Message.java @@ -144,8 +144,6 @@ public abstract class Message implements Part, Body { @Override public abstract void setBody(Body body); - public abstract long getId(); - public abstract boolean hasAttachments(); public abstract long getSize(); diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeMessage.java b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeMessage.java index 01d6a293c..9ce4851f3 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeMessage.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/internet/MimeMessage.java @@ -688,11 +688,6 @@ public class MimeMessage extends Message { return message; } - @Override - public long getId() { - return Long.parseLong(mUid); //or maybe .mMessageId? - } - @Override public boolean hasAttachments() { return false; diff --git a/k9mail/src/main/java/com/fsck/k9/cache/EmailProviderCache.java b/k9mail/src/main/java/com/fsck/k9/cache/EmailProviderCache.java index 81b785997..50d486168 100644 --- a/k9mail/src/main/java/com/fsck/k9/cache/EmailProviderCache.java +++ b/k9mail/src/main/java/com/fsck/k9/cache/EmailProviderCache.java @@ -126,7 +126,7 @@ public class EmailProviderCache { public void hideMessages(List messages) { synchronized (mHiddenMessageCache) { for (LocalMessage message : messages) { - long messageId = message.getId(); + long messageId = message.getDatabaseId(); mHiddenMessageCache.put(messageId, message.getFolder().getId()); } } @@ -145,7 +145,7 @@ public class EmailProviderCache { synchronized (mHiddenMessageCache) { for (Message message : messages) { LocalMessage localMessage = (LocalMessage) message; - long messageId = localMessage.getId(); + long messageId = localMessage.getDatabaseId(); long folderId = ((LocalFolder) localMessage.getFolder()).getId(); Long hiddenInFolder = mHiddenMessageCache.get(messageId); diff --git a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java index 83802b033..7238ff473 100644 --- a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -305,7 +305,7 @@ public class MessagingController { } private boolean isMessageSuppressed(LocalMessage message) { - long messageId = message.getId(); + long messageId = message.getDatabaseId(); long folderId = message.getFolder().getId(); EmailProviderCache cache = EmailProviderCache.getCache(message.getFolder().getAccountUuid(), context); @@ -2511,7 +2511,7 @@ public class MessagingController { localFolder.open(Folder.OPEN_MODE_RW); LocalMessage message = localFolder.getMessage(uid); - if (message == null || message.getId() == 0) { + if (message == null || message.getDatabaseId() == 0) { throw new IllegalArgumentException("Message not found: folder=" + folderName + ", uid=" + uid); } @@ -2530,7 +2530,7 @@ public class MessagingController { throws MessagingException { if (account.isMarkMessageAsReadOnView() && !message.isSet(Flag.SEEN)) { - List messageIds = Collections.singletonList(message.getId()); + List messageIds = Collections.singletonList(message.getDatabaseId()); setFlag(account, messageIds, Flag.SEEN, true); message.setFlagInternal(Flag.SEEN, true); @@ -3996,7 +3996,7 @@ public class MessagingController { public long getId(Message message) { long id; if (message instanceof LocalMessage) { - id = message.getId(); + id = ((LocalMessage) message).getDatabaseId(); } else { Timber.w("MessagingController.getId() called without a LocalMessage"); id = INVALID_MESSAGE_ID; diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalBodyPart.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalBodyPart.java index 412c02ce4..7fd31aaa6 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalBodyPart.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalBodyPart.java @@ -26,7 +26,7 @@ public class LocalBodyPart extends MimeBodyPart implements LocalPart { } @Override - public long getId() { + public long getPartId() { return messagePartId; } diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java index 2086c228d..7233ce60b 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java @@ -1046,7 +1046,7 @@ public class LocalFolder extends Folder implements Serializable { "id %d currently in folder %s", lDestFolder.getId(), message.getUid(), - lMessage.getId(), + lMessage.getDatabaseId(), getName()); String newUid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString(); @@ -1060,7 +1060,7 @@ public class LocalFolder extends Folder implements Serializable { /* * "Move" the message into the new folder */ - long msgId = lMessage.getId(); + long msgId = lMessage.getDatabaseId(); String[] idArg = new String[] { Long.toString(msgId) }; ContentValues cv = new ContentValues(); @@ -1309,7 +1309,7 @@ public class LocalFolder extends Folder implements Serializable { LocalMessage oldMessage = getMessage(uid); if (oldMessage != null) { - oldMessageId = oldMessage.getId(); + oldMessageId = oldMessage.getDatabaseId(); long oldRootMessagePartId = oldMessage.getMessagePartId(); deleteMessagePartsAndDataFromDisk(oldRootMessagePartId); @@ -1689,7 +1689,7 @@ public class LocalFolder extends Folder implements Serializable { @Override public Void doDbWork(final SQLiteDatabase db) throws WrappedException, UnavailableStorageException { db.update("messages", cv, "id = ?", new String[] - { Long.toString(message.getId()) }); + { Long.toString(message.getDatabaseId()) }); return null; } }); @@ -1844,7 +1844,7 @@ public class LocalFolder extends Folder implements Serializable { } void destroyMessage(LocalMessage localMessage) throws MessagingException { - destroyMessage(localMessage.getId(), localMessage.getMessagePartId(), localMessage.getMessageId()); + destroyMessage(localMessage.getDatabaseId(), localMessage.getMessagePartId(), localMessage.getMessageId()); } private void destroyMessage(final long messageId, final long messagePartId, final String messageIdHeader) 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 e4db34de3..85b14dd8c 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMessage.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMessage.java @@ -29,7 +29,7 @@ import timber.log.Timber; public class LocalMessage extends MimeMessage { private final LocalStore localStore; - private long id; + private long databaseId; private long rootId; private long threadId; private long messagePartId; @@ -79,7 +79,7 @@ public class LocalMessage extends MimeMessage { } } } - this.id = cursor.getLong(5); + 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))); @@ -246,9 +246,8 @@ public class LocalMessage extends MimeMessage { super.setFlag(flag, set); } - @Override - public long getId() { - return id; + public long getDatabaseId() { + return databaseId; } @Override @@ -277,7 +276,7 @@ public class LocalMessage extends MimeMessage { cv.put("answered", isSet(Flag.ANSWERED) ? 1 : 0); cv.put("forwarded", isSet(Flag.FORWARDED) ? 1 : 0); - db.update("messages", cv, "id = ?", new String[] { Long.toString(id) }); + db.update("messages", cv, "id = ?", new String[] { Long.toString(databaseId) }); return null; } @@ -311,7 +310,7 @@ public class LocalMessage extends MimeMessage { cv.putNull("reply_to_list"); cv.putNull("message_part_id"); - db.update("messages", cv, "id = ?", new String[] { Long.toString(id) }); + db.update("messages", cv, "id = ?", new String[] { Long.toString(databaseId) }); try { ((LocalFolder) mFolder).deleteMessagePartsAndDataFromDisk(messagePartId); @@ -319,7 +318,7 @@ public class LocalMessage extends MimeMessage { throw new WrappedException(e); } - getFolder().deleteFulltextIndexEntry(db, id); + getFolder().deleteFulltextIndexEntry(db, databaseId); return null; } @@ -343,7 +342,7 @@ public class LocalMessage extends MimeMessage { ContentValues cv = new ContentValues(); cv.putNull("message_part_id"); - db.update("messages", cv, "id = ?", new String[] { Long.toString(id) }); + db.update("messages", cv, "id = ?", new String[] { Long.toString(databaseId) }); try { ((LocalFolder) mFolder).deleteMessagePartsAndDataFromDisk(messagePartId); @@ -380,7 +379,7 @@ public class LocalMessage extends MimeMessage { super.copy(message); message.messageReference = messageReference; - message.id = id; + message.databaseId = databaseId; message.attachmentCount = attachmentCount; message.subject = subject; message.preview = preview; diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMimeMessage.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMimeMessage.java index 3684f615b..a29459dde 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMimeMessage.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalMimeMessage.java @@ -24,7 +24,7 @@ public class LocalMimeMessage extends MimeMessage implements LocalPart { } @Override - public long getId() { + public long getPartId() { return messagePartId; } diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalPart.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalPart.java index 57b0b36de..42dd65fdc 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalPart.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalPart.java @@ -3,7 +3,7 @@ package com.fsck.k9.mailstore; public interface LocalPart { String getAccountUuid(); - long getId(); + long getPartId(); long getSize(); LocalMessage getMessage(); } 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 dc8302082..dafe98fd6 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java @@ -756,7 +756,7 @@ public class LocalStore extends Store implements Serializable { if (part instanceof LocalPart) { LocalPart localBodyPart = (LocalPart) part; - if (localBodyPart.getId() == partId) { + if (localBodyPart.getPartId() == partId) { return part; } } diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo55.java b/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo55.java index 849630bfc..ca2cda2fa 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo55.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/migrations/MigrationTo55.java @@ -9,7 +9,6 @@ import android.database.sqlite.SQLiteDatabase; import android.text.TextUtils; import timber.log.Timber; -import com.fsck.k9.K9; import com.fsck.k9.mail.FetchProfile; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mailstore.LocalFolder; @@ -38,13 +37,13 @@ class MigrationTo55 { String fulltext = fulltextCreator.createFulltext(localMessage); if (!TextUtils.isEmpty(fulltext)) { - Timber.d("fulltext for msg id %d is %d chars long", localMessage.getId(), fulltext.length()); + Timber.d("fulltext for msg id %d is %d chars long", localMessage.getDatabaseId(), fulltext.length()); cv.clear(); - cv.put("docid", localMessage.getId()); + cv.put("docid", localMessage.getDatabaseId()); cv.put("fulltext", fulltext); db.insert("messages_fulltext", null, cv); } else { - Timber.d("no fulltext for msg id %d :(", localMessage.getId()); + Timber.d("no fulltext for msg id %d :(", localMessage.getDatabaseId()); } } } diff --git a/k9mail/src/main/java/com/fsck/k9/message/extractors/AttachmentInfoExtractor.java b/k9mail/src/main/java/com/fsck/k9/message/extractors/AttachmentInfoExtractor.java index 76f96d3fb..7012663d9 100644 --- a/k9mail/src/main/java/com/fsck/k9/message/extractors/AttachmentInfoExtractor.java +++ b/k9mail/src/main/java/com/fsck/k9/message/extractors/AttachmentInfoExtractor.java @@ -14,7 +14,6 @@ import timber.log.Timber; import android.support.annotation.WorkerThread; import com.fsck.k9.Globals; -import com.fsck.k9.K9; import com.fsck.k9.mail.Body; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.Part; @@ -64,7 +63,7 @@ public class AttachmentInfoExtractor { if (part instanceof LocalPart) { LocalPart localPart = (LocalPart) part; String accountUuid = localPart.getAccountUuid(); - long messagePartId = localPart.getId(); + long messagePartId = localPart.getPartId(); size = localPart.getSize(); isContentAvailable = part.getBody() != null; uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId); diff --git a/k9mail/src/main/java/com/fsck/k9/provider/MessageProvider.java b/k9mail/src/main/java/com/fsck/k9/provider/MessageProvider.java index aab721055..7fb9c1452 100644 --- a/k9mail/src/main/java/com/fsck/k9/provider/MessageProvider.java +++ b/k9mail/src/main/java/com/fsck/k9/provider/MessageProvider.java @@ -358,13 +358,13 @@ public class MessageProvider extends ContentProvider { } /** - * Extracts the {@link LocalMessage#getId() ID} from the given {@link MessageInfoHolder}. The underlying + * Extracts the {@link LocalMessage#getDatabaseId() ID} from the given {@link MessageInfoHolder}. The underlying * {@link Message} is expected to be a {@link LocalMessage}. */ public static class IdExtractor implements FieldExtractor { @Override public Long getField(MessageInfoHolder source) { - return source.message.getId(); + return source.message.getDatabaseId(); } } diff --git a/k9mail/src/main/java/com/fsck/k9/view/MessageHeader.java b/k9mail/src/main/java/com/fsck/k9/view/MessageHeader.java index ce008876e..57a7fc70c 100644 --- a/k9mail/src/main/java/com/fsck/k9/view/MessageHeader.java +++ b/k9mail/src/main/java/com/fsck/k9/view/MessageHeader.java @@ -283,7 +283,7 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo /* We hide the subject by default for each new message, and MessageTitleView might show * it later by calling showSubjectLine(). */ - boolean newMessageShown = mMessage == null || mMessage.getId() != message.getId(); + boolean newMessageShown = mMessage == null || !mMessage.getUid().equals(message.getUid()); if (newMessageShown) { mSubjectView.setVisibility(GONE); } diff --git a/k9mail/src/test/java/com/fsck/k9/cache/EmailProviderCacheTest.java b/k9mail/src/test/java/com/fsck/k9/cache/EmailProviderCacheTest.java index 4bc8e03ce..a288a82d4 100644 --- a/k9mail/src/test/java/com/fsck/k9/cache/EmailProviderCacheTest.java +++ b/k9mail/src/test/java/com/fsck/k9/cache/EmailProviderCacheTest.java @@ -40,7 +40,7 @@ public class EmailProviderCacheTest { MockitoAnnotations.initMocks(this); cache = EmailProviderCache.getCache(UUID.randomUUID().toString(), RuntimeEnvironment.application); - when(mockLocalMessage.getId()).thenReturn(localMessageId); + when(mockLocalMessage.getDatabaseId()).thenReturn(localMessageId); when(mockLocalMessage.getFolder()).thenReturn(mockLocalMessageFolder); when(mockLocalMessageFolder.getId()).thenReturn(localMessageFolderId); } diff --git a/k9mail/src/test/java/com/fsck/k9/mailstore/MigrationTest.java b/k9mail/src/test/java/com/fsck/k9/mailstore/MigrationTest.java index 21e589010..20099ecc3 100644 --- a/k9mail/src/test/java/com/fsck/k9/mailstore/MigrationTest.java +++ b/k9mail/src/test/java/com/fsck/k9/mailstore/MigrationTest.java @@ -163,7 +163,7 @@ public class MigrationTest { localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); Assert.assertEquals("text/plain", msg.getMimeType()); - Assert.assertEquals(2, msg.getId()); + Assert.assertEquals(2, msg.getDatabaseId()); Assert.assertEquals(13, msg.getHeaderNames().size()); Assert.assertEquals(0, msg.getAttachmentCount()); @@ -229,7 +229,7 @@ public class MigrationTest { fp.add(FetchProfile.Item.BODY); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); - Assert.assertEquals(3, msg.getId()); + Assert.assertEquals(3, msg.getDatabaseId()); Assert.assertEquals(8, msg.getHeaderNames().size()); Assert.assertEquals("multipart/mixed", msg.getMimeType()); Assert.assertEquals(1, msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE).length); @@ -301,7 +301,7 @@ public class MigrationTest { fp.add(FetchProfile.Item.BODY); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); - Assert.assertEquals(4, msg.getId()); + Assert.assertEquals(4, msg.getDatabaseId()); Assert.assertEquals(8, msg.getHeaderNames().size()); Assert.assertEquals("multipart/mixed", msg.getMimeType()); Assert.assertEquals(2, msg.getAttachmentCount()); @@ -360,7 +360,7 @@ public class MigrationTest { fp.add(FetchProfile.Item.BODY); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); - Assert.assertEquals(5, msg.getId()); + Assert.assertEquals(5, msg.getDatabaseId()); Assert.assertEquals(13, msg.getHeaderNames().size()); Assert.assertEquals("multipart/encrypted", msg.getMimeType()); Assert.assertEquals(2, msg.getAttachmentCount()); @@ -478,7 +478,7 @@ public class MigrationTest { fp.add(FetchProfile.Item.BODY); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); - Assert.assertEquals(6, msg.getId()); + Assert.assertEquals(6, msg.getDatabaseId()); Assert.assertEquals(12, msg.getHeaderNames().size()); Assert.assertEquals("text/plain", msg.getMimeType()); Assert.assertEquals(0, msg.getAttachmentCount()); @@ -565,7 +565,7 @@ public class MigrationTest { fp.add(FetchProfile.Item.BODY); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); - Assert.assertEquals(7, msg.getId()); + Assert.assertEquals(7, msg.getDatabaseId()); Assert.assertEquals(12, msg.getHeaderNames().size()); Assert.assertEquals("text/plain", msg.getMimeType()); Assert.assertEquals(0, msg.getAttachmentCount()); @@ -623,7 +623,7 @@ public class MigrationTest { fp.add(FetchProfile.Item.BODY); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); - Assert.assertEquals(8, msg.getId()); + Assert.assertEquals(8, msg.getDatabaseId()); Assert.assertEquals(9, msg.getHeaderNames().size()); Assert.assertEquals("multipart/alternative", msg.getMimeType()); Assert.assertEquals(0, msg.getAttachmentCount()); @@ -688,7 +688,7 @@ public class MigrationTest { fp.add(FetchProfile.Item.BODY); localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null); - Assert.assertEquals(9, msg.getId()); + Assert.assertEquals(9, msg.getDatabaseId()); Assert.assertEquals(11, msg.getHeaderNames().size()); Assert.assertEquals("multipart/mixed", msg.getMimeType()); Assert.assertEquals(1, msg.getAttachmentCount()); From 472733edcd53b73df0271c1520669d3671325603 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 22 Aug 2017 16:33:19 +0200 Subject: [PATCH 5/9] 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"; From f37f4233a27ae7b4bfd9a782b1e88611c5e8fca8 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 22 Aug 2017 16:51:51 +0200 Subject: [PATCH 6/9] remove Serializable interface from LocalStore and LocalFolder --- k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java | 4 +--- k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java index 7233ce60b..35ab09d95 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java @@ -9,7 +9,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -69,8 +68,7 @@ import org.apache.james.mime4j.util.MimeUtil; import timber.log.Timber; -public class LocalFolder extends Folder implements Serializable { - private static final long serialVersionUID = -1973296520918624767L; +public class LocalFolder extends Folder { private static final int MAX_BODY_SIZE_FOR_DATABASE = 16 * 1024; private static final long INVALID_MESSAGE_PART_ID = -1; 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 0f08aa443..1e8763d36 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java @@ -9,7 +9,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -75,9 +74,7 @@ import org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource; * Implements a SQLite database backed local store for Messages. * */ -public class LocalStore extends Store implements Serializable { - private static final long serialVersionUID = -5142141896809423072L; - +public class LocalStore extends Store { static final String[] EMPTY_STRING_ARRAY = new String[0]; static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; From 427906f742e84a924132e77f1a67d32e87503e17 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 22 Aug 2017 21:55:29 +0200 Subject: [PATCH 7/9] get rid of uuid field in LocalStore --- .../com/fsck/k9/mailstore/LocalFolder.java | 2 +- .../java/com/fsck/k9/mailstore/LocalStore.java | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java index 35ab09d95..49a3a7cd9 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java @@ -543,7 +543,7 @@ public class LocalFolder extends Folder { private String getPrefId(String name) { if (prefId == null) { - prefId = this.localStore.getUUid() + "." + name; + prefId = getAccount().getUuid() + "." + name; } return prefId; 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 1e8763d36..0d9a6acdd 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalStore.java @@ -188,7 +188,6 @@ public class LocalStore extends Store { private final AttachmentInfoExtractor attachmentInfoExtractor; private final Account account; - private final String uUid; private final LockableDatabase database; /** @@ -207,7 +206,6 @@ public class LocalStore extends Store { attachmentInfoExtractor = AttachmentInfoExtractor.getInstance(); this.account = account; - this.uUid = account.getUuid(); database = new LockableDatabase(context, account.getUuid(), new StoreSchemaDefinition(this)); database.setStorageProviderId(account.getLocalStorageProviderId()); @@ -270,10 +268,6 @@ public class LocalStore extends Store { return account; } - String getUUid() { - return uUid; - } - protected Storage getStorage() { return Preferences.getPreferences(context).getStorage(); } @@ -282,7 +276,7 @@ public class LocalStore extends Store { final StorageManager storageManager = StorageManager.getInstance(context); - final File attachmentDirectory = storageManager.getAttachmentDirectory(uUid, + final File attachmentDirectory = storageManager.getAttachmentDirectory(account.getUuid(), database.getStorageProviderId()); return database.execute(false, new DbCallback() { @@ -298,7 +292,7 @@ public class LocalStore extends Store { } } - final File dbFile = storageManager.getDatabase(uUid, database.getStorageProviderId()); + final File dbFile = storageManager.getDatabase(account.getUuid(), database.getStorageProviderId()); return dbFile.length() + attachmentLength; } }); @@ -468,7 +462,8 @@ public class LocalStore extends Store { private void deleteAllMessagePartsDataFromDisk() { final StorageManager storageManager = StorageManager.getInstance(context); - File attachmentDirectory = storageManager.getAttachmentDirectory(uUid, database.getStorageProviderId()); + File attachmentDirectory = storageManager.getAttachmentDirectory( + account.getUuid(), database.getStorageProviderId()); File[] files = attachmentDirectory.listFiles(); if (files == null) { return; @@ -897,7 +892,8 @@ public class LocalStore extends Store { File getAttachmentFile(String attachmentId) { final StorageManager storageManager = StorageManager.getInstance(context); - final File attachmentDirectory = storageManager.getAttachmentDirectory(uUid, database.getStorageProviderId()); + final File attachmentDirectory = storageManager.getAttachmentDirectory( + account.getUuid(), database.getStorageProviderId()); return new File(attachmentDirectory, attachmentId); } @@ -999,7 +995,7 @@ public class LocalStore extends Store { } void notifyChange() { - Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + uUid + "/messages"); + Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + account.getUuid() + "/messages"); contentResolver.notifyChange(uri, null); } From 311efc66753ee7b0c9e12c18fc2bda14c9aeb202 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 22 Aug 2017 21:57:18 +0200 Subject: [PATCH 8/9] remove folder* prefix for field names in LocalFolder --- .../com/fsck/k9/mailstore/LocalFolder.java | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java index 49a3a7cd9..7eb9c08ba 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java @@ -77,8 +77,8 @@ public class LocalFolder extends Folder { private final AttachmentInfoExtractor attachmentInfoExtractor; - private String folderName = null; - private long folderId = -1; + private String name = null; + private long id = -1; private int visibleLimit = -1; private String prefId = null; @@ -100,7 +100,7 @@ public class LocalFolder extends Folder { public LocalFolder(LocalStore localStore, String name) { super(); this.localStore = localStore; - this.folderName = name; + this.name = name; attachmentInfoExtractor = localStore.getAttachmentInfoExtractor(); if (getAccount().getInboxFolderName().equals(getName())) { @@ -113,12 +113,12 @@ public class LocalFolder extends Folder { public LocalFolder(LocalStore localStore, long id) { super(); this.localStore = localStore; - this.folderId = id; + this.id = id; attachmentInfoExtractor = localStore.getAttachmentInfoExtractor(); } public long getId() { - return folderId; + return id; } public String getAccountUuid() @@ -157,11 +157,11 @@ public class LocalFolder extends Folder { try { String baseQuery = "SELECT " + LocalStore.GET_FOLDER_COLS + " FROM folders "; - if (folderName != null) { - cursor = db.rawQuery(baseQuery + "where folders.name = ?", new String[] { folderName }); + if (name != null) { + cursor = db.rawQuery(baseQuery + "where folders.name = ?", new String[] { name }); } else { cursor = db.rawQuery(baseQuery + "where folders.id = ?", new String[] { Long.toString( - folderId) }); + id) }); } if (cursor.moveToFirst() && !cursor.isNull(LocalStore.FOLDER_ID_INDEX)) { @@ -188,8 +188,8 @@ public class LocalFolder extends Folder { } void open(Cursor cursor) throws MessagingException { - folderId = cursor.getInt(LocalStore.FOLDER_ID_INDEX); - folderName = cursor.getString(LocalStore.FOLDER_NAME_INDEX); + id = cursor.getInt(LocalStore.FOLDER_ID_INDEX); + name = cursor.getString(LocalStore.FOLDER_NAME_INDEX); visibleLimit = cursor.getInt(LocalStore.FOLDER_VISIBLE_LIMIT_INDEX); pushState = cursor.getString(LocalStore.FOLDER_PUSH_STATE_INDEX); super.setStatus(cursor.getString(LocalStore.FOLDER_STATUS_INDEX)); @@ -214,7 +214,7 @@ public class LocalFolder extends Folder { @Override public boolean isOpen() { - return (folderId != -1 && folderName != null); + return (id != -1 && name != null); } @Override @@ -224,7 +224,7 @@ public class LocalFolder extends Folder { @Override public String getName() { - return folderName; + return name; } @Override @@ -257,7 +257,7 @@ public class LocalFolder extends Folder { @Override public boolean create(FolderType type, final int visibleLimit) throws MessagingException { if (exists()) { - throw new MessagingException("Folder " + folderName + " already exists."); + throw new MessagingException("Folder " + name + " already exists."); } List foldersToCreate = new ArrayList<>(1); foldersToCreate.add(this); @@ -277,7 +277,7 @@ public class LocalFolder extends Folder { @Override public void close() { - folderId = -1; + id = -1; } @Override @@ -296,7 +296,7 @@ public class LocalFolder extends Folder { cursor = db.rawQuery( "SELECT COUNT(id) FROM messages " + "WHERE empty = 0 AND deleted = 0 and folder_id = ?", - new String[] { Long.toString(folderId) }); + new String[] { Long.toString(id) }); cursor.moveToFirst(); return cursor.getInt(0); //messagecount } finally { @@ -311,7 +311,7 @@ public class LocalFolder extends Folder { @Override public int getUnreadMessageCount() throws MessagingException { - if (folderId == -1) { + if (id == -1) { open(OPEN_MODE_RW); } @@ -322,7 +322,7 @@ public class LocalFolder extends Folder { int unreadMessageCount = 0; Cursor cursor = db.query("messages", new String[] { "COUNT(id)" }, "folder_id = ? AND empty = 0 AND deleted = 0 AND read=0", - new String[] { Long.toString(folderId) }, null, null, null); + new String[] { Long.toString(id) }, null, null, null); try { if (cursor.moveToFirst()) { @@ -342,7 +342,7 @@ public class LocalFolder extends Folder { @Override public int getFlaggedMessageCount() throws MessagingException { - if (folderId == -1) { + if (id == -1) { open(OPEN_MODE_RW); } @@ -353,7 +353,7 @@ public class LocalFolder extends Folder { int flaggedMessageCount = 0; Cursor cursor = db.query("messages", new String[] { "COUNT(id)" }, "folder_id = ? AND empty = 0 AND deleted = 0 AND flagged = 1", - new String[] { Long.toString(folderId) }, null, null, null); + new String[] { Long.toString(id) }, null, null, null); try { if (cursor.moveToFirst()) { @@ -455,7 +455,7 @@ public class LocalFolder extends Folder { } catch (MessagingException e) { throw new WrappedException(e); } - db.execSQL("UPDATE folders SET " + column + " = ? WHERE id = ?", new Object[] { value, folderId }); + db.execSQL("UPDATE folders SET " + column + " = ? WHERE id = ?", new Object[] { value, id }); return null; } }); @@ -551,7 +551,7 @@ public class LocalFolder extends Folder { private String getPrefId() throws MessagingException { open(OPEN_MODE_RW); - return getPrefId(folderName); + return getPrefId(name); } public void delete() throws MessagingException { @@ -814,7 +814,7 @@ public class LocalFolder extends Folder { try { cursor = db.rawQuery( "SELECT uid FROM messages WHERE id = ? AND folder_id = ?", - new String[] { Long.toString(id), Long.toString(folderId) }); + new String[] { Long.toString(id), Long.toString(LocalFolder.this.id) }); if (!cursor.moveToNext()) { return null; } @@ -851,7 +851,7 @@ public class LocalFolder extends Folder { "LEFT JOIN message_parts ON (message_parts.id = messages.message_part_id) " + "LEFT JOIN threads ON (threads.message_id = messages.id) " + "WHERE uid = ? AND folder_id = ?", - new String[] { message.getUid(), Long.toString(folderId) }); + new String[] { message.getUid(), Long.toString(id) }); if (!cursor.moveToNext()) { return null; @@ -887,7 +887,7 @@ public class LocalFolder extends Folder { "FROM messages " + "WHERE empty = 0 AND deleted = 0 AND " + "folder_id = ? ORDER BY date DESC", - new String[] { Long.toString(folderId) }); + new String[] { Long.toString(id) }); while (cursor.moveToNext()) { String uid = cursor.getString(0); @@ -928,7 +928,7 @@ public class LocalFolder extends Folder { "WHERE empty = 0 AND " + (includeDeleted ? "" : "deleted = 0 AND ") + "folder_id = ? ORDER BY date DESC", - new String[] { Long.toString(folderId) }); + new String[] { Long.toString(id) }); } catch (MessagingException e) { throw new WrappedException(e); } @@ -955,7 +955,7 @@ public class LocalFolder extends Folder { "FROM messages " + "WHERE empty = 0 AND deleted = 0 AND " + "folder_id = ? ORDER BY date DESC", - new String[] { Long.toString(folderId) }); + new String[] { Long.toString(id) }); while (cursor.moveToNext()) { String uid = cursor.getString(0); @@ -1100,7 +1100,7 @@ public class LocalFolder extends Folder { cv.putNull("flags"); cv.put("read", 1); cv.put("deleted", 1); - cv.put("folder_id", folderId); + cv.put("folder_id", id); cv.put("empty", 0); String messageId = message.getMessageId(); @@ -1220,7 +1220,7 @@ public class LocalFolder extends Folder { "WHERE m.folder_id = ? AND m.message_id = ? " + ((onlyEmpty) ? "AND m.empty = 1 " : "") + "ORDER BY m.id LIMIT 1"; - String[] selectionArgs = { Long.toString(folderId), messageId }; + String[] selectionArgs = { Long.toString(id), messageId }; Cursor cursor = db.rawQuery(sql, selectionArgs); if (cursor != null) { @@ -1353,7 +1353,7 @@ public class LocalFolder extends Folder { cv.put("flagged", message.isSet(Flag.FLAGGED) ? 1 : 0); cv.put("answered", message.isSet(Flag.ANSWERED) ? 1 : 0); cv.put("forwarded", message.isSet(Flag.FORWARDED) ? 1 : 0); - cv.put("folder_id", folderId); + cv.put("folder_id", id); cv.put("to_list", Address.pack(message.getRecipients(RecipientType.TO))); cv.put("cc_list", Address.pack(message.getRecipients(RecipientType.CC))); cv.put("bcc_list", Address.pack(message.getRecipients(RecipientType.BCC))); @@ -1747,7 +1747,7 @@ public class LocalFolder extends Folder { "LEFT JOIN message_parts ON (message_parts.id = messages.message_part_id) " + "LEFT JOIN threads ON (threads.message_id = messages.id) " + "WHERE empty = 0 AND (folder_id = ? and date < ?)", - new String[] { Long.toString(folderId), Long.toString(cutoff) }); + new String[] { Long.toString(id), Long.toString(cutoff) }); for (Message message : messages) { message.destroy(); @@ -1757,7 +1757,7 @@ public class LocalFolder extends Folder { } public void clearAllMessages() throws MessagingException { - final String[] folderIdArg = new String[] { Long.toString(folderId) }; + final String[] folderIdArg = new String[] { Long.toString(id) }; open(OPEN_MODE_RO); @@ -1819,7 +1819,7 @@ public class LocalFolder extends Folder { throw new WrappedException(e); } db.execSQL("DELETE FROM folders WHERE id = ?", new Object[] - { Long.toString(folderId), }); + { Long.toString(id), }); return null; } }); @@ -1831,14 +1831,14 @@ public class LocalFolder extends Folder { @Override public boolean equals(Object o) { if (o instanceof LocalFolder) { - return ((LocalFolder)o).folderName.equals(folderName); + return ((LocalFolder)o).name.equals(name); } return super.equals(o); } @Override public int hashCode() { - return folderName.hashCode(); + return name.hashCode(); } void destroyMessage(LocalMessage localMessage) throws MessagingException { @@ -2068,7 +2068,7 @@ public class LocalFolder extends Folder { try { open(OPEN_MODE_RO); cursor = db.rawQuery("SELECT MAX(uid) FROM messages WHERE folder_id=?", new String[] { Long.toString( - folderId) }); + id) }); if (cursor.getCount() > 0) { cursor.moveToFirst(); return cursor.getInt(0); @@ -2082,7 +2082,7 @@ public class LocalFolder extends Folder { } }); - Timber.d("Updated last UID for folder %s to %s", folderName, lastUid); + Timber.d("Updated last UID for folder %s to %s", name, lastUid); this.lastUid = lastUid; } @@ -2094,7 +2094,7 @@ public class LocalFolder extends Folder { try { open(OPEN_MODE_RO); cursor = db.rawQuery("SELECT MIN(date) FROM messages WHERE folder_id=?", new String[] { Long.toString( - folderId) }); + id) }); if (cursor.getCount() > 0) { cursor.moveToFirst(); return cursor.getLong(0); @@ -2154,7 +2154,7 @@ public class LocalFolder extends Folder { // Create placeholder message in 'messages' table ContentValues cv = new ContentValues(); cv.put("message_id", reference); - cv.put("folder_id", folderId); + cv.put("folder_id", id); cv.put("empty", 1); long newMsgId = db.insert("messages", null, cv); @@ -2235,7 +2235,7 @@ public class LocalFolder extends Folder { StringBuilder selection = new StringBuilder(); selection.append("folder_id = ? AND UID IN ("); - selectionArgs.add(Long.toString(folderId)); + selectionArgs.add(Long.toString(id)); int count = Math.min(messages.size() - start, LocalStore.UID_CHECK_BATCH_SIZE); From 8b8ee1ea6d8f7ba69b6ec0e5b797b921e393ec5f Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Wed, 23 Aug 2017 20:33:54 +0200 Subject: [PATCH 9/9] rename id field to databaseId in LocalFolder --- .../com/fsck/k9/cache/EmailProviderCache.java | 4 +- .../k9/controller/MessagingController.java | 8 +-- .../com/fsck/k9/mailstore/LocalFolder.java | 68 +++++++++---------- .../com/fsck/k9/search/SqlQueryBuilder.java | 3 +- .../fsck/k9/cache/EmailProviderCacheTest.java | 2 +- .../controller/MessagingControllerTest.java | 2 +- 6 files changed, 43 insertions(+), 44 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/cache/EmailProviderCache.java b/k9mail/src/main/java/com/fsck/k9/cache/EmailProviderCache.java index 50d486168..c4328f6bb 100644 --- a/k9mail/src/main/java/com/fsck/k9/cache/EmailProviderCache.java +++ b/k9mail/src/main/java/com/fsck/k9/cache/EmailProviderCache.java @@ -127,7 +127,7 @@ public class EmailProviderCache { synchronized (mHiddenMessageCache) { for (LocalMessage message : messages) { long messageId = message.getDatabaseId(); - mHiddenMessageCache.put(messageId, message.getFolder().getId()); + mHiddenMessageCache.put(messageId, message.getFolder().getDatabaseId()); } } @@ -146,7 +146,7 @@ public class EmailProviderCache { for (Message message : messages) { LocalMessage localMessage = (LocalMessage) message; long messageId = localMessage.getDatabaseId(); - long folderId = ((LocalFolder) localMessage.getFolder()).getId(); + long folderId = ((LocalFolder) localMessage.getFolder()).getDatabaseId(); Long hiddenInFolder = mHiddenMessageCache.get(messageId); if (hiddenInFolder != null && hiddenInFolder.longValue() == folderId) { diff --git a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java index 7238ff473..8e86a2c39 100644 --- a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -306,7 +306,7 @@ public class MessagingController { private boolean isMessageSuppressed(LocalMessage message) { long messageId = message.getDatabaseId(); - long folderId = message.getFolder().getId(); + long folderId = message.getFolder().getDatabaseId(); EmailProviderCache cache = EmailProviderCache.getCache(message.getFolder().getAccountUuid(), context); return cache.isMessageHidden(messageId, folderId); @@ -2721,7 +2721,7 @@ public class MessagingController { fp.add(FetchProfile.Item.BODY); Timber.i("Scanning folder '%s' (%d) for messages to send", - account.getOutboxFolderName(), localFolder.getId()); + account.getOutboxFolderName(), localFolder.getDatabaseId()); Transport transport = transportProvider.getTransport(K9.app, account); @@ -2836,11 +2836,11 @@ public class MessagingController { message.setFlag(Flag.DELETED, true); } else { LocalFolder localSentFolder = localStore.getFolder(account.getSentFolderName()); - Timber.i("Moving sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getId()); + Timber.i("Moving sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getDatabaseId()); localFolder.moveMessages(Collections.singletonList(message), localSentFolder); - Timber.i("Moved sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getId()); + Timber.i("Moved sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getDatabaseId()); PendingCommand command = PendingAppend.create(localSentFolder.getName(), message.getUid()); queuePendingCommand(account, command); diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java index 7eb9c08ba..be22b37dc 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/LocalFolder.java @@ -78,7 +78,7 @@ public class LocalFolder extends Folder { private String name = null; - private long id = -1; + private long databaseId = -1; private int visibleLimit = -1; private String prefId = null; @@ -110,15 +110,15 @@ public class LocalFolder extends Folder { } } - public LocalFolder(LocalStore localStore, long id) { + public LocalFolder(LocalStore localStore, long databaseId) { super(); this.localStore = localStore; - this.id = id; + this.databaseId = databaseId; attachmentInfoExtractor = localStore.getAttachmentInfoExtractor(); } - public long getId() { - return id; + public long getDatabaseId() { + return databaseId; } public String getAccountUuid() @@ -161,7 +161,7 @@ public class LocalFolder extends Folder { cursor = db.rawQuery(baseQuery + "where folders.name = ?", new String[] { name }); } else { cursor = db.rawQuery(baseQuery + "where folders.id = ?", new String[] { Long.toString( - id) }); + databaseId) }); } if (cursor.moveToFirst() && !cursor.isNull(LocalStore.FOLDER_ID_INDEX)) { @@ -170,7 +170,7 @@ public class LocalFolder extends Folder { open(cursor); } } else { - Timber.w("Creating folder %s with existing id %d", getName(), getId()); + Timber.w("Creating folder %s with existing id %d", getName(), getDatabaseId()); create(FolderType.HOLDS_MESSAGES); open(mode); } @@ -188,7 +188,7 @@ public class LocalFolder extends Folder { } void open(Cursor cursor) throws MessagingException { - id = cursor.getInt(LocalStore.FOLDER_ID_INDEX); + databaseId = cursor.getInt(LocalStore.FOLDER_ID_INDEX); name = cursor.getString(LocalStore.FOLDER_NAME_INDEX); visibleLimit = cursor.getInt(LocalStore.FOLDER_VISIBLE_LIMIT_INDEX); pushState = cursor.getString(LocalStore.FOLDER_PUSH_STATE_INDEX); @@ -214,7 +214,7 @@ public class LocalFolder extends Folder { @Override public boolean isOpen() { - return (id != -1 && name != null); + return (databaseId != -1 && name != null); } @Override @@ -277,7 +277,7 @@ public class LocalFolder extends Folder { @Override public void close() { - id = -1; + databaseId = -1; } @Override @@ -296,7 +296,7 @@ public class LocalFolder extends Folder { cursor = db.rawQuery( "SELECT COUNT(id) FROM messages " + "WHERE empty = 0 AND deleted = 0 and folder_id = ?", - new String[] { Long.toString(id) }); + new String[] { Long.toString(databaseId) }); cursor.moveToFirst(); return cursor.getInt(0); //messagecount } finally { @@ -311,7 +311,7 @@ public class LocalFolder extends Folder { @Override public int getUnreadMessageCount() throws MessagingException { - if (id == -1) { + if (databaseId == -1) { open(OPEN_MODE_RW); } @@ -322,7 +322,7 @@ public class LocalFolder extends Folder { int unreadMessageCount = 0; Cursor cursor = db.query("messages", new String[] { "COUNT(id)" }, "folder_id = ? AND empty = 0 AND deleted = 0 AND read=0", - new String[] { Long.toString(id) }, null, null, null); + new String[] { Long.toString(databaseId) }, null, null, null); try { if (cursor.moveToFirst()) { @@ -342,7 +342,7 @@ public class LocalFolder extends Folder { @Override public int getFlaggedMessageCount() throws MessagingException { - if (id == -1) { + if (databaseId == -1) { open(OPEN_MODE_RW); } @@ -353,7 +353,7 @@ public class LocalFolder extends Folder { int flaggedMessageCount = 0; Cursor cursor = db.query("messages", new String[] { "COUNT(id)" }, "folder_id = ? AND empty = 0 AND deleted = 0 AND flagged = 1", - new String[] { Long.toString(id) }, null, null, null); + new String[] { Long.toString(databaseId) }, null, null, null); try { if (cursor.moveToFirst()) { @@ -455,7 +455,7 @@ public class LocalFolder extends Folder { } catch (MessagingException e) { throw new WrappedException(e); } - db.execSQL("UPDATE folders SET " + column + " = ? WHERE id = ?", new Object[] { value, id }); + db.execSQL("UPDATE folders SET " + column + " = ? WHERE id = ?", new Object[] { value, databaseId }); return null; } }); @@ -814,7 +814,7 @@ public class LocalFolder extends Folder { try { cursor = db.rawQuery( "SELECT uid FROM messages WHERE id = ? AND folder_id = ?", - new String[] { Long.toString(id), Long.toString(LocalFolder.this.id) }); + new String[] { Long.toString(id), Long.toString(LocalFolder.this.databaseId) }); if (!cursor.moveToNext()) { return null; } @@ -851,7 +851,7 @@ public class LocalFolder extends Folder { "LEFT JOIN message_parts ON (message_parts.id = messages.message_part_id) " + "LEFT JOIN threads ON (threads.message_id = messages.id) " + "WHERE uid = ? AND folder_id = ?", - new String[] { message.getUid(), Long.toString(id) }); + new String[] { message.getUid(), Long.toString(databaseId) }); if (!cursor.moveToNext()) { return null; @@ -887,7 +887,7 @@ public class LocalFolder extends Folder { "FROM messages " + "WHERE empty = 0 AND deleted = 0 AND " + "folder_id = ? ORDER BY date DESC", - new String[] { Long.toString(id) }); + new String[] { Long.toString(databaseId) }); while (cursor.moveToNext()) { String uid = cursor.getString(0); @@ -928,7 +928,7 @@ public class LocalFolder extends Folder { "WHERE empty = 0 AND " + (includeDeleted ? "" : "deleted = 0 AND ") + "folder_id = ? ORDER BY date DESC", - new String[] { Long.toString(id) }); + new String[] { Long.toString(databaseId) }); } catch (MessagingException e) { throw new WrappedException(e); } @@ -955,7 +955,7 @@ public class LocalFolder extends Folder { "FROM messages " + "WHERE empty = 0 AND deleted = 0 AND " + "folder_id = ? ORDER BY date DESC", - new String[] { Long.toString(id) }); + new String[] { Long.toString(databaseId) }); while (cursor.moveToNext()) { String uid = cursor.getString(0); @@ -1042,7 +1042,7 @@ public class LocalFolder extends Folder { Timber.d("Updating folder_id to %s for message with UID %s, " + "id %d currently in folder %s", - lDestFolder.getId(), + lDestFolder.getDatabaseId(), message.getUid(), lMessage.getDatabaseId(), getName()); @@ -1062,7 +1062,7 @@ public class LocalFolder extends Folder { String[] idArg = new String[] { Long.toString(msgId) }; ContentValues cv = new ContentValues(); - cv.put("folder_id", lDestFolder.getId()); + cv.put("folder_id", lDestFolder.getDatabaseId()); cv.put("uid", newUid); db.update("messages", cv, "id = ?", idArg); @@ -1100,7 +1100,7 @@ public class LocalFolder extends Folder { cv.putNull("flags"); cv.put("read", 1); cv.put("deleted", 1); - cv.put("folder_id", id); + cv.put("folder_id", databaseId); cv.put("empty", 0); String messageId = message.getMessageId(); @@ -1220,7 +1220,7 @@ public class LocalFolder extends Folder { "WHERE m.folder_id = ? AND m.message_id = ? " + ((onlyEmpty) ? "AND m.empty = 1 " : "") + "ORDER BY m.id LIMIT 1"; - String[] selectionArgs = { Long.toString(id), messageId }; + String[] selectionArgs = { Long.toString(databaseId), messageId }; Cursor cursor = db.rawQuery(sql, selectionArgs); if (cursor != null) { @@ -1353,7 +1353,7 @@ public class LocalFolder extends Folder { cv.put("flagged", message.isSet(Flag.FLAGGED) ? 1 : 0); cv.put("answered", message.isSet(Flag.ANSWERED) ? 1 : 0); cv.put("forwarded", message.isSet(Flag.FORWARDED) ? 1 : 0); - cv.put("folder_id", id); + cv.put("folder_id", databaseId); cv.put("to_list", Address.pack(message.getRecipients(RecipientType.TO))); cv.put("cc_list", Address.pack(message.getRecipients(RecipientType.CC))); cv.put("bcc_list", Address.pack(message.getRecipients(RecipientType.BCC))); @@ -1747,7 +1747,7 @@ public class LocalFolder extends Folder { "LEFT JOIN message_parts ON (message_parts.id = messages.message_part_id) " + "LEFT JOIN threads ON (threads.message_id = messages.id) " + "WHERE empty = 0 AND (folder_id = ? and date < ?)", - new String[] { Long.toString(id), Long.toString(cutoff) }); + new String[] { Long.toString(databaseId), Long.toString(cutoff) }); for (Message message : messages) { message.destroy(); @@ -1757,7 +1757,7 @@ public class LocalFolder extends Folder { } public void clearAllMessages() throws MessagingException { - final String[] folderIdArg = new String[] { Long.toString(id) }; + final String[] folderIdArg = new String[] { Long.toString(databaseId) }; open(OPEN_MODE_RO); @@ -1819,7 +1819,7 @@ public class LocalFolder extends Folder { throw new WrappedException(e); } db.execSQL("DELETE FROM folders WHERE id = ?", new Object[] - { Long.toString(id), }); + { Long.toString(databaseId), }); return null; } }); @@ -1862,7 +1862,7 @@ public class LocalFolder extends Folder { // make it an empty message. ContentValues cv = new ContentValues(); cv.put("id", messageId); - cv.put("folder_id", getId()); + cv.put("folder_id", getDatabaseId()); cv.put("deleted", 0); cv.put("message_id", messageIdHeader); cv.put("empty", 1); @@ -2068,7 +2068,7 @@ public class LocalFolder extends Folder { try { open(OPEN_MODE_RO); cursor = db.rawQuery("SELECT MAX(uid) FROM messages WHERE folder_id=?", new String[] { Long.toString( - id) }); + databaseId) }); if (cursor.getCount() > 0) { cursor.moveToFirst(); return cursor.getInt(0); @@ -2094,7 +2094,7 @@ public class LocalFolder extends Folder { try { open(OPEN_MODE_RO); cursor = db.rawQuery("SELECT MIN(date) FROM messages WHERE folder_id=?", new String[] { Long.toString( - id) }); + databaseId) }); if (cursor.getCount() > 0) { cursor.moveToFirst(); return cursor.getLong(0); @@ -2154,7 +2154,7 @@ public class LocalFolder extends Folder { // Create placeholder message in 'messages' table ContentValues cv = new ContentValues(); cv.put("message_id", reference); - cv.put("folder_id", id); + cv.put("folder_id", databaseId); cv.put("empty", 1); long newMsgId = db.insert("messages", null, cv); @@ -2235,7 +2235,7 @@ public class LocalFolder extends Folder { StringBuilder selection = new StringBuilder(); selection.append("folder_id = ? AND UID IN ("); - selectionArgs.add(Long.toString(id)); + selectionArgs.add(Long.toString(databaseId)); int count = Math.min(messages.size() - start, LocalStore.UID_CHECK_BATCH_SIZE); diff --git a/k9mail/src/main/java/com/fsck/k9/search/SqlQueryBuilder.java b/k9mail/src/main/java/com/fsck/k9/search/SqlQueryBuilder.java index cfac61f73..d3aa89d00 100644 --- a/k9mail/src/main/java/com/fsck/k9/search/SqlQueryBuilder.java +++ b/k9mail/src/main/java/com/fsck/k9/search/SqlQueryBuilder.java @@ -5,7 +5,6 @@ import java.util.List; import timber.log.Timber; import com.fsck.k9.Account; -import com.fsck.k9.K9; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.Folder; import com.fsck.k9.mailstore.LocalFolder; @@ -111,7 +110,7 @@ public class SqlQueryBuilder { LocalStore localStore = account.getLocalStore(); LocalFolder folder = localStore.getFolder(folderName); folder.open(Folder.OPEN_MODE_RO); - folderId = folder.getId(); + folderId = folder.getDatabaseId(); } catch (MessagingException e) { //FIXME e.printStackTrace(); diff --git a/k9mail/src/test/java/com/fsck/k9/cache/EmailProviderCacheTest.java b/k9mail/src/test/java/com/fsck/k9/cache/EmailProviderCacheTest.java index a288a82d4..73168bca4 100644 --- a/k9mail/src/test/java/com/fsck/k9/cache/EmailProviderCacheTest.java +++ b/k9mail/src/test/java/com/fsck/k9/cache/EmailProviderCacheTest.java @@ -42,7 +42,7 @@ public class EmailProviderCacheTest { cache = EmailProviderCache.getCache(UUID.randomUUID().toString(), RuntimeEnvironment.application); when(mockLocalMessage.getDatabaseId()).thenReturn(localMessageId); when(mockLocalMessage.getFolder()).thenReturn(mockLocalMessageFolder); - when(mockLocalMessageFolder.getId()).thenReturn(localMessageFolderId); + when(mockLocalMessageFolder.getDatabaseId()).thenReturn(localMessageFolderId); } @Test diff --git a/k9mail/src/test/java/com/fsck/k9/controller/MessagingControllerTest.java b/k9mail/src/test/java/com/fsck/k9/controller/MessagingControllerTest.java index 9aad30463..58b463c07 100644 --- a/k9mail/src/test/java/com/fsck/k9/controller/MessagingControllerTest.java +++ b/k9mail/src/test/java/com/fsck/k9/controller/MessagingControllerTest.java @@ -856,7 +856,7 @@ public class MessagingControllerTest { when(account.hasSentFolder()).thenReturn(true); when(account.getSentFolderName()).thenReturn(SENT_FOLDER_NAME); when(localStore.getFolder(SENT_FOLDER_NAME)).thenReturn(sentFolder); - when(sentFolder.getId()).thenReturn(1L); + when(sentFolder.getDatabaseId()).thenReturn(1L); when(localFolder.exists()).thenReturn(true); when(transportProvider.getTransport(appContext, account)).thenReturn(transport); when(localFolder.getMessages(null)).thenReturn(Collections.singletonList(localMessageToSend1));