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
21
22 package org.apache.james.services;
23
24 import org.apache.mailet.Mail;
25
26 import javax.mail.MessagingException;
27
28 import java.util.Collection;
29 import java.util.Iterator;
30
31 /**
32 * Interface for a Repository to store Mails.
33 * @version 1.0.0, 24/04/1999
34 */
35 public interface MailRepository {
36
37 /**
38 * The component role used by components implementing this service
39 */
40 String ROLE = "org.apache.james.services.MailRepository";
41
42 /**
43 * Define a MAIL repository. MAILS are stored in the specified
44 * destination.
45 */
46 String MAIL = "MAIL";
47
48
49 /**
50 * Stores a message in this repository. Shouldn't this return the key
51 * under which it is stored?
52 *
53 * @param mc the mail message to store
54 */
55 void store(Mail mc) throws MessagingException;
56
57 /**
58 * List string keys of messages in repository.
59 *
60 * @return an <code>Iterator</code> over the list of keys in the repository
61 *
62 */
63 Iterator list() throws MessagingException;
64
65 /**
66 * Retrieves a message given a key. At the moment, keys can be obtained
67 * from list() in superinterface Store.Repository
68 *
69 * @param key the key of the message to retrieve
70 * @return the mail corresponding to this key, null if none exists
71 */
72 Mail retrieve(String key) throws MessagingException;
73
74 /**
75 * Removes a specified message
76 *
77 * @param mail the message to be removed from the repository
78 */
79 void remove(Mail mail) throws MessagingException;
80
81 /**
82 * Remove an Collection of mails from the repository
83 *
84 * @param mails The Collection of <code>MailImpl</code>'s to delete
85 * @since 2.2.0
86 */
87 void remove(Collection mails) throws MessagingException;
88
89 /**
90 * Removes a message identified by key.
91 *
92 * @param key the key of the message to be removed from the repository
93 */
94 void remove(String key) throws MessagingException;
95
96 /**
97 * Obtains a lock on a message identified by key
98 *
99 * @param key the key of the message to be locked
100 *
101 * @return true if successfully obtained the lock, false otherwise
102 */
103 boolean lock(String key) throws MessagingException;
104
105 /**
106 * Releases a lock on a message identified the key
107 *
108 * @param key the key of the message to be unlocked
109 *
110 * @return true if successfully released the lock, false otherwise
111 */
112 boolean unlock(String key) throws MessagingException;
113 }