From fcd8ee9aeb7cf0032d2052874ea43ebfde778342 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Tue, 17 Nov 2009 21:13:29 +0000 Subject: [PATCH] Implement References/In-Reply-To/X-User-Agen. Fixes issue 42. Patch from e.w.stemle --- .../email/activity/MessageCompose.java | 35 ++++++++++++++++-- src/com/android/email/mail/Message.java | 8 +++++ .../email/mail/internet/MimeMessage.java | 36 +++++++++++++++++++ .../android/email/mail/store/LocalStore.java | 3 ++ 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/com/android/email/activity/MessageCompose.java b/src/com/android/email/activity/MessageCompose.java index 0d57be7b2..22c0750c1 100644 --- a/src/com/android/email/activity/MessageCompose.java +++ b/src/com/android/email/activity/MessageCompose.java @@ -127,6 +127,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc private View mQuotedTextBar; private ImageButton mQuotedTextDelete; private EditText mQuotedText; + + private String mReferences; + private String mInReplyTo; private boolean mDraftNeedsSaving = false; @@ -640,8 +643,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc message.setRecipients(RecipientType.CC, getAddresses(mCcView)); message.setRecipients(RecipientType.BCC, getAddresses(mBccView)); message.setSubject(mSubjectView.getText().toString()); - // XXX TODO - not sure why this won't add header - // message.setHeader("X-User-Agent", getString(R.string.message_header_mua)); + message.setHeader("X-User-Agent", getString(R.string.message_header_mua)); + + if (mInReplyTo != null) { + message.setInReplyTo(mInReplyTo); + } + + if (mReferences != null) { + message.setReferences(mReferences); + } + /* * Build the Body that will contain the text of the message. We'll decide where to @@ -1085,6 +1096,26 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc addAddresses(mToView, replyToAddresses = message.getFrom()); } + if (message.getMessageId() != null && message.getMessageId().length() > 0) { + String messageId = message.getMessageId(); + mInReplyTo = messageId; + + if (message.getReferences() != null && message.getReferences().length > 0) { + StringBuffer buffy = new StringBuffer(); + for (int i=0; i < message.getReferences().length; i++) + buffy.append(message.getReferences()[i]); + + mReferences = buffy.toString() + " " + mInReplyTo; + } + else { + mReferences = mInReplyTo; + } + + } + else { + Log.d(Email.LOG_TAG, "could not get Message-ID."); + } + Part part = MimeUtility.findFirstPartByMimeType(mSourceMessage, "text/plain"); if (part != null) { diff --git a/src/com/android/email/mail/Message.java b/src/com/android/email/mail/Message.java index e612b15d6..3b1f9d010 100644 --- a/src/com/android/email/mail/Message.java +++ b/src/com/android/email/mail/Message.java @@ -66,6 +66,14 @@ public abstract class Message implements Part, Body { public abstract void setReplyTo(Address[] from) throws MessagingException; + public abstract String getMessageId() throws MessagingException; + + public abstract void setInReplyTo(String inReplyTo) throws MessagingException; + + public abstract String[] getReferences() throws MessagingException; + + public abstract void setReferences(String references) throws MessagingException; + public abstract Body getBody() throws MessagingException; public abstract String getContentType() throws MessagingException; diff --git a/src/com/android/email/mail/internet/MimeMessage.java b/src/com/android/email/mail/internet/MimeMessage.java index 3b1570bb1..cab90c68c 100644 --- a/src/com/android/email/mail/internet/MimeMessage.java +++ b/src/com/android/email/mail/internet/MimeMessage.java @@ -19,6 +19,9 @@ import org.apache.james.mime4j.MimeStreamParser; import org.apache.james.mime4j.field.DateTimeField; import org.apache.james.mime4j.field.Field; +import android.util.Log; + +import com.android.email.Email; import com.android.email.mail.Address; import com.android.email.mail.Body; import com.android.email.mail.BodyPart; @@ -37,6 +40,11 @@ public class MimeMessage extends Message { protected Address[] mCc; protected Address[] mBcc; protected Address[] mReplyTo; + + protected String mMessageId; + protected String[] mReferences; + protected String[] mInReplyTo; + protected Date mSentDate; protected SimpleDateFormat mDateFormat; @@ -56,6 +64,7 @@ public class MimeMessage extends Message { sb.append("."); sb.append(Long.toString(System.currentTimeMillis())); sb.append("@email.android.com>"); + return sb.toString(); } @@ -77,6 +86,11 @@ public class MimeMessage extends Message { mCc = null; mBcc = null; mReplyTo = null; + + mMessageId = null; + mReferences = null; + mInReplyTo = null; + mSentDate = null; mBody = null; @@ -259,6 +273,28 @@ public class MimeMessage extends Message { } } + public String getMessageId() throws MessagingException { + if (mMessageId == null) { + mMessageId = getFirstHeader("Message-ID"); + } + return mMessageId; + } + + public void setInReplyTo(String inReplyTo) throws MessagingException { + setHeader("In-Reply-To", inReplyTo); + } + + public String[] getReferences() throws MessagingException { + if (mReferences == null) { + mReferences = getHeader("References"); + } + return mReferences; + } + + public void setReferences(String references) throws MessagingException { + setHeader("References", references); + } + public void saveChanges() throws MessagingException { throw new MessagingException("saveChanges not yet implemented"); } diff --git a/src/com/android/email/mail/store/LocalStore.java b/src/com/android/email/mail/store/LocalStore.java index 3e4169ff6..1d518b413 100644 --- a/src/com/android/email/mail/store/LocalStore.java +++ b/src/com/android/email/mail/store/LocalStore.java @@ -80,6 +80,9 @@ public class LocalStore extends Store implements Serializable { static { HEADERS_TO_SAVE.add(Email.K9MAIL_IDENTITY); + HEADERS_TO_SAVE.add("In-Reply-To"); + HEADERS_TO_SAVE.add("References"); + HEADERS_TO_SAVE.add("X-User-Agent"); } /**