Permalink
Browse files

start implementing delete/move messages features

  • Loading branch information...
1 parent adf0183 commit 9eb7067a368d99d6087d5c5c7fab484799e4de14 Vincent Richomme committed Mar 7, 2012
@@ -421,6 +421,61 @@ public JSONObject mailContentForMessageId(JSONObject parameters, HttpSession htt
}
}
+
+
+ public JSONObject moveMessages(JSONObject parameters, HttpSession httpSession, Boolean isDelete) throws MessagingException, IOException {
+ Store imapStore = ImapSession.imapConnect(httpSession); // TODO: get cached opened
+ // and connected imapStore,
+ // or reconnect.
+
+ JSONObject result = new JSONObject();
+ Folder srcFolder = null;
+ Folder dstFolder = null;
+
+ try {
+ srcFolder = imapStore.getFolder(parameters.getString("srcFolder"));
+ srcFolder.open(Folder.READ_WRITE);
+ dstFolder = imapStore.getFolder(parameters.getString("dstFolder"));
+
+ JSONArray messageIds = parameters.getJSONArray("messageIds");
+ if (messageIds != null)
+ {
+ for (int i=0;i < messageIds.size();i++) {
+
+ String messageId = messageIds.getString(i);
+ Message[] messages = srcFolder.search(new MessageIDTerm(messageId));
+ if (messages.length > 0)
+ {
+ srcFolder.copyMessages(messages, dstFolder);
+
+ for(int j = 0; j < messages.length; j++)
+ {
+ messages[j].setFlag(Flags.Flag.DELETED, true);
+ }
+ }
+ }
+
+ result.put("messagesMoved","OK");
+ }
+ }
+ finally {
+ srcFolder.close(true);
+ imapStore.close();
+ }
+
+ return result;
+ }
+
+
+ public JSONObject deleteMessages(JSONObject parameters, HttpSession httpSession) throws MessagingException, IOException {
+ // Don't really like to pass arguments as JSONObject.
+ // I would prefer a more static api.
+
+ parameters.put("dstFolder", "Trash");
+ return moveMessages(parameters, httpSession, true);
+ }
+
+
/*
* Rename IMAP folder.
* Result is "" if no errors, or result is string with
@@ -646,11 +646,40 @@ var IsReadImage,
[[emailContextMenu addItemWithTitle:@"Forward" action:nil keyEquivalent:nil] setTarget:self];
[[emailContextMenu addItemWithTitle:@"Mark as Read" action:nil keyEquivalent:nil] setTarget:self];
[[emailContextMenu addItemWithTitle:@"Mark as Unread" action:nil keyEquivalent:nil] setTarget:self];
- [[emailContextMenu addItemWithTitle:@"Delete" action:nil keyEquivalent:nil] setTarget:self];
+ [[emailContextMenu addItemWithTitle:@"Delete" action:@selector(deleteMessages:) keyEquivalent:nil] setTarget:self];
return emailContextMenu;
}
+- (IBAction)deleteMessages:(id)sender
+{
+ CPLog.trace(@"deleteMessages");
+
+ //var row = [emailsHeaderView selectedRow];
+ var msgIds = [CPMutableArray array];
+ var folderName = [self.selectedMailbox name]
+ var indexes = [emailsHeaderView selectedRowIndexes]
+ for (var j=0; j<[indexes count]; j++)
+ {
+ var msgId = [[[selectedMailbox mailHeaders] objectAtIndex:j] messageId]
+ [msgIds addObject:msgId];
+ }
+
+ [_serverConnection callRemoteFunction:@"deleteMessages"
+ withFunctionParametersAsObject:{ "messageIds":msgIds, "srcFolder":folderName }
+ delegate:self
+ didEndSelector:@selector(imapServerMessagesDeleted:withParametersObject:)
+ error:nil];
+
+
+}
+
+- (void)imapServerMessagesDeleted:(id)sender withParametersObject:parametersObject
+{
+ CPLog.debug(@"%@%@", _cmd, "TEST");
+ [emailsHeaderView reloadData];
+}
+
- (IBAction)openMessage:(id)sender
{

0 comments on commit 9eb7067

Please sign in to comment.