Package org.apache.james.transport.matchers

Source Code of org.apache.james.transport.matchers.RelayLimit

/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.james.transport.matchers;

import org.apache.mailet.GenericMatcher;
import org.apache.mailet.Mail;

import javax.mail.Header;
import javax.mail.internet.MimeMessage;
import java.util.Collection;
import java.util.Enumeration;

/**
*
* @author  Serge Knystautas <sergek@lokitech.com>
* @version 1.0.0, 1/5/2000
*/

public class RelayLimit extends GenericMatcher {
    int limit = 30;

    public void init() {
        limit = Integer.parseInt(getCondition());
    }

    public Collection match(Mail mail) throws javax.mail.MessagingException {
        MimeMessage mm = mail.getMessage();
        int count = 0;
        for (Enumeration e = mm.getAllHeaders(); e.hasMoreElements();) {
            Header hdr = (Header)e.nextElement();
            if (hdr.getName().equals("Received")) {
                count++;
            }
        }
        if (count >= limit) {
            return mail.getRecipients();
        } else {
            return null;
        }
    }
}
TOP

Related Classes of org.apache.james.transport.matchers.RelayLimit

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.