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 no...@apache.org on 2006/12/25 18:31:12 UTC
svn commit: r490155 [3/3] - in
/james/server/sandbox/handlerapi-experiment/src:
java/org/apache/james/core/ java/org/apache/james/nntpserver/
java/org/apache/james/pop3server/ java/org/apache/james/remotemanager/
java/org/apache/james/smtpserver/ java/...
Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SupressDuplicateRcptHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SupressDuplicateRcptHandler.java?view=diff&rev=490155&r1=490154&r2=490155
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SupressDuplicateRcptHandler.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SupressDuplicateRcptHandler.java Mon Dec 25 09:31:07 2006
@@ -1,69 +1,71 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one *
- * or more contributor license agreements. See the NOTICE file *
- * distributed with this work for additional information *
- * regarding copyright ownership. The ASF licenses this file *
- * to you 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.smtpserver.core.filter.fastfail;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.james.smtpserver.CommandHandler;
-import org.apache.james.smtpserver.SMTPSession;
-import org.apache.james.util.mail.dsn.DSNStatus;
-import org.apache.mailet.MailAddress;
-
-/**
- *
- * This handler can be used to just ignore duplicated recipients.
- */
-public class SupressDuplicateRcptHandler extends AbstractLogEnabled implements CommandHandler {
-
- /**
- * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
- */
- public Collection getImplCommands() {
- Collection c = new ArrayList();
- c.add("RCPT");
-
- return c;
- }
-
- /**
- * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
- */
- public void onCommand(SMTPSession session) {
- MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
- Collection rcptList = (Collection) session.getState().get(SMTPSession.RCPT_LIST);
-
- // Check if the recipient is allready in the rcpt list
- if(rcptList != null && rcptList.contains(rcpt)) {
- StringBuffer responseBuffer = new StringBuffer();
-
- responseBuffer.append("250 " + DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.ADDRESS_VALID) + " Recipient <")
- .append(rcpt.toString()).append("> OK");
- session.writeResponse(responseBuffer.toString());
- session.setStopHandlerProcessing(true);
-
- getLogger().debug("Duplicate recipient not add to recipient list: " + rcpt.toString());
- }
- }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you 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.smtpserver.core.filter.fastfail;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.SMTPResponse;
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.mail.dsn.DSNStatus;
+import org.apache.mailet.MailAddress;
+
+/**
+ *
+ * This handler can be used to just ignore duplicated recipients.
+ */
+public class SupressDuplicateRcptHandler extends AbstractLogEnabled implements CommandHandler {
+
+ /**
+ * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+ */
+ public Collection getImplCommands() {
+ Collection c = new ArrayList();
+ c.add("RCPT");
+
+ return c;
+ }
+
+ /**
+ * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+ */
+ public SMTPResponse onCommand(SMTPSession session, String command, String parameters) {
+ MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
+ Collection rcptList = (Collection) session.getState().get(SMTPSession.RCPT_LIST);
+
+ // Check if the recipient is allready in the rcpt list
+ if(rcptList != null && rcptList.contains(rcpt)) {
+ StringBuffer responseBuffer = new StringBuffer();
+
+ responseBuffer.append(DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.ADDRESS_VALID))
+ .append(" Recipient <")
+ .append(rcpt.toString())
+ .append("> OK");
+ getLogger().debug("Duplicate recipient not add to recipient list: " + rcpt.toString());
+ return new SMTPResponse("250", responseBuffer);
+ }
+ return null;
+ }
+}
Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java?view=diff&rev=490155&r1=490154&r2=490155
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java Mon Dec 25 09:31:07 2006
@@ -29,6 +29,7 @@
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.SMTPResponse;
import org.apache.james.smtpserver.SMTPSession;
public class TarpitHandler extends AbstractLogEnabled implements
@@ -99,7 +100,7 @@
/**
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
*/
- public void onCommand(SMTPSession session) {
+ public SMTPResponse onCommand(SMTPSession session, String command, String parameters) {
int rcptCount = 0;
rcptCount = session.getRcptCount();
@@ -111,6 +112,8 @@
} catch (InterruptedException e) {
}
}
+
+ return null;
}
/**
Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java?view=diff&rev=490155&r1=490154&r2=490155
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java Mon Dec 25 09:31:07 2006
@@ -1,240 +1,239 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one *
- * or more contributor license agreements. See the NOTICE file *
- * distributed with this work for additional information *
- * regarding copyright ownership. The ASF licenses this file *
- * to you 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.smtpserver.core.filter.fastfail;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.StringTokenizer;
-
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.james.services.VirtualUserTable;
-import org.apache.james.services.VirtualUserTableStore;
-import org.apache.james.smtpserver.CommandHandler;
-import org.apache.james.smtpserver.SMTPSession;
-import org.apache.james.util.mail.dsn.DSNStatus;
-import org.apache.james.vut.ErrorMappingException;
-import org.apache.mailet.MailAddress;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
-
-/**
- * Handler which reject invalid recipients
- */
-public class ValidRcptHandler extends AbstractLogEnabled implements CommandHandler, Configurable, Serviceable {
-
- private Collection recipients = new ArrayList();
- private Collection domains = new ArrayList();
- private Collection regex = new ArrayList();
- private boolean vut = true;
- private VirtualUserTable table;
- private String tableName = null;
-
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager arg0) throws ServiceException {
- if (tableName == null || tableName.equals("")) {
- table = (VirtualUserTable) arg0.lookup(VirtualUserTable.ROLE);
- } else {
- table = ((VirtualUserTableStore) arg0.lookup(VirtualUserTableStore.ROLE)).getTable(tableName);
- }
- }
-
- /**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
- */
- public void configure(Configuration arg0) throws ConfigurationException {
- Configuration recipientsConfig = arg0.getChild("validRecipients");
- if (recipientsConfig != null) {
- setValidRecipients(recipientsConfig.getValue());
- }
-
- Configuration domainConfig = arg0.getChild("validDomains");
- if (domainConfig != null) {
- setValidDomains(domainConfig.getValue());
- }
-
- Configuration regexConfig = arg0.getChild("validRegexPattern");
- if (regexConfig != null) {
- try {
- setValidRegex(regexConfig.getValue());
- } catch(MalformedPatternException mpe) {
- throw new ConfigurationException("Malformed pattern: ", mpe);
- }
- }
- Configuration vutConfig = arg0.getChild("enableVirtualUserTable");
-
- if (vutConfig != null) {
- vut = vutConfig.getValueAsBoolean(true);
- }
- Configuration tableConfig = arg0.getChild("table");
-
- if (tableConfig != null) {
- tableName = tableConfig.getValue(null);
- }
- }
-
- /**
- * Set the valid recipients.
- *
- * @param recip The valid recipients. Commaseperated list
- */
- public void setValidRecipients(String recip) {
- StringTokenizer st = new StringTokenizer(recip, ", ", false);
-
- while (st.hasMoreTokens()) {
- String recipient = st.nextToken().toLowerCase();
-
- getLogger().debug("Add recipient to valid recipients: " + recipient);
- recipients.add(recipient);
- }
- }
-
- /**
- * Set the domains for which every rcpt will be accepted.
- *
- * @param dom The valid domains. Commaseperated list
- */
- public void setValidDomains(String dom) {
- StringTokenizer st = new StringTokenizer(dom, ", ", false);
-
- while (st.hasMoreTokens()) {
- String domain = st.nextToken().toLowerCase();
- getLogger().debug("Add domain to valid domains: " + domain);
- domains.add(domain);
- }
- }
-
- /**
- *
- * @param reg
- * @throws MalformedPatternException
- */
- public void setValidRegex(String reg) throws MalformedPatternException {
- Perl5Compiler compiler = new Perl5Compiler();
-
- StringTokenizer st = new StringTokenizer(reg, ", ", false);
-
- while (st.hasMoreTokens()) {
- String patternString = st.nextToken().trim();
-
- getLogger().debug("Add regex to valid regex: " + patternString);
-
- Pattern pattern = compiler.compile(patternString, Perl5Compiler.READ_ONLY_MASK);
- regex.add(pattern);
-
- }
- }
-
- public void setVirtualUserTableSupport(boolean vut) {
- this.vut = vut;
- }
-
- /**
- * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
- */
- public Collection getImplCommands() {
- Collection c = new ArrayList();
- c.add("RCPT");
-
- return c;
- }
-
- /**
- * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
- */
- public void onCommand(SMTPSession session) {
- if (!session.isRelayingAllowed() && !(session.isAuthRequired() && session.getUser() != null)) {
- checkValidRcpt(session);
- } else {
- getLogger().debug("Sender allowed");
- }
- }
-
-
-
- /**
- * Check if the recipient should be accepted
- *
- * @param session The SMTPSession
- */
- private void checkValidRcpt(SMTPSession session) {
- MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
- boolean invalidUser = true;
-
- if (session.getConfigurationData().getUsersRepository().contains(rcpt.getUser()) == true || recipients.contains(rcpt.toString().toLowerCase()) || domains.contains(rcpt.getHost().toLowerCase())) {
- invalidUser = false;
- }
-
- // check if an valid virtual mapping exists
- if (invalidUser == true && vut == true) {
- try {
- Collection targetString = table.getMappings(rcpt.getUser(), rcpt.getHost());
-
- if (targetString != null && targetString.isEmpty() == false) {
- invalidUser = false;
- }
- } catch (ErrorMappingException e) {
-
- String responseString = e.getMessage();
-
- getLogger().info("Rejected message. Reject Message: " + responseString);
-
- session.writeResponse(responseString);
- session.setStopHandlerProcessing(true);
- }
- }
-
- if (invalidUser == true && !regex.isEmpty()) {
- Iterator reg = regex.iterator();
- Perl5Matcher matcher = new Perl5Matcher();
-
- while (reg.hasNext()) {
- if (matcher.matches(rcpt.toString(), (Pattern) reg.next())) {
- // regex match
- invalidUser = false;
- break;
- }
- }
- }
-
- if (invalidUser == true) {
- //user not exist
- String responseString = "554 " + DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_MAILBOX) + " Unknown user: " + rcpt.toString();
-
- getLogger().info("Rejected message. Unknown user: " + rcpt.toString());
-
- session.writeResponse(responseString);
- session.setStopHandlerProcessing(true);
- }
- }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you 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.smtpserver.core.filter.fastfail;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.james.services.VirtualUserTable;
+import org.apache.james.services.VirtualUserTableStore;
+import org.apache.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.SMTPResponse;
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.mail.dsn.DSNStatus;
+import org.apache.james.vut.ErrorMappingException;
+import org.apache.mailet.MailAddress;
+import org.apache.oro.text.regex.MalformedPatternException;
+import org.apache.oro.text.regex.Pattern;
+import org.apache.oro.text.regex.Perl5Compiler;
+import org.apache.oro.text.regex.Perl5Matcher;
+
+/**
+ * Handler which reject invalid recipients
+ */
+public class ValidRcptHandler extends AbstractLogEnabled implements CommandHandler, Configurable, Serviceable {
+
+ private Collection recipients = new ArrayList();
+ private Collection domains = new ArrayList();
+ private Collection regex = new ArrayList();
+ private boolean vut = true;
+ private VirtualUserTable table;
+ private String tableName = null;
+
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager arg0) throws ServiceException {
+ if (tableName == null || tableName.equals("")) {
+ table = (VirtualUserTable) arg0.lookup(VirtualUserTable.ROLE);
+ } else {
+ table = ((VirtualUserTableStore) arg0.lookup(VirtualUserTableStore.ROLE)).getTable(tableName);
+ }
+ }
+
+ /**
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+ */
+ public void configure(Configuration arg0) throws ConfigurationException {
+ Configuration recipientsConfig = arg0.getChild("validRecipients");
+ if (recipientsConfig != null) {
+ setValidRecipients(recipientsConfig.getValue());
+ }
+
+ Configuration domainConfig = arg0.getChild("validDomains");
+ if (domainConfig != null) {
+ setValidDomains(domainConfig.getValue());
+ }
+
+ Configuration regexConfig = arg0.getChild("validRegexPattern");
+ if (regexConfig != null) {
+ try {
+ setValidRegex(regexConfig.getValue());
+ } catch(MalformedPatternException mpe) {
+ throw new ConfigurationException("Malformed pattern: ", mpe);
+ }
+ }
+ Configuration vutConfig = arg0.getChild("enableVirtualUserTable");
+
+ if (vutConfig != null) {
+ vut = vutConfig.getValueAsBoolean(true);
+ }
+ Configuration tableConfig = arg0.getChild("table");
+
+ if (tableConfig != null) {
+ tableName = tableConfig.getValue(null);
+ }
+ }
+
+ /**
+ * Set the valid recipients.
+ *
+ * @param recip The valid recipients. Commaseperated list
+ */
+ public void setValidRecipients(String recip) {
+ StringTokenizer st = new StringTokenizer(recip, ", ", false);
+
+ while (st.hasMoreTokens()) {
+ String recipient = st.nextToken().toLowerCase();
+
+ getLogger().debug("Add recipient to valid recipients: " + recipient);
+ recipients.add(recipient);
+ }
+ }
+
+ /**
+ * Set the domains for which every rcpt will be accepted.
+ *
+ * @param dom The valid domains. Commaseperated list
+ */
+ public void setValidDomains(String dom) {
+ StringTokenizer st = new StringTokenizer(dom, ", ", false);
+
+ while (st.hasMoreTokens()) {
+ String domain = st.nextToken().toLowerCase();
+ getLogger().debug("Add domain to valid domains: " + domain);
+ domains.add(domain);
+ }
+ }
+
+ /**
+ *
+ * @param reg
+ * @throws MalformedPatternException
+ */
+ public void setValidRegex(String reg) throws MalformedPatternException {
+ Perl5Compiler compiler = new Perl5Compiler();
+
+ StringTokenizer st = new StringTokenizer(reg, ", ", false);
+
+ while (st.hasMoreTokens()) {
+ String patternString = st.nextToken().trim();
+
+ getLogger().debug("Add regex to valid regex: " + patternString);
+
+ Pattern pattern = compiler.compile(patternString, Perl5Compiler.READ_ONLY_MASK);
+ regex.add(pattern);
+
+ }
+ }
+
+ public void setVirtualUserTableSupport(boolean vut) {
+ this.vut = vut;
+ }
+
+ /**
+ * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+ */
+ public Collection getImplCommands() {
+ Collection c = new ArrayList();
+ c.add("RCPT");
+
+ return c;
+ }
+
+ /**
+ * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+ */
+ public SMTPResponse onCommand(SMTPSession session, String command, String parameters) {
+ if (!session.isRelayingAllowed() && !(session.isAuthRequired() && session.getUser() != null)) {
+ return checkValidRcpt(session);
+ } else {
+ getLogger().debug("Sender allowed");
+ return null;
+ }
+ }
+
+
+
+ /**
+ * Check if the recipient should be accepted
+ *
+ * @param session The SMTPSession
+ * @return
+ */
+ private SMTPResponse checkValidRcpt(SMTPSession session) {
+ MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
+ boolean invalidUser = true;
+
+ if (session.getConfigurationData().getUsersRepository().contains(rcpt.getUser()) == true || recipients.contains(rcpt.toString().toLowerCase()) || domains.contains(rcpt.getHost().toLowerCase())) {
+ invalidUser = false;
+ }
+
+ // check if an valid virtual mapping exists
+ if (invalidUser == true && vut == true) {
+ try {
+ Collection targetString = table.getMappings(rcpt.getUser(), rcpt.getHost());
+
+ if (targetString != null && targetString.isEmpty() == false) {
+ invalidUser = false;
+ }
+ } catch (ErrorMappingException e) {
+
+ String responseString = e.getMessage();
+
+ getLogger().info("Rejected message. Reject Message: " + responseString);
+
+ return new SMTPResponse(responseString);
+ }
+ }
+
+ if (invalidUser == true && !regex.isEmpty()) {
+ Iterator reg = regex.iterator();
+ Perl5Matcher matcher = new Perl5Matcher();
+
+ while (reg.hasNext()) {
+ if (matcher.matches(rcpt.toString(), (Pattern) reg.next())) {
+ // regex match
+ invalidUser = false;
+ break;
+ }
+ }
+ }
+
+ if (invalidUser == true) {
+ //user not exist
+ getLogger().info("Rejected message. Unknown user: " + rcpt.toString());
+ return new SMTPResponse("554", DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_MAILBOX) + " Unknown user: " + rcpt.toString());
+ }
+ return null;
+ }
+}
Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java?view=diff&rev=490155&r1=490154&r2=490155
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java Mon Dec 25 09:31:07 2006
@@ -1,185 +1,186 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one *
- * or more contributor license agreements. See the NOTICE file *
- * distributed with this work for additional information *
- * regarding copyright ownership. The ASF licenses this file *
- * to you 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.smtpserver.core.filter.fastfail;
-
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-
-
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.james.dnsserver.TemporaryResolutionException;
-import org.apache.james.services.DNSServer;
-import org.apache.james.smtpserver.CommandHandler;
-import org.apache.james.smtpserver.SMTPSession;
-import org.apache.james.util.NetMatcher;
-import org.apache.james.util.mail.dsn.DSNStatus;
-import org.apache.mailet.MailAddress;
-
-/**
- * This class can be used to reject email with bogus MX which is send from a authorized user or an authorized
- * network.
- */
-public class ValidRcptMX extends AbstractJunkHandler implements CommandHandler,
- Serviceable {
-
- private DNSServer dnsServer = null;
-
- private static final String LOCALHOST = "localhost";
-
- private NetMatcher bNetwork = null;
-
- /**
- * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#configure(org.apache.avalon.framework.configuration.Configuration)
- */
- public void configure(Configuration arg0) throws ConfigurationException {
-
- Configuration[] badMX = arg0.getChildren("invalidMXNetworks");
-
- if (badMX.length != 0) {
-
- Collection bannedNetworks = new ArrayList();
-
- for (int i = 0; i < badMX.length; i++) {
- String network = badMX[i].getValue(null);
-
- if (network != null) {
- bannedNetworks.add(network);
- }
- }
-
- setBannedNetworks(bannedNetworks, dnsServer);
-
- getLogger().info("Invalid MX Networks: " + bNetwork.toString());
-
- } else {
- throw new ConfigurationException(
- "Please configure at least on invalid MX network");
- }
-
- super.configure(arg0);
- }
-
- /**
- * Set the banned networks
- *
- * @param networks Collection of networks
- * @param dnsServer The DNSServer
- */
- public void setBannedNetworks(Collection networks, DNSServer dnsServer) {
- bNetwork = new NetMatcher(networks, dnsServer) {
- protected void log(String s) {
- getLogger().debug(s);
- }
-
- };
- }
-
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
- */
- public void service(ServiceManager arg0) throws ServiceException {
- setDNSServer((DNSServer) arg0.lookup(DNSServer.ROLE));
- }
-
- /**
- * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
- */
- public Collection getImplCommands() {
- Collection c = new ArrayList();
- c.add("RCPT");
- return c;
- }
-
- /**
- * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
- */
- public void onCommand(SMTPSession session) {
- doProcessing(session);
- }
-
- /**
- * Set the DNSServer
- *
- * @param dnsServer
- * The dnsServer
- */
- public void setDNSServer(DNSServer dnsServer) {
- this.dnsServer = dnsServer;
- }
-
- /**
- * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#check(org.apache.james.smtpserver.SMTPSession)
- */
- protected boolean check(SMTPSession session) {
- MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
-
- String domain = rcpt.getHost();
-
- // Email should be deliver local
- if (domain.equals(LOCALHOST)) return false;
-
- Iterator mx = null;
- try {
- mx = dnsServer.findMXRecords(domain).iterator();
- } catch (TemporaryResolutionException e1) {
- // TODO: Should we reject temporary ?
- }
-
- if (mx != null && mx.hasNext()) {
- while (mx.hasNext()) {
- String mxRec = mx.next().toString();
-
- try {
- String ip = dnsServer.getByName(mxRec).getHostAddress();
-
- // Check for invalid MX
- if (bNetwork.matchInetNetwork(ip)) {
- return true;
- }
- } catch (UnknownHostException e) {
- // Ignore this
- }
- }
- }
- return false;
- }
-
- /**
- * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkHandlerData(org.apache.james.smtpserver.SMTPSession)
- */
- public JunkHandlerData getJunkHandlerData(SMTPSession session) {
- MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
- JunkHandlerData data = new JunkHandlerData();
-
- data.setRejectResponseString("530" + DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " Invalid MX " + session.getRemoteIPAddress()
- + " for domain " + rcpt.getHost() + ". Reject email");
-
- data.setJunkScoreLogString("Invalid MX " + session.getRemoteIPAddress() + " for domain " + rcpt.getHost() + ". Add JunkScore: " + getScore());
- data.setRejectLogString("Invalid MX " + session.getRemoteIPAddress() + " for domain " + rcpt.getHost() + ". Reject email");
- data.setScoreName("ValidRcptMXCheck");
- return data;
- }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you 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.smtpserver.core.filter.fastfail;
+
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.james.dnsserver.TemporaryResolutionException;
+import org.apache.james.services.DNSServer;
+import org.apache.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.SMTPResponse;
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.NetMatcher;
+import org.apache.james.util.mail.dsn.DSNStatus;
+import org.apache.mailet.MailAddress;
+
+/**
+ * This class can be used to reject email with bogus MX which is send from a authorized user or an authorized
+ * network.
+ */
+public class ValidRcptMX extends AbstractJunkHandler implements CommandHandler,
+ Serviceable {
+
+ private DNSServer dnsServer = null;
+
+ private static final String LOCALHOST = "localhost";
+
+ private NetMatcher bNetwork = null;
+
+ /**
+ * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#configure(org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void configure(Configuration arg0) throws ConfigurationException {
+
+ Configuration[] badMX = arg0.getChildren("invalidMXNetworks");
+
+ if (badMX.length != 0) {
+
+ Collection bannedNetworks = new ArrayList();
+
+ for (int i = 0; i < badMX.length; i++) {
+ String network = badMX[i].getValue(null);
+
+ if (network != null) {
+ bannedNetworks.add(network);
+ }
+ }
+
+ setBannedNetworks(bannedNetworks, dnsServer);
+
+ getLogger().info("Invalid MX Networks: " + bNetwork.toString());
+
+ } else {
+ throw new ConfigurationException(
+ "Please configure at least on invalid MX network");
+ }
+
+ super.configure(arg0);
+ }
+
+ /**
+ * Set the banned networks
+ *
+ * @param networks Collection of networks
+ * @param dnsServer The DNSServer
+ */
+ public void setBannedNetworks(Collection networks, DNSServer dnsServer) {
+ bNetwork = new NetMatcher(networks, dnsServer) {
+ protected void log(String s) {
+ getLogger().debug(s);
+ }
+
+ };
+ }
+
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
+ */
+ public void service(ServiceManager arg0) throws ServiceException {
+ setDNSServer((DNSServer) arg0.lookup(DNSServer.ROLE));
+ }
+
+ /**
+ * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+ */
+ public Collection getImplCommands() {
+ Collection c = new ArrayList();
+ c.add("RCPT");
+ return c;
+ }
+
+ /**
+ * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+ */
+ public SMTPResponse onCommand(SMTPSession session, String command, String parameters) {
+ return doProcessing(session);
+ }
+
+ /**
+ * Set the DNSServer
+ *
+ * @param dnsServer
+ * The dnsServer
+ */
+ public void setDNSServer(DNSServer dnsServer) {
+ this.dnsServer = dnsServer;
+ }
+
+ /**
+ * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#check(org.apache.james.smtpserver.SMTPSession)
+ */
+ protected boolean check(SMTPSession session) {
+ MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
+
+ String domain = rcpt.getHost();
+
+ // Email should be deliver local
+ if (domain.equals(LOCALHOST)) return false;
+
+ Iterator mx = null;
+ try {
+ mx = dnsServer.findMXRecords(domain).iterator();
+ } catch (TemporaryResolutionException e1) {
+ // TODO: Should we reject temporary ?
+ }
+
+ if (mx != null && mx.hasNext()) {
+ while (mx.hasNext()) {
+ String mxRec = mx.next().toString();
+
+ try {
+ String ip = dnsServer.getByName(mxRec).getHostAddress();
+
+ // Check for invalid MX
+ if (bNetwork.matchInetNetwork(ip)) {
+ return true;
+ }
+ } catch (UnknownHostException e) {
+ // Ignore this
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkHandlerData(org.apache.james.smtpserver.SMTPSession)
+ */
+ public JunkHandlerData getJunkHandlerData(SMTPSession session) {
+ MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
+ JunkHandlerData data = new JunkHandlerData();
+
+ data.setRejectResponseString("530" + DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " Invalid MX " + session.getRemoteIPAddress()
+ + " for domain " + rcpt.getHost() + ". Reject email");
+
+ data.setJunkScoreLogString("Invalid MX " + session.getRemoteIPAddress() + " for domain " + rcpt.getHost() + ". Add JunkScore: " + getScore());
+ data.setRejectLogString("Invalid MX " + session.getRemoteIPAddress() + " for domain " + rcpt.getHost() + ". Reject email");
+ data.setScoreName("ValidRcptMXCheck");
+ return data;
+ }
+}
Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java?view=diff&rev=490155&r1=490154&r2=490155
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java Mon Dec 25 09:31:07 2006
@@ -16,9 +16,6 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
-
-
-
package org.apache.james.smtpserver.core.filter.fastfail;
import java.util.ArrayList;
@@ -33,6 +30,7 @@
import org.apache.james.dnsserver.TemporaryResolutionException;
import org.apache.james.services.DNSServer;
import org.apache.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.SMTPResponse;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.util.mail.dsn.DSNStatus;
import org.apache.mailet.MailAddress;
@@ -87,8 +85,8 @@
/**
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
*/
- public void onCommand(SMTPSession session) {
- doProcessing(session);
+ public SMTPResponse onCommand(SMTPSession session, String command, String parameters) {
+ return doProcessing(session);
}
/**
Added: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/CRLFDelimitedByteBuffer.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/CRLFDelimitedByteBuffer.java?view=auto&rev=490155
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/CRLFDelimitedByteBuffer.java (added)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/CRLFDelimitedByteBuffer.java Mon Dec 25 09:31:07 2006
@@ -0,0 +1,315 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you 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.util;
+
+/*
+ * A simple, synchronized, queue of CRLF-delimited lines.
+ *
+ * NOTA BENE: as bytes arrive, they are buffered internally up to a
+ * configured maximum. The maximum is intended to reflect a line length
+ * limiter, but there is a potential corner case that should be
+ * understood. If the working buffer is almost full, and a new packet
+ * arrives with enough data to overflow the buffer, the code will
+ * consider that an error and discard the entire working buffer, even
+ * though the beginning of the new packet might have terminated the
+ * currently accumulating line. And the reported position of the
+ * overflow is based upon the buffer position before scanning for lines,
+ * not an actualy line length (perhaps we need not even report the
+ * position). Since the purpose for this maximum is to prevent memory
+ * flooding attacks, this does not appear to be a particularly critical
+ * corner case. We simply need to make sure that the working buffer is
+ * at least twice the size of the maximum desired line length.
+ *
+ * After buffering the incoming data, it is scanned for CRLF. As each
+ * line is found, it is moved to an ArrayList of Line objects. When all
+ * data has been scanned, any remaining bytes are shifted within the
+ * working buffer to prepare for the next packet.
+ *
+ * The code enforces CRLF pairing (RFC 2821 #2.7.1). The Line object,
+ * which is for internal use only, can hold the bytes for each line or
+ * record an exception (line termination or line length) associated
+ * with processing the data that would otherwise have. The exceptions
+ * are rethrown during the read operation, rather than during the write
+ * operation, so that the order of responses perserves the order of
+ * input.
+ *
+ * This code does not handle dot stuffing. Dot Stuffing, Message size
+ * limiting, and buffering of the message in a file are all expected to
+ * be performed by the I/O handler associated with the DATA accumulation
+ * state.
+ */
+
+public class CRLFDelimitedByteBuffer {
+ static public class TerminationException extends java.io.IOException {
+ private int where;
+ public TerminationException(int where) {
+ super();
+ this.where = where;
+ }
+
+ public TerminationException(String s, int where) {
+ super(s);
+ this.where = where;
+ }
+
+ public int position() {
+ return where;
+ }
+ }
+
+ static public class LineLengthExceededException extends java.io.IOException {
+ public LineLengthExceededException(String s) {
+ super(s);
+ }
+ }
+
+ public CRLFDelimitedByteBuffer() {
+ this(2048);
+ }
+
+ public CRLFDelimitedByteBuffer(int maxLineLength) {
+ lines = new java.util.ArrayList();
+ workLine = new byte[maxLineLength];
+ }
+
+ synchronized public boolean isEmpty() {
+ return lines.isEmpty();
+ }
+
+ synchronized public byte[] read() throws LineLengthExceededException, TerminationException {
+ return lines.isEmpty() ? null : ((Line) lines.remove(0)).getBytes();
+ }
+
+ synchronized public String readString() throws LineLengthExceededException, TerminationException {
+ if (lines.isEmpty()) return null;
+ else {
+ byte[] bytes = ((Line) lines.remove(0)).getBytes();
+ try {
+ return new String(bytes, "US-ASCII");
+ } catch (java.io.UnsupportedEncodingException uee) {
+ return new String(bytes);
+ }
+ }
+ }
+
+ synchronized public void write(byte[] data, int length) {
+ if (canFit(length)) {
+ System.arraycopy(data, 0, workLine, writeindex, length);
+ writeindex += length;
+ buildlines();
+ }
+ }
+
+ synchronized public void write(byte data) {
+ if (canFit(1)) {
+ workLine[writeindex++] = data;
+ buildlines();
+ }
+ }
+
+ synchronized public void write(String s) {
+ write(s.getBytes(), s.getBytes().length);
+ }
+
+ private boolean canFit(int length) {
+ if (writeindex + length > workLine.length) {
+ reset();
+ lines.add(new Line(new LineLengthExceededException("Exceeded maximum line length")));
+ return false;
+ } else return true;
+ }
+
+ static private class Line {
+ java.io.IOException e;
+ byte[] bytes;
+
+ public Line(byte[] data) {
+ bytes = data;
+ }
+
+ public Line(String data) {
+ bytes = data.getBytes();
+ }
+
+ public Line(java.io.IOException e) {
+ this.e = e;
+ }
+
+ public Line(byte[] data, int offset, int length) {
+ bytes = new byte[length];
+ System.arraycopy(data, offset, bytes, 0, length);
+ }
+
+ public byte[] getBytes() throws LineLengthExceededException, TerminationException {
+ if (e != null) {
+ if (e instanceof LineLengthExceededException) throw (LineLengthExceededException) e;
+ else throw (TerminationException) e;
+ }
+ return bytes;
+ }
+ }
+
+ private java.util.ArrayList lines;
+
+ private byte[] workLine;
+ private int writeindex = 0;
+ private int readindex = 0;
+ private int scanindex = 0; // current index for matching within the working buffer
+
+ private void reset() {
+ writeindex = 0;
+ readindex = 0;
+ scanindex = 0;
+ }
+
+ private void shift() {
+ System.arraycopy(workLine, readindex, workLine, 0, writeindex - readindex);
+ writeindex -= readindex;
+ scanindex -= readindex;
+ readindex = 0;
+ }
+
+ private void buildlines() {
+ for (; scanindex < writeindex; scanindex++) {
+ if (workLine[scanindex] == '\n') {
+ final int pos = scanindex;
+ reset();
+ lines.add(new Line(new TerminationException("\"bare\" LF in data stream.", pos)));
+ break;
+ } else if (workLine[scanindex] == '\r') {
+ if (scanindex+1 == writeindex) break;
+ else if (workLine[++scanindex] == '\n') {
+ lines.add(new Line(workLine, readindex, scanindex - readindex + 1));
+ readindex = scanindex + 1;
+ } else {
+ final int pos = scanindex - 1;
+ reset();
+ lines.add(new Line(new TerminationException("\"bare\" CR in data stream.", pos)));
+ break;
+ }
+ }
+ }
+
+ if (readindex != 0) shift();
+ }
+
+ /*** THE CODE BELOW IS PURELY FOR TESTING ***/
+ /*
+ synchronized private void status() {
+ System.out.println("\n--------------------------------------------------\n");
+ if (lines.isEmpty()) System.out.println("Lines: None");
+ else {
+ System.out.println("Lines:");
+ java.util.Iterator i = lines.iterator();
+ while (i.hasNext()) {
+ Line line = (Line) i.next();
+ try {
+ System.out.println("\tData[" + line.getBytes().length + "]: " + new String(line.getBytes(), 0, line.getBytes().length, "US-ASCII"));
+ } catch (java.io.UnsupportedEncodingException uee) {
+ } catch (TerminationException te) {
+ System.out.println("\tSyntax error at character position " + te.position() + ". CR and LF must be CRLF paired. See RFC 2821 #2.7.1.");
+ } catch (LineLengthExceededException llee) {
+ System.out.println("\tLine length exceeded. See RFC 2821 #4.5.3.1.");
+ }
+ }
+ }
+
+ System.out.println("Buffer Status:");
+ System.out.println("\tworkline length: " + workLine.length);
+ System.out.println("\tnext read index: " + readindex);
+ System.out.println("\tnext scan index: " + scanindex);
+ System.out.println("\tnext write index: " + writeindex);
+
+ try {
+ System.out.println("\tOld data: " + new String(workLine, 0, readindex, "US-ASCII"));
+ System.out.println("\tData: " + new String(workLine, readindex, writeindex - readindex, "US-ASCII"));
+ } catch (java.io.UnsupportedEncodingException uee) {
+ System.err.println(uee);
+ }
+ System.out.println("\n--------------------------------------------------\n");
+ }
+
+
+ static public void main(String[] args) throws java.io.IOException {
+ CRLFDelimitedByteBuffer dbb = new CRLFDelimitedByteBuffer();
+ dbb.status();
+ dbb.write("Hello"); dbb.status();
+ dbb.write(" "); dbb.status();
+ dbb.write("World."); dbb.status();
+ dbb.write("\r"); dbb.status();
+ dbb.write("\n"); dbb.status();
+ dbb.write("\r\n"); dbb.status();
+ dbb.write("\n"); dbb.status();
+ dbb.write("\r\r"); dbb.status();
+ dbb.write("stuff\n"); dbb.status();
+ dbb.write("morestuff\r\r"); dbb.status();
+ for (int i = 0; i < 2500; i++) dbb.write("\0"); dbb.status();
+
+ while (!dbb.isEmpty()) {
+ try {
+ byte[] line = dbb.read();
+ System.out.println("Read line[" + line.length + "]: " + new String(line, 0, line.length, "US-ASCII"));
+ } catch (java.io.UnsupportedEncodingException uee) {
+ } catch (TerminationException te) {
+ System.out.println("Syntax error at character position " + te.position() + ". CR and LF must be CRLF paired. See RFC 2821 #2.7.1.");
+ } catch (LineLengthExceededException llee) {
+ System.out.println("Line length exceeded. See RFC 2821 #4.5.3.1.");
+ }
+ }
+ dbb.status();
+
+ dbb.write("This is a test.\015\012.... Three dots\015\012.\015\012");
+ dbb.status();
+
+ while (!dbb.isEmpty()) {
+ try {
+ byte[] line = dbb.read();
+ System.out.println("Read line[" + line.length + "]: " + new String(line, 0, line.length, "US-ASCII"));
+ } catch (java.io.UnsupportedEncodingException uee) {
+ } catch (TerminationException te) {
+ System.out.println("Syntax error at character position " + te.position() + ". CR and LF must be CRLF paired. See RFC 2821 #2.7.1.");
+ } catch (LineLengthExceededException llee) {
+ System.out.println("Line length exceeded. See RFC 2821 #4.5.3.1.");
+ }
+ }
+ dbb.status();
+
+ dbb.write("This is"); dbb.status();
+ dbb.write(" a tes"); dbb.status();
+ dbb.write("t.\015"); dbb.status();
+ dbb.write("\012..."); dbb.status();
+ dbb.write(". Three dot"); dbb.status();
+ dbb.write("s\015\012.\015\012"); dbb.status();
+
+ while (!dbb.isEmpty()) {
+ try {
+ String text = dbb.readString();
+ System.out.println ("read : " + text);
+ dbb.status();
+ } catch (TerminationException te) {
+ System.out.println("Syntax error at character position " + te.position() + ". CR and LF must be CRLF paired. See RFC 2821 #2.7.1.");
+ } catch (LineLengthExceededException llee) {
+ System.out.println("Line length exceeded. See RFC 2821 #4.5.3.1.");
+ }
+ }
+ }
+ */
+}
Propchange: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/CRLFDelimitedByteBuffer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/mail/SMTPRetCode.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/mail/SMTPRetCode.java?view=auto&rev=490155
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/mail/SMTPRetCode.java (added)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/mail/SMTPRetCode.java Mon Dec 25 09:31:07 2006
@@ -0,0 +1,106 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you 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.util.mail;
+
+/**
+ * Result code defined in RFC 2821
+ */
+public class SMTPRetCode {
+ // System status, or system help reply
+ public static final String SYSTEM_STATUS = "211";
+
+ // Help message
+ // (Information on how to use the receiver or the meaning of a
+ // particular non-standard command; this reply is useful only
+ // to the human user)
+ public static final String HELP_MESSAGE = "214";
+
+ // <domain> Service ready
+ public static final String SERVICE_READY = "220";
+
+ // <domain> Service closing transmission channel
+ public static final String SYSTEM_QUIT = "221";
+
+ // Requested mail action okay, completed
+ public static final String MAIL_OK = "250";
+
+ // 251 User not local; will forward to <forward-path>
+ // (See section 3.4)
+ public static final String MAIL_FORWARDING = "251";
+
+ // Cannot VRFY user, but will accept message and attempt
+ // delivery
+ // (See section 3.5.3)
+ public static final String MAIL_UNDEFINDED = "252";
+
+ // Start mail input; end with <CRLF>.<CRLF>
+ public static final String DATA_READY = "354";
+
+ // <domain> Service not available, closing transmission channel
+ // (This may be a reply to any command if the service knows it
+ // must shut down)
+ public static final String SERVICE_NOT_AVAILABLE = "421";
+
+ // Requested mail action not taken: mailbox unavailable
+ // (e.g., mailbox busy)
+ public static final String MAILBOX_TEMP_UNAVAILABLE = "450";
+
+ // Requested action aborted: local error in processing
+ public static final String LOCAL_ERROR = "451";
+
+ // Requested action not taken: insufficient system storage
+ public static final String SYSTEM_STORAGE_ERROR = "452";
+
+ // Syntax error, command unrecognized
+ // (This may include errors such as command line too long)
+ public static final String SYNTAX_ERROR_COMMAND_UNRECOGNIZED = "500";
+
+ // Syntax error in parameters or arguments
+ public static final String SYNTAX_ERROR_ARGUMENTS = "501";
+
+ // Command not implemented (see section 4.2.4)
+ public static final String UNIMPLEMENTED_COMMAND = "502";
+
+ // Bad sequence of commands
+ public static final String BAD_SEQUENCE = "503";
+
+ // Command parameter not implemented
+ public static final String PARAMETER_NOT_IMPLEMENTED = "504";
+
+ // Requested action not taken: mailbox unavailable
+ // (e.g., mailbox not found, no access, or command rejected
+ // for policy reasons)
+ public static final String MAILBOX_PERM_UNAVAILABLE = "550";
+
+ // User not local; please try <forward-path> (See section 3.4)
+ public static final String USER_NOT_LOCAL = "551";
+
+ // Requested mail action aborted: exceeded storage allocation
+ public static final String QUOTA_EXCEEDED = "552";
+
+ // Requested action not taken: mailbox name not allowed
+ // (e.g., mailbox syntax incorrect)
+ public static final String SYNTAX_ERROR_MAILBOX = "553";
+
+ // Transaction failed (Or, in the case of a connection-opening
+ // response, "No SMTP service here")
+ public static final String TRANSACTION_FAILED = "554";
+
+}
Propchange: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/mail/SMTPRetCode.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/AbstractSMTPSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/AbstractSMTPSession.java?view=diff&rev=490155&r1=490154&r2=490155
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/AbstractSMTPSession.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/AbstractSMTPSession.java Mon Dec 25 09:31:07 2006
@@ -20,11 +20,8 @@
package org.apache.james.smtpserver;
-import org.apache.james.util.watchdog.Watchdog;
import org.apache.mailet.Mail;
-import java.io.IOException;
-import java.io.InputStream;
import java.util.Map;
/**
@@ -82,13 +79,6 @@
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#getInputStream()
- */
- public InputStream getInputStream() {
- throw new UnsupportedOperationException("Unimplemented Stub Method");
- }
-
- /**
* @see org.apache.james.smtpserver.SMTPSession#getMail()
*/
public Mail getMail() {
@@ -152,13 +142,6 @@
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#getWatchdog()
- */
- public Watchdog getWatchdog() {
- throw new UnsupportedOperationException("Unimplemented Stub Method");
- }
-
- /**
* @see org.apache.james.smtpserver.SMTPSession#isAuthRequired()
*/
public boolean isAuthRequired() {
@@ -173,72 +156,72 @@
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#isSessionEnded()
+ * @see org.apache.james.smtpserver.SMTPSession#resetState()
*/
- public boolean isSessionEnded() {
+ public void resetState() {
throw new UnsupportedOperationException("Unimplemented Stub Method");
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#readCommandLine()
+ * @see org.apache.james.smtpserver.SMTPSession#setMail(org.apache.mailet.Mail)
*/
- public String readCommandLine() throws IOException {
+ public void setMail(Mail mail) {
throw new UnsupportedOperationException("Unimplemented Stub Method");
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#resetConnectionState()
+ * @see org.apache.james.smtpserver.SMTPSession#setRelayingAllowed(boolean)
*/
- public void resetConnectionState() {
+ public void setRelayingAllowed(boolean relayingAllowed) {
throw new UnsupportedOperationException("Unimplemented Stub Method");
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#resetState()
+ * @see org.apache.james.smtpserver.SMTPSession#setStopHandlerProcessing(boolean)
*/
- public void resetState() {
+ public void setStopHandlerProcessing(boolean b) {
throw new UnsupportedOperationException("Unimplemented Stub Method");
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#setMail(org.apache.mailet.Mail)
+ * @see org.apache.james.smtpserver.SMTPSession#setUser(java.lang.String)
*/
- public void setMail(Mail mail) {
+ public void setUser(String user) {
throw new UnsupportedOperationException("Unimplemented Stub Method");
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#setRelayingAllowed(boolean)
+ * @see org.apache.james.smtpserver.SMTPSession#useHeloEhloEnforcement()
*/
- public void setRelayingAllowed(boolean relayingAllowed) {
+ public boolean useHeloEhloEnforcement() {
throw new UnsupportedOperationException("Unimplemented Stub Method");
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#setStopHandlerProcessing(boolean)
+ * @see org.apache.james.smtpserver.SMTPSession#writeResponse(java.lang.String)
*/
- public void setStopHandlerProcessing(boolean b) {
+ public void writeResponse(String respString) {
throw new UnsupportedOperationException("Unimplemented Stub Method");
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#setUser(java.lang.String)
+ * @see org.apache.james.smtpserver.SMTPSession#popLineHandler()
*/
- public void setUser(String user) {
+ public void popLineHandler() {
throw new UnsupportedOperationException("Unimplemented Stub Method");
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#useHeloEhloEnforcement()
+ * @see org.apache.james.smtpserver.SMTPSession#pushLineHandler(org.apache.james.smtpserver.LineHandler)
*/
- public boolean useHeloEhloEnforcement() {
+ public void pushLineHandler(LineHandler overrideCommandHandler) {
throw new UnsupportedOperationException("Unimplemented Stub Method");
}
/**
- * @see org.apache.james.smtpserver.SMTPSession#writeResponse(java.lang.String)
+ * @see org.apache.james.smtpserver.SMTPSession#writeSMTPResponse(org.apache.james.smtpserver.SMTPResponse)
*/
- public void writeResponse(String respString) {
+ public void writeSMTPResponse(SMTPResponse response) {
throw new UnsupportedOperationException("Unimplemented Stub Method");
}
Modified: james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java?view=diff&rev=490155&r1=490154&r2=490155
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java Mon Dec 25 09:31:07 2006
@@ -299,7 +299,7 @@
assertNull("No details",mockedSMTPSession.getConnectionState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
assertNotNull("Listed on RBL",mockedSMTPSession.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
- rbl.onCommand(mockedSMTPSession);
+ rbl.onCommand(mockedSMTPSession,"RCPT","<te...@test>");
assertEquals("Score stored",((JunkScore) mockedSMTPSession.getConnectionState().get(JunkScore.JUNK_SCORE_SESSION)).getStoredScore("DNSRBLCheck"), 20.0, 0d);
}
Modified: james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/MaxRcptHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/MaxRcptHandlerTest.java?view=diff&rev=490155&r1=490154&r2=490155
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/MaxRcptHandlerTest.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/MaxRcptHandlerTest.java Mon Dec 25 09:31:07 2006
@@ -52,10 +52,6 @@
return false;
}
- public void writeResponse(String resp) {
- response = resp;
- }
-
public void setStopHandlerProcessing(boolean processing) {
this.processing = processing;
}
@@ -80,9 +76,9 @@
handler.setAction("reject");
handler.setMaxRcpt(2);
- handler.onCommand(session);
+ SMTPResponse response = handler.onCommand(session,"RCPT","<te...@test>");
- assertNotNull("Rejected.. To many recipients", response);
+ assertEquals("Rejected.. To many recipients", response.getRetCode(), "452");
assertTrue("Reject.. Stop processing",session.getStopHandlerProcessing());
}
@@ -97,8 +93,8 @@
handler.setAction("junkScore");
handler.setScore(20);
handler.setMaxRcpt(2);
- handler.onCommand(session);
-
+ SMTPResponse response = handler.onCommand(session,"RCPT","<te...@test>");
+
assertNull("Not Rejected.. we use junkScore action", response);
assertFalse("Not Rejected.. we use junkScore action",session.getStopHandlerProcessing());
assertEquals("Get Score", ((JunkScore) session.getState().get(JunkScore.JUNK_SCORE)).getStoredScore("MaxRcptCheck"),20.0,0d);
@@ -112,7 +108,7 @@
handler.setAction("reject");
handler.setMaxRcpt(4);
- handler.onCommand(session);
+ SMTPResponse response = handler.onCommand(session,"RCPT","<te...@test>");
assertNull("Not Rejected..", response);
assertFalse("Not stop processing",session.getStopHandlerProcessing());
Modified: james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java?view=diff&rev=490155&r1=490154&r2=490155
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java Mon Dec 25 09:31:07 2006
@@ -1003,13 +1003,14 @@
wr.write("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
wr.write("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
wr.write("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
+ wr.write("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100\r\n");
+ // add a CRLF in the middle, to be sure we don't use more than 1000 bytes by RFC.
wr.write("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
wr.write("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
wr.write("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
wr.write("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
wr.write("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
- wr.write("1234567810123456782012345678301234567840123456785012345678601234567870123456788012345678901234567100");
- wr.write("1234567810123456782012\r\n"); // 1022 + CRLF = 1024
+ wr.write("12345678101234567820\r\n"); // 500 + CRLF + 520 + CRLF = 1024
wr.close();
assertTrue(smtpProtocol.completePendingCommand());
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org