From d402c890dc00e2a0b2cf215d8479e59fc3a252f3 Mon Sep 17 00:00:00 2001 From: Paul Westbrook Date: Fri, 5 Apr 2013 13:57:51 -0700 Subject: [PATCH] Fixed make POP and Imap more locale safe Cherry-picks from: https://android-review.googlesource.com/#/c/42334/ https://android-review.googlesource.com/#/c/42332/ Change-Id: I557c3d8c725cf6dc4f13f227dcec63864ab5db67 --- src/com/android/email/mail/store/ImapFolder.java | 12 ++++++------ src/com/android/email/mail/store/Pop3Store.java | 11 +++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/com/android/email/mail/store/ImapFolder.java b/src/com/android/email/mail/store/ImapFolder.java index 8f4fbb140..e45e15d8f 100644 --- a/src/com/android/email/mail/store/ImapFolder.java +++ b/src/com/android/email/mail/store/ImapFolder.java @@ -756,7 +756,7 @@ class ImapFolder extends Folder { } else { if (e.isString()) { - mp.setSubType(bs.getStringOrEmpty(i).getString().toLowerCase()); + mp.setSubType(bs.getStringOrEmpty(i).getString().toLowerCase(Locale.US)); } break; // Ignore the rest of the list. } @@ -781,7 +781,7 @@ class ImapFolder extends Folder { final ImapString type = bs.getStringOrEmpty(0); final ImapString subType = bs.getStringOrEmpty(1); final String mimeType = - (type.getString() + "/" + subType.getString()).toLowerCase(); + (type.getString() + "/" + subType.getString()).toLowerCase(Locale.US); final ImapList bodyParams = bs.getListOrEmpty(2); final ImapString cid = bs.getStringOrEmpty(3); @@ -839,7 +839,7 @@ class ImapFolder extends Folder { if (bodyDisposition.size() > 0) { final String bodyDisposition0Str = - bodyDisposition.getStringOrEmpty(0).getString().toLowerCase(); + bodyDisposition.getStringOrEmpty(0).getString().toLowerCase(Locale.US); if (!TextUtils.isEmpty(bodyDisposition0Str)) { contentDisposition.append(bodyDisposition0Str); } @@ -853,9 +853,9 @@ class ImapFolder extends Folder { for (int i = 1, count = bodyDispositionParams.size(); i < count; i += 2) { // TODO We need to convert " into %22. See above. - contentDisposition.append(String.format(";\n %s=\"%s\"", + contentDisposition.append(String.format(Locale.US, ";\n %s=\"%s\"", bodyDispositionParams.getStringOrEmpty(i - 1) - .getString().toLowerCase(), + .getString().toLowerCase(Locale.US), bodyDispositionParams.getStringOrEmpty(i).getString())); } } @@ -864,7 +864,7 @@ class ImapFolder extends Folder { if ((size > 0) && (MimeUtility.getHeaderParameter(contentDisposition.toString(), "size") == null)) { - contentDisposition.append(String.format(";\n size=%d", size)); + contentDisposition.append(String.format(Locale.US, ";\n size=%d", size)); } if (contentDisposition.length() > 0) { diff --git a/src/com/android/email/mail/store/Pop3Store.java b/src/com/android/email/mail/store/Pop3Store.java index dde393a1b..fe24c92dc 100644 --- a/src/com/android/email/mail/store/Pop3Store.java +++ b/src/com/android/email/mail/store/Pop3Store.java @@ -48,6 +48,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; +import java.util.Locale; public class Pop3Store extends Store { // All flags defining debug or development code settings must be FALSE @@ -559,14 +560,16 @@ public class Pop3Store extends Store { int messageId = mUidToMsgNumMap.get(message.getUid()); if (lines == -1) { // Fetch entire message - response = executeSimpleCommand(String.format("RETR %d", messageId)); + response = executeSimpleCommand(String.format(Locale.US, "RETR %d", messageId)); } else { // Fetch partial message. Try "TOP", and fall back to slower "RETR" if necessary try { - response = executeSimpleCommand(String.format("TOP %d %d", messageId, lines)); + response = executeSimpleCommand( + String.format(Locale.US, "TOP %d %d", messageId, lines)); } catch (MessagingException me) { try { - response = executeSimpleCommand(String.format("RETR %d", messageId)); + response = executeSimpleCommand( + String.format(Locale.US, "RETR %d", messageId)); } catch (MessagingException e) { Log.w(Logging.LOG_TAG, "Can't read message " + messageId); } @@ -647,7 +650,7 @@ public class Pop3Store extends Store { try { String uid = message.getUid(); int msgNum = mUidToMsgNumMap.get(uid); - executeSimpleCommand(String.format("DELE %s", msgNum)); + executeSimpleCommand(String.format(Locale.US, "DELE %s", msgNum)); // Remove from the maps mMsgNumToMsgMap.remove(msgNum); mUidToMsgNumMap.remove(uid);