1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Use Locale.US with toUpperCase() and toLowerCase() where appropriate

This commit is contained in:
cketti 2011-10-27 17:17:43 +02:00
parent 9327c86fe7
commit b69d6cb64c
8 changed files with 29 additions and 25 deletions

View File

@ -1931,7 +1931,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
if (message.getSubject() != null) { if (message.getSubject() != null) {
final String subject = prefix.matcher(message.getSubject()).replaceFirst(""); final String subject = prefix.matcher(message.getSubject()).replaceFirst("");
if (!subject.toLowerCase().startsWith("re:")) { if (!subject.toLowerCase(Locale.US).startsWith("re:")) {
mSubjectView.setText("Re: " + subject); mSubjectView.setText("Re: " + subject);
} else { } else {
mSubjectView.setText(subject); mSubjectView.setText(subject);
@ -2028,10 +2028,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
} }
} }
} else if (ACTION_FORWARD.equals(action)) { } else if (ACTION_FORWARD.equals(action)) {
if (message.getSubject() != null && !message.getSubject().toLowerCase().startsWith("fwd:")) { String subject = message.getSubject();
mSubjectView.setText("Fwd: " + message.getSubject()); if (subject != null && !subject.toLowerCase(Locale.US).startsWith("fwd:")) {
mSubjectView.setText("Fwd: " + subject);
} else { } else {
mSubjectView.setText(message.getSubject()); mSubjectView.setText(subject);
} }
// Quote the message and setup the UI. // Quote the message and setup the UI.

View File

@ -26,6 +26,7 @@ import java.security.cert.CertificateParsingException;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
@ -60,7 +61,7 @@ public class DomainNameChecker {
return false; return false;
} }
thisDomain = thisDomain.toLowerCase(); thisDomain = thisDomain.toLowerCase(Locale.US);
if (!isIpAddress(thisDomain)) { if (!isIpAddress(thisDomain)) {
return matchDns(certificate, thisDomain); return matchDns(certificate, thisDomain);
} else { } else {
@ -223,7 +224,7 @@ public class DomainNameChecker {
return false; return false;
} }
thatDomain = thatDomain.toLowerCase(); thatDomain = thatDomain.toLowerCase(Locale.US);
// (a) domain name strings are equal, ignoring case: X matches X // (a) domain name strings are equal, ignoring case: X matches X
boolean rval = thisDomain.equals(thatDomain); boolean rval = thisDomain.equals(thatDomain);

View File

@ -9,6 +9,7 @@ import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -64,7 +65,7 @@ public class HtmlConverter {
@Override @Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
tag = tag.toLowerCase(); tag = tag.toLowerCase(Locale.US);
if (tag.equals("hr") && opening) { if (tag.equals("hr") && opening) {
// In the case of an <hr>, replace it with a bunch of underscores. This is roughly // In the case of an <hr>, replace it with a bunch of underscores. This is roughly
// the behaviour of Outlook in Rich Text mode. // the behaviour of Outlook in Rich Text mode.

View File

@ -131,7 +131,7 @@ public class MimeMessage extends Message {
@Override @Override
public String getContentType() throws MessagingException { public String getContentType() throws MessagingException {
String contentType = getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE); String contentType = getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE);
return (contentType == null) ? "text/plain" : contentType.toLowerCase(); return (contentType == null) ? "text/plain" : contentType.toLowerCase(Locale.US);
} }
public String getDisposition() throws MessagingException { public String getDisposition() throws MessagingException {

View File

@ -12,6 +12,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.IllegalCharsetNameException;
@ -940,7 +941,7 @@ public class MimeUtility {
return parts[0]; return parts[0];
} }
for (String part : parts) { for (String part : parts) {
if (part.trim().toLowerCase().startsWith(name.toLowerCase())) { if (part.trim().toLowerCase(Locale.US).startsWith(name.toLowerCase(Locale.US))) {
String parameter = part.split("=", 2)[1].trim(); String parameter = part.split("=", 2)[1].trim();
if (parameter.startsWith("\"") && parameter.endsWith("\"")) { if (parameter.startsWith("\"") && parameter.endsWith("\"")) {
return parameter.substring(1, parameter.length() - 1); return parameter.substring(1, parameter.length() - 1);
@ -1184,7 +1185,7 @@ public class MimeUtility {
String extension = null; String extension = null;
if (filename != null && filename.lastIndexOf('.') != -1) { if (filename != null && filename.lastIndexOf('.') != -1) {
extension = filename.substring(filename.lastIndexOf('.') + 1).toLowerCase(); extension = filename.substring(filename.lastIndexOf('.') + 1).toLowerCase(Locale.US);
returnedType = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); returnedType = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
} }
// If the MIME type set by the user's mailer is application/octet-stream, try to figure // If the MIME type set by the user's mailer is application/octet-stream, try to figure
@ -1263,7 +1264,7 @@ public class MimeUtility {
if (charset == null || "0".equals(charset)) if (charset == null || "0".equals(charset))
charset = "US-ASCII"; // No encoding, so use us-ascii, which is the standard. charset = "US-ASCII"; // No encoding, so use us-ascii, which is the standard.
charset = charset.toLowerCase(); charset = charset.toLowerCase(Locale.US);
if (charset.equals("cp932")) if (charset.equals("cp932"))
charset = "shift_jis"; charset = "shift_jis";
else if (charset.equals("koi8-u")) else if (charset.equals("koi8-u"))

View File

@ -1461,7 +1461,7 @@ public class ImapStore extends Store {
* what type it is and bail out. * what type it is and bail out.
*/ */
String subType = bs.getString(i); String subType = bs.getString(i);
mp.setSubType(subType.toLowerCase()); mp.setSubType(subType.toLowerCase(Locale.US));
break; break;
} }
} }
@ -1490,7 +1490,7 @@ public class ImapStore extends Store {
String type = bs.getString(0); String type = bs.getString(0);
String subType = bs.getString(1); String subType = bs.getString(1);
String mimeType = (type + "/" + subType).toLowerCase(); String mimeType = (type + "/" + subType).toLowerCase(Locale.US);
ImapList bodyParams = null; ImapList bodyParams = null;
if (bs.get(2) instanceof ImapList) { if (bs.get(2) instanceof ImapList) {
@ -1546,7 +1546,7 @@ public class ImapStore extends Store {
if (bodyDisposition != null && bodyDisposition.size() > 0) { if (bodyDisposition != null && bodyDisposition.size() > 0) {
if (!"NIL".equalsIgnoreCase(bodyDisposition.getString(0))) { if (!"NIL".equalsIgnoreCase(bodyDisposition.getString(0))) {
contentDisposition = bodyDisposition.getString(0).toLowerCase(); contentDisposition = bodyDisposition.getString(0).toLowerCase(Locale.US);
} }
if ((bodyDisposition.size() > 1) if ((bodyDisposition.size() > 1)
@ -1558,7 +1558,7 @@ public class ImapStore extends Store {
*/ */
for (int i = 0, count = bodyDispositionParams.size(); i < count; i += 2) { for (int i = 0, count = bodyDispositionParams.size(); i < count; i += 2) {
contentDisposition += String.format(";\n %s=\"%s\"", contentDisposition += String.format(";\n %s=\"%s\"",
bodyDispositionParams.getString(i).toLowerCase(), bodyDispositionParams.getString(i).toLowerCase(Locale.US),
bodyDispositionParams.getString(i + 1)); bodyDispositionParams.getString(i + 1));
} }
} }
@ -1841,7 +1841,7 @@ public class ImapStore extends Store {
// { // {
// Log.v(K9.LOG_TAG, "Saving capability '" + capability + "' for " + getLogId()); // Log.v(K9.LOG_TAG, "Saving capability '" + capability + "' for " + getLogId());
// } // }
capabilities.add(((String)capability).toUpperCase()); capabilities.add(((String)capability).toUpperCase(Locale.US));
} }
} }
@ -2151,7 +2151,7 @@ public class ImapStore extends Store {
} }
protected boolean hasCapability(String capability) { protected boolean hasCapability(String capability) {
return capabilities.contains(capability.toUpperCase()); return capabilities.contains(capability.toUpperCase(Locale.US));
} }
public boolean isOpen() { public boolean isOpen() {

View File

@ -1601,10 +1601,10 @@ public class LocalStore extends Store implements Serializable {
String htmlContent = cursor.getString(0); String htmlContent = cursor.getString(0);
String textContent = cursor.getString(1); String textContent = cursor.getString(1);
String mimeType = cursor.getString(2); String mimeType = cursor.getString(2);
if (mimeType != null && mimeType.toLowerCase().startsWith("multipart/")) { if (mimeType != null && mimeType.toLowerCase(Locale.US).startsWith("multipart/")) {
// If this is a multipart message, preserve both text // If this is a multipart message, preserve both text
// and html parts, as well as the subtype. // and html parts, as well as the subtype.
mp.setSubType(mimeType.toLowerCase().replaceFirst("^multipart/", "")); mp.setSubType(mimeType.toLowerCase(Locale.US).replaceFirst("^multipart/", ""));
if (textContent != null) { if (textContent != null) {
LocalTextBody body = new LocalTextBody(textContent, htmlContent); LocalTextBody body = new LocalTextBody(textContent, htmlContent);
MimeBodyPart bp = new MimeBodyPart(body, "text/plain"); MimeBodyPart bp = new MimeBodyPart(body, "text/plain");
@ -2144,7 +2144,7 @@ public class LocalStore extends Store implements Serializable {
cv.put("sender_list", Address.pack(message.getFrom())); cv.put("sender_list", Address.pack(message.getFrom()));
cv.put("date", message.getSentDate() == null cv.put("date", message.getSentDate() == null
? System.currentTimeMillis() : message.getSentDate().getTime()); ? System.currentTimeMillis() : message.getSentDate().getTime());
cv.put("flags", Utility.combine(message.getFlags(), ',').toUpperCase()); cv.put("flags", Utility.combine(message.getFlags(), ',').toUpperCase(Locale.US));
cv.put("deleted", message.isSet(Flag.DELETED) ? 1 : 0); cv.put("deleted", message.isSet(Flag.DELETED) ? 1 : 0);
cv.put("folder_id", mFolderId); cv.put("folder_id", mFolderId);
cv.put("to_list", Address.pack(message.getRecipients(RecipientType.TO))); cv.put("to_list", Address.pack(message.getRecipients(RecipientType.TO)));
@ -2263,7 +2263,7 @@ public class LocalStore extends Store implements Serializable {
message.getSentDate() == null ? System message.getSentDate() == null ? System
.currentTimeMillis() : message.getSentDate() .currentTimeMillis() : message.getSentDate()
.getTime(), .getTime(),
Utility.combine(message.getFlags(), ',').toUpperCase(), Utility.combine(message.getFlags(), ',').toUpperCase(Locale.US),
mFolderId, mFolderId,
Address.pack(message Address.pack(message
.getRecipients(RecipientType.TO)), .getRecipients(RecipientType.TO)),
@ -2337,7 +2337,7 @@ public class LocalStore extends Store implements Serializable {
db.execSQL("UPDATE messages " + "SET flags = ? " + " WHERE id = ?", db.execSQL("UPDATE messages " + "SET flags = ? " + " WHERE id = ?",
new Object[] new Object[]
{ Utility.combine(appendedFlags.toArray(), ',').toUpperCase(), id }); { Utility.combine(appendedFlags.toArray(), ',').toUpperCase(Locale.US), id });
} }
return null; return null;
} }
@ -3189,7 +3189,7 @@ public class LocalStore extends Store implements Serializable {
* Set the flags on the message. * Set the flags on the message.
*/ */
db.execSQL("UPDATE messages " + "SET flags = ? " + " WHERE id = ?", new Object[] db.execSQL("UPDATE messages " + "SET flags = ? " + " WHERE id = ?", new Object[]
{ Utility.combine(getFlags(), ',').toUpperCase(), mId }); { Utility.combine(getFlags(), ',').toUpperCase(Locale.US), mId });
return null; return null;
} }
}); });

View File

@ -1852,7 +1852,7 @@ public class WebDavStore extends Store {
public void setUrl(String url) { public void setUrl(String url) {
// TODO: This is a not as ugly hack (ie, it will actually work) // TODO: This is a not as ugly hack (ie, it will actually work)
// XXX: prevent URLs from getting to us that are broken // XXX: prevent URLs from getting to us that are broken
if (!(url.toLowerCase().contains("http"))) { if (!(url.toLowerCase(Locale.US).contains("http"))) {
if (!(url.startsWith("/"))) { if (!(url.startsWith("/"))) {
url = "/" + url; url = "/" + url;
} }