1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-26 01:28:50 -05:00

Implement References/In-Reply-To/X-User-Agen. Fixes issue 42. Patch from e.w.stemle

This commit is contained in:
Jesse Vincent 2009-11-17 21:13:29 +00:00
parent 690505ea73
commit fcd8ee9aeb
4 changed files with 80 additions and 2 deletions

View File

@ -128,6 +128,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
private ImageButton mQuotedTextDelete; private ImageButton mQuotedTextDelete;
private EditText mQuotedText; private EditText mQuotedText;
private String mReferences;
private String mInReplyTo;
private boolean mDraftNeedsSaving = false; 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.CC, getAddresses(mCcView));
message.setRecipients(RecipientType.BCC, getAddresses(mBccView)); message.setRecipients(RecipientType.BCC, getAddresses(mBccView));
message.setSubject(mSubjectView.getText().toString()); 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 * 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()); 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, Part part = MimeUtility.findFirstPartByMimeType(mSourceMessage,
"text/plain"); "text/plain");
if (part != null) { if (part != null) {

View File

@ -66,6 +66,14 @@ public abstract class Message implements Part, Body {
public abstract void setReplyTo(Address[] from) throws MessagingException; 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 Body getBody() throws MessagingException;
public abstract String getContentType() throws MessagingException; public abstract String getContentType() throws MessagingException;

View File

@ -19,6 +19,9 @@ import org.apache.james.mime4j.MimeStreamParser;
import org.apache.james.mime4j.field.DateTimeField; import org.apache.james.mime4j.field.DateTimeField;
import org.apache.james.mime4j.field.Field; 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.Address;
import com.android.email.mail.Body; import com.android.email.mail.Body;
import com.android.email.mail.BodyPart; import com.android.email.mail.BodyPart;
@ -37,6 +40,11 @@ public class MimeMessage extends Message {
protected Address[] mCc; protected Address[] mCc;
protected Address[] mBcc; protected Address[] mBcc;
protected Address[] mReplyTo; protected Address[] mReplyTo;
protected String mMessageId;
protected String[] mReferences;
protected String[] mInReplyTo;
protected Date mSentDate; protected Date mSentDate;
protected SimpleDateFormat mDateFormat; protected SimpleDateFormat mDateFormat;
@ -56,6 +64,7 @@ public class MimeMessage extends Message {
sb.append("."); sb.append(".");
sb.append(Long.toString(System.currentTimeMillis())); sb.append(Long.toString(System.currentTimeMillis()));
sb.append("@email.android.com>"); sb.append("@email.android.com>");
return sb.toString(); return sb.toString();
} }
@ -77,6 +86,11 @@ public class MimeMessage extends Message {
mCc = null; mCc = null;
mBcc = null; mBcc = null;
mReplyTo = null; mReplyTo = null;
mMessageId = null;
mReferences = null;
mInReplyTo = null;
mSentDate = null; mSentDate = null;
mBody = 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 { public void saveChanges() throws MessagingException {
throw new MessagingException("saveChanges not yet implemented"); throw new MessagingException("saveChanges not yet implemented");
} }

View File

@ -80,6 +80,9 @@ public class LocalStore extends Store implements Serializable {
static static
{ {
HEADERS_TO_SAVE.add(Email.K9MAIL_IDENTITY); 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");
} }
/** /**