001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.geronimo.javamail.store.imap.connection;
019    
020    import java.util.List;
021    
022    import javax.mail.MessagingException;
023    
024    /**
025     * Util class to represent a list response from a IMAP server
026     *
027     * @version $Rev: 594520 $ $Date: 2007-11-13 07:57:39 -0500 (Tue, 13 Nov 2007) $
028     */
029    
030    public class IMAPListResponse extends IMAPUntaggedResponse {
031        // parsed flag responses
032        public boolean noinferiors = false;
033        public boolean noselect = false;
034        public boolean marked = false;
035        public boolean unmarked = false;
036    
037        // the name separator character
038        public char separator;
039        // the mail box name
040        public String mailboxName;
041        // this is for support of the get attributes command
042        public String[] attributes;
043    
044        /**
045         * Construct a LIST response item.  This can be either 
046         * a response from a LIST command or an LSUB command, 
047         * and will be tagged accordingly.
048         * 
049         * @param type   The type of resonse (LIST or LSUB).
050         * @param data   The raw response data.
051         * @param source The tokenizer source.
052         * 
053         * @exception MessagingException
054         */
055        public IMAPListResponse(String type, byte[] data, IMAPResponseTokenizer source) throws MessagingException {
056            super(type, data); 
057    
058            // parse the list of flag values
059            List flags = source.readSystemNameList(); 
060            
061            // copy this into the attributes array. 
062            attributes = new String[flags.size()]; 
063            attributes = (String[])flags.toArray(attributes); 
064    
065            for (int i = 0; i < flags.size(); i++) {
066                String flag = ((String)flags.get(i));
067    
068                if (flag.equalsIgnoreCase("\\Marked")) {
069                    marked = true;
070                }
071                else if (flag.equalsIgnoreCase("\\Unmarked")) {
072                    unmarked = true;
073                }
074                else if (flag.equalsIgnoreCase("\\Noselect")) {
075                    noselect = true;
076                }
077                else if (flag.equalsIgnoreCase("\\Noinferiors")) {
078                    noinferiors = true;
079                }
080            }
081    
082            // set a default sep value 
083            separator = '\0';    
084            // get the separator and name tokens
085            String separatorString = source.readQuotedStringOrNil();
086            if (separatorString != null && separatorString.length() == 1) {
087                separator = separatorString.charAt(0); 
088            }
089            mailboxName = source.readEncodedString();
090        }
091    }
092