Use Locale.US where appropriate

Applicable for strings not intended for user consumption.

A %d string format code can generate eastern-arabic numerals
for users with an arabic locale.

V/k9      (20763): conn1103774136>>> 5 UID SEARCH ٦٤٦:٦٧٠ NOT DELETED
V/k9      (20763): conn1103774136<<<#5# [BAD, Invalid Search criteria]
E/k9      (20763): synchronizeMailbox
E/k9      (20763): com.fsck.k9.mail.store.ImapStore$ImapException: Command: UID SEARCH ٦٤٦:٦٧٠ NOT DELETED; response: #5# [BAD, Invalid Search criteria]
This commit is contained in:
Joe Steele 2014-03-03 10:40:23 -05:00
parent 47e09c92ea
commit 0f991b434e
11 changed files with 33 additions and 25 deletions

View File

@ -1565,7 +1565,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
* title*2*=%2A%2A%2Afun%2A%2A%2A%20
* title*3="isn't it!"
*/
bp.addHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, String.format(
bp.addHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, String.format(Locale.US,
"attachment;\r\n filename=\"%s\";\r\n size=%d",
attachment.name, attachment.size));

View File

@ -24,6 +24,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.Locale;
/**
* Prompts the user for the email address and password.
@ -230,7 +231,7 @@ public class AccountSetupBasics extends K9Activity
mAccount.setTrashFolderName(getString(R.string.special_mailbox_name_trash));
mAccount.setArchiveFolderName(getString(R.string.special_mailbox_name_archive));
// Yahoo! has a special folder for Spam, called "Bulk Mail".
if (incomingUriTemplate.getHost().toLowerCase().endsWith(".yahoo.com")) {
if (incomingUriTemplate.getHost().toLowerCase(Locale.US).endsWith(".yahoo.com")) {
mAccount.setSpamFolderName("Bulk Mail");
} else {
mAccount.setSpamFolderName(getString(R.string.special_mailbox_name_spam));

View File

@ -2,6 +2,7 @@ package com.fsck.k9.fragment;
import java.io.File;
import java.util.Collections;
import java.util.Locale;
import android.app.Activity;
import android.content.Context;
@ -785,7 +786,7 @@ public class MessageViewFragment extends SherlockFragment implements OnClickList
}
private String getDialogTag(int dialogId) {
return String.format("dialog-%d", dialogId);
return String.format(Locale.US, "dialog-%d", dialogId);
}
public void zoom(KeyEvent event) {

View File

@ -26,6 +26,7 @@ import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -498,7 +499,7 @@ public class Utility {
format = filename + "-%d";
}
for (int i = 2; i < Integer.MAX_VALUE; i++) {
file = new File(directory, String.format(format, i));
file = new File(directory, String.format(Locale.US, format, i));
if (!file.exists()) {
return file;
}

View File

@ -3,6 +3,7 @@ package com.fsck.k9.mail.filter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
/**
* A filtering InputStream that stops allowing reads after the given length has been read. This
@ -66,6 +67,6 @@ public class FixedLengthInputStream extends InputStream {
@Override
public String toString() {
return String.format("FixedLengthInputStream(in=%s, length=%d)", mIn.toString(), mLength);
return String.format(Locale.US, "FixedLengthInputStream(in=%s, length=%d)", mIn.toString(), mLength);
}
}

View File

@ -3,6 +3,7 @@ package com.fsck.k9.mail.filter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
/**
* A filtering InputStream that allows single byte "peeks" without consuming the byte. The
@ -59,7 +60,7 @@ public class PeekableInputStream extends InputStream {
@Override
public String toString() {
return String.format("PeekableInputStream(in=%s, peeked=%b, peekedByte=%d)",
return String.format(Locale.US, "PeekableInputStream(in=%s, peeked=%b, peekedByte=%d)",
mIn.toString(), mPeeked, mPeekedByte);
}
}

View File

@ -1284,7 +1284,7 @@ public class ImapStore extends Store {
int count = 0;
int start = 1;
List<ImapResponse> responses = executeSimpleCommand(String.format("SEARCH %d:* %s", start, criteria));
List<ImapResponse> responses = executeSimpleCommand(String.format(Locale.US, "SEARCH %d:* %s", start, criteria));
for (ImapResponse response : responses) {
if (ImapResponseParser.equalsIgnoreCase(response.get(0), "SEARCH")) {
count += response.size() - 1;
@ -1347,7 +1347,7 @@ public class ImapStore extends Store {
throws MessagingException {
if (start < 1 || end < 1 || end < start) {
throw new MessagingException(
String.format("Invalid message set %d %d",
String.format(Locale.US, "Invalid message set %d %d",
start, end));
}
final StringBuilder dateSearchString = new StringBuilder();
@ -1361,7 +1361,7 @@ public class ImapStore extends Store {
ImapSearcher searcher = new ImapSearcher() {
public List<ImapResponse> search() throws IOException, MessagingException {
return executeSimpleCommand(String.format("UID SEARCH %d:%d%s%s", start, end, dateSearchString, includeDeleted ? "" : " NOT DELETED"));
return executeSimpleCommand(String.format(Locale.US, "UID SEARCH %d:%d%s%s", start, end, dateSearchString, includeDeleted ? "" : " NOT DELETED"));
}
};
return search(searcher, listener).toArray(EMPTY_MESSAGE_ARRAY);
@ -1505,7 +1505,7 @@ public class ImapStore extends Store {
if (fp.contains(FetchProfile.Item.BODY_SANE)) {
// If the user wants to download unlimited-size messages, don't go only for the truncated body
if (mAccount.getMaximumAutoDownloadMessageSize() > 0) {
fetchFields.add(String.format("BODY.PEEK[]<0.%d>", mAccount.getMaximumAutoDownloadMessageSize()));
fetchFields.add(String.format(Locale.US, "BODY.PEEK[]<0.%d>", mAccount.getMaximumAutoDownloadMessageSize()));
} else {
fetchFields.add("BODY.PEEK[]");
}
@ -1961,7 +1961,7 @@ public class ImapStore extends Store {
}
if (MimeUtility.getHeaderParameter(contentDisposition.toString(), "size") == null) {
contentDisposition.append(String.format(";\r\n size=%d", size));
contentDisposition.append(String.format(Locale.US, ";\r\n size=%d", size));
}
/*
@ -2010,7 +2010,7 @@ public class ImapStore extends Store {
Map<String, String> uidMap = new HashMap<String, String>();
for (Message message : messages) {
mConnection.sendCommand(
String.format("APPEND %s (%s) {%d}",
String.format(Locale.US, "APPEND %s (%s) {%d}",
encodeString(encodeFolderName(getPrefixedName())),
combineFlags(message.getFlags()),
message.calculateSize()), false);
@ -2627,7 +2627,7 @@ public class ImapStore extends Store {
if (mSettings.getPathDelimeter() == null) {
try {
List<ImapResponse> nameResponses =
executeSimpleCommand(String.format("LIST \"\" \"\""));
executeSimpleCommand("LIST \"\" \"\"");
for (ImapResponse response : nameResponses) {
if (ImapResponseParser.equalsIgnoreCase(response.get(0), "LIST")) {
mSettings.setPathDelimeter(response.getString(2));

View File

@ -223,7 +223,7 @@ public class LocalStore extends Store implements Serializable {
}
private void upgradeDatabase(final SQLiteDatabase db) {
Log.i(K9.LOG_TAG, String.format("Upgrading database from version %d to version %d",
Log.i(K9.LOG_TAG, String.format(Locale.US, "Upgrading database from version %d to version %d",
db.getVersion(), DB_VERSION));
AttachmentProvider.clear(mApplication);
@ -1968,14 +1968,14 @@ public class LocalStore extends Store implements Serializable {
type,
name));
bp.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION,
String.format("%s;\r\n filename=\"%s\";\r\n size=%d",
String.format(Locale.US, "%s;\r\n filename=\"%s\";\r\n size=%d",
contentDisposition,
name, // TODO: Should use encoded word defined in RFC 2231.
size));
} else {
bp.setHeader(MimeHeader.HEADER_CONTENT_TYPE, type);
bp.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION,
String.format("%s;\r\n size=%d",
String.format(Locale.US, "%s;\r\n size=%d",
contentDisposition,
size));
}

View File

@ -26,6 +26,7 @@ import java.util.LinkedList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@ -510,7 +511,7 @@ public class Pop3Store extends Store {
public Message[] getMessages(int start, int end, Date earliestDate, MessageRetrievalListener listener)
throws MessagingException {
if (start < 1 || end < 1 || end < start) {
throw new MessagingException(String.format("Invalid message set %d %d",
throw new MessagingException(String.format(Locale.US, "Invalid message set %d %d",
start, end));
}
try {
@ -791,7 +792,7 @@ public class Pop3Store extends Store {
if (listener != null) {
listener.messageStarted(pop3Message.getUid(), i, count);
}
String response = executeSimpleCommand(String.format(LIST_COMMAND + " %d",
String response = executeSimpleCommand(String.format(Locale.US, LIST_COMMAND + " %d",
mUidToMsgNumMap.get(pop3Message.getUid())));
String[] listParts = response.split(" ");
//int msgNum = Integer.parseInt(listParts[1]);
@ -850,7 +851,7 @@ public class Pop3Store extends Store {
"Checking to see if the TOP command is supported nevertheless.");
}
response = executeSimpleCommand(String.format(TOP_COMMAND + " %d %d",
response = executeSimpleCommand(String.format(Locale.US, TOP_COMMAND + " %d %d",
mUidToMsgNumMap.get(message.getUid()), lines));
// TOP command is supported. Remember this for the next time.
@ -872,7 +873,7 @@ public class Pop3Store extends Store {
}
if (response == null) {
executeSimpleCommand(String.format(RETR_COMMAND + " %d",
executeSimpleCommand(String.format(Locale.US, RETR_COMMAND + " %d",
mUidToMsgNumMap.get(message.getUid())));
}

View File

@ -1479,7 +1479,7 @@ public class WebDavStore extends Store {
end = start + (end - prevStart);
if (start < 0 || end < 0 || end < start) {
throw new MessagingException(String.format("Invalid message set %d %d", start, end));
throw new MessagingException(String.format(Locale.US, "Invalid message set %d %d", start, end));
}
if (start == 0 && end < 10) {

View File

@ -4,6 +4,8 @@
package com.fsck.k9.preferences;
import java.util.Locale;
import android.content.Context;
import android.preference.DialogPreference;
import android.text.format.DateFormat;
@ -94,8 +96,8 @@ public class TimePickerPreference extends DialogPreference implements
@Override
public void onTimeChanged(final TimePicker view, final int hour, final int minute) {
persistString(String.format("%02d:%02d", hour, minute));
callChangeListener(String.format("%02d:%02d", hour, minute));
persistString(String.format(Locale.US, "%02d:%02d", hour, minute));
callChangeListener(String.format(Locale.US, "%02d:%02d", hour, minute));
}
/**
@ -106,8 +108,8 @@ public class TimePickerPreference extends DialogPreference implements
protected void onDialogClosed(boolean positiveResult) {
if (!positiveResult) {
persistString(String.format("%02d:%02d", originalHour, originalMinute));
callChangeListener(String.format("%02d:%02d", originalHour, originalMinute));
persistString(String.format(Locale.US, "%02d:%02d", originalHour, originalMinute));
callChangeListener(String.format(Locale.US, "%02d:%02d", originalHour, originalMinute));
}
super.onDialogClosed(positiveResult);
}