1 /*
2 * Copyright (c) 2004-2007 Creative Sphere Limited.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *
10 * Creative Sphere - initial API and implementation
11 *
12 */
13 package org.abstracthorizon.mercury.imap.response;
14
15 import javax.mail.Folder;
16 import javax.mail.MessagingException;
17 import org.abstracthorizon.mercury.imap.IMAPSession;
18
19 /**
20 * List response
21 *
22 * @author Daniel Sendula
23 */
24 public class ListResponse extends MnemonicResponse {
25
26 /** Message */
27 protected String msg;
28
29 /**
30 * Constructor
31 * @param session imap session
32 * @param f folder
33 * @throws MessagingException
34 */
35 public ListResponse(IMAPSession session, Folder f) throws MessagingException {
36 this(session, "LIST", f);
37 }
38
39 /**
40 * Constructor
41 * @param session imap session
42 * @param mnemonic mnemonic
43 * @param f folder
44 * @throws MessagingException
45 */
46 protected ListResponse(IMAPSession session, String mnemonic, Folder f) throws MessagingException {
47 super(session, Response.UNTAGGED_RESPONSE, mnemonic, composeMessage(f));
48 }
49
50 /**
51 * Composes the message
52 * @param f folder
53 * @return string representation
54 * @throws MessagingException
55 */
56 public static final String composeMessage(Folder f) throws MessagingException {
57 String flags = "";
58 if ((f.getType() & Folder.HOLDS_FOLDERS) == 0) {
59 flags = "\\Noinferiors";
60 } else if ((f.getType() & Folder.HOLDS_MESSAGES) == 0) {
61 flags = "\\Noselect";
62 }
63 return "("+flags+") \""+f.getSeparator()+"\" \""+f.getFullName()+"\"";
64 }
65
66 }