Modified: james/server/branches/v2.3/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java?rev=408539&r1=408538&r2=408539&view=diff ============================================================================== --- james/server/branches/v2.3/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java (original) +++ james/server/branches/v2.3/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java Sun May 21 17:47:05 2006 @@ -1,157 +1,169 @@ -/*********************************************************************** - * Copyright (c) 2000-2006 The Apache Software Foundation. * - * All rights reserved. * - * ------------------------------------------------------------------- * - * Licensed under the Apache License, Version 2.0 (the "License"); you * - * may not use this file except in compliance with the License. You * - * may obtain a copy of the License at: * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software * - * distributed under the License is distributed on an "AS IS" BASIS, * - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * - * implied. See the License for the specific language governing * - * permissions and limitations under the License. * - ***********************************************************************/ - - -package org.apache.james.smtpserver; - -import org.apache.avalon.framework.configuration.Configuration; -import org.apache.avalon.framework.configuration.ConfigurationException; -import org.apache.avalon.framework.configuration.DefaultConfiguration; -import org.apache.james.test.util.Util; - -public class SMTPTestConfiguration extends DefaultConfiguration { - - private int m_smtpListenerPort; - private int m_maxMessageSize = 0; - private String m_authorizedAddresses = "127.0.0.0/8"; - private String m_authorizingMode = "false"; - private boolean m_verifyIdentity = false; - private Integer m_connectionLimit = null; - private boolean m_heloResolv = false; - private boolean m_ehloResolv = false; - private boolean m_senderDomainResolv = false; - private boolean m_checkAuthNetworks = false; - private boolean m_checkAuthClients = false; - private boolean m_heloEhloEnforcement = true; - private int m_maxRcpt = 0; - - - public SMTPTestConfiguration(int smtpListenerPort) { - super("smptserver"); - - m_smtpListenerPort = smtpListenerPort; - } - - public void setCheckAuthNetworks(boolean checkAuth) { - m_checkAuthNetworks = checkAuth; - } - - - public void setMaxMessageSize(int kilobytes) - { - m_maxMessageSize = kilobytes; - } - - public int getMaxMessageSize() { - return m_maxMessageSize; - } - - public String getAuthorizedAddresses() { - return m_authorizedAddresses; - } - - public void setAuthorizedAddresses(String authorizedAddresses) { - m_authorizedAddresses = authorizedAddresses; - } - - public void setAuthorizingNotRequired() { - m_authorizingMode = "false"; - m_verifyIdentity = false; - } - - public void setAuthorizingRequired() { - m_authorizingMode = "true"; - m_verifyIdentity = true; - } - - public void setAuthorizingAnnounce() { - m_authorizingMode = "announce"; - m_verifyIdentity = true; - } - - public void setConnectionLimit(int iConnectionLimit) { - m_connectionLimit = new Integer(iConnectionLimit); - } - - public void setHeloResolv() { - m_heloResolv = true; - } - - public void setEhloResolv() { - m_ehloResolv = true; - } - - public void setSenderDomainResolv() { - m_senderDomainResolv = true; - } - - public void setCheckAuthClients(boolean ignore) { - m_checkAuthClients = ignore; - } - - public void setMaxRcpt(int maxRcpt) { - m_maxRcpt = maxRcpt; - } - - public void setHeloEhloEnforcement(boolean heloEhloEnforcement) { - m_heloEhloEnforcement = heloEhloEnforcement; - } - - public void init() throws ConfigurationException { - - setAttribute("enabled", true); - - addChild(Util.getValuedConfiguration("port", "" + m_smtpListenerPort)); - if (m_connectionLimit != null) addChild(Util.getValuedConfiguration("connectionLimit", "" + m_connectionLimit.intValue())); - - DefaultConfiguration handlerConfig = new DefaultConfiguration("handler"); - handlerConfig.addChild(Util.getValuedConfiguration("helloName", "myMailServer")); - handlerConfig.addChild(Util.getValuedConfiguration("connectiontimeout", "360000")); - handlerConfig.addChild(Util.getValuedConfiguration("authorizedAddresses", m_authorizedAddresses)); - handlerConfig.addChild(Util.getValuedConfiguration("maxmessagesize", "" + m_maxMessageSize)); - handlerConfig.addChild(Util.getValuedConfiguration("authRequired", m_authorizingMode)); - handlerConfig.addChild(Util.getValuedConfiguration("heloEhloEnforcement", m_heloEhloEnforcement+"")); - if (m_verifyIdentity) handlerConfig.addChild(Util.getValuedConfiguration("verifyIdentity", "" + m_verifyIdentity)); - - handlerConfig.addChild(Util.createSMTPHandlerChainConfiguration()); - - // Add Configuration for Helo checks and Ehlo checks - Configuration[] heloConfig = handlerConfig.getChild("handlerchain").getChildren("handler"); - for (int i = 0; i < heloConfig.length; i++) { - if (heloConfig[i] instanceof DefaultConfiguration) { - String cmd = ((DefaultConfiguration) heloConfig[i]).getAttribute("command",null); - if (cmd != null) { - if ("HELO".equals(cmd)) { - ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkResolvableHelo",m_heloResolv+"")); - ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkAuthNetworks",m_checkAuthNetworks+"")); - } else if ("EHLO".equals(cmd)) { - ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkResolvableEhlo",m_ehloResolv+"")); - ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkAuthNetworks",m_checkAuthNetworks+"")); - } else if ("MAIL".equals(cmd)) { - ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkValidSenderDomain",m_senderDomainResolv+"")); - ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkAuthClients",m_checkAuthClients+"")); - } else if ("RCPT".equals(cmd)) { - ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("maxRcpt",m_maxRcpt+"")); - } - } - } - } - - addChild(handlerConfig); - } - -} +/*********************************************************************** + * Copyright (c) 2000-2006 The Apache Software Foundation. * + * All rights reserved. * + * ------------------------------------------------------------------- * + * Licensed under the Apache License, Version 2.0 (the "License"); you * + * may not use this file except in compliance with the License. You * + * may obtain a copy of the License at: * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * + * implied. See the License for the specific language governing * + * permissions and limitations under the License. * + ***********************************************************************/ + + +package org.apache.james.smtpserver; + +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; +import org.apache.avalon.framework.configuration.DefaultConfiguration; +import org.apache.james.test.util.Util; + +public class SMTPTestConfiguration extends DefaultConfiguration { + + private int m_smtpListenerPort; + private int m_maxMessageSizeKB = 0; + private String m_authorizedAddresses = "127.0.0.0/8"; + private String m_authorizingMode = "false"; + private boolean m_verifyIdentity = false; + private Integer m_connectionLimit = null; + private boolean m_heloResolv = false; + private boolean m_ehloResolv = false; + private boolean m_senderDomainResolv = false; + private boolean m_checkAuthNetworks = false; + private boolean m_checkAuthClients = false; + private boolean m_heloEhloEnforcement = true; + private boolean m_reverseEqualsHelo = false; + private boolean m_reverseEqualsEhlo = false; + private int m_maxRcpt = 0; + + + public SMTPTestConfiguration(int smtpListenerPort) { + super("smptserver"); + + m_smtpListenerPort = smtpListenerPort; + } + + public void setCheckAuthNetworks(boolean checkAuth) { + m_checkAuthNetworks = checkAuth; + } + + + public void setMaxMessageSize(int kilobytes) + { + m_maxMessageSizeKB = kilobytes; + } + + public int getMaxMessageSize() { + return m_maxMessageSizeKB; + } + + public String getAuthorizedAddresses() { + return m_authorizedAddresses; + } + + public void setAuthorizedAddresses(String authorizedAddresses) { + m_authorizedAddresses = authorizedAddresses; + } + + public void setAuthorizingNotRequired() { + m_authorizingMode = "false"; + m_verifyIdentity = false; + } + + public void setAuthorizingRequired() { + m_authorizingMode = "true"; + m_verifyIdentity = true; + } + + public void setAuthorizingAnnounce() { + m_authorizingMode = "announce"; + m_verifyIdentity = true; + } + + public void setConnectionLimit(int iConnectionLimit) { + m_connectionLimit = new Integer(iConnectionLimit); + } + + public void setHeloResolv() { + m_heloResolv = true; + } + + public void setEhloResolv() { + m_ehloResolv = true; + } + + public void setReverseEqualsHelo() { + m_reverseEqualsHelo = true; + } + + public void setReverseEqualsEhlo() { + m_reverseEqualsEhlo = true; + } + + public void setSenderDomainResolv() { + m_senderDomainResolv = true; + } + + public void setCheckAuthClients(boolean ignore) { + m_checkAuthClients = ignore; + } + + public void setMaxRcpt(int maxRcpt) { + m_maxRcpt = maxRcpt; + } + + public void setHeloEhloEnforcement(boolean heloEhloEnforcement) { + m_heloEhloEnforcement = heloEhloEnforcement; + } + + public void init() throws ConfigurationException { + + setAttribute("enabled", true); + + addChild(Util.getValuedConfiguration("port", "" + m_smtpListenerPort)); + if (m_connectionLimit != null) addChild(Util.getValuedConfiguration("connectionLimit", "" + m_connectionLimit.intValue())); + + DefaultConfiguration handlerConfig = new DefaultConfiguration("handler"); + handlerConfig.addChild(Util.getValuedConfiguration("helloName", "myMailServer")); + handlerConfig.addChild(Util.getValuedConfiguration("connectiontimeout", "360000")); + handlerConfig.addChild(Util.getValuedConfiguration("authorizedAddresses", m_authorizedAddresses)); + handlerConfig.addChild(Util.getValuedConfiguration("maxmessagesize", "" + m_maxMessageSizeKB)); + handlerConfig.addChild(Util.getValuedConfiguration("authRequired", m_authorizingMode)); + handlerConfig.addChild(Util.getValuedConfiguration("heloEhloEnforcement", m_heloEhloEnforcement+"")); + if (m_verifyIdentity) handlerConfig.addChild(Util.getValuedConfiguration("verifyIdentity", "" + m_verifyIdentity)); + + handlerConfig.addChild(Util.createSMTPHandlerChainConfiguration()); + + // Add Configuration for Helo checks and Ehlo checks + Configuration[] heloConfig = handlerConfig.getChild("handlerchain").getChildren("handler"); + for (int i = 0; i < heloConfig.length; i++) { + if (heloConfig[i] instanceof DefaultConfiguration) { + String cmd = ((DefaultConfiguration) heloConfig[i]).getAttribute("command",null); + if (cmd != null) { + if ("HELO".equals(cmd)) { + ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkResolvableHelo",m_heloResolv+"")); + ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkReverseEqualsHelo",m_reverseEqualsHelo+"")); + ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkAuthNetworks",m_checkAuthNetworks+"")); + } else if ("EHLO".equals(cmd)) { + ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkResolvableEhlo",m_ehloResolv+"")); + ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkReverseEqualsEhlo",m_reverseEqualsEhlo+"")); + ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkAuthNetworks",m_checkAuthNetworks+"")); + } else if ("MAIL".equals(cmd)) { + ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkValidSenderDomain",m_senderDomainResolv+"")); + ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("checkAuthClients",m_checkAuthClients+"")); + } else if ("RCPT".equals(cmd)) { + ((DefaultConfiguration) heloConfig[i]).addChild(Util.getValuedConfiguration("maxRcpt",m_maxRcpt+"")); + } + } + } + } + + addChild(handlerConfig); + } + +}
Added: james/server/branches/v2.3/src/test/org/apache/james/test/mock/james/InMemorySpoolRepository.java URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/test/mock/james/InMemorySpoolRepository.java?rev=408539&view=auto ============================================================================== --- james/server/branches/v2.3/src/test/org/apache/james/test/mock/james/InMemorySpoolRepository.java (added) +++ james/server/branches/v2.3/src/test/org/apache/james/test/mock/james/InMemorySpoolRepository.java Sun May 21 17:47:05 2006 @@ -0,0 +1,418 @@ +/*********************************************************************** + * Copyright (c) 2006 The Apache Software Foundation. * + * All rights reserved. * + * ------------------------------------------------------------------- * + * Licensed under the Apache License, Version 2.0 (the "License"); you * + * may not use this file except in compliance with the License. You * + * may obtain a copy of the License at: * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * + * implied. See the License for the specific language governing * + * permissions and limitations under the License. * + ***********************************************************************/ + +package org.apache.james.test.mock.james; + +import org.apache.james.services.SpoolRepository; +import org.apache.james.test.mock.avalon.MockLogger; +import org.apache.james.util.Lock; +import org.apache.mailet.Mail; + +import javax.mail.MessagingException; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.ConcurrentModificationException; +import java.util.Hashtable; +import java.util.Iterator; + +/** + * Implementation of a MailRepository on a FileSystem. + * + * Requires a configuration element in the .conf.xml file of the form: + * <repository destinationURL="file://path-to-root-dir-for-repository" + * type="MAIL" + * model="SYNCHRONOUS"/> + * Requires a logger called MailRepository. + * + * @version 1.0.0, 24/04/1999 + */ +public class InMemorySpoolRepository + implements SpoolRepository { + + /** + * Whether 'deep debugging' is turned on. + */ + protected final static boolean DEEP_DEBUG = true; + private Lock lock; + private MockLogger logger; + private Hashtable spool; + + private MockLogger getLogger() { + if (logger == null) { + logger = new MockLogger(); + } + return logger; + } + + /** + * Releases a lock on a message identified by a key + * + * @param key the key of the message to be unlocked + * + * @return true if successfully released the lock, false otherwise + */ + public boolean unlock(String key) { + if (lock.unlock(key)) { + if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { + StringBuffer debugBuffer = + new StringBuffer(256) + .append("Unlocked ") + .append(key) + .append(" for ") + .append(Thread.currentThread().getName()) + .append(" @ ") + .append(new java.util.Date(System.currentTimeMillis())); + getLogger().debug(debugBuffer.toString()); + } + return true; + } else { + return false; + } + } + + /** + * Obtains a lock on a message identified by a key + * + * @param key the key of the message to be locked + * + * @return true if successfully obtained the lock, false otherwise + */ + public boolean lock(String key) { + if (lock.lock(key)) { + if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { + StringBuffer debugBuffer = + new StringBuffer(256) + .append("Locked ") + .append(key) + .append(" for ") + .append(Thread.currentThread().getName()) + .append(" @ ") + .append(new java.util.Date(System.currentTimeMillis())); + getLogger().debug(debugBuffer.toString()); + } +// synchronized (this) { +// notifyAll(); +// } + return true; + } else { + return false; + } + } + + /** + * Stores a message in this repository. Shouldn't this return the key + * under which it is stored? + * + * @param mc the mail message to store + */ + public void store(Mail mc) throws MessagingException { + try { + String key = mc.getName(); + //Remember whether this key was locked + boolean wasLocked = true; + synchronized (this) { + wasLocked = lock.isLocked(key); + + if (!wasLocked) { + //If it wasn't locked, we want a lock during the store + lock(key); + } + } + try { + spool.put(key,mc); + } finally { + if (!wasLocked) { + // If it wasn't locked, we need to unlock now + unlock(key); + synchronized (this) { + notify(); + } + } + } + + if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { + StringBuffer logBuffer = + new StringBuffer(64) + .append("Mail ") + .append(key) + .append(" stored."); + getLogger().debug(logBuffer.toString()); + } + + } catch (Exception e) { + getLogger().error("Exception storing mail: " + e); + throw new MessagingException("Exception caught while storing Message Container: ",e); + } + } + + /** + * Retrieves a message given a key. At the moment, keys can be obtained + * from list() in superinterface Store.Repository + * + * @param key the key of the message to retrieve + * @return the mail corresponding to this key, null if none exists + */ + public Mail retrieve(String key) throws MessagingException { + if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { + getLogger().debug("Retrieving mail: " + key); + } + try { + Mail mc = null; + try { + mc = (Mail) spool.get(key); + } + catch (RuntimeException re){ + StringBuffer exceptionBuffer = new StringBuffer(128); + if(re.getCause() instanceof Error){ + exceptionBuffer.append("Error when retrieving mail, not deleting: ") + .append(re.toString()); + }else{ + exceptionBuffer.append("Exception retrieving mail: ") + .append(re.toString()) + .append(", so we're deleting it."); + remove(key); + } + getLogger().warn(exceptionBuffer.toString()); + return null; + } + return mc; + } catch (Exception me) { + getLogger().error("Exception retrieving mail: " + me); + throw new MessagingException("Exception while retrieving mail: " + me.getMessage()); + } + } + + /** + * Removes a specified message + * + * @param mail the message to be removed from the repository + */ + public void remove(Mail mail) throws MessagingException { + remove(mail.getName()); + } + + + /** + * Removes a Collection of mails from the repository + * @param mails The Collection of <code>MailImpl</code>'s to delete + * @throws MessagingException + * @since 2.2.0 + */ + public void remove(Collection mails) throws MessagingException { + Iterator delList = mails.iterator(); + while (delList.hasNext()) { + remove((Mail)delList.next()); + } + } + + /** + * Removes a message identified by key. + * + * @param key the key of the message to be removed from the repository + */ + public void remove(String key) throws MessagingException { + if (lock(key)) { + try { + if (spool != null) spool.remove(key); + } finally { + unlock(key); + } + } else { + StringBuffer exceptionBuffer = + new StringBuffer(64) + .append("Cannot lock ") + .append(key) + .append(" to remove it"); + throw new MessagingException(exceptionBuffer.toString()); + } + } + + /** + * List string keys of messages in repository. + * + * @return an <code>Iterator</code> over the list of keys in the repository + * + */ + public Iterator list() { + // Fix ConcurrentModificationException by cloning + // the keyset before getting an iterator + final ArrayList clone; + synchronized(spool) { + clone = new ArrayList(spool.keySet()); + } + return clone.iterator(); + } + + + /** + * <p>Returns an arbitrarily selected mail deposited in this Repository. + * Usage: SpoolManager calls accept() to see if there are any unprocessed + * mails in the spool repository.</p> + * + * <p>Synchronized to ensure thread safe access to the underlying spool.</p> + * + * @return the mail + */ + public synchronized Mail accept() throws InterruptedException { + if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { + getLogger().debug("Method accept() called"); + } + return accept(new SpoolRepository.AcceptFilter () { + public boolean accept (String _, String __, long ___, String ____) { + return true; + } + + public long getWaitTime () { + return 0; + } + }); + } + + /** + * <p>Returns an arbitrarily selected mail deposited in this Repository that + * is either ready immediately for delivery, or is younger than it's last_updated plus + * the number of failed attempts times the delay time. + * Usage: RemoteDeliverySpool calls accept() with some delay and should block until an + * unprocessed mail is available.</p> + * + * <p>Synchronized to ensure thread safe access to the underlying spool.</p> + * + * @return the mail + */ + public synchronized Mail accept(final long delay) throws InterruptedException + { + if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { + getLogger().debug("Method accept(delay) called"); + } + return accept(new SpoolRepository.AcceptFilter () { + long youngest = 0; + + public boolean accept (String key, String state, long lastUpdated, String errorMessage) { + if (state.equals(Mail.ERROR)) { + //Test the time... + long timeToProcess = delay + lastUpdated; + + if (System.currentTimeMillis() > timeToProcess) { + //We're ready to process this again + return true; + } else { + //We're not ready to process this. + if (youngest == 0 || youngest > timeToProcess) { + //Mark this as the next most likely possible mail to process + youngest = timeToProcess; + } + return false; + } + } else { + //This mail is good to go... return the key + return true; + } + } + + public long getWaitTime () { + if (youngest == 0) { + return 0; + } else { + long duration = youngest - System.currentTimeMillis(); + youngest = 0; //get ready for next round + return duration <= 0 ? 1 : duration; + } + } + }); + } + + + /** + * Returns an arbitrarily select mail deposited in this Repository for + * which the supplied filter's accept method returns true. + * Usage: RemoteDeliverySpool calls accept(filter) with some a filter which determines + * based on number of retries if the mail is ready for processing. + * If no message is ready the method will block until one is, the amount of time to block is + * determined by calling the filters getWaitTime method. + * + * <p>Synchronized to ensure thread safe access to the underlying spool.</p> + * + * @return the mail + */ + public synchronized Mail accept(SpoolRepository.AcceptFilter filter) throws InterruptedException { + if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { + getLogger().debug("Method accept(Filter) called"); + } + while (!Thread.currentThread().isInterrupted()) try { + for (Iterator it = list(); it.hasNext(); ) { + String s = it.next().toString(); + if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { + StringBuffer logBuffer = + new StringBuffer(64) + .append("Found item ") + .append(s) + .append(" in spool."); + getLogger().debug(logBuffer.toString()); + } + if (lock(s)) { + if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { + getLogger().debug("accept(Filter) has locked: " + s); + } + try { + Mail mail = retrieve(s); + // Retrieve can return null if the mail is no longer on the spool + // (i.e. another thread has gotten to it first). + // In this case we simply continue to the next key + if (mail == null || !filter.accept (mail.getName(), + mail.getState(), + mail.getLastUpdated().getTime(), + mail.getErrorMessage())) { + unlock(s); + continue; + } + return mail; + } catch (javax.mail.MessagingException e) { + unlock(s); + getLogger().error("Exception during retrieve -- skipping item " + s, e); + } + } + } + + //We did not find any... let's wait for a certain amount of time + wait (filter.getWaitTime()); + } catch (InterruptedException ex) { + throw ex; + } catch (ConcurrentModificationException cme) { + // Should never get here now that list methods clones keyset for iterator + getLogger().error("CME in spooler - please report to http://james.apache.org", cme); + } + throw new InterruptedException(); + } + + /** + * + */ + public InMemorySpoolRepository() { + spool = new Hashtable(); + lock = new Lock(); + } + + public int size() { + return spool.size(); + } + + public void clear() { + spool.clear(); + } + +} Modified: james/server/branches/v2.3/src/test/org/apache/james/test/mock/james/MockMailServer.java URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/test/mock/james/MockMailServer.java?rev=408539&r1=408538&r2=408539&view=diff ============================================================================== --- james/server/branches/v2.3/src/test/org/apache/james/test/mock/james/MockMailServer.java (original) +++ james/server/branches/v2.3/src/test/org/apache/james/test/mock/james/MockMailServer.java Sun May 21 17:47:05 2006 @@ -1,131 +1,131 @@ -/*********************************************************************** - * Copyright (c) 2000-2006 The Apache Software Foundation. * - * All rights reserved. * - * ------------------------------------------------------------------- * - * Licensed under the Apache License, Version 2.0 (the "License"); you * - * may not use this file except in compliance with the License. You * - * may obtain a copy of the License at: * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software * - * distributed under the License is distributed on an "AS IS" BASIS, * - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * - * implied. See the License for the specific language governing * - * permissions and limitations under the License. * - ***********************************************************************/ -package org.apache.james.test.mock.james; - -import org.apache.james.core.MimeMessageCopyOnWriteProxy; -import org.apache.james.services.MailRepository; -import org.apache.james.services.MailServer; -import org.apache.james.smtpserver.MessageSizeException; -import org.apache.james.userrepository.MockUsersRepository; -import org.apache.mailet.Mail; -import org.apache.mailet.MailAddress; - -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.*; - -public class MockMailServer implements MailServer { - - private final MockUsersRepository m_users = new MockUsersRepository(); - - private int m_counter = 0; - private int m_maxMessageSizeBytes = 0; - - private final ArrayList mails = new ArrayList(); - - private HashMap inboxes; - - public MockUsersRepository getUsersRepository() { - return m_users; - } - - public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg) throws MessagingException { - Object[] mailObjects = new Object[]{sender, recipients, new MimeMessageCopyOnWriteProxy(msg)}; - mails.add(mailObjects); - } - - public void sendMail(MailAddress sender, Collection recipients, InputStream msg) throws MessagingException { - Object[] mailObjects = new Object[]{sender, recipients, msg}; - mails.add(mailObjects); - } - - public void sendMail(Mail mail) throws MessagingException { - int bodySize = mail.getMessage().getSize(); - try { - if (m_maxMessageSizeBytes != 0 && m_maxMessageSizeBytes < bodySize) throw new MessageSizeException(); - } catch (MessageSizeException e) { - throw new MessagingException("message size exception is nested", e); - } - sendMail(mail.getSender(), mail.getRecipients(), mail.getMessage()); - } - - public void sendMail(MimeMessage message) throws MessagingException { - // taken from class org.apache.james.James - MailAddress sender = new MailAddress((InternetAddress)message.getFrom()[0]); - Collection recipients = new HashSet(); - Address addresses[] = message.getAllRecipients(); - if (addresses != null) { - for (int i = 0; i < addresses.length; i++) { - // Javamail treats the "newsgroups:" header field as a - // recipient, so we want to filter those out. - if ( addresses[i] instanceof InternetAddress ) { - recipients.add(new MailAddress((InternetAddress)addresses[i])); - } - } - } - sendMail(sender, recipients, message); - } - - public MailRepository getUserInbox(String userName) { - if (inboxes==null) { - return null; - } else { - return (MailRepository) inboxes.get(userName); - } - - } - - public void setUserInbox(String userName, MailRepository inbox) { - if (inboxes == null) { - inboxes = new HashMap(); - } - inboxes.put(userName,inbox); - } - - public Map getRepositoryCounters() { - return null; // trivial implementation - } - - public synchronized String getId() { - m_counter++; - return "MockMailServer-ID-" + m_counter; - } - - public boolean addUser(String userName, String password) { - m_users.addUser(userName, password); - return true; - } - - public boolean isLocalServer(String serverName) { - return "localhost".equals(serverName); - } - - public Object[] getLastMail() - { - if (mails.size() == 0) return null; - return (Object[])mails.get(mails.size()-1); - } - - public void setMaxMessageSizeBytes(int maxMessageSizeBytes) { - m_maxMessageSizeBytes = maxMessageSizeBytes; - } -} - - +/*********************************************************************** + * Copyright (c) 2000-2006 The Apache Software Foundation. * + * All rights reserved. * + * ------------------------------------------------------------------- * + * Licensed under the Apache License, Version 2.0 (the "License"); you * + * may not use this file except in compliance with the License. You * + * may obtain a copy of the License at: * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * + * implied. See the License for the specific language governing * + * permissions and limitations under the License. * + ***********************************************************************/ +package org.apache.james.test.mock.james; + +import org.apache.james.core.MimeMessageCopyOnWriteProxy; +import org.apache.james.services.MailRepository; +import org.apache.james.services.MailServer; +import org.apache.james.smtpserver.MessageSizeException; +import org.apache.james.userrepository.MockUsersRepository; +import org.apache.mailet.Mail; +import org.apache.mailet.MailAddress; + +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.*; + +public class MockMailServer implements MailServer { + + private final MockUsersRepository m_users = new MockUsersRepository(); + + private int m_counter = 0; + private int m_maxMessageSizeBytes = 0; + + private final ArrayList mails = new ArrayList(); + + private HashMap inboxes; + + public MockUsersRepository getUsersRepository() { + return m_users; + } + + public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg) throws MessagingException { + Object[] mailObjects = new Object[]{sender, recipients, new MimeMessageCopyOnWriteProxy(msg)}; + mails.add(mailObjects); + } + + public void sendMail(MailAddress sender, Collection recipients, InputStream msg) throws MessagingException { + Object[] mailObjects = new Object[]{sender, recipients, msg}; + mails.add(mailObjects); + } + + public void sendMail(Mail mail) throws MessagingException { + int bodySize = mail.getMessage().getSize(); + try { + if (m_maxMessageSizeBytes != 0 && m_maxMessageSizeBytes < bodySize) throw new MessageSizeException(); + } catch (MessageSizeException e) { + throw new MessagingException("message size exception is nested", e); + } + sendMail(mail.getSender(), mail.getRecipients(), mail.getMessage()); + } + + public void sendMail(MimeMessage message) throws MessagingException { + // taken from class org.apache.james.James + MailAddress sender = new MailAddress((InternetAddress)message.getFrom()[0]); + Collection recipients = new HashSet(); + Address addresses[] = message.getAllRecipients(); + if (addresses != null) { + for (int i = 0; i < addresses.length; i++) { + // Javamail treats the "newsgroups:" header field as a + // recipient, so we want to filter those out. + if ( addresses[i] instanceof InternetAddress ) { + recipients.add(new MailAddress((InternetAddress)addresses[i])); + } + } + } + sendMail(sender, recipients, message); + } + + public MailRepository getUserInbox(String userName) { + if (inboxes==null) { + return null; + } else { + return (MailRepository) inboxes.get(userName); + } + + } + + public void setUserInbox(String userName, MailRepository inbox) { + if (inboxes == null) { + inboxes = new HashMap(); + } + inboxes.put(userName,inbox); + } + + public Map getRepositoryCounters() { + return null; // trivial implementation + } + + public synchronized String getId() { + m_counter++; + return "MockMailServer-ID-" + m_counter; + } + + public boolean addUser(String userName, String password) { + m_users.addUser(userName, password); + return true; + } + + public boolean isLocalServer(String serverName) { + return "localhost".equals(serverName); + } + + public Object[] getLastMail() + { + if (mails.size() == 0) return null; + return (Object[])mails.get(mails.size()-1); + } + + public void setMaxMessageSizeBytes(int maxMessageSizeBytes) { + m_maxMessageSizeBytes = maxMessageSizeBytes; + } +} + + Modified: james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMailContext.java URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMailContext.java?rev=408539&r1=408538&r2=408539&view=diff ============================================================================== --- james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMailContext.java (original) +++ james/server/branches/v2.3/src/test/org/apache/james/test/mock/mailet/MockMailContext.java Sun May 21 17:47:05 2006 @@ -1,114 +1,117 @@ -/*********************************************************************** - * Copyright (c) 1999-2006 The Apache Software Foundation. * - * All rights reserved. * - * ------------------------------------------------------------------- * - * Licensed under the Apache License, Version 2.0 (the "License"); you * - * may not use this file except in compliance with the License. You * - * may obtain a copy of the License at: * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software * - * distributed under the License is distributed on an "AS IS" BASIS, * - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * - * implied. See the License for the specific language governing * - * permissions and limitations under the License. * - ***********************************************************************/ -package org.apache.james.test.mock.mailet; - -import org.apache.mailet.MailetContext; -import org.apache.mailet.Mail; -import org.apache.mailet.MailAddress; - -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; -import java.util.Collection; -import java.util.Iterator; - -public class MockMailContext implements MailetContext { - - public void bounce(Mail mail, String message) throws MessagingException { - // trivial implementation - } - - public void bounce(Mail mail, String message, MailAddress bouncer) throws MessagingException { - // trivial implementation - } - - public Collection getMailServers(String host) { - return null; // trivial implementation - } - - public MailAddress getPostmaster() { - return null; // trivial implementation - } - - public Object getAttribute(String name) { - return null; // trivial implementation - } - - public Iterator getAttributeNames() { - return null; // trivial implementation - } - - public int getMajorVersion() { - return 0; // trivial implementation - } - - public int getMinorVersion() { - return 0; // trivial implementation - } - - public String getServerInfo() { - return null; // trivial implementation - } - - public boolean isLocalServer(String serverName) { - return false; // trivial implementation - } - - public boolean isLocalUser(String userAccount) { - return false; // trivial implementation - } - - public void log(String message) { - System.out.println(message); - } - - public void log(String message, Throwable t) { - System.out.println(message); - t.printStackTrace(System.out); - } - - public void removeAttribute(String name) { - // trivial implementation - } - - public void sendMail(MimeMessage msg) throws MessagingException { - // trivial implementation - } - - public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg) throws MessagingException { - // trivial implementation - } - - public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg, String state) throws MessagingException { - // trivial implementation - } - - public void sendMail(Mail mail) throws MessagingException { - // trivial implementation - } - - public void setAttribute(String name, Object object) { - // trivial implementation - } - - public void storeMail(MailAddress sender, MailAddress recipient, MimeMessage msg) throws MessagingException { - // trivial implementation - } - - public Iterator getSMTPHostAddresses(String domainName) { - return null; // trivial implementation - } -} +/*********************************************************************** + * Copyright (c) 1999-2006 The Apache Software Foundation. * + * All rights reserved. * + * ------------------------------------------------------------------- * + * Licensed under the Apache License, Version 2.0 (the "License"); you * + * may not use this file except in compliance with the License. You * + * may obtain a copy of the License at: * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * + * implied. See the License for the specific language governing * + * permissions and limitations under the License. * + ***********************************************************************/ +package org.apache.james.test.mock.mailet; + +import org.apache.mailet.MailetContext; +import org.apache.mailet.Mail; +import org.apache.mailet.MailAddress; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; + +public class MockMailContext implements MailetContext { + + HashMap attributes = new HashMap(); + + public void bounce(Mail mail, String message) throws MessagingException { + // trivial implementation + } + + public void bounce(Mail mail, String message, MailAddress bouncer) throws MessagingException { + // trivial implementation + } + + public Collection getMailServers(String host) { + return null; // trivial implementation + } + + public MailAddress getPostmaster() { + return null; // trivial implementation + } + + public Object getAttribute(String name) { + return attributes.get(name); + } + + public Iterator getAttributeNames() { + return attributes.keySet().iterator(); + } + + public int getMajorVersion() { + return 0; // trivial implementation + } + + public int getMinorVersion() { + return 0; // trivial implementation + } + + public String getServerInfo() { + return "Mock Server"; + } + + public boolean isLocalServer(String serverName) { + return false; // trivial implementation + } + + public boolean isLocalUser(String userAccount) { + return false; // trivial implementation + } + + public void log(String message) { + System.out.println(message); + } + + public void log(String message, Throwable t) { + System.out.println(message); + t.printStackTrace(System.out); + } + + public void removeAttribute(String name) { + // trivial implementation + } + + public void sendMail(MimeMessage msg) throws MessagingException { + // trivial implementation + } + + public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg) throws MessagingException { + // trivial implementation + } + + public void sendMail(MailAddress sender, Collection recipients, MimeMessage msg, String state) throws MessagingException { + // trivial implementation + } + + public void sendMail(Mail mail) throws MessagingException { + // trivial implementation + } + + public void setAttribute(String name, Object object) { + attributes.put(name,object); + } + + public void storeMail(MailAddress sender, MailAddress recipient, MimeMessage msg) throws MessagingException { + // trivial implementation + } + + public Iterator getSMTPHostAddresses(String domainName) { + return null; // trivial implementation + } +} Added: james/server/branches/v2.3/tools/lib/commons-net-1.4.1.jar URL: http://svn.apache.org/viewvc/james/server/branches/v2.3/tools/lib/commons-net-1.4.1.jar?rev=408539&view=auto ============================================================================== Binary file - no diff available. Propchange: james/server/branches/v2.3/tools/lib/commons-net-1.4.1.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]