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 import java.util.ArrayList;
020 import java.util.HashMap;
021 import java.util.List;
022 import java.util.Map;
023
024 import javax.mail.MessagingException;
025
026 import org.apache.geronimo.javamail.store.imap.connection.IMAPResponseTokenizer.Token;
027
028 /**
029 * Util class to represent a CAPABILITY response from a IMAP server
030 *
031 * @version $Rev: 594520 $ $Date: 2007-11-13 07:57:39 -0500 (Tue, 13 Nov 2007) $
032 */
033 public class IMAPCapabilityResponse extends IMAPUntaggedResponse {
034 // the advertised capabilities
035 protected Map capabilities = new HashMap();
036 // the authentication mechanisms. The order is important with
037 // the authentications, as we a) want to process these in the
038 // order presented, and b) need to convert them into String arrays
039 // for Sasl API calls.
040 protected List authentications = new ArrayList();
041
042 /**
043 * Create a reply object from a server response line (normally, untagged). This includes
044 * doing the parsing of the response line.
045 *
046 * @param response The response line used to create the reply object.
047 */
048 public IMAPCapabilityResponse(IMAPResponseTokenizer source, byte [] response) throws MessagingException {
049 super("CAPABILITY", response);
050
051 // parse each of the capability tokens. We're using the default RFC822 parsing rules,
052 // which does not consider "=" to be a delimiter token, so all "AUTH=" capabilities will
053 // come through as a single token.
054 while (source.hasMore()) {
055 // the capabilities are always ATOMs.
056 String value = source.readAtom().toUpperCase();
057 // is this an authentication option?
058 if (value.startsWith("AUTH=")) {
059 // parse off the mechanism that fillows the "=", and add this to the supported list.
060 String mechanism = value.substring(5);
061 authentications.add(mechanism);
062 }
063 else {
064 // just add this to the capabilities map.
065 capabilities.put(value, value);
066 }
067 }
068 }
069
070
071 /**
072 * Return the capability map for the server.
073 *
074 * @return A map of the capability items.
075 */
076 public Map getCapabilities() {
077 return capabilities;
078 }
079
080 /**
081 * Retrieve the map of the server-supported authentication
082 * mechanisms.
083 *
084 * @return
085 */
086 public List getAuthentications() {
087 return authentications;
088 }
089 }
090