From ac022ce467a96996f2e147bb1513e96d24bf757e Mon Sep 17 00:00:00 2001 From: Bao-Long Nguyen-Trong Date: Fri, 25 Sep 2009 19:12:37 +0000 Subject: [PATCH] . Fixed issue 626 and issue 528: Date header was not set properly --- .../android/email/MessagingController.java | 8 +++---- .../email/activity/MessageCompose.java | 2 +- .../email/mail/internet/MimeMessage.java | 21 ++++++++++++++----- .../android/email/mail/store/LocalStore.java | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java index f94b2279c..83579d108 100644 --- a/src/com/android/email/MessagingController.java +++ b/src/com/android/email/MessagingController.java @@ -1528,7 +1528,7 @@ public class MessagingController implements Runnable { Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); LocalFolder localFolder = (LocalFolder)localStore.getFolder(account.getErrorFolderName()); Message[] messages = new Message[1]; - Message message = new MimeMessage(); + MimeMessage message = new MimeMessage(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); t.printStackTrace(ps); @@ -1540,7 +1540,7 @@ public class MessagingController implements Runnable { long nowTime = System.currentTimeMillis(); Date nowDate = new Date(nowTime); message.setInternalDate(nowDate); - message.setSentDate(nowDate); + message.addSentDate(nowDate); message.setFrom(new Address(account.getEmail(), "K9mail internal")); messages[0] = message; @@ -1579,7 +1579,7 @@ public class MessagingController implements Runnable { Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); LocalFolder localFolder = (LocalFolder)localStore.getFolder(account.getErrorFolderName()); Message[] messages = new Message[1]; - Message message = new MimeMessage(); + MimeMessage message = new MimeMessage(); message.setBody(new TextBody(body)); @@ -1589,7 +1589,7 @@ public class MessagingController implements Runnable { long nowTime = System.currentTimeMillis(); Date nowDate = new Date(nowTime); message.setInternalDate(nowDate); - message.setSentDate(nowDate); + message.addSentDate(nowDate); message.setFrom(new Address(account.getEmail(), "K9mail internal")); messages[0] = message; diff --git a/src/com/android/email/activity/MessageCompose.java b/src/com/android/email/activity/MessageCompose.java index 333525e42..aff49bdb8 100644 --- a/src/com/android/email/activity/MessageCompose.java +++ b/src/com/android/email/activity/MessageCompose.java @@ -630,7 +630,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc private MimeMessage createMessage(boolean appendSig) throws MessagingException { MimeMessage message = new MimeMessage(); - message.setSentDate(new Date()); + message.addSentDate(new Date()); Address from = new Address(mIdentity.getEmail(), mIdentity.getName()); message.setFrom(from); message.setRecipients(RecipientType.TO, getAddresses(mToView)); diff --git a/src/com/android/email/mail/internet/MimeMessage.java b/src/com/android/email/mail/internet/MimeMessage.java index c201ddeea..a2cb08029 100644 --- a/src/com/android/email/mail/internet/MimeMessage.java +++ b/src/com/android/email/mail/internet/MimeMessage.java @@ -104,20 +104,31 @@ public class MimeMessage extends Message { return mSentDate; } - public void setSentDate(Date sentDate) throws MessagingException { + /** + * Sets the sent date object member as well as *adds* the 'Date' header + * instead of setting it (for performance reasons). + * + * @see #mSentDate + * @param sentDate + * @throws com.android.email.mail.MessagingException + */ + public void addSentDate(Date sentDate) throws MessagingException { if (mDateFormat == null) { - mDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US); + mDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US); } - setHeader("Date", mDateFormat.format(sentDate)); + addHeader("Date", mDateFormat.format(sentDate)); setInternalSentDate(sentDate); } + public void setSentDate(Date sentDate) throws MessagingException { + removeHeader("Date"); + addSentDate(sentDate); + } + public void setInternalSentDate(Date sentDate) throws MessagingException { this.mSentDate = sentDate; } - - public String getContentType() throws MessagingException { String contentType = getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE); if (contentType == null) { diff --git a/src/com/android/email/mail/store/LocalStore.java b/src/com/android/email/mail/store/LocalStore.java index 574686a34..6c00b32be 100644 --- a/src/com/android/email/mail/store/LocalStore.java +++ b/src/com/android/email/mail/store/LocalStore.java @@ -897,7 +897,7 @@ public class LocalStore extends Store implements Serializable { if (from.length > 0) { message.setFrom(from[0]); } - message.setInternalSentDate(new Date(cursor.getLong(2))); + message.addSentDate(new Date(cursor.getLong(2))); message.setUid(cursor.getString(3)); String flagList = cursor.getString(4); if (flagList != null && flagList.length() > 0) {