001: /****************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one *
003: * or more contributor license agreements. See the NOTICE file *
004: * distributed with this work for additional information *
005: * regarding copyright ownership. The ASF licenses this file *
006: * to you under the Apache License, Version 2.0 (the *
007: * "License"); you may not use this file except in compliance *
008: * with the License. You may obtain a copy of the License at *
009: * *
010: * http://www.apache.org/licenses/LICENSE-2.0 *
011: * *
012: * Unless required by applicable law or agreed to in writing, *
013: * software distributed under the License is distributed on an *
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015: * KIND, either express or implied. See the License for the *
016: * specific language governing permissions and limitations *
017: * under the License. *
018: ****************************************************************/package org.apache.james.transport.mailets;
019:
020: import org.apache.commons.collections.iterators.IteratorChain;
021: import org.apache.mailet.GenericMailet;
022: import org.apache.mailet.Mail;
023: import org.apache.mailet.MailetConfig;
024: import org.apache.mailet.MailetContext;
025:
026: import javax.mail.MessagingException;
027:
028: import java.util.ArrayList;
029: import java.util.Collection;
030: import java.util.Iterator;
031:
032: /**
033: * Receives a Mail from JamesSpoolManager and takes care of delivery of the
034: * message to local inboxes.
035: *
036: * Since James 2.3.0 this mailet is a composition of
037: * UserRepositoryAliasingForwarding and ToMultiRepository
038: * configurated to mimic the old "LocalDelivery" behaviour.
039: */
040: public class LocalDelivery extends GenericMailet {
041:
042: /**
043: * Mailet that apply aliasing and forwarding
044: */
045: private UsersRepositoryAliasingForwarding aliasingMailet;
046:
047: /**
048: * Mailet that actually store the message
049: */
050: private ToMultiRepository deliveryMailet;
051:
052: /**
053: * Delivers a mail to a local mailbox.
054: *
055: * @param mail
056: * the mail being processed
057: *
058: * @throws MessagingException
059: * if an error occurs while storing the mail
060: */
061: public void service(Mail mail) throws MessagingException {
062: aliasingMailet.service(mail);
063: if (mail.getState() != Mail.GHOST) {
064: deliveryMailet.service(mail);
065: }
066: }
067:
068: /**
069: * Return a string describing this mailet.
070: *
071: * @return a string describing this mailet
072: */
073: public String getMailetInfo() {
074: return "Local Delivery Mailet";
075: }
076:
077: /**
078: * @see org.apache.mailet.GenericMailet#init()
079: */
080: public void init() throws MessagingException {
081: super .init();
082: aliasingMailet = new UsersRepositoryAliasingForwarding();
083: aliasingMailet.init(getMailetConfig());
084: deliveryMailet = new ToMultiRepository();
085: MailetConfig m = new MailetConfig() {
086:
087: /**
088: * @see org.apache.mailet.MailetConfig#getInitParameter(java.lang.String)
089: */
090: public String getInitParameter(String name) {
091: if ("addDeliveryHeader".equals(name)) {
092: return "Delivered-To";
093: } else if ("resetReturnPath".equals(name)) {
094: return "true";
095: } else {
096: return getMailetConfig().getInitParameter(name);
097: }
098: }
099:
100: /**
101: * @see org.apache.mailet.MailetConfig#getInitParameterNames()
102: */
103: public Iterator getInitParameterNames() {
104: IteratorChain c = new IteratorChain();
105: Collection h = new ArrayList();
106: h.add("addDeliveryHeader");
107: h.add("resetReturnPath");
108: c
109: .addIterator(getMailetConfig()
110: .getInitParameterNames());
111: c.addIterator(h.iterator());
112: return c;
113: }
114:
115: /**
116: * @see org.apache.mailet.MailetConfig#getMailetContext()
117: */
118: public MailetContext getMailetContext() {
119: return getMailetConfig().getMailetContext();
120: }
121:
122: /**
123: * @see org.apache.mailet.MailetConfig#getMailetName()
124: */
125: public String getMailetName() {
126: return getMailetConfig().getMailetName();
127: }
128:
129: };
130: deliveryMailet.init(m);
131: }
132:
133: }
|