You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ch...@apache.org on 2001/05/11 12:14:16 UTC

cvs commit: jakarta-james/src/org/apache/james/transport/matchers All.java CommandForListserv.java HostIs.java HostIsLocal.java InSpammerBlacklist.java IsSingleRecipient.java RecipientIs.java RecipientIsLocal.java RelayLimit.java RemoteAddrInNetwork.java RemoteAddrNotInNetwork.java SenderInFakeDomain.java SenderIs.java SubjectIs.java SubjectStartsWith.java UserIs.java

charlesb    01/05/11 03:14:15

  Added:       src/java/org/apache/james/transport/matchers All.java
                        CommandForListserv.java HostIs.java
                        HostIsLocal.java InSpammerBlacklist.java
                        IsSingleRecipient.java RecipientIs.java
                        RecipientIsLocal.java RelayLimit.java
                        RemoteAddrInNetwork.java
                        RemoteAddrNotInNetwork.java SenderInFakeDomain.java
                        SenderIs.java SubjectIs.java SubjectStartsWith.java
                        UserIs.java
  Removed:     src/org/apache/james/transport/matchers All.java
                        CommandForListserv.java HostIs.java
                        HostIsLocal.java InSpammerBlacklist.java
                        IsSingleRecipient.java RecipientIs.java
                        RecipientIsLocal.java RelayLimit.java
                        RemoteAddrInNetwork.java
                        RemoteAddrNotInNetwork.java SenderInFakeDomain.java
                        SenderIs.java SubjectIs.java SubjectStartsWith.java
                        UserIs.java
  Log:
  Moving from src/org to src/java/org
  
  Revision  Changes    Path
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/All.java
  
  Index: All.java
  ===================================================================
  /*
   * 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 java.util.*;
  import org.apache.mailet.*;
  
  /**
   * @version 1.0.0, 24/04/1999
   * @author  Federico Barbieri <sc...@pop.systemy.it>
   */
  public class All extends GenericMatcher {
      public Collection match(Mail mail) {
          return mail.getRecipients();
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/CommandForListserv.java
  
  Index: CommandForListserv.java
  ===================================================================
  /*
   * 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 java.util.*;
  import javax.mail.*;
  import javax.mail.internet.*;
  import org.apache.mailet.*;
  
  /**
   * Returns positive if the recipient is a command for a listserv.  For example,
   * if my listserv is james@list.working-dogs.com, this matcher will return true
   * for james-on@list.working-dogs.com and james-off@list.working-dogs.com.
   *
   * @author Serge Knystautas <se...@lokitech.com>
   */
  public class CommandForListserv extends GenericRecipientMatcher {
  
      private MailAddress listservAddress;
  
      public void init() throws MessagingException {
          listservAddress = new MailAddress(getCondition());
      }
  
      public boolean matchRecipient(MailAddress recipient) {
          if (recipient.getHost().equals(listservAddress.getHost())) {
              if (recipient.getUser().equals(listservAddress.getUser() + "-on")
                  || recipient.getUser().equals(listservAddress.getUser() + "-off")) {
                  return true;
              }
          }
          return false;
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/HostIs.java
  
  Index: HostIs.java
  ===================================================================
  /*
   * 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.*;
  import java.util.*;
  
  /**
   * @version 1.0.0, 24/04/1999
   * @author  Federico Barbieri <sc...@pop.systemy.it>
   */
  public class HostIs extends GenericRecipientMatcher {
  
      private Collection hosts;
  
      public void init() {
          StringTokenizer st = new StringTokenizer(getCondition(), ", ", false);
          hosts = new Vector();
          while (st.hasMoreTokens()) {
              hosts.add(st.nextToken().toLowerCase());
          }
      }
  
      public boolean matchRecipient(MailAddress recipient) {
          return hosts.contains(recipient.getHost().toLowerCase());
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/HostIsLocal.java
  
  Index: HostIsLocal.java
  ===================================================================
  /*
   * 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 java.util.*;
  import org.apache.mailet.*;
  
  /**
   * @version 1.0.0, 24/04/1999
   * @author Federico Barbieri <sc...@pop.systemy.it>
   * @author Serge Knystautas <se...@lokitech.com>
   */
  public class HostIsLocal extends GenericRecipientMatcher {
  
      public boolean matchRecipient(MailAddress recipient) {
          return getMailetContext().isLocalServer(recipient.getHost().toLowerCase());
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/InSpammerBlacklist.java
  
  Index: InSpammerBlacklist.java
  ===================================================================
  /*
   * 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 java.net.*;
  import java.util.*;
  import javax.mail.*;
  import org.apache.mailet.*;
  
  /**
   * Checks the network IP address of the sending server against a
   * blacklist of spammers.  There are 3 lists that support this...
   * <ul>
   * <li><b>blackholes.mail-abuse.org</b>: Rejected - see  http://www.mail-abuse.org/rbl/
   * <li><b>dialups.mail-abuse.org</b>: Dialup - see http://www.mail-abuse.org/dul/
   * <li><b>relays.mail-abuse.org</b>: Open spam relay - see http://www.mail-abuse.org/rss/
   * </ul>
   *
   * Example:
   * &lt;mailet match="InSpammerBlacklist=blackholes.mail-abuse.org" class="ToProcessor"&gt;
   *   &lt;processor&gt;spam&lt;/processor&gt;
   * &lt;/mailet&gt;
   *
   * @author  Serge Knystautas <se...@lokitech.com>
   */
  public class InSpammerBlacklist extends GenericMatcher {
      String network = null;
  
      public void init() throws MessagingException {
          network = getCondition();
      }
  
      public Collection match(Mail mail) {
          String host = mail.getRemoteAddr();
          try {
              //Have to reverse the octets first
              StringTokenizer st = new StringTokenizer(host, " .", false);
              host = network;
              while (st.hasMoreTokens()) {
                  host = st.nextToken() + ".";
              }
  
              //Try to look it up
              InetAddress.getByName(host);
  
              //If we got here, that's bad... it means the host
              //  was found in the blacklist
              return mail.getRecipients();
          } catch (UnknownHostException uhe) {
              //This is good... it's not on the list
              return null;
          }
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/IsSingleRecipient.java
  
  Index: IsSingleRecipient.java
  ===================================================================
  /*
   * 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.*;
  import java.util.*;
  
  /**
   * @version 1.0.0, 04/12/2000
   * @author  Serge Knystautas <se...@lokitech.com>
   */
  public class IsSingleRecipient extends GenericMatcher {
  
      public Collection match(Mail mail) {
          if (mail.getRecipients().size() == 1) {
              return mail.getRecipients();
          } else {
              return null;
          }
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/RecipientIs.java
  
  Index: RecipientIs.java
  ===================================================================
  /*
   * 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 java.util.*;
  import javax.mail.*;
  import org.apache.mailet.*;
  
  /**
   * @version 1.0.0, 24/04/1999
   * @author Federico Barbieri <sc...@pop.systemy.it>
   * @author Serge Knystautas <se...@lokitech.com>
   */
  public class RecipientIs extends GenericRecipientMatcher {
  
      private Set recipients;
  
      public void init() throws javax.mail.MessagingException {
          StringTokenizer st = new StringTokenizer(getCondition(), ", \t", false);
          recipients = new HashSet();
          while (st.hasMoreTokens()) {
              recipients.add(new MailAddress(st.nextToken()));
          }
      }
  
      public boolean matchRecipient(MailAddress recipient) {
          return recipients.contains(recipient);
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/RecipientIsLocal.java
  
  Index: RecipientIsLocal.java
  ===================================================================
  /*
   * 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.*;
  import java.util.*;
  
  /**
   * @version 1.0.0, 24/04/1999
   * @author Federico Barbieri <sc...@pop.systemy.it>
   * @author Serge Knystautas <se...@lokitech.com>
   */
  public class RecipientIsLocal extends GenericRecipientMatcher {
  
      public boolean matchRecipient(MailAddress recipient) {
          MailetContext mailetContext = getMailetContext();
          //This might change after startup
          return mailetContext.isLocalServer(recipient.getHost().toLowerCase())
              && mailetContext.isLocalUser(recipient.getUser());
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/RelayLimit.java
  
  Index: RelayLimit.java
  ===================================================================
  /*
   * 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.*;
  import javax.mail.*;
  import javax.mail.internet.*;
  import java.util.*;
  
  /**
   *
   * @author  Serge Knystautas <se...@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;
          }
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/RemoteAddrInNetwork.java
  
  Index: RemoteAddrInNetwork.java
  ===================================================================
  /*
   * 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.*;
  import java.net.*;
  import java.util.*;
  import javax.mail.*;
  
  /**
   * Checks the IP address of the sending server against a comma-
   * delimited list of  IP addresses.
   * <P>Networks should be indicated with a wildcard *, e.g. 192.168.* 
   * <br>Note: The wildcard can go at any level, the matcher will match if the
   * sending host's IP address (as a String based on the octet representation)
   * starts with the String indicated in the configuration file, excluding the
   * wildcard.
   * <p>Multiple addresses can be indicated, e.g: '127.0.0.1,192.168.*'
   *
   * @author  Serge Knystautas <se...@lokitech.com>
   */
  public class RemoteAddrInNetwork extends GenericMatcher {
      private Collection networks = null;
  
      public void init() throws MessagingException {
          StringTokenizer st = new StringTokenizer(getCondition(), ", ", false);
          networks = new Vector();
          while (st.hasMoreTokens()) {
              String addr = st.nextToken();
              if (addr.equals("127.0.0.1")) {
                  //Add address of local machine as a match
                  try {
                      InetAddress localaddr = InetAddress.getLocalHost();
                      networks.add(localaddr.getHostAddress());
                  } catch (UnknownHostException uhe) {
                  }
              }
              if (addr.endsWith("*")) {
                  addr = addr.substring(0, addr.length() - 1);
              }
              networks.add(addr);
          }
      }
  
      public Collection match(Mail mail) {
          String host = mail.getRemoteAddr();
          //Check to see whether it's in any of the networks... needs to be smarter to
          // support subnets better
          for (Iterator i = networks.iterator(); i.hasNext(); ) {
              String networkAddr = i.next().toString();
              if (host.startsWith(networkAddr)) {
                  //This is in this network... that's all we need for a match
                  return mail.getRecipients();
              }
          }
          //Could not match this to any network
          return null;
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/RemoteAddrNotInNetwork.java
  
  Index: RemoteAddrNotInNetwork.java
  ===================================================================
  /*
   * 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 java.net.*;
  import java.util.*;
  import javax.mail.*;
  import org.apache.mailet.*;
  
  /**
   * Checks the IP address of the sending server against a comma-
   * delimited list of IP addresses.
   * <P>Networks should be indicated with a wildcard *, e.g. 192.168.*
   * <br>Note: The wildcard can go at any level, the matcher will match if the
   * sending host's IP address (as a String based on the octet representation)
   * starts with the String indicated in the configuration file, excluding the
   * wildcard.
   * <p>Multiple addresses can be indicated, e.g: '127.0.0.1,192.168.*'
   *
   * @author  Serge Knystautas <se...@lokitech.com>
   */
  public class RemoteAddrNotInNetwork extends GenericMatcher {
      private Collection networks = null;
  
      public void init() throws MessagingException {
          StringTokenizer st = new StringTokenizer(getCondition(), ", ", false);
          networks = new Vector();
          while (st.hasMoreTokens()) {
              String addr = st.nextToken();
              if (addr.equals("127.0.0.1")) {
                  //Add address of local machine as a match
                  try {
                      InetAddress localaddr = InetAddress.getLocalHost();
                      networks.add(localaddr.getHostAddress());
                  } catch (UnknownHostException uhe) {
                  }
              }
              if (addr.endsWith("*")) {
                  addr = addr.substring(0, addr.length() - 1);
              }
              networks.add(addr);
          }
      }
  
      public Collection match(Mail mail) {
          String host = mail.getRemoteAddr();
          //Check to see whether it's in any of the networks... needs to be smarter to
          // support subnets better
          for (Iterator i = networks.iterator(); i.hasNext(); ) {
              String invalidNetwork = i.next().toString();
              if (host.startsWith(invalidNetwork)) {
                  //This is in this network... that's all we need for a failed match
                  return null;
              }
          }
          //Could not match this to any network
          return mail.getRecipients();
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/SenderInFakeDomain.java
  
  Index: SenderInFakeDomain.java
  ===================================================================
  /*
   * 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.*;
  import java.util.*;
  
  /**
   * Does a DNS lookup (MX and A/CNAME records) on the sender's domain.  If
   * there are no entries, the domain is fake.
   *
   * @author  Serge Knystautas <se...@lokitech.com>
   */
  public class SenderInFakeDomain extends GenericMatcher {
  
      public Collection match(Mail mail) {
          String domain = mail.getSender().getHost();
          //DNS Lookup for this domain
          Collection servers = getMailetContext().getMailServers(domain);
          if (servers.size() == 0) {
              //No records...could not deliver to this domain, so matches criteria.
  	    log("No MX record found for domain: " + domain);
              return mail.getRecipients();
          } else {
              //Some servers were found... the domain is not fake.
              return null;
          }
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/SenderIs.java
  
  Index: SenderIs.java
  ===================================================================
  /*
   * 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.*;
  import java.util.*;
  
  /**
   * @version 1.0.0, 24/04/1999
   * @author  Federico Barbieri <sc...@pop.systemy.it>
   */
  public class SenderIs extends GenericMatcher {
  
      private Collection senders;
  
      public void init() {
          StringTokenizer st = new StringTokenizer(getCondition(), ", ", false);
          senders = new Vector();
          while (st.hasMoreTokens()) {
              senders.add(st.nextToken());
          }
      }
  
      public Collection match(Mail mail) {
          if (senders.contains(mail.getSender())) {
              return mail.getRecipients();
          } else {
              return null;
          }
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/SubjectIs.java
  
  Index: SubjectIs.java
  ===================================================================
  /*
   * 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 java.util.*;
  import javax.mail.*;
  import javax.mail.internet.*;
  import org.apache.mailet.*;
  
  /**
   *
   * @author  Dino Fancellu <di...@ntlworld.com>
   * @version 1.0.0, 1/5/2000
   */
  
  public class SubjectIs extends GenericMatcher {
      public Collection match(Mail mail) throws javax.mail.MessagingException {
          MimeMessage mm = mail.getMessage();
          String subject = mm.getSubject();
          if (subject != null && subject.equals(getCondition())) {
              return mail.getRecipients();
          }
          return null;
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/SubjectStartsWith.java
  
  Index: SubjectStartsWith.java
  ===================================================================
  /*
   * 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 java.util.*;
  import javax.mail.*;
  import javax.mail.internet.*;
  import org.apache.mailet.*;
  
  /**
   *
   * @author  Dino Fancellu <di...@ntlworld.com>
   * @version 1.0.0, 1/5/2000
   */
  
  public class SubjectStartsWith extends GenericMatcher {
  
      public Collection match(Mail mail) throws MessagingException {
          MimeMessage mm = mail.getMessage();
          String subject = mm.getSubject();
          if (subject != null && subject.startsWith(getCondition())) {
              return mail.getRecipients();
          }
          return null;
      }
  }
  
  
  
  1.1                  jakarta-james/src/java/org/apache/james/transport/matchers/UserIs.java
  
  Index: UserIs.java
  ===================================================================
  /*
   * 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 java.util.*;
  import org.apache.mailet.*;
  
  /**
   * @version 1.0.0, 24/04/1999
   * @author Federico Barbieri <sc...@pop.systemy.it>
   * @author Serge Knystautas <se...@lokitech.com>
   */
  public class UserIs extends GenericRecipientMatcher {
      Vector users = null;
  
      public void init() {
          StringTokenizer st = new StringTokenizer(getCondition(), ", ", false);
          users = new Vector();
          while (st.hasMoreTokens()) {
              users.add(st.nextToken());
          }
      }
  
      public boolean matchRecipient(MailAddress recipient) {
          return users.contains(recipient.getUser());
      }
  }
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org