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
019 package org.apache.geronimo.javamail.store.pop3;
020
021 import javax.mail.Folder;
022 import javax.mail.Message;
023 import javax.mail.MessagingException;
024 import javax.mail.MethodNotSupportedException;
025 import javax.mail.Store;
026
027 import org.apache.geronimo.javamail.store.pop3.connection.POP3Connection;
028
029 /**
030 * An POP3 folder instance for the root of POP3 folder tree. This has
031 * some of the folder operations disabled.
032 */
033 public class POP3RootFolder extends POP3Folder {
034 // the inbox folder is the only one that exists
035 protected Folder inbox;
036
037 /**
038 * Create a default POP3RootFolder attached to a specific Store instance.
039 *
040 * @param store The Store instance this is the root for.
041 */
042 public POP3RootFolder(POP3Store store) {
043 // create a folder with a null string name and the default separator.
044 super(store, "");
045 // this only holds folders
046 folderType = HOLDS_FOLDERS;
047 // this folder does exist
048 exists = true;
049 // no messages in this folder
050 msgCount = 0;
051 }
052
053
054 /**
055 * Get the parent. This is the root folder, which
056 * never has a parent.
057 *
058 * @return Always returns null.
059 */
060 public Folder getParent() {
061 // we never have a parent folder
062 return null;
063 }
064
065 /**
066 * We have a separator because the root folder is "special".
067 */
068 public char getSeparator() throws MessagingException {
069 return '/';
070 }
071
072 /**
073 * Retrieve a list of folders that match a pattern.
074 *
075 * @param pattern The match pattern.
076 *
077 * @return An array of matching folders.
078 * @exception MessagingException
079 */
080 public Folder[] list(String pattern) throws MessagingException {
081 // I'm not sure this is correct, but the Sun implementation appears to
082 // return a array containing the inbox regardless of what pattern was specified.
083 return new Folder[] { getInbox() };
084 }
085
086 /**
087 * Get a folder of a given name from the root folder.
088 * The Sun implementation seems somewhat inconsistent
089 * here. The docs for Store claim that only INBOX is
090 * supported, but it will return a Folder instance for any
091 * name. On the other hand, the root folder raises
092 * an exception for anything but the INBOX.
093 *
094 * @param name The folder name (which must be "INBOX".
095 *
096 * @return The inbox folder instance.
097 * @exception MessagingException
098 */
099 public Folder getFolder(String name) throws MessagingException {
100 if (!name.equalsIgnoreCase("INBOX")) {
101 throw new MessagingException("Only the INBOX folder is supported");
102 }
103 // return the inbox folder
104 return getInbox();
105 }
106
107 /**
108 * Override for the isOpen method. The root folder can
109 * never be opened.
110 *
111 * @return always returns false.
112 */
113 public boolean isOpen() {
114 return false;
115 }
116
117 public void open(int mode) throws MessagingException {
118 throw new MessagingException("POP3 root folder cannot be opened");
119 }
120
121 public void open(boolean expunge) throws MessagingException {
122 throw new MessagingException("POP3 root folder cannot be close");
123 }
124
125
126 /**
127 * Retrieve the INBOX folder from the root.
128 *
129 * @return The Folder instance for the inbox.
130 * @exception MessagingException
131 */
132 protected Folder getInbox() throws MessagingException {
133 // we're the only place that creates folders, and
134 // we only create the single instance.
135 if (inbox == null) {
136 inbox = new POP3Folder((POP3Store)store, "INBOX");
137 }
138 return inbox;
139 }
140 }
141
142