-
Notifications
You must be signed in to change notification settings - Fork 182
/
MoveCommand.java
92 lines (81 loc) · 2.95 KB
/
MoveCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Copyright (c) 2014 Wael Chatila / Icegreen Technologies. All Rights Reserved.
* This software is released under the Apache license 2.0
* This file has been modified by the copyright holder.
* Original file can be found at http://james.apache.org
*/
package com.icegreen.greenmail.imap.commands;
import com.icegreen.greenmail.imap.*;
import com.icegreen.greenmail.store.FolderException;
import com.icegreen.greenmail.store.MailFolder;
import java.util.ArrayList;
import java.util.List;
/**
* Handles MOVE imap command.
* <p>
* See https://www.ietf.org/rfc/rfc6851.txt
* <p>
* capability =/ "MOVE"
* <p>
* command-select =/ move
* move = "MOVE" SP sequence-set SP mailbox
* uid = "UID" SP (copy / fetch / search / store / move)
*/
class MoveCommand extends SelectedStateCommand implements UidEnabledCommand {
public static final String NAME = "MOVE";
public static final String ARGS = "<sequence-set> <mailbox>";
public static final String CAPABILITY = "MOVE";
MoveCommand() {
super(NAME, ARGS);
}
/**
* @see CommandTemplate#doProcess
*/
@Override
protected void doProcess(ImapRequestLineReader request,
ImapResponse response,
ImapSession session)
throws ProtocolException, FolderException {
doProcess(request, response, session, false);
}
@Override
public void doProcess(ImapRequestLineReader request,
ImapResponse response,
ImapSession session,
boolean useUids)
throws ProtocolException, FolderException {
IdRange[] idSet = parser.parseIdRange(request);
String mailboxName = parser.mailbox(request);
parser.endLine(request);
ImapSessionFolder currentMailbox = session.getSelected();
MailFolder toFolder;
try {
toFolder = getMailbox(mailboxName, session, true);
} catch (FolderException e) {
e.setResponseCode("TRYCREATE");
throw e;
}
List<Long> copiedUidsOld = new ArrayList<>();
List<Long> copiedUidsNew = new ArrayList<>();
long[] uids = currentMailbox.getMessageUids();
for (long uid : uids) {
boolean inSet;
if (useUids) {
inSet = includes(idSet, uid);
} else {
int msn = currentMailbox.getMsn(uid);
inSet = includes(idSet, msn);
}
if (inSet) {
long copiedUid = currentMailbox.moveMessage(uid, toFolder);
copiedUidsOld.add(uid);
copiedUidsNew.add(copiedUid);
}
}
if (useUids) {
response.okResponse(CopyCommand.generateCopyUidResponseCode(toFolder, copiedUidsOld, copiedUidsNew), "");
}
session.unsolicitedResponses(response); // EXPUNGE responses
response.commandComplete(this);
}
}