From 7ac7fe2cfecbbd93e1150df10fb4cee69c11d6db Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Mon, 26 May 2014 14:56:28 -0700 Subject: [PATCH] Issue 3559: Use From or ReplyTo hostname in Message-ID if available. I wrote this fix to avoid obviously specifying that I am using a mobile device to reply to an email. Others want this for ease of filtering messages from their host by Message-ID. --- src/com/fsck/k9/mail/internet/MimeMessage.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/com/fsck/k9/mail/internet/MimeMessage.java b/src/com/fsck/k9/mail/internet/MimeMessage.java index d80b7bb22..c37abe02d 100644 --- a/src/com/fsck/k9/mail/internet/MimeMessage.java +++ b/src/com/fsck/k9/mail/internet/MimeMessage.java @@ -313,7 +313,22 @@ public class MimeMessage extends Message { } private String generateMessageId() { - return "<" + UUID.randomUUID().toString() + "@email.android.com>"; + String hostname = null; + if (mFrom != null) { + int hostIdx = mFrom[0].getAddress().lastIndexOf("@"); + hostname = mFrom[0].getAddress().substring(hostIdx); + } + + if (hostname == null && mReplyTo != null) { + int hostIdx = mReplyTo[0].getAddress().lastIndexOf("@"); + hostname = mReplyTo[0].getAddress().substring(hostIdx); + } + + if (hostname != null) { + return "<" + UUID.randomUUID().toString() + hostname + ">"; + } else { + return "<" + UUID.randomUUID().toString() + "@email.android.com>"; + } } public void setMessageId(String messageId) throws UnavailableStorageException {