Hello,
As an exercise to learn the matcher API, I wrote a matcher base on the
SenderInFakeDomain matcher. I turned on the logging and it seems to work
fine except for one thing. When I return null, the mail is dropped. All
other returns act as expected.
What can I do to further debug this.
config.xml:
<code>
<mailet match="NoMXforSenderHost"ToProcessor">
<processor> spam </processor>
</mailet>
</code>
My source:
<code>
package org.mymatcher;
/***********************************************************************
* Copyright (c) 2000-2006 The Apache Software Foundation. *
* All rights reserved. *
* ------------------------------------------------------------------- *
* Licensed under the Apache License, Version 2.0 (the "License"); you *
* may not use this file except in compliance with the License. You *
* may obtain a copy of the License at: *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
* implied. See the License for the specific language governing *
* permissions and limitations under the License. *
***********************************************************************/
//package org.apache.james.transport.matchers;
import org.apache.mailet.GenericMatcher;
import org.apache.mailet.Mail;
import java.util.Collection;
import java.util.Iterator;
/**
* Does a DNS lookup (MX and A/CNAME records) on the sender's domain. If
there
* are no entries, the domain is considered fake and the match is
successful.
* If there are entries it checks to see if the specific host has a MX
record.
*/
public class NoMXforSenderHost extends GenericMatcher {
public Collection match(Mail mail) {
String nextServer ;
if (mail.getSender() == null) {
log("Returning null");
return null;
}
String domain = mail.getSender().getHost();
log("Found Host: " + domain);
// 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, A, or CNAME record found for domain: " +
domain);
log("Returning: " + mail.getRecipients());
return mail.getRecipients();
}
// Some servers were found... the domain is not fake.
log("Some servers were found... the domain is not fake.: " +
domain);
String remoteHost = mail.getRemoteHost();
log("Looking for Host MX: " + remoteHost);
for (Iterator serversList = servers.iterator();
serversList.hasNext();) {
nextServer = serversList.next().toString();
log("Checking Host: " + nextServer);
if ( nextServer.compareToIgnoreCase(remoteHost)== 0 ) {
log("Host MX found for host: " + remoteHost);
log("Returning null");
return null;
} else {
log("No Host MX found for host: " + remoteHost);
}
}
// o.k. didn't get mail from MX host. Well, lets just make sure
the
sender
// domain matches the domain of the remote host.
log("Checking if host domain (" + domain + ") is in sender e-mail
address (" + remoteHost + ")");
if ( remoteHost.endsWith(domain) == true ) {
log("Host domain (" + domain + ") matches sender e-mail
domain (" +
remoteHost + ")");
log("Returning null");
return null;
} else {
log("Suspected spam from: " + mail.getSender());
log("Returning: " + mail.getRecipients());
return mail.getRecipients();
}
}
}
</code>
--
View this message in context:
http://www.nabble.com/custom-matcher-does-not-spool-mail-tf3336251.html#a9278288
Sent from the James - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]