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.common.command.CommandException;
20 import org.abstracthorizon.mercury.imap.IMAPSession;
21 import org.abstracthorizon.mercury.imap.response.LsubResponse;
22 import org.abstracthorizon.mercury.imap.util.ParserException;
23 import org.abstracthorizon.mercury.imap.util.IMAPScanner;
24
25
26
27
28
29
30 public class LSub extends IMAPCommand {
31
32
33
34
35
36 public LSub(String mnemonic) {
37 super(mnemonic);
38 }
39
40
41
42
43
44
45
46
47
48 protected void execute(IMAPSession session) throws ParserException, MessagingException, CommandException, IOException {
49 Store store = session.getStore();
50 StringBuffer name = new StringBuffer();
51 StringBuffer expr = new StringBuffer();
52 IMAPScanner scanner = session.getScanner();
53
54
55 if (!scanner.mailbox(name)) {
56 throw new ParserException("<mailbox_name>");
57 }
58 if (!scanner.is_char(' ')) {
59 throw new ParserException("<SP>");
60 }
61 if (!scanner.list_mailbox(expr)) {
62 throw new ParserException("<expr>");
63 }
64 checkEOL(session);
65
66 Folder root = store.getFolder(name.toString());
67
68 Folder[] res = root.list(expr.toString());
69 if (res.length > 0) {
70 for (int i=0; i<res.length; i++) {
71 new LsubResponse(session, res[i]).submit();
72 }
73 }
74 sendOK(session);
75 }
76 }