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.imap;
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.imap.connection.IMAPConnection;
028 import org.apache.geronimo.javamail.store.imap.connection.IMAPEnvelope;
029 import org.apache.geronimo.javamail.store.imap.connection.IMAPBodyStructure;
030
031 /**
032 * An IMAP folder instance for the root of IMAP folder tree. This has
033 * some of the folder operations disabled.
034 */
035 public class IMAPRootFolder extends IMAPFolder {
036
037 /**
038 * Create a default IMAPRootFolder attached to a specific Store instance.
039 *
040 * @param store The Store instance this is the root for.
041 */
042 public IMAPRootFolder(IMAPStore 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 }
048
049 /**
050 * Get the Folder determined by the supplied name; if the name is relative
051 * then it is interpreted relative to this folder. This does not check that
052 * the named folder actually exists.
053 *
054 * @param name the name of the folder to return
055 * @return the named folder
056 * @throws MessagingException if there was a problem accessing the store
057 */
058 public Folder getFolder(String name) throws MessagingException {
059 // The root folder is a dummy one. Any getFolder() request starting
060 // at the root will use the request name for the full name. The separator
061 // used in that folder's namespace will be determined when the folder is
062 // first opened.
063 return new IMAPFolder((IMAPStore)store, name, UNDETERMINED);
064 }
065
066
067 public Folder getParent() {
068 // we never have a parent folder
069 return null;
070 }
071
072
073 public boolean exists() throws MessagingException {
074 // this always exists
075 return true;
076 }
077
078 public boolean hasNewMessages() {
079 // we don't really exist, so the answer is always false.
080 return false;
081 }
082
083
084 public int getMessagesCount() {
085 // we don't really exist, so the answer is always 0;
086 return 0;
087 }
088
089
090 public int getNewMessagesCount() {
091 // we don't really exist, so the answer is always 0;
092 return 0;
093 }
094
095
096 public int getUnreadMessagesCount() {
097 // we don't really exist, so the answer is always 0;
098 return 0;
099 }
100
101
102 public int getDeletedMessagesCount() {
103 // we don't really exist, so the answer is always 0;
104 return 0;
105 }
106
107
108 public boolean create(int newType) throws MessagingException {
109 throw new MethodNotSupportedException("Default IMAP folder cannot be created");
110 }
111
112 public boolean delete(boolean recurse) throws MessagingException {
113 throw new MethodNotSupportedException("Default IMAP folder cannot be deleted");
114 }
115
116
117 public boolean rename(boolean recurse) throws MessagingException {
118 throw new MethodNotSupportedException("Default IMAP folder cannot be renamed");
119 }
120
121
122 public void appendMessages(Message[] msgs) throws MessagingException {
123 throw new MethodNotSupportedException("Messages cannot be appended to Default IMAP folder");
124 }
125
126
127 public Message[] expunge() throws MessagingException {
128 throw new MethodNotSupportedException("Messages cannot be expunged from Default IMAP folder");
129 }
130 }
131