james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [2/3] james-project git commit: MAILBOX-268 Store attachments when storing a mail
Date Thu, 02 Jun 2016 07:12:49 GMT
MAILBOX-268 Store attachments when storing a mail


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

Branch: refs/heads/master
Commit: bbcba2c8b58a234c02ccaf11b03f276d53a20e8d
Parents: 0bfab26
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Fri May 27 15:29:05 2016 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Wed Jun 1 17:15:08 2016 +0200

----------------------------------------------------------------------
 mailbox/cassandra/pom.xml                       |   5 +
 .../cassandra/CassandraMailboxManager.java      |   9 +-
 .../cassandra/CassandraMessageManager.java      |   5 +-
 .../cassandra/CassandraMailboxManagerTest.java  |   9 +-
 .../CassandraMailboxManagerAttachmentTest.java  |  92 +++++++++
 .../ElasticSearchIntegrationTest.java           |   4 +-
 .../mailbox/hbase/HBaseMailboxManager.java      |  12 +-
 .../mailbox/hbase/HBaseMessageManager.java      |   5 +-
 .../mailbox/hbase/HBaseMailboxManagerTest.java  |   4 +-
 .../james/mailbox/jcr/JCRMailboxManager.java    |  12 +-
 .../james/mailbox/jcr/JCRMessageManager.java    |   9 +-
 .../mailbox/jcr/JCRMailboxManagerTest.java      |   4 +-
 .../apache/james/mailbox/jcr/JCRStressTest.java |   4 +-
 .../james/mailbox/jpa/JPAMailboxManager.java    |   5 +-
 .../james/mailbox/jpa/JPAMessageManager.java    |   9 +-
 .../jpa/openjpa/OpenJPAMailboxManager.java      |  16 +-
 .../jpa/openjpa/OpenJPAMessageManager.java      |  15 +-
 .../resources/META-INF/spring/mailbox-jpa.xml   |   3 +-
 .../mailbox/jpa/JPAMailboxManagerTest.java      |   4 +-
 .../apache/james/mailbox/jpa/JPAStressTest.java |   4 +-
 .../META-INF/spring/mailbox-maildir.xml         |   1 +
 .../maildir/MaildirMailboxManagerTest.java      |   4 +-
 .../mailbox/maildir/MaildirStressTest.java      |   4 +-
 .../inmemory/InMemoryMailboxManager.java        |   8 +-
 .../InMemoryMailboxSessionMapperFactory.java    |   4 +-
 .../inmemory/InMemoryMessageManager.java        |   7 +-
 .../inmemory/mail/InMemoryAttachmentMapper.java |  58 ++++++
 .../META-INF/spring/mailbox-memory.xml          |   1 +
 .../inmemory/InMemoryMailboxManagerTest.java    |   4 +-
 .../InMemoryMailboxManagerAttachmentTest.java   |  70 +++++++
 .../manager/InMemoryIntegrationResources.java   |   4 +-
 .../META-INF/spring/spring-mailbox.xml          |   5 +
 .../mailbox/store/StoreMailboxManager.java      |  16 +-
 .../mailbox/store/StoreMessageManager.java      |  54 +++--
 .../AbstractMailboxManagerAttachmentTest.java   | 197 +++++++++++++++++++
 .../mailbox/store/StoreMailboxManagerTest.java  |   3 +-
 .../store/src/test/resources/eml/4037_014.jpg   | Bin 0 -> 846 bytes
 .../store/src/test/resources/eml/4037_015.jpg   | Bin 0 -> 597 bytes
 .../james/mailbox/copier/MailboxCopierTest.java |   5 +-
 .../cassandra/host/CassandraHostSystem.java     |   7 +-
 .../host/ElasticSearchHostSystem.java           |   4 +-
 .../imapmailbox/hbase/host/HBaseHostSystem.java |   4 +-
 .../InMemoryEventAsynchronousHostSystem.java    |   4 +-
 .../inmemory/host/InMemoryHostSystem.java       |   4 +-
 .../mpt/imapmailbox/jcr/host/JCRHostSystem.java |   4 +-
 .../mpt/imapmailbox/jpa/host/JPAHostSystem.java |   4 +-
 .../maildir/host/MaildirHostSystem.java         |   4 +-
 .../modules/mailbox/CassandraMailboxModule.java |   1 +
 .../adapter/mailbox/MailboxManagementTest.java  |   4 +-
 .../META-INF/org/apache/james/spring-server.xml |   1 +
 .../jmap/methods/GetMailboxesMethodTest.java    |   4 +-
 .../jmap/methods/GetMessagesMethodTest.java     |   4 +-
 .../jmap/send/PostDequeueDecoratorTest.java     |   4 +-
 .../apache/james/pop3server/POP3ServerTest.java |   4 +-
 54 files changed, 641 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/cassandra/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/pom.xml b/mailbox/cassandra/pom.xml
index 6839e75..7bae6c7 100644
--- a/mailbox/cassandra/pom.xml
+++ b/mailbox/cassandra/pom.xml
@@ -241,6 +241,11 @@
                     <scope>test</scope>
                 </dependency>
                 <dependency>
+                    <groupId>org.mockito</groupId>
+                    <artifactId>mockito-core</artifactId>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
                     <groupId>com.github.fge</groupId>
                     <artifactId>throwing-lambdas</artifactId>
                     <version>0.5.0</version>

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
index 1ba5369..3a9375e 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java
@@ -34,6 +34,7 @@ import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.apache.james.mailbox.store.search.MessageSearchIndex;
 
@@ -46,12 +47,13 @@ public class CassandraMailboxManager extends StoreMailboxManager {
     private final MailboxPathLocker locker;
 
     @Inject
-    public CassandraMailboxManager(CassandraMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxPathLocker locker) {
+    public CassandraMailboxManager(CassandraMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxPathLocker locker, MessageParser messageParser) {
         super(mapperFactory,
             authenticator,
             locker,
             new UnionMailboxACLResolver(),
-            new SimpleGroupMembershipResolver());
+            new SimpleGroupMembershipResolver(),
+            messageParser);
         this.locker = locker;
     }
 
@@ -81,7 +83,8 @@ public class CassandraMailboxManager extends StoreMailboxManager {
             this.locker,
             mailboxRow,
             getQuotaManager(),
-            getQuotaRootResolver());
+            getQuotaRootResolver(),
+            getMessageParser());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMessageManager.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMessageManager.java
index 4c4486b..a2845ee 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMessageManager.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMessageManager.java
@@ -32,6 +32,7 @@ import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.search.MessageSearchIndex;
 
 /**
@@ -40,8 +41,8 @@ import org.apache.james.mailbox.store.search.MessageSearchIndex;
  */
 public class CassandraMessageManager extends StoreMessageManager {
 
-    public CassandraMessageManager(MailboxSessionMapperFactory mapperFactory, MessageSearchIndex index, MailboxEventDispatcher dispatcher, MailboxPathLocker locker, Mailbox mailbox, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver) throws MailboxException {
-        super(mapperFactory, index, dispatcher, locker, mailbox, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), quotaManager, quotaRootResolver);
+    public CassandraMessageManager(MailboxSessionMapperFactory mapperFactory, MessageSearchIndex index, MailboxEventDispatcher dispatcher, MailboxPathLocker locker, Mailbox mailbox, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver, MessageParser messageParser) throws MailboxException {
+        super(mapperFactory, index, dispatcher, locker, mailbox, new UnionMailboxACLResolver(), new SimpleGroupMembershipResolver(), quotaManager, quotaRootResolver, messageParser);
 
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
index 5f0371b..ad61efe 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
@@ -25,6 +25,7 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.cassandra.mail.CassandraModSeqProvider;
 import org.apache.james.mailbox.cassandra.mail.CassandraUidProvider;
 import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraAttachmentModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxCounterModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMessageModule;
@@ -33,7 +34,8 @@ import org.apache.james.mailbox.cassandra.modules.CassandraUidModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraModSeqModule;
 import org.apache.james.mailbox.exception.BadCredentialsException;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.NoMailboxPathLocker;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.junit.After;
 import org.junit.Before;
 import org.slf4j.LoggerFactory;
@@ -51,7 +53,8 @@ public class CassandraMailboxManagerTest extends AbstractMailboxManagerTest {
         new CassandraMailboxCounterModule(),
         new CassandraUidModule(),
         new CassandraModSeqModule(),
-        new CassandraSubscriptionModule()));
+        new CassandraSubscriptionModule(),
+        new CassandraAttachmentModule()));
 
     /**
      * Setup the mailboxManager.
@@ -92,7 +95,7 @@ public class CassandraMailboxManagerTest extends AbstractMailboxManagerTest {
             CASSANDRA.getConf(),
             CASSANDRA.getTypesProvider());
 
-        final CassandraMailboxManager manager = new CassandraMailboxManager(mapperFactory, null, new JVMMailboxPathLocker());
+        final CassandraMailboxManager manager = new CassandraMailboxManager(mapperFactory, null, new NoMailboxPathLocker(), new MessageParser());
         manager.init();
 
         setMailboxManager(manager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
new file mode 100644
index 0000000..9e1517c
--- /dev/null
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxManagerAttachmentTest.java
@@ -0,0 +1,92 @@
+/****************************************************************
+ * 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.james.mailbox.cassandra.mail;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.james.backends.cassandra.CassandraCluster;
+import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.cassandra.CassandraMailboxManager;
+import org.apache.james.mailbox.cassandra.CassandraMailboxSessionMapperFactory;
+import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraAttachmentModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraMailboxCounterModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraMessageModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraModSeqModule;
+import org.apache.james.mailbox.cassandra.modules.CassandraUidModule;
+import org.apache.james.mailbox.store.AbstractMailboxManagerAttachmentTest;
+import org.apache.james.mailbox.store.Authenticator;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.NoMailboxPathLocker;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
+
+public class CassandraMailboxManagerAttachmentTest extends AbstractMailboxManagerAttachmentTest {
+    private static final CassandraCluster cassandra = CassandraCluster.create(new CassandraModuleComposite(
+            new CassandraAclModule(),
+            new CassandraMailboxModule(),
+            new CassandraMessageModule(),
+            new CassandraMailboxCounterModule(),
+            new CassandraModSeqModule(),
+            new CassandraUidModule(),
+            new CassandraAttachmentModule()));
+
+    private CassandraMailboxSessionMapperFactory mailboxSessionMapperFactory;
+    private CassandraMailboxManager mailboxManager;
+    private CassandraMailboxManager parseFailingMailboxManager;
+
+    public CassandraMailboxManagerAttachmentTest() throws Exception {
+        mailboxSessionMapperFactory = new CassandraMailboxSessionMapperFactory(
+                new CassandraUidProvider(cassandra.getConf()),
+                new CassandraModSeqProvider(cassandra.getConf()),
+                cassandra.getConf(),
+                cassandra.getTypesProvider());
+        Authenticator noAuthenticator = null;
+        mailboxManager = new CassandraMailboxManager(mailboxSessionMapperFactory, noAuthenticator, new NoMailboxPathLocker(), new MessageParser());
+        mailboxManager.init();
+        MessageParser failingMessageParser = mock(MessageParser.class);
+        when(failingMessageParser.retrieveAttachments(any()))
+            .thenThrow(new RuntimeException("Message parser set to fail"));
+        parseFailingMailboxManager = new CassandraMailboxManager(mailboxSessionMapperFactory, noAuthenticator, new NoMailboxPathLocker(), failingMessageParser);
+        parseFailingMailboxManager.init();
+    }
+
+    @Override
+    protected MailboxManager getMailboxManager() {
+        return mailboxManager;
+    }
+
+    @Override
+    protected MailboxSessionMapperFactory getMailboxSessionMapperFactory() {
+        return mailboxSessionMapperFactory;
+    }
+
+    @Override
+    protected MailboxManager getParseFailingMailboxManager() {
+        return parseFailingMailboxManager;
+    }
+
+    @Override
+    protected void clean() {
+        cassandra.clearAllTables();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index bc82a95..7899b98 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -48,6 +48,7 @@ import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.elasticsearch.client.Client;
 import org.junit.Before;
 import org.junit.Rule;
@@ -177,7 +178,8 @@ public class ElasticSearchIntegrationTest {
             new MockAuthenticator(),
             new JVMMailboxPathLocker(),
             new UnionMailboxACLResolver(),
-            new SimpleGroupMembershipResolver());
+            new SimpleGroupMembershipResolver(),
+            new MessageParser());
         storeMailboxManager.setMessageSearchIndex(elasticSearchListeningMessageSearchIndex);
         storeMailboxManager.init();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxManager.java b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxManager.java
index 9f5954f..17d5ef4 100644
--- a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxManager.java
+++ b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxManager.java
@@ -31,6 +31,7 @@ import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.transaction.TransactionalMapper;
 
 /**
@@ -39,12 +40,12 @@ import org.apache.james.mailbox.store.transaction.TransactionalMapper;
  */
 public class HBaseMailboxManager extends StoreMailboxManager {
 
-    public HBaseMailboxManager(HBaseMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxPathLocker locker, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
-        super(mapperFactory, authenticator, locker, aclResolver, groupMembershipResolver);
+    public HBaseMailboxManager(HBaseMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxPathLocker locker, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, MessageParser messageParser) {
+        super(mapperFactory, authenticator, locker, aclResolver, groupMembershipResolver, messageParser);
     }
 
-    public HBaseMailboxManager(HBaseMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
-        super(mapperFactory, authenticator, new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver);
+    public HBaseMailboxManager(HBaseMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, MessageParser messageParser) {
+        super(mapperFactory, authenticator, new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver, messageParser);
     }
 
     @Override
@@ -88,6 +89,7 @@ public class HBaseMailboxManager extends StoreMailboxManager {
             getAclResolver(),
             getGroupMembershipResolver(),
             getQuotaManager(),
-            getQuotaRootResolver());
+            getQuotaRootResolver(),
+            getMessageParser());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMessageManager.java b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMessageManager.java
index a434c8d..8c6fff3 100644
--- a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMessageManager.java
+++ b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMessageManager.java
@@ -31,6 +31,7 @@ import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.search.MessageSearchIndex;
 
 /**
@@ -40,8 +41,8 @@ import org.apache.james.mailbox.store.search.MessageSearchIndex;
 public class HBaseMessageManager extends StoreMessageManager {
 
     public HBaseMessageManager(MailboxSessionMapperFactory mapperFactory, MessageSearchIndex index,
-            MailboxEventDispatcher dispatcher, MailboxPathLocker locker, Mailbox mailbox, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver) throws MailboxException {
-        super(mapperFactory, index, dispatcher, locker, mailbox, aclResolver, groupMembershipResolver, quotaManager, quotaRootResolver);
+            MailboxEventDispatcher dispatcher, MailboxPathLocker locker, Mailbox mailbox, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver, MessageParser messageParser) throws MailboxException {
+        super(mapperFactory, index, dispatcher, locker, mailbox, aclResolver, groupMembershipResolver, quotaManager, quotaRootResolver, messageParser);
 
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java b/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
index 2021a13..c4cdaeb 100644
--- a/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
+++ b/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
@@ -30,6 +30,7 @@ import org.apache.james.mailbox.exception.MailboxException;
 import static org.apache.james.mailbox.hbase.HBaseNames.*;
 import org.apache.james.mailbox.hbase.mail.HBaseModSeqProvider;
 import org.apache.james.mailbox.hbase.mail.HBaseUidProvider;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.junit.After;
 import org.junit.Before;
 import org.slf4j.LoggerFactory;
@@ -92,9 +93,10 @@ public class HBaseMailboxManagerTest extends AbstractMailboxManagerTest {
 
         final MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
         final GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
+        final MessageParser messageParser = new MessageParser();
 
         final HBaseMailboxManager manager = new HBaseMailboxManager(mapperFactory, null, aclResolver,
-                groupMembershipResolver);
+                groupMembershipResolver, messageParser);
         manager.init();
 
         setMailboxManager(manager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java
index 15c618c..853d7c6 100644
--- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java
+++ b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxManager.java
@@ -30,6 +30,7 @@ import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,12 +42,12 @@ public class JCRMailboxManager extends StoreMailboxManager implements JCRImapCon
 
     private final Logger logger = LoggerFactory.getLogger(JCRMailboxManager.class);
     
-    public JCRMailboxManager(JCRMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
-	    this(mapperFactory, authenticator, new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver);
+    public JCRMailboxManager(JCRMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, MessageParser messageParser) {
+	    this(mapperFactory, authenticator, new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver, messageParser);
     }
 
-    public JCRMailboxManager(JCRMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxPathLocker locker, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
-        super(mapperFactory, authenticator, locker, aclResolver, groupMembershipResolver);
+    public JCRMailboxManager(JCRMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxPathLocker locker, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, MessageParser messageParser) {
+        super(mapperFactory, authenticator, locker, aclResolver, groupMembershipResolver, messageParser);
     }
 
     
@@ -61,7 +62,8 @@ public class JCRMailboxManager extends StoreMailboxManager implements JCRImapCon
             getGroupMembershipResolver(),
             logger,
             getQuotaManager(),
-            getQuotaRootResolver());
+            getQuotaRootResolver(),
+            getMessageParser());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java
index b7452c8..dcfaed4 100644
--- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java
+++ b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java
@@ -19,6 +19,7 @@
 package org.apache.james.mailbox.jcr;
 
 import java.util.Date;
+import java.util.List;
 
 import javax.mail.Flags;
 import javax.mail.internet.SharedInputStream;
@@ -35,7 +36,9 @@ import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.mail.model.Attachment;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.search.MessageSearchIndex;
 import org.slf4j.Logger;
@@ -49,14 +52,14 @@ public class JCRMessageManager extends StoreMessageManager {
     private final Logger log;
 
     public JCRMessageManager(MailboxSessionMapperFactory mapperFactory, MessageSearchIndex index, 
-            final MailboxEventDispatcher dispatcher, MailboxPathLocker locker, JCRMailbox mailbox, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, Logger log, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver) throws MailboxException {
-        super(mapperFactory, index, dispatcher, locker, mailbox, aclResolver, groupMembershipResolver, quotaManager, quotaRootResolver);
+            final MailboxEventDispatcher dispatcher, MailboxPathLocker locker, JCRMailbox mailbox, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, Logger log, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver, MessageParser messageParser) throws MailboxException {
+        super(mapperFactory, index, dispatcher, locker, mailbox, aclResolver, groupMembershipResolver, quotaManager, quotaRootResolver, messageParser);
         this.log = log;
     }
 
 
     @Override
-    protected MailboxMessage createMessage(Date internalDate, int size, int bodyStartOctet, SharedInputStream content, Flags flags, PropertyBuilder propertyBuilder) throws MailboxException{
+    protected MailboxMessage createMessage(Date internalDate, int size, int bodyStartOctet, SharedInputStream content, Flags flags, PropertyBuilder propertyBuilder, List<Attachment> attachments) throws MailboxException{
         JCRId mailboxId = (JCRId) getMailboxEntity().getMailboxId();
         return new JCRMailboxMessage(mailboxId, internalDate,
                 size, flags, content, bodyStartOctet, propertyBuilder, log);

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java b/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
index 3fd1da6..9abeb32 100644
--- a/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
+++ b/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
@@ -38,6 +38,7 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.jcr.mail.JCRModSeqProvider;
 import org.apache.james.mailbox.jcr.mail.JCRUidProvider;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.junit.After;
 import org.junit.Before;
 import org.slf4j.LoggerFactory;
@@ -93,8 +94,9 @@ public class JCRMailboxManagerTest extends AbstractMailboxManagerTest {
 
         MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
         GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
+        MessageParser messageParser = new MessageParser();
 
-        JCRMailboxManager manager = new JCRMailboxManager(mf, null, locker, aclResolver, groupMembershipResolver);
+        JCRMailboxManager manager = new JCRMailboxManager(mf, null, locker, aclResolver, groupMembershipResolver, messageParser);
         manager.init();
         setMailboxManager(manager);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java b/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java
index 954ce6f..50bd955 100644
--- a/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java
+++ b/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java
@@ -37,6 +37,7 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.jcr.mail.JCRModSeqProvider;
 import org.apache.james.mailbox.jcr.mail.JCRUidProvider;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.junit.After;
 import org.junit.Before;
 import org.slf4j.LoggerFactory;
@@ -65,8 +66,9 @@ public class JCRStressTest extends AbstractStressTest {
         JCRMailboxSessionMapperFactory mf = new JCRMailboxSessionMapperFactory(sessionRepos, uidProvider, modSeqProvider);
         MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
         GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
+        MessageParser messageParser = new MessageParser();
 
-        mailboxManager = new JCRMailboxManager(mf, null, locker, aclResolver, groupMembershipResolver);
+        mailboxManager = new JCRMailboxManager(mf, null, locker, aclResolver, groupMembershipResolver, messageParser);
         mailboxManager.init();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
index 1e74805..34db106 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxManager.java
@@ -29,6 +29,7 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.transaction.TransactionalMapper;
 
 /**
@@ -37,8 +38,8 @@ import org.apache.james.mailbox.store.transaction.TransactionalMapper;
 public abstract class JPAMailboxManager extends StoreMailboxManager {
     
     public JPAMailboxManager(JPAMailboxSessionMapperFactory mailboxSessionMapperFactory,
-            final Authenticator authenticator, MailboxPathLocker locker, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
-        super(mailboxSessionMapperFactory, authenticator, locker, aclResolver, groupMembershipResolver);
+            final Authenticator authenticator, MailboxPathLocker locker, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, MessageParser messageParser) {
+        super(mailboxSessionMapperFactory, authenticator, locker, aclResolver, groupMembershipResolver, messageParser);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
index f798b9d..ce36f27 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
@@ -19,6 +19,7 @@
 package org.apache.james.mailbox.jpa;
 
 import java.util.Date;
+import java.util.List;
 
 import javax.mail.Flags;
 import javax.mail.internet.SharedInputStream;
@@ -35,8 +36,10 @@ import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.mail.model.Attachment;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.search.MessageSearchIndex;
 
@@ -49,15 +52,15 @@ public class JPAMessageManager extends StoreMessageManager {
     			final MailboxEventDispatcher dispatcher, MailboxPathLocker locker, 
     			final Mailbox mailbox, MailboxACLResolver aclResolver, 
     			GroupMembershipResolver groupMembershipResolver, QuotaManager quotaManager,
-                QuotaRootResolver quotaRootResolver) throws MailboxException {
+                QuotaRootResolver quotaRootResolver, MessageParser messageParser) throws MailboxException {
     	
         super(mapperFactory, index, dispatcher, locker, mailbox, aclResolver, groupMembershipResolver,
-            quotaManager, quotaRootResolver);
+            quotaManager, quotaRootResolver, messageParser);
     }
     
     @Override
     protected MailboxMessage createMessage(Date internalDate, int size, int bodyStartOctet, SharedInputStream content,
-                                                  final Flags flags, PropertyBuilder propertyBuilder) throws MailboxException{
+                                                  final Flags flags, PropertyBuilder propertyBuilder, List<Attachment> attachments) throws MailboxException{
 
         return new JPAMailboxMessage((JPAMailbox) getMailboxEntity(), internalDate, size, flags, content,  bodyStartOctet,  propertyBuilder);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java
index 21e49df..377d29d 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMailboxManager.java
@@ -33,6 +33,7 @@ import org.apache.james.mailbox.store.Authenticator;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 
 /**
  * OpenJPA implementation of MailboxManager
@@ -42,8 +43,8 @@ public class OpenJPAMailboxManager extends JPAMailboxManager {
 
     private final AdvancedFeature feature;
 
-    public OpenJPAMailboxManager(JPAMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxPathLocker locker, boolean useStreaming, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
-        super(mapperFactory, authenticator,  locker, aclResolver, groupMembershipResolver);
+    public OpenJPAMailboxManager(JPAMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxPathLocker locker, boolean useStreaming, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, MessageParser messageParser) {
+        super(mapperFactory, authenticator,  locker, aclResolver, groupMembershipResolver, messageParser);
         if (useStreaming) {
             feature = AdvancedFeature.Streaming;
         } else {
@@ -51,8 +52,8 @@ public class OpenJPAMailboxManager extends JPAMailboxManager {
         }
     }
 
-    public OpenJPAMailboxManager(JPAMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxPathLocker locker,  String encryptPass, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
-        super(mapperFactory, authenticator,  locker, aclResolver, groupMembershipResolver);
+    public OpenJPAMailboxManager(JPAMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxPathLocker locker,  String encryptPass, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, MessageParser messageParser) {
+        super(mapperFactory, authenticator,  locker, aclResolver, groupMembershipResolver, messageParser);
         if (encryptPass != null) {
             EncryptDecryptHelper.init(encryptPass);
             feature = AdvancedFeature.Encryption;
@@ -61,8 +62,8 @@ public class OpenJPAMailboxManager extends JPAMailboxManager {
         }
     }
     
-    public OpenJPAMailboxManager(JPAMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
-        this(mapperFactory, authenticator, new JVMMailboxPathLocker(), false, aclResolver, groupMembershipResolver);
+    public OpenJPAMailboxManager(JPAMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, MessageParser messageParser) {
+        this(mapperFactory, authenticator, new JVMMailboxPathLocker(), false, aclResolver, groupMembershipResolver, messageParser);
     }
 
     @Override
@@ -76,6 +77,7 @@ public class OpenJPAMailboxManager extends JPAMailboxManager {
             getAclResolver(),
             getGroupMembershipResolver(),
             getQuotaManager(),
-            getQuotaRootResolver());
+            getQuotaRootResolver(),
+            getMessageParser());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
index 6e1f3bc..332ded6 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
@@ -20,6 +20,7 @@
 package org.apache.james.mailbox.jpa.openjpa;
 
 import java.util.Date;
+import java.util.List;
 
 import javax.mail.Flags;
 import javax.mail.internet.SharedInputStream;
@@ -36,8 +37,10 @@ import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.mail.model.Attachment;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.search.MessageSearchIndex;
 
@@ -58,22 +61,22 @@ public class OpenJPAMessageManager extends JPAMessageManager {
     		MessageSearchIndex index,MailboxEventDispatcher dispatcher, 
     		MailboxPathLocker locker, Mailbox mailbox, MailboxACLResolver aclResolver, 
     		GroupMembershipResolver groupMembershipResolver,
-            QuotaManager quotaManager, QuotaRootResolver quotaRootResolver) throws MailboxException {
-        this(mapperFactory, index, dispatcher, locker,  mailbox, AdvancedFeature.None, aclResolver, groupMembershipResolver, quotaManager, quotaRootResolver);
+            QuotaManager quotaManager, QuotaRootResolver quotaRootResolver, MessageParser messageParser) throws MailboxException {
+        this(mapperFactory, index, dispatcher, locker,  mailbox, AdvancedFeature.None, aclResolver, groupMembershipResolver, quotaManager, quotaRootResolver, messageParser);
     }
 
     public OpenJPAMessageManager(MailboxSessionMapperFactory mapperFactory, 
     		MessageSearchIndex index, MailboxEventDispatcher dispatcher, 
     		MailboxPathLocker locker, Mailbox mailbox, AdvancedFeature f, 
     		MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver,
-            QuotaManager quotaManager, QuotaRootResolver quotaRootResolver) throws MailboxException {
+            QuotaManager quotaManager, QuotaRootResolver quotaRootResolver, MessageParser messageParser) throws MailboxException {
     	
-        super(mapperFactory,  index, dispatcher, locker, mailbox, aclResolver, groupMembershipResolver, quotaManager, quotaRootResolver);
+        super(mapperFactory,  index, dispatcher, locker, mailbox, aclResolver, groupMembershipResolver, quotaManager, quotaRootResolver, messageParser);
         this.feature = f;
     }
 
     @Override
-    protected MailboxMessage createMessage(Date internalDate, int size, int bodyStartOctet, SharedInputStream content, Flags flags, PropertyBuilder propertyBuilder) throws MailboxException {
+    protected MailboxMessage createMessage(Date internalDate, int size, int bodyStartOctet, SharedInputStream content, Flags flags, PropertyBuilder propertyBuilder, List<Attachment> attachments) throws MailboxException {
         int headerEnd = bodyStartOctet -2;
         if (headerEnd < 0) {
             headerEnd = 0;
@@ -84,7 +87,7 @@ public class OpenJPAMessageManager extends JPAMessageManager {
         case Encryption:
             return new JPAEncryptedMailboxMessage((JPAMailbox) getMailboxEntity(), internalDate, size, flags, content, bodyStartOctet, propertyBuilder);
         default:
-            return super.createMessage(internalDate, size, bodyStartOctet, content, flags,  propertyBuilder);
+            return super.createMessage(internalDate, size, bodyStartOctet, content, flags,  propertyBuilder, attachments);
         }
        
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/jpa/src/main/resources/META-INF/spring/mailbox-jpa.xml
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/resources/META-INF/spring/mailbox-jpa.xml b/mailbox/jpa/src/main/resources/META-INF/spring/mailbox-jpa.xml
index 7122318..21caf57 100644
--- a/mailbox/jpa/src/main/resources/META-INF/spring/mailbox-jpa.xml
+++ b/mailbox/jpa/src/main/resources/META-INF/spring/mailbox-jpa.xml
@@ -26,7 +26,7 @@
     <!-- 
       Mailbox JPA
      -->
-          
+
     <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
 
     <bean id="jpa-mailboxmanager" class="org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager" init-method="init">
@@ -36,6 +36,7 @@
         <constructor-arg index="3" type="boolean" value="false"/>
         <constructor-arg index="4" ref="aclResolver"/>
         <constructor-arg index="5" ref="groupMembershipResolver"/>
+        <constructor-arg index="6" ref="messageParser"/>
         <property name="quotaManager" ref="quotaManager"/>
         <property name="quotaRootResolver" ref="quotaRootResolver"/>
         <property name="quotaUpdater" ref="quotaUpdater"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
index be75d4b..aa7ab42 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
@@ -40,6 +40,7 @@ import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage;
 import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager;
 import org.apache.james.mailbox.jpa.user.model.JPASubscription;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
 import org.junit.After;
 import org.junit.Before;
@@ -105,8 +106,9 @@ public class JPAMailboxManagerTest extends AbstractMailboxManagerTest {
 
         MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
         GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
+        MessageParser messageParser = new MessageParser();
 
-        JPAMailboxManager mailboxManager = new OpenJPAMailboxManager(mf, null, aclResolver, groupMembershipResolver);
+        JPAMailboxManager mailboxManager = new OpenJPAMailboxManager(mf, null, aclResolver, groupMembershipResolver, messageParser);
         mailboxManager.init();
 
         setMailboxManager(mailboxManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java
index 96f3874..7eab4ea 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java
@@ -41,6 +41,7 @@ import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage;
 import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager;
 import org.apache.james.mailbox.jpa.user.model.JPASubscription;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
 import org.junit.After;
 import org.junit.Before;
@@ -81,8 +82,9 @@ public class JPAStressTest extends AbstractStressTest {
 
         MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
         GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
+        MessageParser messageParser = new MessageParser();
 
-        mailboxManager = new OpenJPAMailboxManager(mf, null, aclResolver, groupMembershipResolver);
+        mailboxManager = new OpenJPAMailboxManager(mf, null, aclResolver, groupMembershipResolver, messageParser);
         mailboxManager.init();
 
         // Set the lock timeout via SQL because of a bug in openJPA

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/maildir/src/main/resources/META-INF/spring/mailbox-maildir.xml
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/resources/META-INF/spring/mailbox-maildir.xml b/mailbox/maildir/src/main/resources/META-INF/spring/mailbox-maildir.xml
index ae81198..5e369f8 100644
--- a/mailbox/maildir/src/main/resources/META-INF/spring/mailbox-maildir.xml
+++ b/mailbox/maildir/src/main/resources/META-INF/spring/mailbox-maildir.xml
@@ -39,6 +39,7 @@
         <constructor-arg index="2" ref="maildir-locker"/>
         <constructor-arg index="3" ref="aclResolver"/>
         <constructor-arg index="4" ref="groupMembershipResolver"/>
+        <constructor-arg index="5" ref="messageParser"/>
 <!--         <property name="messageSearchIndex" ref="lazyIndex"/> -->
         <property name="quotaManager" ref="quotaManager"/>
         <property name="quotaRootResolver" ref="quotaRootResolver"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java
index fce99e4..8203a40 100644
--- a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java
+++ b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java
@@ -28,6 +28,7 @@ import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Rule;
@@ -59,8 +60,9 @@ public class MaildirMailboxManagerTest {
             
             MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
             GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
+            MessageParser messageParser = new MessageParser();
 
-            StoreMailboxManager manager = new StoreMailboxManager(mf, null, new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver);
+            StoreMailboxManager manager = new StoreMailboxManager(mf, null, new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver, messageParser);
             manager.init();
             setMailboxManager(manager);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirStressTest.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirStressTest.java b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirStressTest.java
index 64124f4..ea56353 100644
--- a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirStressTest.java
+++ b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirStressTest.java
@@ -31,6 +31,7 @@ import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.junit.After;
 import org.junit.Before;
 
@@ -47,8 +48,9 @@ public class MaildirStressTest extends AbstractStressTest {
         MaildirMailboxSessionMapperFactory mf = new MaildirMailboxSessionMapperFactory(store);
         MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
         GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
+        MessageParser messageParser = new MessageParser();
 
-        mailboxManager = new StoreMailboxManager(mf, null, new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver);
+        mailboxManager = new StoreMailboxManager(mf, null, new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver, messageParser);
         mailboxManager.init();
 
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
index c7b38b8..003eb46 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java
@@ -33,14 +33,15 @@ import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 
 import com.google.common.collect.Lists;
 
 public class InMemoryMailboxManager extends StoreMailboxManager {
 
     @Inject
-    public InMemoryMailboxManager(MailboxSessionMapperFactory mailboxSessionMapperFactory, Authenticator authenticator, MailboxPathLocker locker, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
-        super(mailboxSessionMapperFactory, authenticator, locker, aclResolver, groupMembershipResolver);
+    public InMemoryMailboxManager(MailboxSessionMapperFactory mailboxSessionMapperFactory, Authenticator authenticator, MailboxPathLocker locker, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, MessageParser messageParser) {
+        super(mailboxSessionMapperFactory, authenticator, locker, aclResolver, groupMembershipResolver, messageParser);
     }
 
     @Override
@@ -58,6 +59,7 @@ public class InMemoryMailboxManager extends StoreMailboxManager {
             getAclResolver(),
             getGroupMembershipResolver(),
             getQuotaManager(),
-            getQuotaRootResolver());
+            getQuotaRootResolver(),
+            getMessageParser());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java
index db46861..25f0adc 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxSessionMapperFactory.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.inmemory;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.SubscriptionException;
+import org.apache.james.mailbox.inmemory.mail.InMemoryAttachmentMapper;
 import org.apache.james.mailbox.inmemory.mail.InMemoryMailboxMapper;
 import org.apache.james.mailbox.inmemory.mail.InMemoryMessageMapper;
 import org.apache.james.mailbox.inmemory.mail.InMemoryModSeqProvider;
@@ -30,7 +31,6 @@ import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.mail.AttachmentMapper;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.NoopAttachmentMapper;
 import org.apache.james.mailbox.store.user.SubscriptionMapper;
 
 public class InMemoryMailboxSessionMapperFactory extends MailboxSessionMapperFactory {
@@ -44,7 +44,7 @@ public class InMemoryMailboxSessionMapperFactory extends MailboxSessionMapperFac
         mailboxMapper = new InMemoryMailboxMapper();
         messageMapper = new InMemoryMessageMapper(null, new InMemoryUidProvider(), new InMemoryModSeqProvider());
         subscriptionMapper = new InMemorySubscriptionMapper();
-        attachmentMapper = new NoopAttachmentMapper();
+        attachmentMapper = new InMemoryAttachmentMapper();
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageManager.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageManager.java
index bc30379..667948a 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageManager.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageManager.java
@@ -9,16 +9,17 @@ import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
-import org.apache.james.mailbox.store.mail.MessageMapperFactory;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.search.MessageSearchIndex;
 
 public class InMemoryMessageManager extends StoreMessageManager {
 
-    public InMemoryMessageManager(MessageMapperFactory mapperFactory, MessageSearchIndex index, MailboxEventDispatcher dispatcher, MailboxPathLocker locker, Mailbox mailbox, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver) throws MailboxException {
-        super(mapperFactory, index, dispatcher, locker, mailbox, aclResolver, groupMembershipResolver, quotaManager, quotaRootResolver);
+    public InMemoryMessageManager(MailboxSessionMapperFactory mapperFactory, MessageSearchIndex index, MailboxEventDispatcher dispatcher, MailboxPathLocker locker, Mailbox mailbox, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver, MessageParser messageParser) throws MailboxException {
+        super(mapperFactory, index, dispatcher, locker, mailbox, aclResolver, groupMembershipResolver, quotaManager, quotaRootResolver, messageParser);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java
new file mode 100644
index 0000000..2b0339d
--- /dev/null
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java
@@ -0,0 +1,58 @@
+/****************************************************************
+ * 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.james.mailbox.inmemory.mail;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.james.mailbox.exception.AttachmentNotFoundException;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.store.mail.AttachmentMapper;
+import org.apache.james.mailbox.store.mail.model.Attachment;
+import org.apache.james.mailbox.store.mail.model.AttachmentId;
+
+public class InMemoryAttachmentMapper implements AttachmentMapper {
+    
+    private static final int INITIAL_SIZE = 128;
+    private final Map<AttachmentId, Attachment> attachmentsById;
+
+    public InMemoryAttachmentMapper() {
+        attachmentsById = new ConcurrentHashMap<AttachmentId, Attachment>(INITIAL_SIZE);
+    }
+
+    @Override
+    public Attachment getAttachment(AttachmentId attachmentId) throws AttachmentNotFoundException {
+        return attachmentsById.get(attachmentId);
+    }
+
+    @Override
+    public void storeAttachment(Attachment attachment) throws MailboxException {
+        attachmentsById.put(attachment.getAttachmentId(), attachment);
+    }
+
+    @Override
+    public void endRequest() {
+        // Do nothing
+    }
+
+    @Override
+    public <T> T execute(Transaction<T> transaction) throws MailboxException {
+        return transaction.run();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/memory/src/main/resources/META-INF/spring/mailbox-memory.xml
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/resources/META-INF/spring/mailbox-memory.xml b/mailbox/memory/src/main/resources/META-INF/spring/mailbox-memory.xml
index 296b292..5da789a 100644
--- a/mailbox/memory/src/main/resources/META-INF/spring/mailbox-memory.xml
+++ b/mailbox/memory/src/main/resources/META-INF/spring/mailbox-memory.xml
@@ -35,6 +35,7 @@
         <constructor-arg index="2" ref="memory-locker"/>
         <constructor-arg index="3" ref="aclResolver"/>
         <constructor-arg index="4" ref="groupMembershipResolver"/>
+        <constructor-arg index="5" ref="messageParser"/>
 <!--         <property name="messageSearchIndex" ref="lazyIndex"/> -->
         <property name="quotaManager" ref="quotaManager"/>
         <property name="quotaRootResolver" ref="quotaRootResolver"/>

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
index 5aa4277..b876f44 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
@@ -36,6 +36,7 @@ import org.apache.james.mailbox.model.MailboxQuery;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.MockAuthenticator;
 import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -82,9 +83,10 @@ public class InMemoryMailboxManagerTest extends AbstractMailboxManagerTest {
 
         MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
         GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
+        MessageParser messageParser = new MessageParser();
 
         InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
-        StoreMailboxManager mailboxManager = new InMemoryMailboxManager(mailboxSessionMapperFactory, new MockAuthenticator(), new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver);
+        StoreMailboxManager mailboxManager = new InMemoryMailboxManager(mailboxSessionMapperFactory, new MockAuthenticator(), new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver, messageParser);
         mailboxManager.init();
         
         setMailboxManager(mailboxManager);

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java
new file mode 100644
index 0000000..db95b61
--- /dev/null
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxManagerAttachmentTest.java
@@ -0,0 +1,70 @@
+/****************************************************************
+ * 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.james.mailbox.inmemory.mail;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.InputStream;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.AbstractMailboxManagerAttachmentTest;
+import org.apache.james.mailbox.store.Authenticator;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.NoMailboxPathLocker;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
+
+public class InMemoryMailboxManagerAttachmentTest extends AbstractMailboxManagerAttachmentTest {
+
+    private InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory;
+    private InMemoryMailboxManager mailboxManager;
+    private InMemoryMailboxManager parseFailingMailboxManager;
+
+    public InMemoryMailboxManagerAttachmentTest() throws Exception {
+        mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
+        Authenticator noAuthenticator = null;
+        mailboxManager = new InMemoryMailboxManager(mailboxSessionMapperFactory, noAuthenticator, new NoMailboxPathLocker(), new UnionMailboxACLResolver(), null, new MessageParser());
+        mailboxManager.init();
+        MessageParser failingMessageParser = mock(MessageParser.class);
+        when(failingMessageParser.retrieveAttachments(any(InputStream.class)))
+            .thenThrow(new RuntimeException("Message parser set to fail"));
+        parseFailingMailboxManager = new InMemoryMailboxManager(mailboxSessionMapperFactory, noAuthenticator, new NoMailboxPathLocker(), new UnionMailboxACLResolver(), null, failingMessageParser);
+        parseFailingMailboxManager.init();
+    }
+
+    @Override
+    protected MailboxManager getMailboxManager() {
+        return mailboxManager;
+    }
+
+    @Override
+    protected MailboxSessionMapperFactory getMailboxSessionMapperFactory() {
+        return mailboxSessionMapperFactory;
+    }
+
+    @Override
+    protected MailboxManager getParseFailingMailboxManager() {
+        return parseFailingMailboxManager;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
index 89d4ce8..bd399a5 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryIntegrationResources.java
@@ -36,6 +36,7 @@ import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.MockAuthenticator;
 import org.apache.james.mailbox.store.NoMailboxPathLocker;
 import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.quota.CurrentQuotaCalculator;
 import org.apache.james.mailbox.store.quota.DefaultQuotaRootResolver;
 import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
@@ -56,7 +57,8 @@ public class InMemoryIntegrationResources implements IntegrationResources {
             mockAuthenticator,
             new NoMailboxPathLocker(),
             new UnionMailboxACLResolver(),
-            groupMembershipResolver);
+            groupMembershipResolver,
+            new MessageParser());
         manager.init();
         return manager;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml b/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
index 05af738..33e557c 100644
--- a/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
+++ b/mailbox/spring/src/main/resources/META-INF/spring/spring-mailbox.xml
@@ -52,6 +52,11 @@
       Group Membership Resolver
      -->
     <bean id="groupMembershipResolver" class="org.apache.james.mailbox.acl.SimpleGroupMembershipResolver"/>
+    <!--
+      Attachments
+     -->
+    <bean id="messageParser" class="org.apache.james.mailbox.store.mail.model.impl.MessageParser"/>
+
 
 
     <beans profile="cassandra">

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index 228344e..d701c46 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -58,6 +58,7 @@ import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.apache.james.mailbox.store.quota.DefaultQuotaRootResolver;
 import org.apache.james.mailbox.store.quota.NoQuotaManager;
@@ -114,18 +115,21 @@ public class StoreMailboxManager implements MailboxManager {
 
     private int fetchBatchSize = DEFAULT_FETCH_BATCH_SIZE;
 
+    private final MessageParser messageParser;
+
 
     @Inject
-    public StoreMailboxManager(MailboxSessionMapperFactory mailboxSessionMapperFactory, Authenticator authenticator, MailboxPathLocker locker, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
+    public StoreMailboxManager(MailboxSessionMapperFactory mailboxSessionMapperFactory, Authenticator authenticator, MailboxPathLocker locker, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, MessageParser messageParser) {
         this.authenticator = authenticator;
         this.locker = locker;
         this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
         this.aclResolver = aclResolver;
         this.groupMembershipResolver = groupMembershipResolver;
+        this.messageParser = messageParser;
     }
 
-    public StoreMailboxManager(MailboxSessionMapperFactory mailboxSessionMapperFactory, Authenticator authenticator, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver) {
-        this(mailboxSessionMapperFactory, authenticator, new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver);
+    public StoreMailboxManager(MailboxSessionMapperFactory mailboxSessionMapperFactory, Authenticator authenticator, MailboxACLResolver aclResolver, GroupMembershipResolver groupMembershipResolver, MessageParser messageParser) {
+        this(mailboxSessionMapperFactory, authenticator, new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver, messageParser);
     }
 
     public void setMailboxSessionIdGenerator(MailboxSessionIdGenerator idGenerator) {
@@ -259,6 +263,10 @@ public class StoreMailboxManager implements MailboxManager {
         return groupMembershipResolver;
     }
 
+    public MessageParser getMessageParser() {
+        return messageParser;
+    }
+
     /**
      * Set the {@link DelegatingMailboxListener} to use with this {@link MailboxManager} instance. If none is set here a {@link DefaultDelegatingMailboxListener} instance will
      * be created lazy
@@ -357,7 +365,7 @@ public class StoreMailboxManager implements MailboxManager {
      * @return storeMailbox
      */
     protected StoreMessageManager createMessageManager(Mailbox mailbox, MailboxSession session) throws MailboxException {
-        return new StoreMessageManager(getMapperFactory(), getMessageSearchIndex(), getEventDispatcher(), getLocker(), mailbox, getAclResolver(), getGroupMembershipResolver(), getQuotaManager(), getQuotaRootResolver());
+        return new StoreMessageManager(getMapperFactory(), getMessageSearchIndex(), getEventDispatcher(), getLocker(), mailbox, getAclResolver(), getGroupMembershipResolver(), getQuotaManager(), getQuotaRootResolver(), getMessageParser());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/bbcba2c8/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index 6a8d300..02f480f 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -61,11 +61,14 @@ import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
+import org.apache.james.mailbox.store.mail.AttachmentMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
-import org.apache.james.mailbox.store.mail.MessageMapperFactory;
+import org.apache.james.mailbox.store.mail.model.Attachment;
+import org.apache.james.mailbox.store.mail.model.AttachmentId;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 import org.apache.james.mailbox.store.quota.QuotaChecker;
@@ -81,6 +84,10 @@ import org.apache.james.mime4j.stream.EntityState;
 import org.apache.james.mime4j.stream.MimeConfig;
 import org.apache.james.mime4j.stream.MimeTokenStream;
 import org.apache.james.mime4j.stream.RecursionMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableList;
 
 /**
  * Base class for {@link org.apache.james.mailbox.MessageManager}
@@ -111,11 +118,14 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
         MINIMAL_PERMANET_FLAGS.add(Flags.Flag.SEEN);
     }
 
+    private static final Logger LOG = LoggerFactory.getLogger(StoreMessageManager.class);
+
+
     private final Mailbox mailbox;
 
     private final MailboxEventDispatcher dispatcher;
 
-    private final MessageMapperFactory mapperFactory;
+    private final MailboxSessionMapperFactory mapperFactory;
 
     private final MessageSearchIndex index;
 
@@ -129,10 +139,12 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
 
     private final MailboxPathLocker locker;
 
+    private final MessageParser messageParser;
+
     private int fetchBatchSize;
 
-    public StoreMessageManager(MessageMapperFactory mapperFactory, MessageSearchIndex index, MailboxEventDispatcher dispatcher, MailboxPathLocker locker, Mailbox mailbox, MailboxACLResolver aclResolver,
-            final GroupMembershipResolver groupMembershipResolver, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver) throws MailboxException {
+    public StoreMessageManager(MailboxSessionMapperFactory mapperFactory, MessageSearchIndex index, MailboxEventDispatcher dispatcher, MailboxPathLocker locker, Mailbox mailbox, MailboxACLResolver aclResolver,
+            final GroupMembershipResolver groupMembershipResolver, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver, MessageParser messageParser) throws MailboxException {
         this.mailbox = mailbox;
         this.dispatcher = dispatcher;
         this.mapperFactory = mapperFactory;
@@ -142,6 +154,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
         this.groupMembershipResolver = groupMembershipResolver;
         this.quotaManager = quotaManager;
         this.quotaRootResolver = quotaRootResolver;
+        this.messageParser = messageParser;
     }
 
     public void setFetchBatchSize(int fetchBatchSize) {
@@ -370,7 +383,8 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
             contentIn = new SharedFileInputStream(file);
             final int size = (int) file.length();
 
-            final MailboxMessage message = createMessage(internalDate, size, bodyStartOctet, contentIn, flags, propertyBuilder);
+            final List<Attachment> attachments = extractAttachments(contentIn);
+            final MailboxMessage message = createMessage(internalDate, size, bodyStartOctet, contentIn, flags, propertyBuilder, attachments);
 
             new QuotaChecker(quotaManager, quotaRootResolver, mailbox).tryAddition(1, size);
 
@@ -378,7 +392,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
 
                 @Override
                 public Long execute() throws MailboxException {
-                    MessageMetaData data = appendMessageToStore(message, mailboxSession);
+                    MessageMetaData data = appendMessageToStore(message, attachments, mailboxSession);
 
                     SortedMap<Long, MessageMetaData> uids = new TreeMap<Long, MessageMetaData>();
                     uids.put(data.getUid(), data);
@@ -409,6 +423,15 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
 
     }
 
+    private List<Attachment> extractAttachments(SharedFileInputStream contentIn) {
+        try {
+            return messageParser.retrieveAttachments(contentIn);
+        } catch (Exception e) {
+            LOG.warn("Error while parsing mail's attachments: " + e.getMessage(), e);
+            return ImmutableList.of();
+        }
+    }
+
     /**
      * Create a new {@link MailboxMessage} for the given data
      * 
@@ -417,11 +440,16 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
      * @param bodyStartOctet
      * @param content
      * @param flags
+     * @param attachments 
      * @return membership
      * @throws MailboxException
      */
-    protected MailboxMessage createMessage(Date internalDate, int size, int bodyStartOctet, SharedInputStream content, Flags flags, PropertyBuilder propertyBuilder) throws MailboxException {
-        return new SimpleMailboxMessage(internalDate, size, bodyStartOctet, content, flags, propertyBuilder, getMailboxEntity().getMailboxId());
+    protected MailboxMessage createMessage(Date internalDate, int size, int bodyStartOctet, SharedInputStream content, Flags flags, PropertyBuilder propertyBuilder, List<Attachment> attachments) throws MailboxException {
+        ImmutableList.Builder<AttachmentId> attachmentsIds = ImmutableList.builder();
+        for (Attachment attachment: attachments) {
+            attachmentsIds.add(attachment.getAttachmentId());
+        }
+        return new SimpleMailboxMessage(internalDate, size, bodyStartOctet, content, flags, propertyBuilder, getMailboxEntity().getMailboxId(), attachmentsIds.build());
     }
 
     /**
@@ -607,12 +635,16 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
         }, true);
     }
 
-    protected MessageMetaData appendMessageToStore(final MailboxMessage message, MailboxSession session) throws MailboxException {
-        final MessageMapper mapper = mapperFactory.getMessageMapper(session);
+    protected MessageMetaData appendMessageToStore(final MailboxMessage message, final List<Attachment> attachments, MailboxSession session) throws MailboxException {
+        final MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
+        final AttachmentMapper attachmentMapper = mapperFactory.getAttachmentMapper(session);
         return mapperFactory.getMessageMapper(session).execute(new Mapper.Transaction<MessageMetaData>() {
 
             public MessageMetaData run() throws MailboxException {
-                return mapper.add(getMailboxEntity(), message);
+                for (Attachment attachment: attachments) {
+                    attachmentMapper.storeAttachment(attachment);
+                }
+                return messageMapper.add(getMailboxEntity(), message);
             }
 
         });


---------------------------------------------------------------------
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