mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-24 16:48:50 -05:00
Defer creation of a MessageId until we actually need it. This was ~75% of our message load-from-db time
This commit is contained in:
parent
4117175b0f
commit
95159d8121
@ -54,23 +54,8 @@ public class MimeMessage extends Message
|
||||
|
||||
public MimeMessage()
|
||||
{
|
||||
addHeader("Message-ID", generateMessageId());
|
||||
}
|
||||
|
||||
private String generateMessageId()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("<");
|
||||
for (int i = 0; i < 24; i++)
|
||||
{
|
||||
sb.append(Integer.toString((int)(Math.random() * 35), 36));
|
||||
}
|
||||
sb.append(".");
|
||||
sb.append(Long.toString(System.currentTimeMillis()));
|
||||
sb.append("@email.android.com>");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given InputStream using Apache Mime4J to build a MimeMessage.
|
||||
@ -349,10 +334,29 @@ public class MimeMessage extends Message
|
||||
{
|
||||
mMessageId = getFirstHeader("Message-ID");
|
||||
}
|
||||
if (mMessageId == null) // even after checking the header
|
||||
{
|
||||
setMessageId(generateMessageId());
|
||||
}
|
||||
return mMessageId;
|
||||
}
|
||||
|
||||
public void setMessageId(String messageId) throws MessagingException
|
||||
private String generateMessageId()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("<");
|
||||
for (int i = 0; i < 24; i++)
|
||||
{
|
||||
sb.append(Integer.toString((int)(Math.random() * 35), 36));
|
||||
}
|
||||
sb.append(".");
|
||||
sb.append(Long.toString(System.currentTimeMillis()));
|
||||
sb.append("@email.android.com>");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void setMessageId(String messageId)
|
||||
{
|
||||
setHeader("Message-ID", messageId);
|
||||
mMessageId = messageId;
|
||||
@ -437,6 +441,7 @@ public class MimeMessage extends Message
|
||||
|
||||
public void writeTo(OutputStream out) throws IOException, MessagingException
|
||||
{
|
||||
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024);
|
||||
mHeader.writeTo(out);
|
||||
writer.write("\r\n");
|
||||
|
@ -1457,11 +1457,12 @@ public class LocalStore extends Store implements Serializable
|
||||
String uid = message.getUid();
|
||||
if (uid == null)
|
||||
{
|
||||
message.setUid(Email.LOCAL_UID_PREFIX + UUID.randomUUID().toString());
|
||||
uid = Email.LOCAL_UID_PREFIX + UUID.randomUUID().toString();
|
||||
message.setUid(uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
Message oldMessage = getMessage(message.getUid());
|
||||
Message oldMessage = getMessage(uid);
|
||||
if (oldMessage != null && oldMessage.isSet(Flag.SEEN) == false)
|
||||
{
|
||||
setUnreadMessageCount(getUnreadMessageCount() - 1);
|
||||
@ -1510,7 +1511,7 @@ public class LocalStore extends Store implements Serializable
|
||||
try
|
||||
{
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put("uid", message.getUid());
|
||||
cv.put("uid", uid);
|
||||
cv.put("subject", message.getSubject());
|
||||
cv.put("sender_list", Address.pack(message.getFrom()));
|
||||
cv.put("date", message.getSentDate() == null
|
||||
@ -1527,17 +1528,19 @@ public class LocalStore extends Store implements Serializable
|
||||
cv.put("attachment_count", attachments.size());
|
||||
cv.put("internal_date", message.getInternalDate() == null
|
||||
? System.currentTimeMillis() : message.getInternalDate().getTime());
|
||||
String[] mHeaders = message.getHeader("Message-ID");
|
||||
if (mHeaders != null && mHeaders.length > 0)
|
||||
String messageId = message.getMessageId();
|
||||
Log.e(Email.LOG_TAG, "saving a messag");
|
||||
if (messageId != null )
|
||||
{
|
||||
cv.put("message_id", mHeaders[0]);
|
||||
Log.e(Email.LOG_TAG, "saving a message messasgeid is "+messageId);
|
||||
cv.put("message_id", messageId);
|
||||
}
|
||||
long messageId = mDb.insert("messages", "uid", cv);
|
||||
long messageUid = mDb.insert("messages", "uid", cv);
|
||||
for (Part attachment : attachments)
|
||||
{
|
||||
saveAttachment(messageId, attachment, copy);
|
||||
saveAttachment(messageUid, attachment, copy);
|
||||
}
|
||||
saveHeaders(messageId, (MimeMessage)message);
|
||||
saveHeaders(messageUid, (MimeMessage)message);
|
||||
if (message.isSet(Flag.SEEN) == false)
|
||||
{
|
||||
setUnreadMessageCount(getUnreadMessageCount() + 1);
|
||||
@ -1565,6 +1568,9 @@ public class LocalStore extends Store implements Serializable
|
||||
open(OpenMode.READ_WRITE);
|
||||
ArrayList<Part> viewables = new ArrayList<Part>();
|
||||
ArrayList<Part> attachments = new ArrayList<Part>();
|
||||
|
||||
message.buildMimeRepresentation();
|
||||
|
||||
MimeUtility.collectParts(message, viewables, attachments);
|
||||
|
||||
StringBuffer sbHtml = new StringBuffer();
|
||||
@ -2124,7 +2130,7 @@ public class LocalStore extends Store implements Serializable
|
||||
super.setRecipients(RecipientType.TO, mTo);
|
||||
super.setRecipients(RecipientType.CC, mCc);
|
||||
super.setRecipients(RecipientType.BCC, mBcc);
|
||||
|
||||
if (mMessageId != null) super.setMessageId(mMessageId);
|
||||
|
||||
mMessageDirty = false;
|
||||
return;
|
||||
@ -2146,7 +2152,7 @@ public class LocalStore extends Store implements Serializable
|
||||
}
|
||||
|
||||
|
||||
public void setMessageId(String messageId) throws MessagingException
|
||||
public void setMessageId(String messageId)
|
||||
{
|
||||
mMessageId = messageId;
|
||||
mMessageDirty = true;
|
||||
|
Loading…
Reference in New Issue
Block a user