1 /*********************************************************************** 2 * Copyright (c) 1999-2004 The Apache Software Foundation. * 3 * All rights reserved. * 4 * ------------------------------------------------------------------- * 5 * Licensed under the Apache License, Version 2.0 (the "License"); you * 6 * may not use this file except in compliance with the License. You * 7 * 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 * 14 * implied. See the License for the specific language governing * 15 * permissions and limitations under the License. * 16 ***********************************************************************/ 17 18 package org.apache.james.services; 19 20 import org.apache.james.core.MailImpl; 21 22 import javax.mail.MessagingException; 23 24 import java.util.Collection; 25 import java.util.Iterator; 26 27 /** 28 * Interface for a Repository to store Mails. 29 * @version 1.0.0, 24/04/1999 30 */ 31 public interface MailRepository { 32 33 /** 34 * Define a MAIL repository. MAILS are stored in the specified 35 * destination. 36 */ 37 String MAIL = "MAIL"; 38 39 40 /** 41 * Stores a message in this repository. Shouldn't this return the key 42 * under which it is stored? 43 * 44 * @param mc the mail message to store 45 */ 46 void store(MailImpl mc) throws MessagingException; 47 48 /** 49 * List string keys of messages in repository. 50 * 51 * @return an <code>Iterator</code> over the list of keys in the repository 52 * 53 */ 54 Iterator list() throws MessagingException; 55 56 /** 57 * Retrieves a message given a key. At the moment, keys can be obtained 58 * from list() in superinterface Store.Repository 59 * 60 * @param key the key of the message to retrieve 61 * @return the mail corresponding to this key, null if none exists 62 */ 63 MailImpl retrieve(String key) throws MessagingException; 64 65 /** 66 * Removes a specified message 67 * 68 * @param mail the message to be removed from the repository 69 */ 70 void remove(MailImpl mail) throws MessagingException; 71 72 /** 73 * Remove an Collection of mails from the repository 74 * 75 * @param mails The Collection of <code>MailImpl</code>'s to delete 76 * @since 2.2.0 77 */ 78 void remove(Collection mails) throws MessagingException; 79 80 /** 81 * Removes a message identified by key. 82 * 83 * @param key the key of the message to be removed from the repository 84 */ 85 void remove(String key) throws MessagingException; 86 87 /** 88 * Obtains a lock on a message identified by key 89 * 90 * @param key the key of the message to be locked 91 * 92 * @return true if successfully obtained the lock, false otherwise 93 */ 94 boolean lock(String key) throws MessagingException; 95 96 /** 97 * Releases a lock on a message identified the key 98 * 99 * @param key the key of the message to be unlocked 100 * 101 * @return true if successfully released the lock, false otherwise 102 */ 103 boolean unlock(String key) throws MessagingException; 104 } 105