From d67a59b77fd84a1f9c5b332b8f6d9f9bbd2d7a0a Mon Sep 17 00:00:00 2001 From: Mike Perry Date: Fri, 13 Jun 2014 17:38:48 -0700 Subject: [PATCH] Fixes for cketti's code review on pull req #472 Leave the hostname == null checks so we can fall back if a hostname is not found. Also convert message-id to upper case to match Apple Mail (for privacy). --- src/com/fsck/k9/mail/Address.java | 10 ++++++++++ .../fsck/k9/mail/internet/MimeMessage.java | 20 +++++++++---------- src/com/fsck/k9/preferences/Settings.java | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/com/fsck/k9/mail/Address.java b/src/com/fsck/k9/mail/Address.java index b49f425c0..a8ef1ee0c 100644 --- a/src/com/fsck/k9/mail/Address.java +++ b/src/com/fsck/k9/mail/Address.java @@ -93,6 +93,16 @@ public class Address { return mAddress; } + public String getHostname() { + int hostIdx = mAddress.lastIndexOf("@"); + + if (hostIdx == -1) { + return null; + } + + return mAddress.substring(hostIdx+1); + } + public void setAddress(String address) { this.mAddress = address; } diff --git a/src/com/fsck/k9/mail/internet/MimeMessage.java b/src/com/fsck/k9/mail/internet/MimeMessage.java index 7c6fe6b2c..2f69cba39 100644 --- a/src/com/fsck/k9/mail/internet/MimeMessage.java +++ b/src/com/fsck/k9/mail/internet/MimeMessage.java @@ -321,21 +321,21 @@ public class MimeMessage extends Message { private String generateMessageId() { String hostname = null; - if (mFrom != null) { - int hostIdx = mFrom[0].getAddress().lastIndexOf("@"); - hostname = mFrom[0].getAddress().substring(hostIdx); + + if (mFrom != null && mFrom.length >= 1) { + hostname = mFrom[0].getHostname(); } - if (hostname == null && mReplyTo != null) { - int hostIdx = mReplyTo[0].getAddress().lastIndexOf("@"); - hostname = mReplyTo[0].getAddress().substring(hostIdx); + if (hostname == null && mReplyTo != null && mReplyTo.length >= 1) { + hostname = mReplyTo[0].getHostname(); } - if (hostname != null) { - return "<" + UUID.randomUUID().toString() + hostname + ">"; - } else { - return "<" + UUID.randomUUID().toString() + "@email.android.com>"; + if (hostname == null) { + hostname = "email.android.com"; } + + /* We use upper case here to match Apple Mail Message-ID format (for privacy) */ + return "<" + UUID.randomUUID().toString().toUpperCase(Locale.US) + "@" + hostname + ">"; } public void setMessageId(String messageId) throws UnavailableStorageException { diff --git a/src/com/fsck/k9/preferences/Settings.java b/src/com/fsck/k9/preferences/Settings.java index 11ecc921a..b4dd8ef41 100644 --- a/src/com/fsck/k9/preferences/Settings.java +++ b/src/com/fsck/k9/preferences/Settings.java @@ -35,7 +35,7 @@ public class Settings { * * @see SettingsExporter */ - public static final int VERSION = 31; + public static final int VERSION = 32; public static Map validate(int version, Map> settings,