001 /*
002 * Copyright 2010 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package com.hs.mail.imap.mailbox;
017
018 import java.io.File;
019 import java.io.IOException;
020 import java.util.Date;
021 import java.util.List;
022 import java.util.Map;
023
024 import javax.mail.Flags;
025
026 import com.hs.mail.imap.event.EventDispatcher;
027 import com.hs.mail.imap.event.EventListener;
028 import com.hs.mail.imap.message.FetchData;
029 import com.hs.mail.imap.message.MailMessage;
030 import com.hs.mail.imap.message.search.SearchKey;
031
032 /**
033 *
034 * @author WonChul Doh
035 * @since Feb 2, 2010
036 *
037 */
038 public interface MailboxManager {
039
040 public EventDispatcher getEventDispatcher();
041
042 public void addEventListener(EventListener listener);
043
044 public void removeEventListener(EventListener listener);
045
046 /**
047 * Returns user's <code>Mailbox</code> with a given path
048 *
049 * @param ownerID
050 * owner of the mailbox
051 * @param mailboxName
052 * path to the mailbox
053 * @return the mailbox as <code>Mailbox</code>
054 */
055 public Mailbox getMailbox(long ownerID, String mailboxName);
056
057 /**
058 * Check if given mailbox exists.
059 *
060 * @param ownerID
061 * owner of this mailbox
062 * @param mailboxName
063 * the name of mailbox for checking existence
064 * @return true when the mailbox exists, false otherwise
065 */
066 public boolean mailboxExists(long ownerID, String mailboxName);
067
068 public List<Mailbox> getChildren(long userID, long ownerID,
069 String mailboxName, boolean subscribed);
070
071 public List<Long> getMailboxIDList(String mailboxName);
072
073 /**
074 * Does the mailbox have inferior child mailboxes?
075 *
076 * @param mailbox
077 * ID of the mailbox
078 * @return true when the mailbox has children, false otherwise
079 */
080 public boolean hasChildren(Mailbox mailbox);
081
082 /**
083 * Gets the UIDs of messages which has /Deleted flag.
084 *
085 * @param mailboxID
086 * ID of mailbox
087 * @return list of UIDs of messages which has /Deleted flag
088 */
089 public List<Long> expunge(long mailboxID);
090
091 /**
092 * Searches for the messages matching the given query.
093 *
094 * @param map
095 * UID to MSN converting map
096 * @param mailboxID
097 * ID of mailbox to search
098 * @param key
099 * the search query
100 * @return list of UIDs of messages searched
101 */
102 public List<Long> search(UidToMsnMapper map, long mailboxID, SearchKey key);
103
104 /**
105 * Creates a new mailbox. Any intermediary mailboxes missing from the
106 * hierarchy will be created.
107 *
108 * @param ownerID
109 * owner of the mailbox
110 * @param mailboxName
111 * the name of mailbox to create
112 * @return <code>Mailbox</code> created
113 */
114 public Mailbox createMailbox(final long ownerID, final String mailboxName);
115
116 /**
117 * Renames a mailbox.
118 *
119 * @param source
120 * original mailbox
121 * @param targetName
122 * new name for the mailbox
123 */
124 public void renameMailbox(final Mailbox source, final String targetName);
125
126 /**
127 * Delete or empty a mailbox from store.
128 *
129 * @param ownerID
130 * ID of the user who owns the mailbox
131 * @param mailboxID
132 * ID of the mailbox
133 * @param delete
134 * true when delete, false when empty
135 */
136 public void deleteMailbox(final long ownerID, final long mailboxID,
137 final boolean delete);
138
139 /**
140 * Check if given mailbox is subscribed to user
141 *
142 * @param userID
143 * ID of user
144 * @param mailboxID
145 * ID of mailbox
146 * @return true if mailbox is subscribed, otherwise false
147 */
148 public boolean isSubscribed(long userID, String mailboxName);
149
150 /**
151 * Subscribe the user to the given mailbox.
152 *
153 * @param userID
154 * ID of the user
155 * @param mailboxID
156 * ID of the mailbox to subscribe
157 */
158 public void addSubscription(final long userID, final long mailboxID,
159 final String mailboxName);
160 /**
161 * Unsubscribes the user from the given mailbox.
162 *
163 * @param mailboxID
164 * ID of the mailbox to unsubscribe
165 */
166 public void deleteSubscription(final long userID, final String mailboxName);
167
168 public FetchData getMessageFetchData(long uid);
169
170 public Flags getFlags(long uid);
171
172 public List<Long> getMessageIDList(long mailboxID);
173
174 /**
175 * Appends a message to the user's INBOX. This method is called by MDA.
176 */
177 public void addMessage(final long ownerID, final MailMessage message,
178 String mailboxName);
179
180 /**
181 * Appends a message to this mailbox.
182 *
183 * @param mailboxID
184 * ID of mailbox to append a message
185 * @param internalDate
186 * the time of addition to be set
187 * @param flags
188 * optionally set these flags on created message, or null when no
189 * additional flags should be set
190 * @param file
191 * the file containing the mail contents
192 * @throws IOException
193 */
194 public void appendMessage(long mailboxID, Date internalDate, Flags flags,
195 File file) throws IOException;
196
197 /**
198 * Deletes the given message.
199 *
200 * @param uid
201 * ID of the message to delete
202 */
203 public void deleteMessage(final long uid);
204
205 /**
206 * Copies a message to the given mailbox.
207 *
208 * @param uid
209 * ID of the message to copy
210 * @param mailboxID
211 * ID of mailbox where message will be copied
212 */
213 public void copyMessage(final long uid, final long mailboxID);
214
215 public void resetRecent(final long mailboxID);
216
217 /**
218 * Sets flags on this message.
219 *
220 * @param uid
221 * ID of the message to set flags
222 * @param flags
223 * flags to be set
224 * @param replace
225 * true if to replace
226 * @param set
227 * true if to set, false to reset
228 */
229 public void setFlags(final long uid, final Flags flags,
230 final boolean replace, final boolean set);
231
232 /**
233 * Gets the headers of the message.
234 *
235 * @param physMessageID
236 * ID of the physical message
237 * @return map containing header name and value entries
238 */
239 public Map<String, String> getHeader(long physMessageID);
240
241 /**
242 * Gets the headers of the message.
243 *
244 * @param physMessageID
245 * ID of the physical message
246 * @param fields
247 * Array of fields to retrieve
248 * @return map containing header name and value entries
249 */
250 public Map<String, String> getHeader(long physMessageID, String[] fields);
251
252 }