FileDocCategorySizeDatePackage
MockMimeMessage.javaAPI DocApache James 2.3.116541Fri Jan 12 12:56:36 GMT 2007org.apache.james.test.mock.javaxmail

MockMimeMessage

public class MockMimeMessage extends MimeMessage
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 List
m_fromAddresses
private Address
m_senderAddress
private final List
m_toRecepients
private final List
m_ccRecepients
private final List
m_bccRecepients
private final List
m_replyToAddresses
private String
m_subject
private int
m_iMessageNumber
private boolean
m_bIsExpunged
private Object
m_content
private Date
m_sentDate
private String[]
m_contentLanguage
private String
m_fileName
private DataHandler
m_dataHandler
private HashMap
m_contentHeaders
private Flags
m_setFlags
private boolean
m_doMatch
Constructors Summary
public MockMimeMessage()


        
        super((Session)null);
    
public MockMimeMessage(MimeMessage mimeMessage)

        super(mimeMessage); // trivial implementation
    
Methods Summary
public voidaddFrom(javax.mail.Address[] addresses)

        m_fromAddresses.add(addresses);
    
public voidaddHeader(java.lang.String name, java.lang.String value)

        m_contentHeaders.put(name, value);
    
public voidaddHeaderLine(java.lang.String headerLine)

        int separatorIndex = headerLine.indexOf(":");
        if (separatorIndex < 0) throw new MessagingException("header line does not conform to standard");
        
        addHeader(headerLine.substring(0,separatorIndex), headerLine.substring(separatorIndex,headerLine.length()));
    
public voidaddRecipient(javax.mail.Message$RecipientType recipientType, javax.mail.Address address)

        setRecipients(recipientType, new Address[]{address});
    
public voidaddRecipients(javax.mail.Message$RecipientType recipientType, javax.mail.Address[] addresses)

        getRecipientsList(recipientType).addAll(Arrays.asList(addresses));
    
public voidaddRecipients(javax.mail.Message$RecipientType recipientType, java.lang.String recipient)

        getRecipientsList(recipientType).add(recipient);
    
protected javax.mail.internet.InternetHeaderscreateInternetHeaders(java.io.InputStream inputStream)

        return new InternetHeaders();
    
public java.util.EnumerationgetAllHeaderLines()

        return Collections.enumeration(getHeadersAsStrings(m_contentHeaders));
    
public java.util.EnumerationgetAllHeaders()

        return Collections.enumeration(m_contentHeaders.values());
    
public javax.mail.Address[]getAllRecipients()

        List allRecipients = new ArrayList();
        allRecipients.addAll(m_toRecepients);
        allRecipients.addAll(m_ccRecepients);
        allRecipients.addAll(m_bccRecepients);
        return (Address[]) allRecipients.toArray();
    
public java.lang.ObjectgetContent()

        return m_content;
    
public java.lang.StringgetContentID()

        return getHeader("Content-ID", null);
    
public java.lang.String[]getContentLanguage()

        return m_contentLanguage;
    
public java.lang.StringgetContentMD5()

        return getHeader("Content-MD5", null);
    
protected java.io.InputStreamgetContentStream()

        return null; // trivial implementation
    
public java.lang.StringgetContentType()

        return getHeader("Content-Type", null);
    
public synchronized javax.activation.DataHandlergetDataHandler()

        return m_dataHandler;
    
public java.lang.StringgetDescription()

        return getHeader("Content-Description", null);
    
public java.lang.StringgetDisposition()

        return getHeader("Content-Disposition", null);
    
public java.lang.StringgetEncoding()

        return getHeader("Content-Transfer-Encoding", null);
    
public java.lang.StringgetFileName()

        return m_fileName;
    
public synchronized javax.mail.FlagsgetFlags()

        return new Flags(m_setFlags);
    
public javax.mail.FoldergetFolder()

        return null;
    
public javax.mail.Address[]getFrom()

        return (Address[])m_fromAddresses.toArray();
    
public java.lang.String[]getHeader(java.lang.String name)

        String value = (String) m_contentHeaders.get(name);
        if (value == null) return null;
        return new String[] {value};
    
public java.lang.StringgetHeader(java.lang.String name, java.lang.String delimiter)

        String[] header = getHeader(name);
        if (header == null || header.length == 0) return null;
        return header[0];
    
private java.util.ArrayListgetHeadersAsStrings(java.util.HashMap contentHeaders)

        ArrayList headerLines = new ArrayList();
        Iterator iterator = contentHeaders.keySet().iterator();
        while (iterator.hasNext()) {
            String key = (String) iterator.next();
            String value = (String) contentHeaders.get(key);
            headerLines.add(key + ":" + value);
        }
        return headerLines;
    
public java.io.InputStreamgetInputStream()

        return null; // trivial implementation
    
public intgetLineCount()

        return -1; // trivial implementation
    
public java.util.EnumerationgetMatchingHeaderLines(java.lang.String[] names)

        ArrayList matchingHeaders = new ArrayList();
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            String value = getHeader(name, null);
            if (value == null) continue;
            matchingHeaders.add(name + ":" + value);
        }
        return Collections.enumeration(matchingHeaders); 
    
public java.util.EnumerationgetMatchingHeaders(java.lang.String[] names)

        ArrayList matchingHeaders = new ArrayList();
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            String value = getHeader(name, null);
            if (value == null) continue;
            matchingHeaders.add(value);
        }
        return Collections.enumeration(matchingHeaders); 
    
public java.lang.StringgetMessageID()

        return "ID-" + m_iMessageNumber; // trivial implementation
    
public intgetMessageNumber()

        return m_iMessageNumber;
    
public java.util.EnumerationgetNonMatchingHeaderLines(java.lang.String[] names)

        List existingHeaders = names != null ? Arrays.asList(names) : null;

        ArrayList nonMatchingHeaders = new ArrayList();
        
        Iterator iterator = m_contentHeaders.keySet().iterator();
        while (iterator.hasNext()) {
            String name = (String) iterator.next();
            if (existingHeaders!=null && existingHeaders.contains(name)) continue;
            String value = getHeader(name, null);
            if (value == null) continue;
            nonMatchingHeaders.add(name + ":" + value);
        }
        return Collections.enumeration(nonMatchingHeaders); 
    
public java.util.EnumerationgetNonMatchingHeaders(java.lang.String[] names)

        List existingHeaders = Arrays.asList(names);

        ArrayList nonMatchingHeaders = new ArrayList();
        
        Iterator iterator = m_contentHeaders.keySet().iterator();
        while (iterator.hasNext()) {
            String name = (String) iterator.next();
            if (existingHeaders.contains(name)) continue;
            String value = getHeader(name, null);
            if (value == null) continue;
            nonMatchingHeaders.add(value);
        }
        return Collections.enumeration(nonMatchingHeaders); 
    
public java.io.InputStreamgetRawInputStream()

        return null; // trivial implementation
    
public java.util.DategetReceivedDate()

        return null; // trivial implementation
    
public javax.mail.Address[]getRecipients(javax.mail.Message$RecipientType recipientType)

        return (Address[]) getRecipientsList(recipientType).toArray();
    
private java.util.ListgetRecipientsList(javax.mail.Message$RecipientType recipientType)

        if (Message.RecipientType.TO.equals(recipientType)) return m_toRecepients; 
        if (Message.RecipientType.CC.equals(recipientType)) return m_ccRecepients; 
        if (Message.RecipientType.BCC.equals(recipientType)) return m_bccRecepients;
        return null;
    
public javax.mail.Address[]getReplyTo()

        return (Address[]) m_replyToAddresses.toArray();
    
public javax.mail.AddressgetSender()

        return m_senderAddress;
    
public java.util.DategetSentDate()

        return m_sentDate;
    
public intgetSize()

        return -1; // trivial implementation
    
public java.lang.StringgetSubject()

        return m_subject;
    
public booleanisExpunged()

        return m_bIsExpunged;
    
public booleanisMimeType(java.lang.String mimeType)

        return mimeType.startsWith(getContentType());
    
public synchronized booleanisSet(javax.mail.Flags$Flag flag)

        return m_setFlags.contains(flag);
    
public booleanmatch(javax.mail.search.SearchTerm searchTerm)

        return m_doMatch; 
    
public voidremoveHeader(java.lang.String name)

        m_contentHeaders.remove(name);
    
public Messagereply(boolean b)

        return new MockMimeMessage(this); // trivial implementation
    
public voidsaveChanges()

        ; // trivial implementation
    
public voidsetContent(java.lang.Object object, java.lang.String mimeType)

        m_content = object;  // trivial implementation
    
public voidsetContent(javax.mail.Multipart multipart)

        m_content = multipart;
    
public voidsetContentID(java.lang.String contentID)

        setHeader("Content-ID", contentID);
    
public voidsetContentLanguage(java.lang.String[] contentLanguage)

        m_contentLanguage = contentLanguage;
    
public voidsetContentMD5(java.lang.String value)

        setHeader("Content-MD5", value);
    
public synchronized voidsetDataHandler(javax.activation.DataHandler dataHandler)

        m_dataHandler = dataHandler;
    
public voidsetDescription(java.lang.String description)

 
        setHeader("Content-Description", description);
    
public voidsetDescription(java.lang.String description, java.lang.String charset)

        try {
            setDescription(new String(description.getBytes(charset)));
        } catch (UnsupportedEncodingException e) {
            throw new MessagingException("setting description failed", e);
        }
    
public voidsetDisposition(java.lang.String disposition)

        setHeader("Content-Disposition", disposition);
    
protected voidsetExpunged(boolean b)

        m_bIsExpunged = b;
    
public voidsetFileName(java.lang.String fileName)

        m_fileName = fileName;
    
public voidsetFlag(javax.mail.Flags$Flag flag, boolean set)

        if (set) m_setFlags.add(flag);
        else m_setFlags.remove(flag);
    
public synchronized voidsetFlags(javax.mail.Flags flags, boolean set)

        if (set) m_setFlags.add(flags);
        else m_setFlags.remove(flags);
    
public voidsetFrom(javax.mail.Address address)

        m_fromAddresses.clear();
        m_fromAddresses.add(address);
    
public voidsetFrom()

        m_fromAddresses.clear();
        m_fromAddresses.add(InternetAddress.getLocalAddress(null));
    
public voidsetHeader(java.lang.String name, java.lang.String value)

        addHeader(name, value);
    
protected voidsetMessageNumber(int i)

        m_iMessageNumber = i;
    
public voidsetRecipient(javax.mail.Message$RecipientType recipientType, javax.mail.Address address)

        setRecipients(recipientType, new Address[]{address});
    
public voidsetRecipients(javax.mail.Message$RecipientType recipientType, javax.mail.Address[] addresses)

        getRecipientsList(recipientType).addAll(Arrays.asList(addresses));
    
public voidsetRecipients(javax.mail.Message$RecipientType recipientType, java.lang.String recipient)

        getRecipientsList(recipientType).add(recipient);
    
public voidsetReplyTo(javax.mail.Address[] addresses)

        m_replyToAddresses.addAll(Arrays.asList(addresses));
    
public voidsetSender(javax.mail.Address address)

        m_senderAddress = address;
    
public voidsetSentDate(java.util.Date date)

        m_sentDate = date;
    
public voidsetShouldMatch(boolean doMatch)

        m_doMatch = doMatch;
    
public voidsetSubject(java.lang.String subject)

        m_subject = subject;
    
public voidsetSubject(java.lang.String subject, java.lang.String charset)

        if (subject == null)
        {
            m_subject = null;
            return;
        }
        try {
            m_subject = new String(subject.getBytes(charset));
        } catch (UnsupportedEncodingException e) {
            throw new MessagingException("setting subject failed", e);
        }
    
public voidsetText(java.lang.String string)

        setContent(string, "text/plain");
    
public voidsetText(java.lang.String string, java.lang.String charset)

        try {
            setContent(new String(string.getBytes(charset)) , "text/plain");
        } catch (UnsupportedEncodingException e) {
            throw new MessagingException("setting text content failed", e);
        }
    
protected voidupdateHeaders()

        ; // trivial implementation 
    
public voidwriteTo(java.io.OutputStream outputStream)

        ; // trivial implementation
    
public voidwriteTo(java.io.OutputStream outputStream, java.lang.String[] strings)

        ; // trivial implementation