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
19 package org.apache.geronimo.javamail.store.imap;
20
21 import javax.mail.Folder;
22 import javax.mail.Message;
23 import javax.mail.MessagingException;
24 import javax.mail.MethodNotSupportedException;
25 import javax.mail.Store;
26
27 import org.apache.geronimo.javamail.store.imap.connection.IMAPConnection;
28 import org.apache.geronimo.javamail.store.imap.connection.IMAPEnvelope;
29 import org.apache.geronimo.javamail.store.imap.connection.IMAPBodyStructure;
30
31 /**
32 * An IMAP folder instance for the root of IMAP folder tree. This has
33 * some of the folder operations disabled.
34 */
35 public class IMAPRootFolder extends IMAPFolder {
36
37 /**
38 * Create a default IMAPRootFolder attached to a specific Store instance.
39 *
40 * @param store The Store instance this is the root for.
41 */
42 public IMAPRootFolder(IMAPStore store) {
43 // create a folder with a null string name and the default separator.
44 super(store, "", '/');
45 // this only holds folders
46 folderType = HOLDS_FOLDERS;
47 }
48
49 /**
50 * Get the Folder determined by the supplied name; if the name is relative
51 * then it is interpreted relative to this folder. This does not check that
52 * the named folder actually exists.
53 *
54 * @param name the name of the folder to return
55 * @return the named folder
56 * @throws MessagingException if there was a problem accessing the store
57 */
58 public Folder getFolder(String name) throws MessagingException {
59 // The root folder is a dummy one. Any getFolder() request starting
60 // at the root will use the request name for the full name. The separator
61 // used in that folder's namespace will be determined when the folder is
62 // first opened.
63 return new IMAPFolder((IMAPStore)store, name, UNDETERMINED);
64 }
65
66
67 public Folder getParent() {
68 // we never have a parent folder
69 return null;
70 }
71
72
73 public boolean exists() throws MessagingException {
74 // this always exists
75 return true;
76 }
77
78 public boolean hasNewMessages() {
79 // we don't really exist, so the answer is always false.
80 return false;
81 }
82
83
84 public int getMessagesCount() {
85 // we don't really exist, so the answer is always 0;
86 return 0;
87 }
88
89
90 public int getNewMessagesCount() {
91 // we don't really exist, so the answer is always 0;
92 return 0;
93 }
94
95
96 public int getUnreadMessagesCount() {
97 // we don't really exist, so the answer is always 0;
98 return 0;
99 }
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