From 2fbd6f61a886a822f6953ab8cc374c8e0ca2db59 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 22 Aug 2017 16:27:09 +0200 Subject: [PATCH] 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());