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..c4328f6bb 100644
--- a/k9mail/src/main/java/com/fsck/k9/cache/EmailProviderCache.java
+++ b/k9mail/src/main/java/com/fsck/k9/cache/EmailProviderCache.java
@@ -126,8 +126,8 @@ public class EmailProviderCache {
public void hideMessages(List messages) {
synchronized (mHiddenMessageCache) {
for (LocalMessage message : messages) {
- long messageId = message.getId();
- mHiddenMessageCache.put(messageId, message.getFolder().getId());
+ long messageId = message.getDatabaseId();
+ mHiddenMessageCache.put(messageId, message.getFolder().getDatabaseId());
}
}
@@ -145,8 +145,8 @@ public class EmailProviderCache {
synchronized (mHiddenMessageCache) {
for (Message message : messages) {
LocalMessage localMessage = (LocalMessage) message;
- long messageId = localMessage.getId();
- long folderId = ((LocalFolder) localMessage.getFolder()).getId();
+ long messageId = localMessage.getDatabaseId();
+ 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 83802b033..8e86a2c39 100644
--- a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java
+++ b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java
@@ -305,8 +305,8 @@ public class MessagingController {
}
private boolean isMessageSuppressed(LocalMessage message) {
- long messageId = message.getId();
- long folderId = message.getFolder().getId();
+ long messageId = message.getDatabaseId();
+ long folderId = message.getFolder().getDatabaseId();
EmailProviderCache cache = EmailProviderCache.getCache(message.getFolder().getAccountUuid(), context);
return cache.isMessageHidden(messageId, folderId);
@@ -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);
@@ -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);
@@ -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 f6d26b5a5..be22b37dc 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,53 +68,57 @@ 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;
- 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 name = null;
+ private long databaseId = -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;
- attachmentInfoExtractor = localStore.attachmentInfoExtractor;
+ this.name = name;
+ attachmentInfoExtractor = localStore.getAttachmentInfoExtractor();
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) {
+ public LocalFolder(LocalStore localStore, long databaseId) {
super();
this.localStore = localStore;
- this.mFolderId = id;
- attachmentInfoExtractor = localStore.attachmentInfoExtractor;
+ this.databaseId = databaseId;
+ attachmentInfoExtractor = localStore.getAttachmentInfoExtractor();
}
- public long getId() {
- return mFolderId;
+ public long getDatabaseId() {
+ return databaseId;
}
public String getAccountUuid()
@@ -147,17 +150,18 @@ 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;
try {
String baseQuery = "SELECT " + LocalStore.GET_FOLDER_COLS + " FROM folders ";
- if (mName != null) {
- cursor = db.rawQuery(baseQuery + "where folders.name = ?", new String[] { mName });
+ 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(mFolderId) });
+ cursor = db.rawQuery(baseQuery + "where folders.id = ?", new String[] { Long.toString(
+ databaseId) });
}
if (cursor.moveToFirst() && !cursor.isNull(LocalStore.FOLDER_ID_INDEX)) {
@@ -166,7 +170,7 @@ public class LocalFolder extends Folder implements Serializable {
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);
}
@@ -184,33 +188,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);
+ 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);
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 (databaseId != -1 && name != null);
}
@Override
@@ -220,12 +224,12 @@ public class LocalFolder extends Folder implements Serializable {
@Override
public String getName() {
- return mName;
+ return name;
}
@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;
@@ -253,7 +257,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 " + name + " already exists.");
}
List foldersToCreate = new ArrayList<>(1);
foldersToCreate.add(this);
@@ -263,23 +267,23 @@ 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;
+ databaseId = -1;
}
@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 {
@@ -292,7 +296,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(databaseId) });
cursor.moveToFirst();
return cursor.getInt(0); //messagecount
} finally {
@@ -307,18 +311,18 @@ public class LocalFolder extends Folder implements Serializable {
@Override
public int getUnreadMessageCount() throws MessagingException {
- if (mFolderId == -1) {
+ if (databaseId == -1) {
open(OPEN_MODE_RW);
}
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;
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(databaseId) }, null, null, null);
try {
if (cursor.moveToFirst()) {
@@ -338,18 +342,18 @@ public class LocalFolder extends Folder implements Serializable {
@Override
public int getFlaggedMessageCount() throws MessagingException {
- if (mFolderId == -1) {
+ if (databaseId == -1) {
open(OPEN_MODE_RW);
}
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;
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(databaseId) }, null, null, null);
try {
if (cursor.moveToFirst()) {
@@ -391,18 +395,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 extends Message> 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 +417,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,13 +441,13 @@ public class LocalFolder extends Folder implements Serializable {
}
public void setPushState(final String pushState) throws MessagingException {
- mPushState = pushState;
+ this.pushState = pushState;
updateFolderColumn("push_state", pushState);
}
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 {
@@ -451,7 +455,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, databaseId });
return null;
}
});
@@ -461,67 +465,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() {
@@ -539,7 +543,7 @@ public class LocalFolder extends Folder implements Serializable {
private String getPrefId(String name) {
if (prefId == null) {
- prefId = this.localStore.uUid + "." + name;
+ prefId = getAccount().getUuid() + "." + name;
}
return prefId;
@@ -547,7 +551,7 @@ public class LocalFolder extends Folder implements Serializable {
private String getPrefId() throws MessagingException {
open(OPEN_MODE_RW);
- return getPrefId(mName);
+ return getPrefId(name);
}
public void delete() throws MessagingException {
@@ -574,32 +578,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);
}
@@ -656,7 +660,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 {
@@ -800,7 +804,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 {
@@ -810,7 +814,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(LocalFolder.this.databaseId) });
if (!cursor.moveToNext()) {
return null;
}
@@ -831,7 +835,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 {
@@ -847,7 +851,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(databaseId) });
if (!cursor.moveToNext()) {
return null;
@@ -869,7 +873,7 @@ public class LocalFolder extends Folder implements Serializable {
public Map getAllMessagesAndEffectiveDates() throws MessagingException {
try {
- return localStore.database.execute(false, new DbCallback
- * @throws MessagingException
*/
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;
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(
+ databaseId) });
if (cursor.getCount() > 0) {
cursor.moveToFirst();
return cursor.getInt(0);
@@ -2080,18 +2082,19 @@ 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", name, lastUid);
+ this.lastUid = lastUid;
}
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;
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(
+ databaseId) });
if (cursor.getCount() > 0) {
cursor.moveToFirst();
return cursor.getLong(0);
@@ -2151,7 +2154,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", databaseId);
cv.put("empty", 1);
long newMsgId = db.insert("messages", null, cv);
@@ -2213,7 +2216,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 {
@@ -2232,7 +2235,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(databaseId));
int count = Math.min(messages.size() - start, LocalStore.UID_CHECK_BATCH_SIZE);
@@ -2287,7 +2290,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;
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..e842c9adc 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 databaseId;
+ 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;
@@ -56,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(",");
@@ -81,39 +79,39 @@ public class LocalMessage extends MimeMessage {
}
}
}
- this.mId = 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.mAttachmentCount = 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) {
- mPreview = cursor.getString(14);
+ preview = cursor.getString(LocalStore.MSG_INDEX_PREVIEW);
} else {
- mPreview = "";
+ 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;
}
- mThreadId = (cursor.isNull(15)) ? -1 : cursor.getLong(15);
- mRootId = (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);
@@ -121,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 {
@@ -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
@@ -248,16 +246,15 @@ public class LocalMessage extends MimeMessage {
super.setFlag(flag, set);
}
- @Override
- public long getId() {
- return mId;
+ public long getDatabaseId() {
+ return databaseId;
}
@Override
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 {
@@ -273,13 +270,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(databaseId) });
return null;
}
@@ -297,7 +294,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();
@@ -313,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(mId) });
+ db.update("messages", cv, "id = ?", new String[] { Long.toString(databaseId) });
try {
((LocalFolder) mFolder).deleteMessagePartsAndDataFromDisk(messagePartId);
@@ -321,7 +318,7 @@ public class LocalMessage extends MimeMessage {
throw new WrappedException(e);
}
- getFolder().deleteFulltextIndexEntry(db, mId);
+ getFolder().deleteFulltextIndexEntry(db, databaseId);
return null;
}
@@ -339,13 +336,13 @@ 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();
cv.putNull("message_part_id");
- db.update("messages", cv, "id = ?", new String[] { Long.toString(mId) });
+ db.update("messages", cv, "id = ?", new String[] { Long.toString(databaseId) });
try {
((LocalFolder) mFolder).deleteMessagePartsAndDataFromDisk(messagePartId);
@@ -381,13 +378,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.databaseId = databaseId;
+ 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 +394,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 +406,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 +431,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 +476,4 @@ public class LocalMessage extends MimeMessage {
private String getAccountUuid() {
return getAccount().getUuid();
}
-
- public boolean isBodyMissing() {
- return getBody() == null;
- }
}
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 c1aa977e9..0d9a6acdd 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];
@@ -103,6 +100,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";
@@ -155,41 +179,16 @@ 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 LockableDatabase database;
/**
* local://localhost/path/to/database/uuid.db
@@ -197,13 +196,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 +205,10 @@ public class LocalStore extends Store implements Serializable {
pendingCommandSerializer = PendingCommandSerializer.getInstance();
attachmentInfoExtractor = AttachmentInfoExtractor.getInstance();
+ this.account = account;
+
+ database = new LockableDatabase(context, account.getUuid(), new StoreSchemaDefinition(this));
+ database.setStorageProviderId(account.getLocalStorageProviderId());
database.open();
}
@@ -266,8 +264,8 @@ public class LocalStore extends Store implements Serializable {
return context;
}
- protected Account getAccount() {
- return mAccount;
+ Account getAccount() {
+ return account;
}
protected Storage getStorage() {
@@ -278,7 +276,7 @@ public class LocalStore extends Store implements Serializable {
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() {
@@ -294,7 +292,7 @@ public class LocalStore extends Store implements Serializable {
}
}
- final File dbFile = storageManager.getDatabase(uUid, database.getStorageProviderId());
+ final File dbFile = storageManager.getDatabase(account.getUuid(), database.getStorageProviderId());
return dbFile.length() + attachmentLength;
}
});
@@ -358,7 +356,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 +372,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) {
@@ -464,7 +462,8 @@ public class LocalStore extends Store implements Serializable {
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;
@@ -568,7 +567,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" },
@@ -776,7 +775,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;
}
}
@@ -893,7 +892,8 @@ public class LocalStore extends Store implements Serializable {
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);
}
@@ -914,10 +914,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 +925,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 +978,7 @@ public class LocalStore extends Store implements Serializable {
return database;
}
- public MessagePreviewCreator getMessagePreviewCreator() {
+ MessagePreviewCreator getMessagePreviewCreator() {
return messagePreviewCreator;
}
@@ -986,13 +986,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);
+ Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + account.getUuid() + "/messages");
+ contentResolver.notifyChange(uri, null);
}
/**
@@ -1008,10 +1012,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 +1065,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 +1091,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 +1117,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 +1165,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 +1216,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 +1287,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/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/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/main/java/com/fsck/k9/view/MessageHeader.java b/k9mail/src/main/java/com/fsck/k9/view/MessageHeader.java
index 77d532918..4a2022d62 100644
--- a/k9mail/src/main/java/com/fsck/k9/view/MessageHeader.java
+++ b/k9mail/src/main/java/com/fsck/k9/view/MessageHeader.java
@@ -293,7 +293,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..73168bca4 100644
--- a/k9mail/src/test/java/com/fsck/k9/cache/EmailProviderCacheTest.java
+++ b/k9mail/src/test/java/com/fsck/k9/cache/EmailProviderCacheTest.java
@@ -40,9 +40,9 @@ 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);
+ 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));
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());
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);