james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject james-project git commit: MAILET-118 FakeMimeMessage is harmful as it doesn't behave like a MimeMessage
Date Wed, 07 Sep 2016 08:31:29 GMT
Repository: james-project
Updated Branches:
  refs/heads/master f97e46346 -> 39d0cda0d


MAILET-118 FakeMimeMessage is harmful as it doesn't behave like a MimeMessage


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/39d0cda0
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/39d0cda0
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/39d0cda0

Branch: refs/heads/master
Commit: 39d0cda0df7da48b8ad7c3893ad4d7132bf442d3
Parents: f97e463
Author: Matthieu Baechler <matthieu.baechler@linagora.com>
Authored: Tue Aug 30 17:22:54 2016 +0200
Committer: Matthieu Baechler <matthieu.baechler@linagora.com>
Committed: Wed Sep 7 10:23:14 2016 +0200

----------------------------------------------------------------------
 .../mailet/base/test/FakeMimeMessage.java       | 389 -------------------
 .../org/apache/mailet/base/test/MailUtil.java   |  37 +-
 .../mailets/MailAttributesToMimeHeaders.java    |   2 +-
 .../james/transport/mailets/SetMimeHeader.java  |   2 +-
 .../MailAttributesToMimeHeadersTest.java        |   4 +-
 .../org/apache/james/core/MailImplTest.java     |  11 +-
 .../mailets/RecipientRewriteTableTest.java      |  10 +-
 7 files changed, 37 insertions(+), 418 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/39d0cda0/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMimeMessage.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMimeMessage.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMimeMessage.java
deleted file mode 100644
index d1842cb..0000000
--- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMimeMessage.java
+++ /dev/null
@@ -1,389 +0,0 @@
-/****************************************************************
- * 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.mailet.base.test;
-
-import org.apache.mailet.base.RFC2822Headers;
-
-import javax.activation.DataHandler;
-import javax.mail.*;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.InternetHeaders;
-import javax.mail.internet.MimeMessage;
-import javax.mail.search.SearchTerm;
-import java.io.*;
-import java.util.*;
-
-public class FakeMimeMessage extends MimeMessage {
-
-    private final List<Serializable> m_fromAddresses = new ArrayList<Serializable>();
-    private Address m_senderAddress;
-    private final List<Serializable> m_toRecepients = new ArrayList<Serializable>();
-    private final List<Serializable> m_ccRecepients = new ArrayList<Serializable>();
-    private final List<Serializable> m_bccRecepients = new ArrayList<Serializable>();
-    private final List<Serializable> m_replyToAddresses = new ArrayList<Serializable>();
-    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 final Flags m_setFlags = new Flags();
-    private boolean m_doMatch;
-
-    public FakeMimeMessage() throws MessagingException {
-        super((Session) null);
-    }
-
-    public FakeMimeMessage(int messageNumber) throws MessagingException {
-        super((Session) null);
-        m_iMessageNumber = messageNumber;
-    }
-
-    public FakeMimeMessage(MimeMessage mimeMessage) throws MessagingException {
-        super(mimeMessage); // trivial implementation
-    }
-
-    public Address[] getFrom() throws MessagingException {
-        return m_fromAddresses.toArray(new Address[m_fromAddresses.size()]);
-    }
-
-    public void setFrom(Address address) throws MessagingException {
-        m_fromAddresses.clear();
-        m_fromAddresses.add(address);
-    }
-
-    public void setFrom() throws MessagingException {
-        m_fromAddresses.clear();
-        m_fromAddresses.add(InternetAddress.getLocalAddress(null));
-    }
-
-    public void addFrom(Address[] addresses) throws MessagingException {
-        m_fromAddresses.add(addresses);
-    }
-
-    public Address getSender() throws MessagingException {
-        return m_senderAddress;
-    }
-
-    public void setSender(Address address) throws MessagingException {
-        m_senderAddress = address;
-    }
-
-    public Address[] getRecipients(Message.RecipientType recipientType) throws MessagingException
{
-        List<Serializable> recipientsList = getRecipientsList(recipientType);
-        List<Serializable> recipientAddresses = new ArrayList<Serializable>();
-        for (Serializable aRecipientsList : recipientsList) {
-            String recipient = (String) aRecipientsList;
-            recipientAddresses.add(new InternetAddress(recipient));
-        }
-        return recipientAddresses.toArray(new Address[recipientAddresses.size()]);
-    }
-
-    private List<Serializable> getRecipientsList(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 Address[] getAllRecipients() throws MessagingException {
-        List<Serializable> allRecipients = new ArrayList<Serializable>();
-        allRecipients.addAll(m_toRecepients);
-        allRecipients.addAll(m_ccRecepients);
-        allRecipients.addAll(m_bccRecepients);
-        return (Address[]) allRecipients.toArray();
-    }
-
-    public void setRecipients(Message.RecipientType recipientType, Address[] addresses) throws
MessagingException {
-        getRecipientsList(recipientType).addAll(Arrays.asList(addresses));
-    }
-
-    public void setRecipients(Message.RecipientType recipientType, String recipient) throws
MessagingException {
-        getRecipientsList(recipientType).add(recipient);
-    }
-
-    public void addRecipients(Message.RecipientType recipientType, Address[] addresses) throws
MessagingException {
-        getRecipientsList(recipientType).addAll(Arrays.asList(addresses));
-    }
-
-    public void addRecipients(Message.RecipientType recipientType, String recipient) throws
MessagingException {
-        getRecipientsList(recipientType).add(recipient);
-    }
-
-    public Address[] getReplyTo() throws MessagingException {
-        return (Address[]) m_replyToAddresses.toArray();
-    }
-
-    public void setReplyTo(Address[] addresses) throws MessagingException {
-        m_replyToAddresses.addAll(Arrays.asList(addresses));
-    }
-
-    public Date getSentDate() throws MessagingException {
-        return m_sentDate;
-    }
-
-    public void setSentDate(Date date) throws MessagingException {
-        m_sentDate = date;
-    }
-
-    public Date getReceivedDate() throws MessagingException {
-        return null; // trivial implementation
-    }
-
-    public int getSize() throws MessagingException {
-        return -1; // trivial implementation
-    }
-
-    public int getLineCount() throws MessagingException {
-        return -1; // trivial implementation
-    }
-
-    public String getContentType() throws MessagingException {
-        return getHeader("Content-Type", null);
-    }
-
-    public boolean isMimeType(String mimeType) throws MessagingException {
-        return mimeType.startsWith(getContentType());
-    }
-
-    public String getDisposition() throws MessagingException {
-        return getHeader("Content-Disposition", null);
-    }
-
-    public void setDisposition(String disposition) throws MessagingException {
-        setHeader("Content-Disposition", disposition);
-    }
-
-    public String getEncoding() throws MessagingException {
-        return getHeader("Content-Transfer-Encoding", null);
-    }
-
-    public String getContentID() throws MessagingException {
-        return getHeader("Content-ID", null);
-    }
-
-    public void setContentID(String contentID) throws MessagingException {
-        setHeader("Content-ID", contentID);
-    }
-
-    public String getContentMD5() throws MessagingException {
-        return getHeader("Content-MD5", null);
-    }
-
-    public void setContentMD5(String value) throws MessagingException {
-        setHeader("Content-MD5", value);
-    }
-
-    public String getDescription() throws MessagingException {
-        return getHeader("Content-Description", null);
-    }
-
-    public void setDescription(String description) throws MessagingException {
-        setHeader("Content-Description", description);
-    }
-
-    public void setDescription(String description, String charset) throws MessagingException
{
-        try {
-            setDescription(new String(description.getBytes(charset)));
-        } catch (UnsupportedEncodingException e) {
-            throw new MessagingException("setting description failed", e);
-        }
-    }
-
-    public String[] getContentLanguage() throws MessagingException {
-        return m_contentLanguage;
-    }
-
-    public void setContentLanguage(String[] contentLanguage) throws MessagingException {
-        m_contentLanguage = contentLanguage;
-    }
-
-    public String getMessageID() throws MessagingException {
-        return "ID-" + m_iMessageNumber; // trivial implementation
-    }
-
-    public String getFileName() throws MessagingException {
-        return m_fileName;
-    }
-
-    public void setFileName(String fileName) throws MessagingException {
-        m_fileName = fileName;
-    }
-
-    public InputStream getInputStream() throws IOException, MessagingException {
-        return null; // trivial implementation
-    }
-
-    protected InputStream getContentStream() throws MessagingException {
-        return null; // trivial implementation
-    }
-
-    public InputStream getRawInputStream() throws MessagingException {
-        if (m_content instanceof String) {
-            return new ByteArrayInputStream(m_content.toString().getBytes());
-        }
-        throw new UnsupportedOperationException("Unimplementated method");
-    }
-
-    public synchronized DataHandler getDataHandler() throws MessagingException {
-        return m_dataHandler;
-    }
-
-    public synchronized void setDataHandler(DataHandler dataHandler) throws MessagingException
{
-        m_dataHandler = dataHandler;
-    }
-
-    public Object getContent() throws IOException, MessagingException {
-        return m_content;
-    }
-
-    public void setContent(Object object, String mimeType) throws MessagingException {
-        m_content = object;  // trivial implementation
-        addHeader(RFC2822Headers.CONTENT_TYPE, mimeType);
-    }
-
-    public void setText(String string) throws MessagingException {
-        setContent(string, "text/plain");
-    }
-
-    public void setText(String string, String charset) throws MessagingException {
-        try {
-            setContent(new String(string.getBytes(charset)), "text/plain");
-        } catch (UnsupportedEncodingException e) {
-            throw new MessagingException("setting text content failed", e);
-        }
-    }
-
-    public void setContent(Multipart multipart) throws MessagingException {
-        m_content = multipart;
-    }
-
-    public Message reply(boolean b) throws MessagingException {
-        return new FakeMimeMessage(this); // trivial implementation
-    }
-
-    public void writeTo(OutputStream outputStream) throws IOException, MessagingException
{
-        // trivial implementation
-    }
-
-    public void writeTo(OutputStream outputStream, String[] strings) throws IOException,
MessagingException {
-        // trivial implementation
-    }
-
-    public void setHeader(String name, String value) throws MessagingException {
-        addHeader(name, value);
-    }
-
-    public Enumeration<String> getMatchingHeaders(String[] names) throws MessagingException
{
-        ArrayList<String> matchingHeaders = new ArrayList<String>();
-        for (String name : names) {
-            String value = getHeader(name, null);
-            if (value == null) continue;
-            matchingHeaders.add(value);
-        }
-        return Collections.enumeration(matchingHeaders);
-    }
-
-
-    public void addHeaderLine(String headerLine) throws MessagingException {
-        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 Enumeration<String> getMatchingHeaderLines(String[] names) throws MessagingException
{
-        ArrayList<String> matchingHeaders = new ArrayList<String>();
-        for (String name : names) {
-            String value = getHeader(name, null);
-            if (value == null) continue;
-            matchingHeaders.add(name + ":" + value);
-        }
-        return Collections.enumeration(matchingHeaders);
-    }
-
-    public synchronized Flags getFlags() throws MessagingException {
-        return new Flags(m_setFlags);
-    }
-
-    public synchronized boolean isSet(Flags.Flag flag) throws MessagingException {
-        return m_setFlags.contains(flag);
-    }
-
-    public synchronized void setFlags(Flags flags, boolean set) throws MessagingException
{
-        if (set) m_setFlags.add(flags);
-        else m_setFlags.remove(flags);
-    }
-
-    public void saveChanges() throws MessagingException {
-        // trivial implementation
-    }
-
-    protected void updateHeaders() throws MessagingException {
-        // trivial implementation
-    }
-
-    protected InternetHeaders createInternetHeaders(InputStream inputStream) throws MessagingException
{
-        return new InternetHeaders();
-    }
-
-    public void setRecipient(Message.RecipientType recipientType, Address address) throws
MessagingException {
-        setRecipients(recipientType, new Address[]{address});
-    }
-
-    public void addRecipient(Message.RecipientType recipientType, Address address) throws
MessagingException {
-        setRecipients(recipientType, new Address[]{address});
-    }
-
-    public void setFlag(Flags.Flag flag, boolean set) throws MessagingException {
-        if (set) m_setFlags.add(flag);
-        else m_setFlags.remove(flag);
-    }
-
-    public int getMessageNumber() {
-        return m_iMessageNumber;
-    }
-
-    protected void setMessageNumber(int i) {
-        m_iMessageNumber = i;
-    }
-
-    public Folder getFolder() {
-        return null;
-    }
-
-    public boolean isExpunged() {
-        return m_bIsExpunged;
-    }
-
-    protected void setExpunged(boolean b) {
-        m_bIsExpunged = b;
-    }
-
-    public void setShouldMatch(boolean doMatch) {
-        m_doMatch = doMatch;
-    }
-
-    public boolean match(SearchTerm searchTerm) throws MessagingException {
-        return m_doMatch;
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/39d0cda0/mailet/base/src/test/java/org/apache/mailet/base/test/MailUtil.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/MailUtil.java b/mailet/base/src/test/java/org/apache/mailet/base/test/MailUtil.java
index be356b3..e901b9f 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/test/MailUtil.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/test/MailUtil.java
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.util.Arrays;
 
 import javax.mail.MessagingException;
+import javax.mail.Session;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.ParseException;
@@ -36,6 +37,8 @@ import org.apache.mailet.MailAddress;
  */
 public class MailUtil {
 
+    private static final Session NO_SESSION = null;
+    
     private static int m_counter = 0;
 
     public static String newId() {
@@ -52,34 +55,30 @@ public class MailUtil {
         return mockedMail;
     }
 
-    public static FakeMimeMessage createMimeMessage() throws MessagingException {
+    public static MimeMessage createMimeMessage() throws MessagingException {
         return createMimeMessage(null, null);
     }
     
-    public static FakeMimeMessage createMimeMessageWithSubject(String subject) throws MessagingException
{
-        return createMimeMessage(null, null, subject, 0);
-    }
-    
-    public static FakeMimeMessage createMimeMessage(String subject, int number) throws MessagingException
{
-        return createMimeMessage(null, null, subject, number);
+    public static MimeMessage createMimeMessageWithSubject(String subject) throws MessagingException
{
+        return createMimeMessage(null, null, subject);
     }
-    
-    public static FakeMimeMessage createMimeMessage(String headerName, String headerValue)
throws MessagingException {
-        return createMimeMessage(headerName, headerValue, "testmail", 0);
+
+    public static MimeMessage createMimeMessage(String headerName, String headerValue) throws
MessagingException {
+        return createMimeMessage(headerName, headerValue, "testmail");
     }
     
-    public static FakeMimeMessage createMimeMessage(String headerName, String headerValue,
String subject, int number) throws MessagingException {
+    private static MimeMessage createMimeMessage(String headerName, String headerValue, String
subject) throws MessagingException {
         String sender = "test@james.apache.org";
         String rcpt = "test2@james.apache.org";
 
-        FakeMimeMessage mockedMimeMessage = new FakeMimeMessage(number);
-        mockedMimeMessage.setFrom(new InternetAddress(sender));
-        mockedMimeMessage.setRecipients(MimeMessage.RecipientType.TO, rcpt);
-        if (headerName != null) mockedMimeMessage.setHeader(headerName, headerValue);
-        if (subject != null) mockedMimeMessage.setSubject(subject);
-        mockedMimeMessage.setText("testtext");
-        mockedMimeMessage.saveChanges();
-        return mockedMimeMessage;
+        MimeMessage mimeMessage = new MimeMessage(NO_SESSION);
+        mimeMessage.setFrom(new InternetAddress(sender));
+        mimeMessage.setRecipients(MimeMessage.RecipientType.TO, rcpt);
+        if (headerName != null) mimeMessage.setHeader(headerName, headerValue);
+        if (subject != null) mimeMessage.setSubject(subject);
+        mimeMessage.setText("testtext");
+        mimeMessage.saveChanges();
+        return mimeMessage;
     }
     
     public static String toString(Mail mail, String charset) throws IOException, MessagingException
{

http://git-wip-us.apache.org/repos/asf/james-project/blob/39d0cda0/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesToMimeHeaders.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesToMimeHeaders.java
b/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesToMimeHeaders.java
index 16ea929..8ce278b 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesToMimeHeaders.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/MailAttributesToMimeHeaders.java
@@ -78,7 +78,7 @@ public class MailAttributesToMimeHeaders extends GenericMailet {
                 String value = (String) mail.getAttribute(entry.getKey());
                 if (value != null) {
                     String headerName = entry.getValue();
-                    message.setHeader(headerName, value);
+                    message.addHeader(headerName, value);
                 }
             }
             message.saveChanges();

http://git-wip-us.apache.org/repos/asf/james-project/blob/39d0cda0/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMimeHeader.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMimeHeader.java
b/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMimeHeader.java
index 14fab6e..46c77fe 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMimeHeader.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/SetMimeHeader.java
@@ -64,7 +64,7 @@ public class SetMimeHeader extends GenericMailet {
         try {
             MimeMessage message = mail.getMessage () ;
 
-            message.setHeader(headerName, headerValue);
+            message.addHeader(headerName, headerValue);
             message.saveChanges();
         } catch (javax.mail.MessagingException me) {
             log(me.getMessage());

http://git-wip-us.apache.org/repos/asf/james-project/blob/39d0cda0/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
index bd5764d..9931a17 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
@@ -24,12 +24,12 @@ package org.apache.james.transport.mailets;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
 
 import org.apache.mailet.Mailet;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMailContext;
 import org.apache.mailet.base.test.FakeMailetConfig;
-import org.apache.mailet.base.test.FakeMimeMessage;
 import org.apache.mailet.base.test.MailUtil;
 import org.junit.Before;
 import org.junit.Rule;
@@ -82,7 +82,7 @@ public class MailAttributesToMimeHeadersTest {
         mailetConfig.setProperty("simplemapping", MAIL_ATTRIBUTE_NAME1 + "; " + HEADER_NAME1);
         mailet.init(mailetConfig);
         
-        FakeMimeMessage mimeMessage = MailUtil.createMimeMessage();
+        MimeMessage mimeMessage = MailUtil.createMimeMessage();
         mimeMessage.addHeader(HEADER_NAME1, "first value");
 		FakeMail mockedMail = MailUtil.createMockMail2Recipients(mimeMessage);
         mockedMail.setAttribute(MAIL_ATTRIBUTE_NAME1, MAIL_ATTRIBUTE_VALUE1);

http://git-wip-us.apache.org/repos/asf/james-project/blob/39d0cda0/server/container/core/src/test/java/org/apache/james/core/MailImplTest.java
----------------------------------------------------------------------
diff --git a/server/container/core/src/test/java/org/apache/james/core/MailImplTest.java b/server/container/core/src/test/java/org/apache/james/core/MailImplTest.java
index 121ca3d..57a8ae1 100644
--- a/server/container/core/src/test/java/org/apache/james/core/MailImplTest.java
+++ b/server/container/core/src/test/java/org/apache/james/core/MailImplTest.java
@@ -18,18 +18,23 @@
  ****************************************************************/
 package org.apache.james.core;
 
-import org.apache.mailet.base.test.FakeMimeMessage;
 import org.apache.mailet.base.test.MailUtil;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.Mail;
 
 import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import java.io.ByteArrayInputStream;
 import java.util.ArrayList;
 import static org.junit.Assert.*;
 import org.junit.Test;
 
 public class MailImplTest extends MailTestAllImplementations {
 
+    private static final Session NO_SESSION = null;
+    
     @Override
     protected Mail createMailImplementation() {
         return new MailImpl();
@@ -60,7 +65,7 @@ public class MailImplTest extends MailTestAllImplementations {
         assertEquals("sender", sender, mail.getSender().toString());
         assertEquals("name", name, mail.getName());
 
-        mail.setMessage(new FakeMimeMessage());
+        mail.setMessage(new MimeMessage(NO_SESSION));
         assertNotNull("message", mail.getMessage());
     }
 
@@ -70,7 +75,7 @@ public class MailImplTest extends MailTestAllImplementations {
         String name = MailUtil.newId();
         String sender = "sender@localhost";
         MailAddress senderMailAddress = new MailAddress(sender);
-        FakeMimeMessage mimeMessage = new FakeMimeMessage();
+        MimeMessage mimeMessage = new MimeMessage(NO_SESSION, new ByteArrayInputStream(new
byte[0]));
         MailImpl mail = new MailImpl(name, senderMailAddress, recepients, mimeMessage);
 
         helperTestInitialState(mail);

http://git-wip-us.apache.org/repos/asf/james-project/blob/39d0cda0/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableTest.java
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableTest.java
index 6a8ed7a..42b0a57 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RecipientRewriteTableTest.java
@@ -26,8 +26,10 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Properties;
 
+import javax.mail.Address;
 import javax.mail.Message;
 import javax.mail.MessagingException;
+import javax.mail.Session;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.mailet.Mail;
@@ -36,13 +38,14 @@ import org.apache.mailet.MailetContext;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMailContext;
 import org.apache.mailet.base.test.FakeMailetConfig;
-import org.apache.mailet.base.test.FakeMimeMessage;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
 public class RecipientRewriteTableTest {
 
+    private static final Session NO_SESSION = null;
+    
     private org.apache.james.transport.mailets.RecipientRewriteTable table;
 
     @Before
@@ -96,7 +99,7 @@ public class RecipientRewriteTableTest {
             a.add(new MailAddress(recipient));
         }
         mail.setRecipients(a);
-        mail.setMessage(new FakeMimeMessage());
+        mail.setMessage(new MimeMessage(NO_SESSION));
         return mail;
     }
 
@@ -117,7 +120,8 @@ public class RecipientRewriteTableTest {
         if (msg == null) {
             msg = context.getSendmails().get(0).getMail().getMessage();
         }
-        if (msg.getRecipients(Message.RecipientType.TO).length == 1) {
+        Address[] mimeMessageRecipients = msg.getRecipients(Message.RecipientType.TO);
+        if (mimeMessageRecipients != null && mimeMessageRecipients.length == 1) {
             assertEquals(msg.getRecipients(Message.RecipientType.TO)[0].toString(), "b@remote.com");
         } else {
             assertEquals(context.getSendmails().get(0).getRecipients().size(), 1);


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message