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

MockMailServer

public class MockMailServer extends Object implements org.apache.james.services.MailServer
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. *

Fields Summary
private final org.apache.james.userrepository.MockUsersRepository
m_users
private int
m_counter
private int
m_maxMessageSizeBytes
private final ArrayList
mails
private HashMap
inboxes
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()

        m_counter++;
        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 org.apache.james.services.MailRepositorygetUserInbox(java.lang.String 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)};
        mails.add(mailObjects);
    
public voidsendMail(org.apache.mailet.MailAddress sender, java.util.Collection recipients, java.io.InputStream msg)

        Object[] mailObjects = new Object[]{sender, recipients, msg};
        mails.add(mailObjects);
    
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, org.apache.james.services.MailRepository inbox)

        if (inboxes == null) {
            inboxes = new HashMap();
        }
        inboxes.put(userName,inbox);