Author: eric
Date: Thu Jun 14 09:26:03 2012
New Revision: 1350154
URL: http://svn.apache.org/viewvc?rev=1350154&view=rev
Log:
Impact code to use james3 components (POSTAGE-23)
Added:
james/postage/trunk/src/main/java/org/apache/james/postage/client/ReaderInputStream.java
Removed:
james/postage/trunk/src/main/java/org/apache/james/postage/client/RemoteManagerClient.java
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/AvalonToPostageLogger.java
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleServiceManager.java
Modified:
james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3Client.java
james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java
james/postage/trunk/src/main/java/org/apache/james/postage/client/SMTPClient.java
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailSink.java
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleMailServer.java
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleSMTPServerConfiguration.java
Modified:
james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3Client.java
URL:
http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3Client.java?rev=1350154&r1=1350153&r2=1350154&view=diff
==============================================================================
---
james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3Client.java
(original)
+++
james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3Client.java
Thu Jun 14 09:26:03 2012
@@ -41,16 +41,16 @@ public class POP3Client implements Sampl
private static Log log = LogFactory.getLog(POP3Client.class);
- private String m_host;
- private int m_port;
- private UserList m_internalUsers;
- private PostageRunnerResult m_results;
+ private String host;
+ private int port;
+ private UserList internalUsers;
+ private PostageRunnerResult results;
public POP3Client(String host, int port, UserList internalUsers,
PostageRunnerResult results) {
- m_host = host;
- m_port = port;
- m_internalUsers = internalUsers;
- m_results = results;
+ this.host = host;
+ this.port = port;
+ this.internalUsers = internalUsers;
+ this.results = results;
}
/**
@@ -58,7 +58,7 @@ public class POP3Client implements Sampl
*/
public boolean checkAvailability() throws StartupException {
try {
- org.apache.commons.net.pop3.POP3Client pop3Client =
openConnection(m_internalUsers.getRandomUsername());
+ org.apache.commons.net.pop3.POP3Client pop3Client =
openConnection(this.internalUsers.getRandomUsername());
closeSession(pop3Client);
} catch (PostageException e) {
throw new StartupException("error checking availability");
@@ -78,8 +78,10 @@ public class POP3Client implements Sampl
private org.apache.commons.net.pop3.POP3Client openConnection(String
username) throws PostageException {
org.apache.commons.net.pop3.POP3Client pop3Client = new
org.apache.commons.net.pop3.POP3Client();
try {
- pop3Client.connect(m_host, m_port);
- pop3Client.login(username, m_internalUsers.getPassword());
+ pop3Client.connect(this.host, this.port);
+ if
(!pop3Client.login(this.internalUsers.getEmailAddress(username),
this.internalUsers.getPassword())) {
+ log.warn("Login did not work for user: " + username);
+ }
} catch (IOException e) {
throw new PostageException("POP3 service not available", e);
}
@@ -90,7 +92,7 @@ public class POP3Client implements Sampl
* take one POP3 sample for a random user
*/
public void doSample() throws SamplingException {
- String username = m_internalUsers.getRandomUsername();
+ String username = this.internalUsers.getRandomUsername();
try {
findAllMatchingTestMail(username);
@@ -105,7 +107,7 @@ public class POP3Client implements Sampl
* unprocessed by the random access. this is done by iterating over all
user accounts, looking for mail
*/
public void doMatchMailForAllUsers() {
- Iterator<String> usernames = m_internalUsers.getUsernames();
+ Iterator<String> usernames = this.internalUsers.getUsernames();
while (usernames.hasNext()) {
String username = usernames.next();
try {
@@ -131,7 +133,7 @@ public class POP3Client implements Sampl
entries = pop3Client.listMessages();
} catch (Exception e) {
String errorMessage = "failed to read pop3 account mail list
for " + username;
- m_results.addError(500, errorMessage);
+ this.results.addError(500, errorMessage);
log.info(errorMessage);
return;
}
@@ -140,7 +142,7 @@ public class POP3Client implements Sampl
POP3MessageInfo entry = entries[i];
try {
- new POP3MailAnalyzeStrategy("pop3", m_results, pop3Client,
entry.number, i).handle();
+ new POP3MailAnalyzeStrategy("pop3", this.results,
pop3Client, entry.number, i).handle();
} catch (Exception exception) {
log.warn("error processing pop3 mail", exception);
}
Modified:
james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java
URL:
http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java?rev=1350154&r1=1350153&r2=1350154&view=diff
==============================================================================
---
james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java
(original)
+++
james/postage/trunk/src/main/java/org/apache/james/postage/client/POP3MailAnalyzeStrategy.java
Thu Jun 14 09:26:03 2012
@@ -26,7 +26,6 @@ import java.io.Reader;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
-import org.apache.james.smtpserver.ReaderInputStream;
import org.apache.james.postage.mail.MailAnalyzeStrategy;
import org.apache.james.postage.result.PostageRunnerResult;
Added:
james/postage/trunk/src/main/java/org/apache/james/postage/client/ReaderInputStream.java
URL:
http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/client/ReaderInputStream.java?rev=1350154&view=auto
==============================================================================
---
james/postage/trunk/src/main/java/org/apache/james/postage/client/ReaderInputStream.java
(added)
+++
james/postage/trunk/src/main/java/org/apache/james/postage/client/ReaderInputStream.java
Thu Jun 14 09:26:03 2012
@@ -0,0 +1,40 @@
+/****************************************************************
+ * 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.postage.client;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+/**
+ * Simple class to allow a cast from a java.io.Reader to a java.io.InputStream
+ *
+ */
+public class ReaderInputStream extends InputStream {
+ private Reader reader = null;
+ public ReaderInputStream(Reader reader) {
+ this.reader = reader;
+ }
+ /**
+ * @see java.io.InputStream#read()
+ */
+ public int read() throws IOException {
+ return reader.read();
+ }
+}
Modified:
james/postage/trunk/src/main/java/org/apache/james/postage/client/SMTPClient.java
URL:
http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/client/SMTPClient.java?rev=1350154&r1=1350153&r2=1350154&view=diff
==============================================================================
---
james/postage/trunk/src/main/java/org/apache/james/postage/client/SMTPClient.java
(original)
+++
james/postage/trunk/src/main/java/org/apache/james/postage/client/SMTPClient.java
Thu Jun 14 09:26:03 2012
@@ -20,42 +20,43 @@
package org.apache.james.postage.client;
+import java.util.Properties;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+
import org.apache.james.postage.SamplingException;
import org.apache.james.postage.StartupException;
-import org.apache.james.postage.mail.HeaderConstants;
import org.apache.james.postage.configuration.MailSender;
import org.apache.james.postage.execution.Sampler;
+import org.apache.james.postage.mail.HeaderConstants;
import org.apache.james.postage.result.MailProcessingRecord;
import org.apache.james.postage.result.PostageRunnerResult;
import org.apache.james.postage.user.UserList;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.Transport;
-import javax.mail.internet.InternetAddress;
-import java.util.Properties;
-
/**
* connects as a SMTP client and handles all mail according to its
configuration.<br/>
* it is threadsafe and reentrant and thus can be reused over multiple
parallel client session<br/>
*/
public class SMTPClient implements Sampler {
- private String m_host;
- private int m_port;
- private UserList m_internalUsers;
- private UserList m_externalUsers;
- private PostageRunnerResult m_results;
- private MailSender m_mailSender;
+ private String host;
+ private int port;
+ private UserList internalUsers;
+ private UserList externalUsers;
+ private PostageRunnerResult results;
+ private MailSender mailSender;
public SMTPClient(String host, int port, UserList internalUsers, UserList
externalUsers, PostageRunnerResult results, MailSender mailSender) {
- m_host = host;
- m_port = port;
- m_internalUsers = internalUsers;
- m_externalUsers = externalUsers;
- m_mailSender = mailSender;
- m_results = results;
+ this.host = host;
+ this.port = port;
+ this.internalUsers = internalUsers;
+ this.externalUsers = externalUsers;
+ this.mailSender = mailSender;
+ this.results = results;
}
public boolean checkAvailability() throws StartupException {
@@ -64,11 +65,11 @@ public class SMTPClient implements Sampl
MailProcessingRecord proformaMailProcessingRecord = new
MailProcessingRecord();
Session session = getMailSession();
proformaMailProcessingRecord.setMailId(HeaderConstants.JAMES_POSTAGE_STARTUPCHECK_HEADER_ID);
- Message message = m_mailSender.createMail(session,
proformaMailProcessingRecord);
+ Message message = this.mailSender.createMail(session,
proformaMailProcessingRecord);
setMailFromAndTo(message, proformaMailProcessingRecord);
Transport.send(message);
} catch (Exception e) {
- throw new StartupException("inbound SMTP service not available",
e);
+ throw new StartupException("Inbound SMTP service not available
with " + this.toString() , e);
}
return true;
}
@@ -77,15 +78,15 @@ public class SMTPClient implements Sampl
String senderUsername;
String senderMailAddress;
- if (m_mailSender.getParentProfile().isSourceInternal()) {
- senderUsername = m_internalUsers.getRandomUsername();
+ if (this.mailSender.getParentProfile().isSourceInternal()) {
+ senderUsername = this.internalUsers.getRandomUsername();
} else {
- senderUsername = m_externalUsers.getRandomUsername();
+ senderUsername = this.externalUsers.getRandomUsername();
}
- if (m_mailSender.getParentProfile().isSourceInternal()) {
- senderMailAddress =
m_internalUsers.getEmailAddress(senderUsername);
+ if (this.mailSender.getParentProfile().isSourceInternal()) {
+ senderMailAddress =
this.internalUsers.getEmailAddress(senderUsername);
} else {
- senderMailAddress =
m_externalUsers.getEmailAddress(senderUsername);
+ senderMailAddress =
this.externalUsers.getEmailAddress(senderUsername);
}
mailProcessingRecord.setSender(senderUsername);
mailProcessingRecord.setSenderMailAddress(senderMailAddress);
@@ -93,15 +94,15 @@ public class SMTPClient implements Sampl
String recepientUsername;
String recepientMailAddress;
- if (m_mailSender.getParentProfile().isTargetInternal()) {
- recepientUsername = m_internalUsers.getRandomUsername();
+ if (this.mailSender.getParentProfile().isTargetInternal()) {
+ recepientUsername = this.internalUsers.getRandomUsername();
} else {
- recepientUsername = m_externalUsers.getRandomUsername();
+ recepientUsername = this.externalUsers.getRandomUsername();
}
- if (m_mailSender.getParentProfile().isTargetInternal()) {
- recepientMailAddress =
m_internalUsers.getEmailAddress(recepientUsername);
+ if (this.mailSender.getParentProfile().isTargetInternal()) {
+ recepientMailAddress =
this.internalUsers.getEmailAddress(recepientUsername);
} else {
- recepientMailAddress =
m_externalUsers.getEmailAddress(recepientUsername);
+ recepientMailAddress =
this.externalUsers.getEmailAddress(recepientUsername);
}
mailProcessingRecord.setReceiver(recepientUsername);
mailProcessingRecord.setReceiverMailAddress(recepientMailAddress);
@@ -112,14 +113,14 @@ public class SMTPClient implements Sampl
MailProcessingRecord mailProcessingRecord = new MailProcessingRecord();
mailProcessingRecord.setMailId(MailProcessingRecord.getNextId());
- m_results.addNewMailRecord(mailProcessingRecord);
+ this.results.addNewMailRecord(mailProcessingRecord);
mailProcessingRecord.setTimeConnectStart(System.currentTimeMillis());
Message message = null;
try {
try {
Session session = getMailSession();
- message = m_mailSender.createMail(session,
mailProcessingRecord);
+ message = this.mailSender.createMail(session,
mailProcessingRecord);
} catch (Exception e) {
mailProcessingRecord.setErrorTextSending("Could not send
mail");
throw e;
@@ -145,8 +146,14 @@ public class SMTPClient implements Sampl
private Session getMailSession() {
Properties props = System.getProperties();
- props.put("mail.smtp.host", m_host);
- props.put("mail.smtp.port", Integer.toString(m_port));
+ props.put("mail.smtp.host", this.host);
+ props.put("mail.smtp.port", Integer.toString(this.port));
return Session.getDefaultInstance(props, null);
}
+
+ @Override
+ public String toString() {
+ return "SMTPClient [host=" + host + ", port=" + port + "]";
+ }
+
}
Modified:
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailSink.java
URL:
http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailSink.java?rev=1350154&r1=1350153&r2=1350154&view=diff
==============================================================================
---
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailSink.java
(original)
+++
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SMTPMailSink.java
Thu Jun 14 09:26:03 2012
@@ -16,108 +16,261 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
-
-
package org.apache.james.postage.smtpserver;
-import org.apache.avalon.cornerstone.blocks.sockets.DefaultServerSocketFactory;
-import org.apache.avalon.cornerstone.blocks.sockets.DefaultSocketFactory;
-import org.apache.avalon.cornerstone.services.sockets.ServerSocketFactory;
-import org.apache.avalon.cornerstone.services.sockets.SocketFactory;
-import org.apache.avalon.cornerstone.services.sockets.SocketManager;
-import org.apache.avalon.cornerstone.services.threads.ThreadManager;
-import org.apache.avalon.excalibur.thread.impl.DefaultThreadPool;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.service.ServiceManager;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.excalibur.thread.ThreadPool;
-import org.apache.james.api.dnsservice.DNSService;
-import org.apache.james.dnsserver.DNSServer;
+import org.apache.james.dnsservice.api.DNSService;
+import org.apache.james.domainlist.api.mock.SimpleDomainList;
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.filesystem.api.mock.MockFileSystem;
+import org.apache.james.mailrepository.api.MailRepositoryStore;
+import org.apache.james.mailrepository.mock.MockMailRepositoryStore;
import org.apache.james.postage.SamplingException;
import org.apache.james.postage.execution.Sampler;
import org.apache.james.postage.result.PostageRunnerResult;
-import org.apache.james.smtpserver.SMTPServer;
-import org.apache.james.socket.JamesConnectionManager;
-import org.apache.james.util.connection.SimpleConnectionManager;
+import org.apache.james.protocols.lib.mock.MockProtocolHandlerLoader;
+import org.apache.james.queue.api.MailQueue;
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.james.queue.api.mock.MockMailQueue;
+import org.apache.james.queue.api.mock.MockMailQueueFactory;
+import org.apache.james.rrt.api.RecipientRewriteTable;
+import org.apache.james.rrt.api.RecipientRewriteTableException;
+import org.apache.james.smtpserver.netty.SMTPServer;
+import org.apache.james.user.api.UsersRepository;
+import org.apache.james.user.lib.mock.MockUsersRepository;
+import org.apache.mailet.HostAddress;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * puts up a gateway SMTP server acting as a mail sink for the external mail
sent out by James.<br/>
- * mails are catched, test mails are identified and tracked
+ * <p>
+ * Puts up a gateway SMTP server acting as a mail sink for the external mail
sent out by James.
+ * </p>
+ * <p>
+ * Mails are catched, test mails are identified and tracked.
+ * </p>
*/
-public class SMTPMailSink implements Sampler, SocketManager, ThreadManager {
+public class SMTPMailSink implements Sampler {
private static Log log = LogFactory.getLog(SMTPMailSink.class);
- private int m_smtpListenerPort = 2525;
- private SimpleMailServer m_mailServer = new SimpleMailServer();
- private SMTPServer m_smtpServer = new SMTPServer();
+ private int smtpListenerPort = 2525;
+ private SimpleMailServer mailServer = new SimpleMailServer();
+ private SMTPServer smtpServer = new SMTPServer();
+
+ protected HierarchicalConfiguration configuration;
+ protected UsersRepository usersRepository = new MockUsersRepository();
+ protected AlterableDNSServer dnsServer;
+ protected MailRepositoryStore store;
+ protected FileSystem fileSystem;
+ protected DNSService dnsService;
+ protected MockProtocolHandlerLoader chain;
+ protected MailQueueFactory queueFactory;
+ protected MailQueue queue;
public int getSmtpListenerPort() {
- return m_smtpListenerPort;
+ return this.smtpListenerPort;
}
public void setSmtpListenerPort(int smtpListenerPort) {
- m_smtpListenerPort = smtpListenerPort;
+ this.smtpListenerPort = smtpListenerPort;
}
public void setResults(PostageRunnerResult results) {
- m_mailServer.setResults(results);
+ this.mailServer.setResults(results);
}
+
public void initialize() throws Exception {
- m_smtpServer.enableLogging(new AvalonToPostageLogger());
- m_smtpServer.service(setUpServiceManager());
+ Logger log = LoggerFactory.getLogger("SMTP");
- SimpleSMTPServerConfiguration testConfiguration = new
SimpleSMTPServerConfiguration(m_smtpListenerPort);
- testConfiguration.init();
- m_smtpServer.configure(testConfiguration);
+ chain = new MockProtocolHandlerLoader();
- m_smtpServer.initialize();
- }
+ chain.put("usersrepository", this.usersRepository);
- private ServiceManager setUpServiceManager() throws Exception {
- SimpleServiceManager serviceManager = new SimpleServiceManager();
- SimpleConnectionManager connectionManager = new
SimpleConnectionManager();
- connectionManager.enableLogging(new AvalonToPostageLogger());
- serviceManager.put(JamesConnectionManager.ROLE, connectionManager);
- serviceManager.put("org.apache.mailet.MailetContext", new
TrivialMailContext());
- serviceManager.put("org.apache.james.services.MailServer",
m_mailServer);
- serviceManager.put("org.apache.james.services.UsersRepository", null);
//m_usersRepository);
- DNSServer server = new DNSServer();
- server.enableLogging(new AvalonToPostageLogger());
- server.configure(new DefaultConfiguration("dnsserver"));
- server.initialize();
- serviceManager.put(DNSService.ROLE, server);
- serviceManager.put(SocketManager.ROLE, this);
- serviceManager.put(ThreadManager.ROLE, this);
- return serviceManager;
- }
+ this.dnsServer = new AlterableDNSServer();
+ chain.put("dnsservice", this.dnsServer);
- public ServerSocketFactory getServerSocketFactory(String string) throws
Exception {
- return new DefaultServerSocketFactory();
- }
+ store = new MockMailRepositoryStore();
+ chain.put("mailStore", store);
+ fileSystem = new MockFileSystem();
+
+ chain.put("filesystem", fileSystem);
+ chain.put("org.apache.james.smtpserver.protocol.DNSService",
dnsService);
+ chain.put("recipientrewritetable", new RecipientRewriteTable() {
+ @Override
+ public void addRegexMapping(String user, String domain, String
regex) throws RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public void removeRegexMapping(String user, String domain, String
regex) throws
+ RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public void addAddressMapping(String user, String domain, String
address) throws
+ RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public void removeAddressMapping(String user, String domain,
String address) throws
+ RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public void addErrorMapping(String user, String domain, String
error) throws RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public void removeErrorMapping(String user, String domain, String
error) throws
+ RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public Collection<String> getUserDomainMappings(String user,
String domain) throws
+ RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public void addMapping(String user, String domain, String mapping)
throws RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public void removeMapping(String user, String domain, String
mapping) throws RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public Map<String, Collection<String>> getAllMappings() throws
RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public void addAliasDomainMapping(String aliasDomain, String
realDomain) throws
+ RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public void removeAliasDomainMapping(String aliasDomain, String
realDomain) throws
+ RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ @Override
+ public Collection<String> getMappings(String user, String domain)
throws ErrorMappingException,
+ RecipientRewriteTableException {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ });
+
+ chain.put("org.apache.james.smtpserver.protocol.DNSService",
dnsService);
+ queueFactory = new MockMailQueueFactory();
+ queue = (MockMailQueue)
queueFactory.getQueue(MockMailQueueFactory.SPOOL);
+ chain.put("mailqueuefactory", queueFactory);
+ chain.put("domainlist", new SimpleDomainList() {
+
+ @Override
+ public boolean containsDomain(String serverName) {
+ return "localhost".equals(serverName);
+ }
+ });
+
+ this.smtpServer = new SMTPServer();
+ this.smtpServer.setDNSService(this.dnsServer);
+ this.smtpServer.setFileSystem(fileSystem);
+
+ this.smtpServer.setProtocolHandlerLoader(chain);
+
+ this.smtpServer.setLog(log);
+
+// this.configuration = new
SimpleSMTPServerConfiguration(getSmtpListenerPort());
+// this.smtpServer.configure(this.configuration);
- public SocketFactory getSocketFactory(String string) throws Exception {
- return new DefaultSocketFactory();
- }
+ this.smtpServer.init();
- public ThreadPool getThreadPool(String string) throws
IllegalArgumentException {
- return getDefaultThreadPool();
}
- public ThreadPool getDefaultThreadPool() {
- try {
- DefaultThreadPool defaultThreadPool = new DefaultThreadPool(1);
- defaultThreadPool.enableLogging(new AvalonToPostageLogger());
- return defaultThreadPool;
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
+ protected void setUpFakeLoader() throws Exception {
}
public void doSample() throws SamplingException {
log.debug("sampling while mails are coming in.");
}
+
+ final class AlterableDNSServer implements DNSService {
+ private InetAddress localhostByName = null;
+ @Override
+ public Collection<String> findMXRecords(String hostname) {
+ List<String> res = new ArrayList<String>();
+ if (hostname == null) {
+ return res;
+ }
+ if ("james.apache.org".equals(hostname)) {
+ res.add("nagoya.apache.org");
+ }
+ return res;
+ }
+ public Iterator<HostAddress> getSMTPHostAddresses(String domainName) {
+ throw new UnsupportedOperationException("Unimplemented mock
service");
+ }
+ @Override
+ public InetAddress[] getAllByName(String host) throws
UnknownHostException {
+ return new InetAddress[]{getByName(host)};
+ }
+ @Override
+ public InetAddress getByName(String host) throws UnknownHostException {
+ if (getLocalhostByName() != null) {
+ if ("127.0.0.1".equals(host)) {
+ return getLocalhostByName();
+ }
+ }
+ if ("1.0.0.127.bl.spamcop.net.".equals(host)) {
+ return InetAddress.getByName("localhost");
+ }
+ if ("james.apache.org".equals(host)) {
+ return InetAddress.getByName("james.apache.org");
+ }
+ if ("abgsfe3rsf.de".equals(host)) {
+ throw new UnknownHostException();
+ }
+ if ("128.0.0.1".equals(host) || "192.168.0.1".equals(host) ||
"127.0.0.1".equals(host) || "127.0.0.0".equals(
+ host) || "255.0.0.0".equals(host) ||
"255.255.255.255".equals(host)) {
+ return InetAddress.getByName(host);
+ }
+ throw new UnsupportedOperationException("getByName not implemented
in mock for host: " + host);
+ }
+ @Override
+ public Collection<String> findTXTRecords(String hostname) {
+ List<String> res = new ArrayList<String>();
+ if (hostname == null) {
+ return res;
+ }
+ if ("2.0.0.127.bl.spamcop.net.".equals(hostname)) {
+ res.add("Blocked - see
http://www.spamcop.net/bl.shtml?127.0.0.2");
+ }
+ return res;
+ }
+ public InetAddress getLocalhostByName() {
+ return localhostByName;
+ }
+ public void setLocalhostByName(InetAddress localhostByName) {
+ this.localhostByName = localhostByName;
+ }
+ @Override
+ public String getHostName(InetAddress addr) {
+ return addr.getHostName();
+ }
+ @Override
+ public InetAddress getLocalHost() throws UnknownHostException {
+ return InetAddress.getLocalHost();
+ }
+ }
+
}
Modified:
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleMailServer.java
URL:
http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleMailServer.java?rev=1350154&r1=1350153&r2=1350154&view=diff
==============================================================================
---
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleMailServer.java
(original)
+++
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleMailServer.java
Thu Jun 14 09:26:03 2012
@@ -16,38 +16,37 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
-
-
package org.apache.james.postage.smtpserver;
-import org.apache.james.postage.result.PostageRunnerResult;
-import org.apache.james.services.MailRepository;
-import org.apache.james.services.MailServer;
-import org.apache.mailet.Mail;
-import org.apache.mailet.MailAddress;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashSet;
import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.HashSet;
-
+import org.apache.james.mailrepository.api.MailRepository;
+import org.apache.james.postage.result.PostageRunnerResult;
+import org.apache.james.smtpserver.netty.SMTPServer;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
/**
- * a quite simple (only receiving) SMTP server which reads mails and tries to
match them with sent test mails.<br/>
- * reuses James' own SMTP server components
+ * <p>
+ * A quite simple (only receiving) {@link SMTPServer} which reads mails and
tries to match
+ * them with sent test mails. It reuses James' own SMTP server components.
+ * </p>
*/
-public class SimpleMailServer implements MailServer {
+public class SimpleMailServer {
- private int m_counter = 0;
- private PostageRunnerResult m_results;
+ private int counter = 0;
+ private PostageRunnerResult results;
public void sendMail(MailAddress sender, Collection recipients,
MimeMessage message) throws MessagingException {
try {
- new SMTPMailAnalyzeStrategy("smtpOutbound", m_results,
message).handle();
+ new SMTPMailAnalyzeStrategy("smtpOutbound", this.results,
message).handle();
} catch (Exception e) {
throw new MessagingException("error handling message", e);
}
@@ -84,8 +83,8 @@ public class SimpleMailServer implements
}
public synchronized String getId() {
- m_counter++;
- return "SimpleMailServer-ID-" + m_counter;
+ this.counter++;
+ return "SimpleMailServer-ID-" + this.counter;
}
public boolean addUser(String userName, String password) {
@@ -97,11 +96,9 @@ public class SimpleMailServer implements
}
public void setResults(PostageRunnerResult results) {
- m_results = results;
+ this.results = results;
}
- /* JAMES 3.0-SNAPSHOT specific methods */
-
public String getDefaultDomain() {
return "localhost";
}
Modified:
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleSMTPServerConfiguration.java
URL:
http://svn.apache.org/viewvc/james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleSMTPServerConfiguration.java?rev=1350154&r1=1350153&r2=1350154&view=diff
==============================================================================
---
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleSMTPServerConfiguration.java
(original)
+++
james/postage/trunk/src/main/java/org/apache/james/postage/smtpserver/SimpleSMTPServerConfiguration.java
Thu Jun 14 09:26:03 2012
@@ -16,66 +16,89 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
-
-
package org.apache.james.postage.smtpserver;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.configuration.Configuration;
-
-public class SimpleSMTPServerConfiguration extends DefaultConfiguration {
- private int m_smtpListenerPort;
- private String m_authorizedAddresses = "127.0.0.0/8";
- private String m_authorizingMode = "false";
-
- public static Configuration getValuedConfiguration(String name, String
value) {
- DefaultConfiguration defaultConfiguration = new
DefaultConfiguration(name);
- defaultConfiguration.setValue(value);
- return defaultConfiguration;
- }
-
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.james.smtpserver.CoreCmdHandlerLoader;
+import org.apache.james.smtpserver.fastfail.DNSRBLHandler;
+import org.apache.james.smtpserver.fastfail.MaxRcptHandler;
+import org.apache.james.smtpserver.fastfail.ResolvableEhloHeloHandler;
+import org.apache.james.smtpserver.fastfail.ReverseEqualsEhloHeloHandler;
+import org.apache.james.smtpserver.fastfail.ValidSenderDomainHandler;
+
+public class SimpleSMTPServerConfiguration extends DefaultConfigurationBuilder
{
+ private static final long serialVersionUID = 6459491961488047925L;
+ private int smtpListenerPort;
+ private int maxMessageSizeKB = 0;
+ private String authorizedAddresses = "127.0.0.0/8";
+ private String authorizingMode = "false";
+ private boolean verifyIdentity = false;
+ private Integer connectionLimit = null;
+ private Integer connectionBacklog = null;
+ private boolean heloResolv = false;
+ private boolean ehloResolv = false;
+ private boolean senderDomainResolv = false;
+ private boolean checkAuthNetworks = false;
+ private boolean heloEhloEnforcement = true;
+ private boolean reverseEqualsHelo = false;
+ private boolean reverseEqualsEhlo = false;
+ private int maxRcpt = 0;
+ private boolean useRBL = false;
+ private boolean addressBracketsEnforcement = true;
+ private boolean startTLS = false;
+
public SimpleSMTPServerConfiguration(int smtpListenerPort) {
- super("smptserver");
-
- m_smtpListenerPort = smtpListenerPort;
- }
-
- public String getAuthorizedAddresses() {
- return m_authorizedAddresses;
- }
-
- public void setAuthorizedAddresses(String authorizedAddresses) {
- m_authorizedAddresses = authorizedAddresses;
- }
-
- public void setAuthorizingNotRequired() {
- m_authorizingMode = "false";
- }
-
- public void setAuthorizingRequired() {
- m_authorizingMode = "true";
- //m_verifyIdentity = true;
+ this.smtpListenerPort = smtpListenerPort;
}
- public void setAuthorizingAnnounce() {
- m_authorizingMode = "announce";
- //m_verifyIdentity = true;
- }
-
- public void init() {
-
- setAttribute("enabled", true);
-
- addChild(getValuedConfiguration("port", "" + m_smtpListenerPort));
+ public void init() throws ConfigurationException {
- DefaultConfiguration handlerConfig = new
DefaultConfiguration("handler");
- handlerConfig.addChild(getValuedConfiguration("helloName",
"myMailServer"));
- handlerConfig.addChild(getValuedConfiguration("connectiontimeout",
"360000"));
- handlerConfig.addChild(getValuedConfiguration("authorizedAddresses",
m_authorizedAddresses));
- handlerConfig.addChild(getValuedConfiguration("maxmessagesize", "" +
0));
- handlerConfig.addChild(getValuedConfiguration("authRequired",
m_authorizingMode));
+ addProperty("[@enabled]", true);
- addChild(handlerConfig);
+ addProperty("bind", "127.0.0.1:" + smtpListenerPort);
+ if (connectionLimit != null)
+ addProperty("connectionLimit", "" + connectionLimit.intValue());
+ if (connectionBacklog != null)
+ addProperty("connectionBacklog", "" +
connectionBacklog.intValue());
+
+ addProperty("helloName", "myMailServer");
+ addProperty("connectiontimeout", 360000);
+ addProperty("authorizedAddresses", authorizedAddresses);
+ addProperty("maxmessagesize", maxMessageSizeKB);
+ addProperty("authRequired", authorizingMode);
+ addProperty("heloEhloEnforcement", heloEhloEnforcement);
+ addProperty("addressBracketsEnforcement", addressBracketsEnforcement);
+
+ addProperty("tls.[@startTLS]", startTLS);
+ addProperty("tls.keystore", "file://conf/test_keystore");
+ addProperty("tls.secret", "jamestest");
+ if (verifyIdentity)
+ addProperty("verifyIdentity", verifyIdentity);
+
+ // add the rbl handler
+ if (useRBL) {
+
+ addProperty("handlerchain.handler.[@class]",
DNSRBLHandler.class.getName());
+ addProperty("handlerchain.handler.rblservers.blacklist",
"bl.spamcop.net.");
+ }
+ if (heloResolv || ehloResolv) {
+ addProperty("handlerchain.handler.[@class]",
ResolvableEhloHeloHandler.class.getName());
+ addProperty("handlerchain.handler.checkAuthNetworks",
checkAuthNetworks);
+ }
+ if (reverseEqualsHelo || reverseEqualsEhlo) {
+ addProperty("handlerchain.handler.[@class]",
ReverseEqualsEhloHeloHandler.class.getName());
+ addProperty("handlerchain.handler.checkAuthNetworks",
checkAuthNetworks);
+ }
+ if (senderDomainResolv) {
+ addProperty("handlerchain.handler.[@class]",
ValidSenderDomainHandler.class.getName());
+ addProperty("handlerchain.handler.checkAuthNetworks",
checkAuthNetworks);
+ }
+ if (maxRcpt > 0) {
+ addProperty("handlerchain.handler.[@class]",
MaxRcptHandler.class.getName());
+ addProperty("handlerchain.handler.maxRcpt", maxRcpt);
+ }
+ addProperty("handlerchain.[@coreHandlersPackage]",
CoreCmdHandlerLoader.class.getName());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]