use of com.fsck.k9.controller.MessagingControllerCommands.PendingAppend in project k-9 by k9mail.
the class MigrationTo60Test method migrateAppend.
@Test
public void migrateAppend() {
OldPendingCommand command = queueAppend(SOURCE_FOLDER, UID);
PendingAppend pendingCommand = (PendingAppend) MigrationTo60.migratePendingCommand(command);
assertEquals(SOURCE_FOLDER, pendingCommand.folder);
assertEquals(UID, pendingCommand.uid);
}
use of com.fsck.k9.controller.MessagingControllerCommands.PendingAppend in project k-9 by k9mail.
the class MessagingController method processPendingAppend.
/**
* Process a pending append message command. This command uploads a local message to the
* server, first checking to be sure that the server message is not newer than
* the local message. Once the local message is successfully processed it is deleted so
* that the server message will be synchronized down without an additional copy being
* created.
*/
void processPendingAppend(PendingAppend command, Account account) throws MessagingException {
LocalStore localStore = localStoreProvider.getInstance(account);
long folderId = command.folderId;
LocalFolder localFolder = localStore.getFolder(folderId);
localFolder.open();
String folderServerId = localFolder.getServerId();
String uid = command.uid;
LocalMessage localMessage = localFolder.getMessage(uid);
if (localMessage == null) {
return;
}
if (!localMessage.getUid().startsWith(K9.LOCAL_UID_PREFIX)) {
// FIXME: This should never happen. Throw in debug builds.
return;
}
Backend backend = getBackend(account);
if (localMessage.isSet(Flag.X_REMOTE_COPY_STARTED)) {
Timber.w("Local message with uid %s has flag %s already set, checking for remote message with " + "same message id", localMessage.getUid(), X_REMOTE_COPY_STARTED);
String messageServerId = backend.findByMessageId(folderServerId, localMessage.getMessageId());
if (messageServerId != null) {
Timber.w("Local message has flag %s already set, and there is a remote message with uid %s, " + "assuming message was already copied and aborting this copy", X_REMOTE_COPY_STARTED, messageServerId);
String oldUid = localMessage.getUid();
localMessage.setUid(messageServerId);
localFolder.changeUid(localMessage);
for (MessagingListener l : getListeners()) {
l.messageUidChanged(account, folderId, oldUid, localMessage.getUid());
}
return;
} else {
Timber.w("No remote message with message-id found, proceeding with append");
}
}
/*
* If the message does not exist remotely we just upload it and then
* update our local copy with the new uid.
*/
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.BODY);
localFolder.fetch(Collections.singletonList(localMessage), fp, null);
String oldUid = localMessage.getUid();
localMessage.setFlag(Flag.X_REMOTE_COPY_STARTED, true);
String messageServerId = backend.uploadMessage(folderServerId, localMessage);
if (messageServerId == null) {
// We didn't get the server UID of the uploaded message. Remove the local message now. The uploaded
// version will be downloaded during the next sync.
localFolder.destroyMessages(Collections.singletonList(localMessage));
} else {
localMessage.setUid(messageServerId);
localFolder.changeUid(localMessage);
for (MessagingListener l : getListeners()) {
l.messageUidChanged(account, folderId, oldUid, localMessage.getUid());
}
}
}
use of com.fsck.k9.controller.MessagingControllerCommands.PendingAppend in project k-9 by k9mail.
the class PendingCommandSerializerTest method testSerializeDeserialize__withArguments.
@Test
public void testSerializeDeserialize__withArguments() {
PendingCommand pendingCommand = PendingAppend.create(SOURCE_FOLDER_ID, UID);
String serializedCommand = pendingCommandSerializer.serialize(pendingCommand);
PendingAppend unserializedCommand = (PendingAppend) pendingCommandSerializer.unserialize(DATABASE_ID, pendingCommand.getCommandName(), serializedCommand);
assertEquals(DATABASE_ID, unserializedCommand.databaseId);
assertEquals(SOURCE_FOLDER_ID, unserializedCommand.folderId);
assertEquals(UID, unserializedCommand.uid);
}
Aggregations