From 2c51862087a7e137998412f82a512d139be6de2b Mon Sep 17 00:00:00 2001 From: Daniel Applebaum Date: Sun, 18 Jan 2009 16:31:37 +0000 Subject: [PATCH] Issue 190 Handle uppercase MIME type sent by non-compliant MUAs such as Pine. --- src/com/android/email/mail/internet/MimeBodyPart.java | 2 +- src/com/android/email/mail/internet/MimeMessage.java | 2 +- src/com/android/email/mail/internet/MimeUtility.java | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/com/android/email/mail/internet/MimeBodyPart.java b/src/com/android/email/mail/internet/MimeBodyPart.java index f41caedde..1fecd8589 100644 --- a/src/com/android/email/mail/internet/MimeBodyPart.java +++ b/src/com/android/email/mail/internet/MimeBodyPart.java @@ -81,7 +81,7 @@ public class MimeBodyPart extends BodyPart { if (contentType == null) { return "text/plain"; } else { - return contentType; + return contentType.toLowerCase(); } } diff --git a/src/com/android/email/mail/internet/MimeMessage.java b/src/com/android/email/mail/internet/MimeMessage.java index a1a474f15..8b8e3e891 100644 --- a/src/com/android/email/mail/internet/MimeMessage.java +++ b/src/com/android/email/mail/internet/MimeMessage.java @@ -115,7 +115,7 @@ public class MimeMessage extends Message { if (contentType == null) { return "text/plain"; } else { - return contentType; + return contentType.toLowerCase(); } } diff --git a/src/com/android/email/mail/internet/MimeUtility.java b/src/com/android/email/mail/internet/MimeUtility.java index 9ee711014..462b94778 100644 --- a/src/com/android/email/mail/internet/MimeUtility.java +++ b/src/com/android/email/mail/internet/MimeUtility.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; +import java.util.regex.Pattern; import java.nio.charset.Charset; @@ -196,7 +197,9 @@ public class MimeUtility { * @return */ public static boolean mimeTypeMatches(String mimeType, String matchAgainst) { - return mimeType.matches(matchAgainst.replaceAll("\\*", "\\.\\*")); + Pattern p = Pattern.compile(matchAgainst.replaceAll("\\*", "\\.\\*"), + Pattern.CASE_INSENSITIVE); + return p.matcher(mimeType).matches(); } /** @@ -208,9 +211,9 @@ public class MimeUtility { */ public static boolean mimeTypeMatches(String mimeType, String[] matchAgainst) { for (String matchType : matchAgainst) { - if (mimeType.matches(matchType.replaceAll("\\*", "\\.\\*"))) { - return true; - } + if (mimeTypeMatches(mimeType, matchType)) { + return true; + } } return false; }