am d1a87bc0: Fix IMAP sync with Arabic language

* commit 'd1a87bc02d65dde9e635848531e09aadc79ff538':
  Fix IMAP sync with Arabic language
This commit is contained in:
Paul Westbrook 2013-04-02 12:57:07 -07:00 committed by Android Git Automerger
commit 96af4ae6e9
3 changed files with 32 additions and 26 deletions

View File

@ -57,6 +57,7 @@ import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Locale;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
@ -186,7 +187,7 @@ class ImapFolder extends Folder {
} }
} }
try { try {
connection.executeSimpleCommand(String.format( connection.executeSimpleCommand(String.format(Locale.US,
ImapConstants.STATUS + " \"%s\" (" + ImapConstants.UIDVALIDITY + ")", ImapConstants.STATUS + " \"%s\" (" + ImapConstants.UIDVALIDITY + ")",
ImapStore.encodeFolderName(mName, mStore.mPathPrefix))); ImapStore.encodeFolderName(mName, mStore.mPathPrefix)));
mExists = true; mExists = true;
@ -232,7 +233,8 @@ class ImapFolder extends Folder {
} }
} }
try { try {
connection.executeSimpleCommand(String.format(ImapConstants.CREATE + " \"%s\"", connection.executeSimpleCommand(String.format(Locale.US,
ImapConstants.CREATE + " \"%s\"",
ImapStore.encodeFolderName(mName, mStore.mPathPrefix))); ImapStore.encodeFolderName(mName, mStore.mPathPrefix)));
return true; return true;
@ -256,7 +258,7 @@ class ImapFolder extends Folder {
checkOpen(); checkOpen();
try { try {
List<ImapResponse> responseList = mConnection.executeSimpleCommand( List<ImapResponse> responseList = mConnection.executeSimpleCommand(
String.format(ImapConstants.UID_COPY + " %s \"%s\"", String.format(Locale.US, ImapConstants.UID_COPY + " %s \"%s\"",
ImapStore.joinMessageUids(messages), ImapStore.joinMessageUids(messages),
ImapStore.encodeFolderName(folder.getName(), mStore.mPathPrefix))); ImapStore.encodeFolderName(folder.getName(), mStore.mPathPrefix)));
// Build a message map for faster UID matching // Build a message map for faster UID matching
@ -305,14 +307,15 @@ class ImapFolder extends Folder {
} }
// If the server doesn't support UIDPLUS, try a different way to get the new UID(s) // If the server doesn't support UIDPLUS, try a different way to get the new UID(s)
if (callbacks != null && !handledUidPlus) { if (callbacks != null && !handledUidPlus) {
ImapFolder newFolder = (ImapFolder)folder; final ImapFolder newFolder = (ImapFolder)folder;
try { try {
// Temporarily select the destination folder // Temporarily select the destination folder
newFolder.open(OpenMode.READ_WRITE); newFolder.open(OpenMode.READ_WRITE);
// Do the search(es) ... // Do the search(es) ...
for (Message m : messages) { for (Message m : messages) {
String searchString = "HEADER Message-Id \"" + m.getMessageId() + "\""; final String searchString =
String[] newIdArray = newFolder.searchForUids(searchString); "HEADER Message-Id \"" + m.getMessageId() + "\"";
final String[] newIdArray = newFolder.searchForUids(searchString);
if (newIdArray.length == 1) { if (newIdArray.length == 1) {
callbacks.onMessageUidChange(m, newIdArray[0]); callbacks.onMessageUidChange(m, newIdArray[0]);
} }
@ -343,9 +346,10 @@ class ImapFolder extends Folder {
checkOpen(); checkOpen();
try { try {
int unreadMessageCount = 0; int unreadMessageCount = 0;
List<ImapResponse> responses = mConnection.executeSimpleCommand(String.format( final List<ImapResponse> responses = mConnection.executeSimpleCommand(
ImapConstants.STATUS + " \"%s\" (" + ImapConstants.UNSEEN + ")", String.format(Locale.US,
ImapStore.encodeFolderName(mName, mStore.mPathPrefix))); ImapConstants.STATUS + " \"%s\" (" + ImapConstants.UNSEEN + ")",
ImapStore.encodeFolderName(mName, mStore.mPathPrefix)));
// S: * STATUS mboxname (MESSAGES 231 UIDNEXT 44292) // S: * STATUS mboxname (MESSAGES 231 UIDNEXT 44292)
for (ImapResponse response : responses) { for (ImapResponse response : responses) {
if (response.isDataResponse(0, ImapConstants.STATUS)) { if (response.isDataResponse(0, ImapConstants.STATUS)) {
@ -407,7 +411,7 @@ class ImapFolder extends Folder {
public Message getMessage(String uid) throws MessagingException { public Message getMessage(String uid) throws MessagingException {
checkOpen(); checkOpen();
String[] uids = searchForUids(ImapConstants.UID + " " + uid); final String[] uids = searchForUids(ImapConstants.UID + " " + uid);
for (int i = 0; i < uids.length; i++) { for (int i = 0; i < uids.length; i++) {
if (uids[i].equals(uid)) { if (uids[i].equals(uid)) {
return new ImapMessage(uid, this); return new ImapMessage(uid, this);
@ -436,7 +440,7 @@ class ImapFolder extends Folder {
public Message[] getMessages(SearchParams params, MessageRetrievalListener listener) public Message[] getMessages(SearchParams params, MessageRetrievalListener listener)
throws MessagingException { throws MessagingException {
List<String> commands = new ArrayList<String>(); List<String> commands = new ArrayList<String>();
String filter = params.mFilter; final String filter = params.mFilter;
// All servers MUST accept US-ASCII, so we'll send this as the CHARSET unless we're really // All servers MUST accept US-ASCII, so we'll send this as the CHARSET unless we're really
// dealing with a string that contains non-ascii characters // dealing with a string that contains non-ascii characters
String charset = "US-ASCII"; String charset = "US-ASCII";
@ -444,7 +448,7 @@ class ImapFolder extends Folder {
charset = "UTF-8"; charset = "UTF-8";
} }
// This is the length of the string in octets (bytes), formatted as a string literal {n} // This is the length of the string in octets (bytes), formatted as a string literal {n}
String octetLength = "{" + filter.getBytes().length + "}"; final String octetLength = "{" + filter.getBytes().length + "}";
// Break the command up into pieces ending with the string literal length // Break the command up into pieces ending with the string literal length
commands.add(ImapConstants.UID_SEARCH + " CHARSET " + charset + " OR FROM " + octetLength); commands.add(ImapConstants.UID_SEARCH + " CHARSET " + charset + " OR FROM " + octetLength);
commands.add(filter + " (OR TO " + octetLength); commands.add(filter + " (OR TO " + octetLength);
@ -478,7 +482,7 @@ class ImapFolder extends Folder {
throw new MessagingException(String.format("Invalid range: %d %d", start, end)); throw new MessagingException(String.format("Invalid range: %d %d", start, end));
} }
return getMessagesInternal( return getMessagesInternal(
searchForUids(String.format("%d:%d NOT DELETED", start, end)), listener); searchForUids(String.format(Locale.US, "%d:%d NOT DELETED", start, end)), listener);
} }
@Override @Override
@ -564,7 +568,7 @@ class ImapFolder extends Folder {
final Part fetchPart = fp.getFirstPart(); final Part fetchPart = fp.getFirstPart();
if (fetchPart != null) { if (fetchPart != null) {
String[] partIds = final String[] partIds =
fetchPart.getHeader(MimeHeader.HEADER_ANDROID_ATTACHMENT_STORE_DATA); fetchPart.getHeader(MimeHeader.HEADER_ANDROID_ATTACHMENT_STORE_DATA);
if (partIds != null) { if (partIds != null) {
fetchFields.add(ImapConstants.FETCH_FIELD_BODY_PEEK_BARE fetchFields.add(ImapConstants.FETCH_FIELD_BODY_PEEK_BARE
@ -573,7 +577,7 @@ class ImapFolder extends Folder {
} }
try { try {
mConnection.sendCommand(String.format( mConnection.sendCommand(String.format(Locale.US,
ImapConstants.UID_FETCH + " %s (%s)", ImapStore.joinMessageUids(messages), ImapConstants.UID_FETCH + " %s (%s)", ImapStore.joinMessageUids(messages),
Utility.combine(fetchFields.toArray(new String[fetchFields.size()]), ' ') Utility.combine(fetchFields.toArray(new String[fetchFields.size()]), ' ')
), false); ), false);
@ -936,7 +940,7 @@ class ImapFolder extends Folder {
} }
mConnection.sendCommand( mConnection.sendCommand(
String.format(ImapConstants.APPEND + " \"%s\" (%s) {%d}", String.format(Locale.US, ImapConstants.APPEND + " \"%s\" (%s) {%d}",
ImapStore.encodeFolderName(mName, mStore.mPathPrefix), ImapStore.encodeFolderName(mName, mStore.mPathPrefix),
flagList, flagList,
out.getCount()), false); out.getCount()), false);
@ -975,19 +979,20 @@ class ImapFolder extends Folder {
* Message-ID header. If there are more than one response, take the * Message-ID header. If there are more than one response, take the
* last one, as it's most likely the newest (the one we just uploaded). * last one, as it's most likely the newest (the one we just uploaded).
*/ */
String messageId = message.getMessageId(); final String messageId = message.getMessageId();
if (messageId == null || messageId.length() == 0) { if (messageId == null || messageId.length() == 0) {
continue; continue;
} }
// Most servers don't care about parenthesis in the search query [and, some // Most servers don't care about parenthesis in the search query [and, some
// fail to work if they are used] // fail to work if they are used]
String[] uids = searchForUids(String.format("HEADER MESSAGE-ID %s", messageId)); String[] uids = searchForUids(
String.format(Locale.US, "HEADER MESSAGE-ID %s", messageId));
if (uids.length > 0) { if (uids.length > 0) {
message.setUid(uids[0]); message.setUid(uids[0]);
} }
// However, there's at least one server [AOL] that fails to work unless there // However, there's at least one server [AOL] that fails to work unless there
// are parenthesis, so, try this as a last resort // are parenthesis, so, try this as a last resort
uids = searchForUids(String.format("(HEADER MESSAGE-ID %s)", messageId)); uids = searchForUids(String.format(Locale.US, "(HEADER MESSAGE-ID %s)", messageId));
if (uids.length > 0) { if (uids.length > 0) {
message.setUid(uids[0]); message.setUid(uids[0]);
} }
@ -1035,7 +1040,7 @@ class ImapFolder extends Folder {
allFlags = flagList.substring(1); allFlags = flagList.substring(1);
} }
try { try {
mConnection.executeSimpleCommand(String.format( mConnection.executeSimpleCommand(String.format(Locale.US,
ImapConstants.UID_STORE + " %s %s" + ImapConstants.FLAGS_SILENT + " (%s)", ImapConstants.UID_STORE + " %s %s" + ImapConstants.FLAGS_SILENT + " (%s)",
ImapStore.joinMessageUids(messages), ImapStore.joinMessageUids(messages),
value ? "+" : "-", value ? "+" : "-",
@ -1072,8 +1077,8 @@ class ImapFolder extends Folder {
* must be selected. * must be selected.
*/ */
private void doSelect() throws IOException, MessagingException { private void doSelect() throws IOException, MessagingException {
List<ImapResponse> responses = mConnection.executeSimpleCommand( final List<ImapResponse> responses = mConnection.executeSimpleCommand(
String.format(ImapConstants.SELECT + " \"%s\"", String.format(Locale.US, ImapConstants.SELECT + " \"%s\"",
ImapStore.encodeFolderName(mName, mStore.mPathPrefix))); ImapStore.encodeFolderName(mName, mStore.mPathPrefix)));
// Assume the folder is opened read-write; unless we are notified otherwise // Assume the folder is opened read-write; unless we are notified otherwise

View File

@ -384,7 +384,7 @@ public class ImapService extends Service {
Store remoteStore = Store.getInstance(account, context); Store remoteStore = Store.getInstance(account, context);
// The account might have been deleted // The account might have been deleted
if (remoteStore == null) return; if (remoteStore == null) return;
Folder remoteFolder = remoteStore.getFolder(mailbox.mServerId); final Folder remoteFolder = remoteStore.getFolder(mailbox.mServerId);
/* /*
* If the folder is a "special" folder we need to see if it exists * If the folder is a "special" folder we need to see if it exists
@ -431,7 +431,7 @@ public class ImapService extends Service {
// 7. Create a list of messages to download // 7. Create a list of messages to download
Message[] remoteMessages = new Message[0]; Message[] remoteMessages = new Message[0];
final ArrayList<Message> unsyncedMessages = new ArrayList<Message>(); final ArrayList<Message> unsyncedMessages = new ArrayList<Message>();
HashMap<String, Message> remoteUidMap = new HashMap<String, Message>(); final HashMap<String, Message> remoteUidMap = new HashMap<String, Message>();
if (remoteMessageCount > 0) { if (remoteMessageCount > 0) {
/* /*
@ -532,8 +532,9 @@ public class ImapService extends Service {
} }
// 10. Remove any messages that are in the local store but no longer on the remote store. // 10. Remove any messages that are in the local store but no longer on the remote store.
HashSet<String> localUidsToDelete = new HashSet<String>(localMessageMap.keySet()); final HashSet<String> localUidsToDelete = new HashSet<String>(localMessageMap.keySet());
localUidsToDelete.removeAll(remoteUidMap.keySet()); localUidsToDelete.removeAll(remoteUidMap.keySet());
for (String uidToDelete : localUidsToDelete) { for (String uidToDelete : localUidsToDelete) {
LocalMessageInfo infoToDelete = localMessageMap.get(uidToDelete); LocalMessageInfo infoToDelete = localMessageMap.get(uidToDelete);

View File

@ -45,7 +45,7 @@ import com.android.emailcommon.service.EmailServiceProxy;
import java.util.ArrayList; import java.util.ArrayList;
public class PopImapSyncAdapterService extends Service { public class PopImapSyncAdapterService extends Service {
private static final String TAG = "PopImapSyncAdapterService"; private static final String TAG = "PopImapSyncService";
private static SyncAdapterImpl sSyncAdapter = null; private static SyncAdapterImpl sSyncAdapter = null;
private static final Object sSyncAdapterLock = new Object(); private static final Object sSyncAdapterLock = new Object();