From 1ca1ef5c845f0c72d9e594ca7c348c25f6f2e790 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Mon, 2 Sep 2013 18:43:51 -0400 Subject: [PATCH] Content-type case-conversion changes. Don't convert the content-type to lower case in MimeMessage.getContentType. The content-type may have optional parameters that are case sensitive (boundary, name). In removing the lower-case conversion from getContentType, a review was made for inappropriate case-sensitive comparisons which use data obtained with getContentType. The only ones found were in isMimeType in both Message and MimeBodyPart. Case-sensitive instances of isMimeType were made case-insensitive. Also, isMimeType was moved from Message to MimeMessage for symmetry with MimeBodyPart (MimeMessage & MimeBodyPart are similar and contain a good bit of duplication such as this). The unit test required fixing now that the case of the boundary text is preserved. References: Commits 2c5186 and dc4002 added the toLowerCase to getContentType in MimeMessage & MimeBodyPart (Issue 94). Later, commit 50cd60 removed the toLowerCase addition from MimeBodyPart (Issue 1289). --- src/com/fsck/k9/mail/Message.java | 4 ---- .../fsck/k9/mail/internet/MimeBodyPart.java | 2 +- .../fsck/k9/mail/internet/MimeMessage.java | 6 ++++- tests/src/com/fsck/k9/mail/MessageTest.java | 22 +++++++++---------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/com/fsck/k9/mail/Message.java b/src/com/fsck/k9/mail/Message.java index 21ff61f8a..70ee13f30 100644 --- a/src/com/fsck/k9/mail/Message.java +++ b/src/com/fsck/k9/mail/Message.java @@ -139,10 +139,6 @@ public abstract class Message implements Part, CompositeBody { public abstract void setBody(Body body) throws MessagingException; - public boolean isMimeType(String mimeType) throws MessagingException { - return getContentType().startsWith(mimeType); - } - public abstract long getId(); public abstract String getPreview(); diff --git a/src/com/fsck/k9/mail/internet/MimeBodyPart.java b/src/com/fsck/k9/mail/internet/MimeBodyPart.java index f59f4f7bc..60e3b4cca 100644 --- a/src/com/fsck/k9/mail/internet/MimeBodyPart.java +++ b/src/com/fsck/k9/mail/internet/MimeBodyPart.java @@ -122,7 +122,7 @@ public class MimeBodyPart extends BodyPart { } public boolean isMimeType(String mimeType) throws MessagingException { - return getMimeType().equals(mimeType); + return getMimeType().equalsIgnoreCase(mimeType); } public int getSize() { diff --git a/src/com/fsck/k9/mail/internet/MimeMessage.java b/src/com/fsck/k9/mail/internet/MimeMessage.java index c87b26561..922b7ba36 100644 --- a/src/com/fsck/k9/mail/internet/MimeMessage.java +++ b/src/com/fsck/k9/mail/internet/MimeMessage.java @@ -164,7 +164,7 @@ public class MimeMessage extends Message { @Override public String getContentType() throws MessagingException { String contentType = getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE); - return (contentType == null) ? "text/plain" : contentType.toLowerCase(Locale.US); + return (contentType == null) ? "text/plain" : contentType; } public String getDisposition() throws MessagingException { @@ -177,6 +177,10 @@ public class MimeMessage extends Message { return MimeUtility.getHeaderParameter(getContentType(), null); } + public boolean isMimeType(String mimeType) throws MessagingException { + return getMimeType().equalsIgnoreCase(mimeType); + } + public int getSize() { return mSize; } diff --git a/tests/src/com/fsck/k9/mail/MessageTest.java b/tests/src/com/fsck/k9/mail/MessageTest.java index cedb32e40..3e56b228d 100644 --- a/tests/src/com/fsck/k9/mail/MessageTest.java +++ b/tests/src/com/fsck/k9/mail/MessageTest.java @@ -187,10 +187,10 @@ public class MessageTest extends AndroidTestCase { + "Subject: Test Message\r\n" + "Date: Wed, 28 Aug 2013 08:51:09 -0400\r\n" + "MIME-Version: 1.0\r\n" - + "Content-Type: multipart/mixed; boundary=\"----boundary102\"\r\n" + + "Content-Type: multipart/mixed; boundary=\"----Boundary102\"\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" - + "------boundary102\r\n" + + "------Boundary102\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "\r\n" @@ -199,7 +199,7 @@ public class MessageTest extends AndroidTestCase { + "=CE=B1=CE=B2=CE=B3=CE=B4=CE=B5=CE=B6=CE=B7=CE=B8\r\n" + "End of test=2E\r\n" + "\r\n" - + "------boundary102\r\n" + + "------Boundary102\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "\r\n" @@ -208,13 +208,13 @@ public class MessageTest extends AndroidTestCase { + "=CE=B1=CE=B2=CE=B3=CE=B4=CE=B5=CE=B6=CE=B7=CE=B8\r\n" + "End of test=2E\r\n" + "\r\n" - + "------boundary102\r\n" + + "------Boundary102\r\n" + "Content-Type: application/octet-stream\r\n" + "Content-Transfer-Encoding: base64\r\n" + "\r\n" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\r\n" + "\r\n" - + "------boundary102\r\n" + + "------Boundary102\r\n" + "Content-Type: message/rfc822\r\n" + "Content-Disposition: attachment\r\n" + "Content-Transfer-Encoding: 7bit\r\n" @@ -224,10 +224,10 @@ public class MessageTest extends AndroidTestCase { + "Subject: Test Message\r\n" + "Date: Wed, 28 Aug 2013 08:51:09 -0400\r\n" + "MIME-Version: 1.0\r\n" - + "Content-Type: multipart/mixed; boundary=\"----boundary101\"\r\n" + + "Content-Type: multipart/mixed; boundary=\"----Boundary101\"\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" - + "------boundary101\r\n" + + "------Boundary101\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "\r\n" @@ -236,7 +236,7 @@ public class MessageTest extends AndroidTestCase { + "=CE=B1=CE=B2=CE=B3=CE=B4=CE=B5=CE=B6=CE=B7=CE=B8\r\n" + "End of test=2E\r\n" + "\r\n" - + "------boundary101\r\n" + + "------Boundary101\r\n" + "Content-Type: text/plain; charset=utf-8\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "\r\n" @@ -245,15 +245,15 @@ public class MessageTest extends AndroidTestCase { + "=CE=B1=CE=B2=CE=B3=CE=B4=CE=B5=CE=B6=CE=B7=CE=B8\r\n" + "End of test=2E\r\n" + "\r\n" - + "------boundary101\r\n" + + "------Boundary101\r\n" + "Content-Type: application/octet-stream\r\n" + "Content-Transfer-Encoding: base64\r\n" + "\r\n" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\r\n" + "\r\n" - + "------boundary101--\r\n" + + "------Boundary101--\r\n" + "\r\n" - + "------boundary102--\r\n" + + "------Boundary102--\r\n" + "\r\n" + "------Boundary103--\r\n";