1 /*****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
18 ****************************************************************/
19
20 package org.apache.james.services;
21
22 import org.apache.mailet.Mail;
23
24 import javax.mail.MessagingException;
25
26 import java.util.Collection;
27 import java.util.Iterator;
28
29 /***
30 * Interface for a Repository to store Mails.
31 * @version 1.0.0, 24/04/1999
32 */
33 public interface MailRepository {
34
35 /***
36 * The component role used by components implementing this service
37 */
38 String ROLE = "org.apache.james.services.MailRepository";
39
40 /***
41 * Define a MAIL repository. MAILS are stored in the specified
42 * destination.
43 */
44 String MAIL = "MAIL";
45
46
47 /***
48 * Stores a message in this repository. Shouldn't this return the key
49 * under which it is stored?
50 *
51 * @param mc the mail message to store
52 */
53 void store(Mail mc) throws MessagingException;
54
55 /***
56 * List string keys of messages in repository.
57 *
58 * @return an <code>Iterator</code> over the list of keys in the repository
59 *
60 */
61 Iterator list() throws MessagingException;
62
63 /***
64 * Retrieves a message given a key. At the moment, keys can be obtained
65 * from list() in superinterface Store.Repository
66 *
67 * @param key the key of the message to retrieve
68 * @return the mail corresponding to this key, null if none exists
69 */
70 Mail retrieve(String key) throws MessagingException;
71
72 /***
73 * Removes a specified message
74 *
75 * @param mail the message to be removed from the repository
76 */
77 void remove(Mail mail) throws MessagingException;
78
79 /***
80 * Remove an Collection of mails from the repository
81 *
82 * @param mails The Collection of <code>MailImpl</code>'s to delete
83 * @since 2.2.0
84 */
85 void remove(Collection mails) throws MessagingException;
86
87 /***
88 * Removes a message identified by key.
89 *
90 * @param key the key of the message to be removed from the repository
91 */
92 void remove(String key) throws MessagingException;
93
94 /***
95 * Obtains a lock on a message identified by key
96 *
97 * @param key the key of the message to be locked
98 *
99 * @return true if successfully obtained the lock, false otherwise
100 */
101 boolean lock(String key) throws MessagingException;
102
103 /***
104 * Releases a lock on a message identified the key
105 *
106 * @param key the key of the message to be unlocked
107 *
108 * @return true if successfully released the lock, false otherwise
109 */
110 boolean unlock(String key) throws MessagingException;
111 }