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.mailet;
017    
018    import java.util.Set;
019    
020    import javax.mail.MessagingException;
021    
022    import com.hs.mail.smtp.message.Recipient;
023    import com.hs.mail.smtp.message.SmtpMessage;
024    
025    /**
026     * 
027     * @author Won Chul Doh
028     * @since Jun 7, 2010
029     * 
030     */
031    public interface Mailet {
032    
033            /**
034             * Initialize the mailet. Called by the SmtpMessageConsumer to indicate to a
035             * mailet that the mailet is being placed into service.
036             * <p>
037             * The SmtpMessageConsumer calls the init method exactly once after
038             * instantiating the mailet. The init method must complete successfully
039             * before the mailet can receive any requests.
040             */
041            public void init(MailetContext context);
042    
043            /**
044             * Check if the mailet is interested in the given recipients and message. If
045             * this method returns false, the service method will not be called for this
046             * message.
047             * 
048             * @param recipients
049             *            collection of recipients this mailet must process
050             * @param message
051             *            the Mail object that contains the message and routing
052             *            information
053             * @return true if the mailet want to process the message, otherwise false
054             */
055            public boolean accept(Set<Recipient> recipients, SmtpMessage message);
056    
057            /**
058             * Called by the SmtpMessageConsumer to allow the mailet to process the
059             * message.
060             * 
061             * @param recipients
062             *            collection of recipients this mailet must process
063             * @param message
064             *            the Mail object that contains the message and routing
065             *            information
066             * @throws MessagingException
067             */
068            public void service(Set<Recipient> recipients, SmtpMessage message)
069                            throws MessagingException;
070    
071    }