always load headers immediately for LocalMessage
This commit is contained in:
parent
3f0fb9fd3e
commit
2b5064ea55
3 changed files with 10 additions and 74 deletions
|
@ -660,7 +660,6 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
|||
LocalMessage localMessage = (LocalMessage) message;
|
||||
|
||||
loadMessageParts(db, localMessage);
|
||||
localMessage.loadHeadersIfNecessary();
|
||||
}
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
|
@ -793,25 +792,6 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
|||
throw new IllegalStateException("Not implemented");
|
||||
}
|
||||
|
||||
void populateHeaders(final LocalMessage message) throws MessagingException {
|
||||
this.localStore.database.execute(false, new DbCallback<Void>() {
|
||||
@Override
|
||||
public Void doDbWork(final SQLiteDatabase db) throws WrappedException, MessagingException {
|
||||
Cursor cursor = db.query("message_parts", new String[] { "header" }, "id = ?",
|
||||
new String[] { Long.toString(message.getMessagePartId()) }, null, null, null);
|
||||
try {
|
||||
if (cursor.moveToFirst()) {
|
||||
byte[] header = cursor.getBlob(0);
|
||||
parseHeaderBytes(message, header);
|
||||
}
|
||||
} finally {
|
||||
Utility.closeQuietly(cursor);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getMessageUidById(final long id) throws MessagingException {
|
||||
try {
|
||||
return this.localStore.database.execute(false, new DbCallback<String>() {
|
||||
|
@ -858,6 +838,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
|||
"SELECT " +
|
||||
LocalStore.GET_MESSAGES_COLS +
|
||||
"FROM messages " +
|
||||
"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) });
|
||||
|
@ -895,6 +876,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
|||
return LocalFolder.this.localStore.getMessages(listener, LocalFolder.this,
|
||||
"SELECT " + LocalStore.GET_MESSAGES_COLS +
|
||||
"FROM messages " +
|
||||
"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 " +
|
||||
(includeDeleted ? "" : "deleted = 0 AND ") +
|
||||
|
@ -1662,6 +1644,7 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
|||
List<? extends Message> messages = this.localStore.getMessages(null, this,
|
||||
"SELECT " + LocalStore.GET_MESSAGES_COLS +
|
||||
"FROM messages " +
|
||||
"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) });
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.fsck.k9.mailstore;
|
||||
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Date;
|
||||
|
@ -21,6 +22,7 @@ import com.fsck.k9.mail.Flag;
|
|||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.internet.MimeMessage;
|
||||
import com.fsck.k9.mail.message.MessageHeaderParser;
|
||||
import com.fsck.k9.mailstore.LockableDatabase.DbCallback;
|
||||
import com.fsck.k9.mailstore.LockableDatabase.WrappedException;
|
||||
import com.fsck.k9.message.extractors.PreviewResult.PreviewType;
|
||||
|
@ -36,8 +38,6 @@ public class LocalMessage extends MimeMessage {
|
|||
|
||||
private String mPreview = "";
|
||||
|
||||
private boolean mHeadersLoaded = false;
|
||||
|
||||
private long mThreadId;
|
||||
private long mRootId;
|
||||
private long messagePartId;
|
||||
|
@ -122,6 +122,9 @@ public class LocalMessage extends MimeMessage {
|
|||
|
||||
messagePartId = cursor.getLong(22);
|
||||
mimeType = cursor.getString(23);
|
||||
|
||||
byte[] header = cursor.getBlob(25);
|
||||
MessageHeaderParser.parse(this, new ByteArrayInputStream(header));
|
||||
}
|
||||
|
||||
public long getMessagePartId() {
|
||||
|
@ -137,15 +140,6 @@ public class LocalMessage extends MimeMessage {
|
|||
* changes.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void writeTo(OutputStream out) throws IOException, MessagingException {
|
||||
if (!mHeadersLoaded) {
|
||||
loadHeaders();
|
||||
}
|
||||
|
||||
super.writeTo(out);
|
||||
}
|
||||
|
||||
public PreviewType getPreviewType() {
|
||||
return previewType;
|
||||
}
|
||||
|
@ -500,47 +494,6 @@ public class LocalMessage extends MimeMessage {
|
|||
db.delete("threads", "message_id = ?", idArg);
|
||||
}
|
||||
|
||||
private void loadHeaders() throws MessagingException {
|
||||
mHeadersLoaded = true;
|
||||
getFolder().populateHeaders(this);
|
||||
}
|
||||
|
||||
void loadHeadersIfNecessary() throws MessagingException {
|
||||
if (!mHeadersLoaded) {
|
||||
loadHeaders();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeader(String name, String value) throws MessagingException {
|
||||
if (!mHeadersLoaded)
|
||||
loadHeaders();
|
||||
super.setHeader(name, value);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String[] getHeader(String name) throws MessagingException {
|
||||
if (!mHeadersLoaded) {
|
||||
loadHeaders();
|
||||
}
|
||||
return super.getHeader(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHeader(String name) throws MessagingException {
|
||||
if (!mHeadersLoaded)
|
||||
loadHeaders();
|
||||
super.removeHeader(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getHeaderNames() throws MessagingException {
|
||||
if (!mHeadersLoaded)
|
||||
loadHeaders();
|
||||
return super.getHeaderNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalMessage clone() {
|
||||
LocalMessage message = new LocalMessage(this.localStore);
|
||||
|
@ -550,7 +503,6 @@ public class LocalMessage extends MimeMessage {
|
|||
message.mAttachmentCount = mAttachmentCount;
|
||||
message.mSubject = mSubject;
|
||||
message.mPreview = mPreview;
|
||||
message.mHeadersLoaded = mHeadersLoaded;
|
||||
|
||||
return message;
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class LocalStore extends Store implements Serializable {
|
|||
"subject, sender_list, date, uid, flags, messages.id, to_list, cc_list, " +
|
||||
"bcc_list, reply_to_list, attachment_count, internal_date, messages.message_id, " +
|
||||
"folder_id, preview, threads.id, threads.root, deleted, read, flagged, answered, " +
|
||||
"forwarded, message_part_id, mime_type, preview_type ";
|
||||
"forwarded, message_part_id, messages.mime_type, preview_type, header ";
|
||||
|
||||
static final String GET_FOLDER_COLS =
|
||||
"folders.id, name, visible_limit, last_updated, status, push_state, last_pushed, " +
|
||||
|
@ -574,6 +574,7 @@ public class LocalStore extends Store implements Serializable {
|
|||
|
||||
String sqlQuery = "SELECT " + GET_MESSAGES_COLS + "FROM messages " +
|
||||
"LEFT JOIN threads ON (threads.message_id = messages.id) " +
|
||||
"LEFT JOIN message_parts ON (message_parts.id = messages.message_part_id) " +
|
||||
"LEFT JOIN folders ON (folders.id = messages.folder_id) WHERE " +
|
||||
"(empty = 0 AND deleted = 0)" +
|
||||
((!TextUtils.isEmpty(where)) ? " AND (" + where + ")" : "") +
|
||||
|
|
Loading…
Reference in a new issue