1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.mercury.imap.cmd;
14
15 import java.io.IOException;
16 import javax.mail.Folder;
17 import javax.mail.MessagingException;
18 import javax.mail.Store;
19 import org.abstracthorizon.mercury.imap.IMAPSession;
20 import org.abstracthorizon.mercury.imap.response.ListResponse;
21 import org.abstracthorizon.mercury.imap.util.ParserException;
22 import org.abstracthorizon.mercury.imap.util.IMAPScanner;
23
24
25
26
27
28
29 public class List extends IMAPCommand {
30
31
32
33
34
35 public List(String mnemonic) {
36 super(mnemonic);
37 }
38
39
40
41
42
43
44
45
46
47 protected void execute(IMAPSession session) throws ParserException, MessagingException, IOException {
48 Store store = session.getStore();
49 StringBuffer name = new StringBuffer();
50 StringBuffer expr = new StringBuffer();
51 IMAPScanner scanner = session.getScanner();
52
53 if (!scanner.mailbox(name)) {
54 throw new ParserException("<mailbox_name>");
55 }
56 if (!scanner.is_char(' ')) {
57 throw new ParserException("<SP>");
58 }
59 if (!scanner.list_mailbox(expr)) {
60 throw new ParserException("<expr>");
61 }
62 checkEOL(session);
63
64 Folder root = store.getFolder(name.toString());
65
66 Folder[] res = root.list(expr.toString());
67 if (res.length > 0) {
68 for (int i=0; i<res.length; i++) {
69 new ListResponse(session, res[i]).submit();
70 }
71 }
72 sendOK(session);
73 }
74 }