1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.geronimo.javamail.store.imap.connection; 19 import java.util.ArrayList; 20 import java.util.HashMap; 21 import java.util.List; 22 import java.util.Map; 23 24 import javax.mail.MessagingException; 25 26 import org.apache.geronimo.javamail.store.imap.connection.IMAPResponseTokenizer.Token; 27 28 /** 29 * Util class to represent a CAPABILITY response from a IMAP server 30 * 31 * @version $Rev: 594520 $ $Date: 2007-11-13 07:57:39 -0500 (Tue, 13 Nov 2007) $ 32 */ 33 public class IMAPCapabilityResponse extends IMAPUntaggedResponse { 34 // the advertised capabilities 35 protected Map capabilities = new HashMap(); 36 // the authentication mechanisms. The order is important with 37 // the authentications, as we a) want to process these in the 38 // order presented, and b) need to convert them into String arrays 39 // for Sasl API calls. 40 protected List authentications = new ArrayList(); 41 42 /** 43 * Create a reply object from a server response line (normally, untagged). This includes 44 * doing the parsing of the response line. 45 * 46 * @param response The response line used to create the reply object. 47 */ 48 public IMAPCapabilityResponse(IMAPResponseTokenizer source, byte [] response) throws MessagingException { 49 super("CAPABILITY", response); 50 51 // parse each of the capability tokens. We're using the default RFC822 parsing rules, 52 // which does not consider "=" to be a delimiter token, so all "AUTH=" capabilities will 53 // come through as a single token. 54 while (source.hasMore()) { 55 // the capabilities are always ATOMs. 56 String value = source.readAtom().toUpperCase(); 57 // is this an authentication option? 58 if (value.startsWith("AUTH=")) { 59 // parse off the mechanism that fillows the "=", and add this to the supported list. 60 String mechanism = value.substring(5); 61 authentications.add(mechanism); 62 } 63 else { 64 // just add this to the capabilities map. 65 capabilities.put(value, value); 66 } 67 } 68 } 69 70 71 /** 72 * Return the capability map for the server. 73 * 74 * @return A map of the capability items. 75 */ 76 public Map getCapabilities() { 77 return capabilities; 78 } 79 80 /** 81 * Retrieve the map of the server-supported authentication 82 * mechanisms. 83 * 84 * @return 85 */ 86 public List getAuthentications() { 87 return authentications; 88 } 89 } 90