MockMailServer.javaAPI DocApache James 2.3.15009Fri Jan 12 12:56:36 GMT 2007org.apache.james.test.mock.james


public class MockMailServer extends Object implements
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 * * * * 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. *

Fields Summary
private final org.apache.james.userrepository.MockUsersRepository
private int
private int
private final ArrayList
private HashMap
Constructors Summary
Methods Summary
public booleanaddUser(java.lang.String userName, java.lang.String password)

        m_users.addUser(userName, password);
        return true;
public synchronized java.lang.StringgetId()

        return "MockMailServer-ID-" + m_counter;
public java.lang.Object[]getLastMail()

        if (mails.size() == 0) return null;
        return (Object[])mails.get(mails.size()-1);
public java.util.MapgetRepositoryCounters()

        return null; // trivial implementation 
public userName)

        if (inboxes==null) {
            return null;
        } else {
            return (MailRepository) inboxes.get(userName);
public org.apache.james.userrepository.MockUsersRepositorygetUsersRepository()

        return m_users;
public booleanisLocalServer(java.lang.String serverName)

        return "localhost".equals(serverName);
public voidsendMail(org.apache.mailet.MailAddress sender, java.util.Collection recipients, javax.mail.internet.MimeMessage msg)

        Object[] mailObjects = new Object[]{sender, recipients, new MimeMessageCopyOnWriteProxy(msg)};
public voidsendMail(org.apache.mailet.MailAddress sender, java.util.Collection recipients, msg)

        Object[] mailObjects = new Object[]{sender, recipients, msg};
public voidsendMail(org.apache.mailet.Mail mail)

        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 voidsendMail(javax.mail.internet.MimeMessage message)

        // 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 voidsetMaxMessageSizeBytes(int maxMessageSizeBytes)

        m_maxMessageSizeBytes = maxMessageSizeBytes;
public voidsetUserInbox(java.lang.String userName, inbox)

        if (inboxes == null) {
            inboxes = new HashMap();