Cleaned up ImapStore.ImapFolder.appendMessages()
This commit is contained in:
parent
8e1627e1b9
commit
396005974a
1 changed files with 47 additions and 38 deletions
|
@ -54,7 +54,6 @@ 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;
|
||||
|
@ -62,6 +61,7 @@ import com.fsck.k9.Account;
|
|||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.R;
|
||||
import com.fsck.k9.controller.MessageRetrievalListener;
|
||||
import com.fsck.k9.helper.StringUtils;
|
||||
import com.fsck.k9.helper.Utility;
|
||||
import com.fsck.k9.helper.power.TracingPowerManager;
|
||||
import com.fsck.k9.helper.power.TracingPowerManager.TracingWakeLock;
|
||||
|
@ -1099,7 +1099,6 @@ public class ImapStore extends Store {
|
|||
do {
|
||||
response = mConnection.readResponse();
|
||||
handleUntaggedResponse(response);
|
||||
while (response.more());
|
||||
} while (response.mTag == null);
|
||||
|
||||
/*
|
||||
|
@ -1953,21 +1952,30 @@ public class ImapStore extends Store {
|
|||
}
|
||||
|
||||
/**
|
||||
* Appends the given messages to the selected folder. This implementation also determines
|
||||
* the new UID of the given message on the IMAP server and sets the Message's UID to the
|
||||
* new server UID.
|
||||
* Appends the given messages to the selected folder.
|
||||
*
|
||||
* <p>
|
||||
* This implementation also determines the new UIDs of the given messages on the IMAP
|
||||
* server and changes the messages' UIDs to the new server UIDs.
|
||||
* </p>
|
||||
*
|
||||
* @param messages
|
||||
* The messages to append to the folder.
|
||||
*
|
||||
* @return The mapping of original message UIDs to the new server UIDs.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> appendMessages(Message[] messages) throws MessagingException {
|
||||
checkOpen();
|
||||
try {
|
||||
Map<String, String> uidMap = null;
|
||||
Map<String, String> uidMap = new HashMap<String, String>();
|
||||
for (Message message : messages) {
|
||||
mConnection.sendCommand(
|
||||
String.format("APPEND %s (%s) {%d}",
|
||||
encodeString(encodeFolderName(getPrefixedName())),
|
||||
combineFlags(message.getFlags()),
|
||||
message.calculateSize()), false);
|
||||
|
||||
ImapResponse response;
|
||||
do {
|
||||
response = mConnection.readResponse();
|
||||
|
@ -1981,53 +1989,54 @@ public class ImapStore extends Store {
|
|||
}
|
||||
} 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 (response.size() > 1) {
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
Object responseList = response.get(1);
|
||||
|
||||
if (responseList instanceof ImapList) {
|
||||
final ImapList appendList = (ImapList) responseList;
|
||||
if ((appendList.size() >= 3) && appendList.getString(0).equals("APPENDUID")) {
|
||||
String newUid = appendList.getString(2);
|
||||
if (responseList instanceof ImapList) {
|
||||
ImapList appendList = (ImapList) responseList;
|
||||
if (appendList.size() >= 3 &&
|
||||
appendList.getString(0).equals("APPENDUID")) {
|
||||
|
||||
/*
|
||||
* We need uidMap to be null initially to maintain consistency with the behavior of other similar methods (copyMessages, moveMessages) which
|
||||
* return null if new UIDs are not available. Therefore, we initialize uidMap over here.
|
||||
*/
|
||||
if (uidMap == null) {
|
||||
uidMap = new HashMap<String, String>();
|
||||
}
|
||||
uidMap.put(message.getUid(), newUid);
|
||||
if (!TextUtils.isEmpty(newUid)) {
|
||||
message.setUid(newUid);
|
||||
continue;
|
||||
String newUid = appendList.getString(2);
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(newUid)) {
|
||||
message.setUid(newUid);
|
||||
uidMap.put(message.getUid(), newUid);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This part is executed in case the server does not support UIDPLUS or does not implement the APPENDUID response code.
|
||||
* 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)
|
||||
if (K9.DEBUG) {
|
||||
Log.d(K9.LOG_TAG, "Got UID " + newUid + " for message for " + getLogId());
|
||||
}
|
||||
|
||||
if (newUid != null) {
|
||||
if (uidMap == null) {
|
||||
uidMap = new HashMap<String, String>();
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(newUid)) {
|
||||
uidMap.put(message.getUid(), newUid);
|
||||
message.setUid(newUid);
|
||||
}
|
||||
}
|
||||
return uidMap;
|
||||
|
||||
/*
|
||||
* We need uidMap to be null if new UIDs are not available to maintain consistency
|
||||
* with the behavior of other similar methods (copyMessages, moveMessages) which
|
||||
* return null.
|
||||
*/
|
||||
return (uidMap.size() == 0) ? null : uidMap;
|
||||
} catch (IOException ioe) {
|
||||
throw ioExceptionHandler(mConnection, ioe);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue