From 970271dbf943e6a71dcb262832c2eaff5880b7cb Mon Sep 17 00:00:00 2001 From: Apoorv Khatreja Date: Tue, 21 Jun 2011 04:34:57 +0530 Subject: [PATCH] If the response for an APPEND command contains the APPENDUID response code, read the UID of the newly appended message from there. --- src/com/fsck/k9/mail/store/ImapStore.java | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index b639a11f2..f37e44de8 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -52,6 +52,7 @@ import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.PowerManager; +import android.text.TextUtils; import android.util.Log; import com.beetstra.jutf7.CharsetProvider; @@ -1617,6 +1618,31 @@ public class ImapStore extends Store { while (response.more()); } while (response.mTag == null); + /* + * If the server supports UIDPLUS, then along with the APPEND response it will return an APPENDUID response code. + * e.g. 11 OK [APPENDUID 2 238268] APPEND completed + * + * We can use the UID included in this response to update our records. + * + * Code imported from AOSP Email as of git rev a5c3744a247e432acf9f571a9dfb55321c4baa1a + */ + Object responseList = response.get(1); + + if (responseList instanceof ImapList) { + final ImapList appendList = (ImapList) responseList; + if ((appendList.size() >= 3) && appendList.getString(0).equals("APPENDUID")) { + String serverUid = appendList.getString(2); + if (!TextUtils.isEmpty(serverUid)) { + message.setUid(serverUid); + continue; + } + } + } + + + /* + * This part is executed in case the server does not support UIDPLUS or does not implement the APPENDUID response code. + */ String newUid = getUidFromMessageId(message); if (K9.DEBUG) Log.d(K9.LOG_TAG, "Got UID " + newUid + " for message for " + getLogId());