james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [1/2] james-project git commit: MAILBOX-268 Store in Cassandra attachments ids related to a message
Date Mon, 30 May 2016 05:04:23 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 13f3028b9 -> f53d0eb93


MAILBOX-268 Store in Cassandra attachments ids related to a message


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

Branch: refs/heads/master
Commit: f53d0eb93045212d778b211384dde48ef1cefc99
Parents: 02aaedb
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Wed May 25 11:42:46 2016 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Fri May 27 15:30:30 2016 +0200

----------------------------------------------------------------------
 .../cassandra/mail/CassandraMessageMapper.java  | 24 +++++++-
 .../modules/CassandraMessageModule.java         |  2 +
 .../cassandra/table/CassandraMessageTable.java  |  5 +-
 .../mailbox/hbase/mail/HBaseMailboxMessage.java |  7 +++
 .../jcr/mail/model/JCRMailboxMessage.java       |  7 +++
 .../openjpa/AbstractJPAMailboxMessage.java      |  7 +++
 .../maildir/mail/model/MaildirMessage.java      |  7 +++
 .../mail/InMemoryMessageMapperTest.java         | 11 ++++
 .../mail/model/DelegatingMailboxMessage.java    |  5 ++
 .../james/mailbox/store/mail/model/Message.java |  8 +++
 .../mail/model/impl/SimpleMailboxMessage.java   | 36 +++++++----
 .../store/mail/model/impl/SimpleMessage.java    | 27 ++++++--
 .../mailbox/store/SimpleMailboxMembership.java  |  7 +++
 .../mail/model/AbstractMessageMapperTest.java   | 65 ++++++++++++++++++++
 .../mailbox/store/mail/model/MessageAssert.java |  5 ++
 15 files changed, 201 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index 2e18dec..c2420cd 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -28,6 +28,7 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.lte;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.set;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.update;
+import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.ATTACHMENTS_IDS;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.BODY;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.BODY_CONTENT;
 import static org.apache.james.mailbox.cassandra.table.CassandraMessageTable.BODY_OCTECTS;
@@ -89,6 +90,7 @@ import org.apache.james.mailbox.store.SimpleMessageMetaData;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.ModSeqProvider;
 import org.apache.james.mailbox.store.mail.UidProvider;
+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.PropertyBuilder;
@@ -105,6 +107,7 @@ import com.datastax.driver.core.querybuilder.QueryBuilder;
 import com.datastax.driver.core.querybuilder.Select;
 import com.datastax.driver.core.querybuilder.Select.Where;
 import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableList;
 import com.google.common.io.ByteStreams;
 import com.google.common.primitives.Bytes;
 
@@ -300,7 +303,8 @@ public class CassandraMessageMapper implements MessageMapper {
                 buildContent(row, fetchType),
                 getFlags(row),
                 getPropertyBuilder(row),
-                CassandraId.of(row.getUUID(MAILBOX_ID)));
+                CassandraId.of(row.getUUID(MAILBOX_ID)),
+                getAttachmentsIds(row, fetchType));
         message.setUid(row.getLong(IMAP_UID));
         message.setModSeq(row.getLong(MOD_SEQ));
         return message;
@@ -328,6 +332,19 @@ public class CassandraMessageMapper implements MessageMapper {
         return property;
     }
 
+    private List<AttachmentId> getAttachmentsIds(Row row, FetchType fetchType) {
+        switch (fetchType) {
+        case Full:
+        case Body:
+            return row.getList(ATTACHMENTS_IDS, String.class)
+                    .stream()
+                    .map(AttachmentId::from)
+                    .collect(org.apache.james.util.streams.Collectors.toImmutableList());
+        default:
+            return ImmutableList.of();
+        }
+    }
+
     private MessageMetaData save(Mailbox mailbox, MailboxMessage message) throws MailboxException
{
         try {
             CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
@@ -356,7 +373,10 @@ public class CassandraMessageMapper implements MessageMapper {
                         .setString(Properties.NAME, x.getLocalName())
                         .setString(Properties.VALUE, x.getValue()))
                     .collect(Collectors.toList()))
-                .value(TEXTUAL_LINE_COUNT, message.getTextualLineCount()));
+                .value(TEXTUAL_LINE_COUNT, message.getTextualLineCount())
+                .value(ATTACHMENTS_IDS, message.getAttachmentsIds().stream()
+                    .map(AttachmentId::getId)
+                    .collect(Collectors.toList())));
 
             return new SimpleMessageMetaData(message);
         } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraMessageModule.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraMessageModule.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraMessageModule.java
index d401782..3565213 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraMessageModule.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraMessageModule.java
@@ -34,6 +34,7 @@ import static com.datastax.driver.core.DataType.bigint;
 import static com.datastax.driver.core.DataType.blob;
 import static com.datastax.driver.core.DataType.cboolean;
 import static com.datastax.driver.core.DataType.cint;
+import static com.datastax.driver.core.DataType.frozenList;
 import static com.datastax.driver.core.DataType.set;
 import static com.datastax.driver.core.DataType.text;
 import static com.datastax.driver.core.DataType.timestamp;
@@ -68,6 +69,7 @@ public class CassandraMessageModule implements CassandraModule {
                     .addColumn(CassandraMessageTable.Flag.SEEN, cboolean())
                     .addColumn(CassandraMessageTable.Flag.USER, cboolean())
                     .addColumn(CassandraMessageTable.Flag.USER_FLAGS, set(text()))
+                    .addColumn(CassandraMessageTable.ATTACHMENTS_IDS, frozenList(text()))
                     .addUDTListColumn(CassandraMessageTable.PROPERTIES, SchemaBuilder.frozen(CassandraMessageTable.PROPERTIES))));
         index = Arrays.asList(
             new CassandraIndex(

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
index 446ca50..e2e19af 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraMessageTable.java
@@ -37,11 +37,12 @@ public interface CassandraMessageTable {
     String BODY_CONTENT = "bodyContent";
     String HEADER_CONTENT = "headerContent";
     String PROPERTIES = "properties";
+    String ATTACHMENTS_IDS = "attachmentsIds";
 
-    String[] FIELDS = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET, FULL_CONTENT_OCTETS,
BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED, Flag.RECENT, Flag.SEEN,
Flag.USER, Flag.USER_FLAGS, BODY_CONTENT, HEADER_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES };
+    String[] FIELDS = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET, FULL_CONTENT_OCTETS,
BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED, Flag.RECENT, Flag.SEEN,
Flag.USER, Flag.USER_FLAGS, BODY_CONTENT, HEADER_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES,
ATTACHMENTS_IDS };
     String[] METADATA = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET,
FULL_CONTENT_OCTETS, BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED,
Flag.RECENT, Flag.SEEN, Flag.USER, Flag.USER_FLAGS, TEXTUAL_LINE_COUNT, PROPERTIES };
     String[] HEADERS = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET,
FULL_CONTENT_OCTETS, BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED,
Flag.RECENT, Flag.SEEN, Flag.USER, Flag.USER_FLAGS, HEADER_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES
};
-    String[] BODY = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET, FULL_CONTENT_OCTETS,
BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED, Flag.RECENT, Flag.SEEN,
Flag.USER, Flag.USER_FLAGS, BODY_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES };
+    String[] BODY = { MAILBOX_ID, IMAP_UID, INTERNAL_DATE, MOD_SEQ, BODY_START_OCTET, FULL_CONTENT_OCTETS,
BODY_OCTECTS, Flag.ANSWERED, Flag.DELETED, Flag.DRAFT, Flag.FLAGGED, Flag.RECENT, Flag.SEEN,
Flag.USER, Flag.USER_FLAGS, BODY_CONTENT, TEXTUAL_LINE_COUNT, PROPERTIES, ATTACHMENTS_IDS
};
 
     interface Flag {
         String ANSWERED = "flagAnswered";

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
index e56df67..ae8c54b 100644
--- a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
+++ b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
@@ -33,10 +33,12 @@ import java.util.List;
 
 import javax.mail.Flags;
 
+import org.apache.commons.lang.NotImplementedException;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.hbase.HBaseId;
 import org.apache.james.mailbox.hbase.io.ChunkInputStream;
+import org.apache.james.mailbox.store.mail.model.AttachmentId;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
@@ -351,4 +353,9 @@ public class HBaseMailboxMessage implements MailboxMessage {
     public int compareTo(MailboxMessage other) {
         return MESSAGE_UID_COMPARATOR.compare(this, other);
     }
+
+    @Override
+    public List<AttachmentId> getAttachmentsIds() {
+        throw new NotImplementedException("Attachments Ids not implemented");
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
index 8bbf28d..62d17dd 100644
--- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
+++ b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
@@ -35,12 +35,14 @@ import javax.mail.util.SharedByteArrayInputStream;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.input.BoundedInputStream;
+import org.apache.commons.lang.NotImplementedException;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.JcrUtils;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.jcr.JCRId;
 import org.apache.james.mailbox.jcr.JCRImapConstants;
 import org.apache.james.mailbox.jcr.Persistent;
+import org.apache.james.mailbox.store.mail.model.AttachmentId;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
@@ -676,4 +678,9 @@ public class JCRMailboxMessage implements MailboxMessage, JCRImapConstants,
Pers
     public int compareTo(MailboxMessage other) {
         return MESSAGE_UID_COMPARATOR.compare(this, other);
     }
+
+    @Override
+    public List<AttachmentId> getAttachmentsIds() {
+        throw new NotImplementedException("Attachments Ids not implemented");
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
index 02c0425..3488127 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
@@ -40,11 +40,13 @@ import javax.persistence.NamedQuery;
 import javax.persistence.OneToMany;
 import javax.persistence.OrderBy;
 
+import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.jpa.JPAId;
 import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
 import org.apache.james.mailbox.jpa.mail.model.JPAProperty;
 import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag;
+import org.apache.james.mailbox.store.mail.model.AttachmentId;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.apache.james.mailbox.store.mail.model.DelegatingMailboxMessage;
 import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
@@ -574,4 +576,9 @@ public abstract class AbstractJPAMailboxMessage implements MailboxMessage
{
     }
     
 
+    @Override
+    public List<AttachmentId> getAttachmentsIds() {
+        throw new NotImplementedException("Attachments Ids not implemented");
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
index 427a7bb..be2ecaa 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
@@ -19,7 +19,9 @@
 package org.apache.james.mailbox.maildir.mail.model;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.mailbox.maildir.MaildirMessageName;
+import org.apache.james.mailbox.store.mail.model.AttachmentId;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.mail.model.MessageId;
 import org.apache.james.mailbox.store.mail.model.Property;
@@ -274,4 +276,9 @@ public class MaildirMessage implements Message {
         return new LimitingFileInputStream(messageName.getFile(), limit);
     }
 
+    @Override
+    public List<AttachmentId> getAttachmentsIds() {
+        throw new NotImplementedException("Attachments Ids not implemented");
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapperTest.java
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapperTest.java
index 8ab4df2..ad61d5e 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapperTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapperTest.java
@@ -20,10 +20,21 @@
 package org.apache.james.mailbox.inmemory.mail;
 
 import org.apache.james.mailbox.store.mail.model.AbstractMessageMapperTest;
+import org.junit.Ignore;
 
 public class InMemoryMessageMapperTest extends AbstractMessageMapperTest {
 
     public InMemoryMessageMapperTest() {
         super(new InMemoryMapperProvider());
     }
+
+    @Ignore("Partial fetch not supported by InMemory backend")
+    @Override
+    public void messagesRetrievedUsingFetchTypeHeadersShouldHaveAttachmentsIdsEmptyWhenOneAttachment()
{
+    }
+
+    @Ignore("Partial fetch not supported by InMemory backend")
+    @Override
+    public void messagesRetrievedUsingFetchTypeMetadataShouldHaveAttachmentsIdsEmptyWhenOneAttachment()
{
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
index 0ede32d..c8bc67e 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
@@ -115,4 +115,9 @@ public abstract class DelegatingMailboxMessage implements MailboxMessage
{
     public Message getMessage() {
         return message;
     }
+
+    @Override
+    public List<AttachmentId> getAttachmentsIds() {
+        return message.getAttachmentsIds();
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
index 1b14d71..4d3999b 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
@@ -103,4 +103,12 @@ public interface Message {
      * @return unmodifiable list of meta-data, not null
      */
     List<Property> getProperties();
+    
+    /**
+     * Return the list of ids of parsed attachments
+     * 
+     * @return a read only list of attachments ids
+     */
+    List<AttachmentId> getAttachmentsIds();
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
index 1455c79..0122cb1 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.store.mail.model.impl;
 
 import java.io.IOException;
 import java.util.Date;
+import java.util.List;
 
 import javax.mail.Flags;
 import javax.mail.internet.SharedInputStream;
@@ -28,11 +29,13 @@ import javax.mail.util.SharedByteArrayInputStream;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.store.mail.model.AttachmentId;
 import org.apache.james.mailbox.store.mail.model.DelegatingMailboxMessage;
 import org.apache.james.mailbox.store.mail.model.MailboxId;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 
 import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableList;
 import com.google.common.primitives.Ints;
 
 public class SimpleMailboxMessage extends DelegatingMailboxMessage {
@@ -45,7 +48,7 @@ public class SimpleMailboxMessage extends DelegatingMailboxMessage {
         int bodyStartOctet = Ints.checkedCast(original.getFullContentOctets() - original.getBodyOctets());
         PropertyBuilder pBuilder = new PropertyBuilder(original.getProperties());
         pBuilder.setTextualLineCount(original.getTextualLineCount());
-        return new SimpleMailboxMessage(internalDate, size, bodyStartOctet, content, flags,
pBuilder, mailboxId);
+        return new SimpleMailboxMessage(internalDate, size, bodyStartOctet, content, flags,
pBuilder, mailboxId, original.getAttachmentsIds());
     }
 
     private static SharedByteArrayInputStream copyFullContent(MailboxMessage original) throws
MailboxException {
@@ -68,19 +71,28 @@ public class SimpleMailboxMessage extends DelegatingMailboxMessage {
     private long modSeq;
 
     public SimpleMailboxMessage(Date internalDate, long size, int bodyStartOctet,
+            SharedInputStream content, Flags flags,
+            PropertyBuilder propertyBuilder, MailboxId mailboxId, List<AttachmentId>
attachmentsIds) {
+        super(new SimpleMessage(
+                content, size, internalDate, propertyBuilder.getSubType(),
+                propertyBuilder.getMediaType(),
+                bodyStartOctet,
+                propertyBuilder.getTextualLineCount(),
+                propertyBuilder.toProperties(),
+                attachmentsIds
+                ));
+
+            setFlags(flags);
+            this.mailboxId = mailboxId;
+            this.userFlags = flags.getUserFlags();
+    }
+
+    public SimpleMailboxMessage(Date internalDate, long size, int bodyStartOctet,
                                 SharedInputStream content, Flags flags,
                                 PropertyBuilder propertyBuilder, MailboxId mailboxId) {
-        super(new SimpleMessage(
-            content, size, internalDate, propertyBuilder.getSubType(),
-            propertyBuilder.getMediaType(),
-            bodyStartOctet,
-            propertyBuilder.getTextualLineCount(),
-            propertyBuilder.toProperties()
-            ));
-
-        setFlags(flags);
-        this.mailboxId = mailboxId;
-        this.userFlags = flags.getUserFlags();
+        this(internalDate, size, bodyStartOctet,
+                content, flags,
+                propertyBuilder, mailboxId, ImmutableList.<AttachmentId>of());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java
index 32349b3..d77571e 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java
@@ -18,16 +18,20 @@
  ****************************************************************/
 package org.apache.james.mailbox.store.mail.model.impl;
 
-import org.apache.james.mailbox.store.mail.model.Message;
-import org.apache.james.mailbox.store.mail.model.MessageId;
-import org.apache.james.mailbox.store.mail.model.Property;
-
-import javax.mail.internet.SharedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Date;
 import java.util.List;
 
+import javax.mail.internet.SharedInputStream;
+
+import org.apache.james.mailbox.store.mail.model.AttachmentId;
+import org.apache.james.mailbox.store.mail.model.Message;
+import org.apache.james.mailbox.store.mail.model.MessageId;
+import org.apache.james.mailbox.store.mail.model.Property;
+
+import com.google.common.collect.ImmutableList;
+
 public class SimpleMessage implements Message {
 
     private final String subType;
@@ -38,8 +42,9 @@ public class SimpleMessage implements Message {
     private final long size;
     private final Long textualLineCount;
     private final List<Property> properties;
+    private final List<AttachmentId> attachmentsIds;
 
-    public SimpleMessage(SharedInputStream content, long size, Date internalDate, String
subType, String mediaType, int bodyStartOctet, Long textualLineCount, List<Property>
properties) {
+    public SimpleMessage(SharedInputStream content, long size, Date internalDate, String
subType, String mediaType, int bodyStartOctet, Long textualLineCount, List<Property>
properties, List<AttachmentId> attachmentsIds) {
         this.subType = subType;
         this.mediaType = mediaType;
         this.content = content;
@@ -48,6 +53,11 @@ public class SimpleMessage implements Message {
         this.size = size;
         this.textualLineCount = textualLineCount;
         this.properties = properties;
+        this.attachmentsIds = attachmentsIds;
+    }
+
+    public SimpleMessage(SharedInputStream content, long size, Date internalDate, String
subType, String mediaType, int bodyStartOctet, Long textualLineCount, List<Property>
properties) {
+        this(content, size, internalDate, subType, mediaType, bodyStartOctet, textualLineCount,
properties, ImmutableList.<AttachmentId>of());
     }
 
     @Override
@@ -108,4 +118,9 @@ public class SimpleMessage implements Message {
     public List<Property> getProperties() {
         return properties;
     }
+
+    @Override
+    public List<AttachmentId> getAttachmentsIds() {
+        return attachmentsIds;
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
index a1afb98..4d1eb4f 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
@@ -35,6 +35,8 @@ import java.util.Map.Entry;
 
 import javax.mail.Flags;
 
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.mailbox.store.mail.model.AttachmentId;
 import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.Property;
@@ -270,5 +272,10 @@ public class SimpleMailboxMembership implements MailboxMessage {
     public DefaultMessageId getMessageId() {
         return new DefaultMessageId(getMailboxId(), getUid());
     }
+
+    @Override
+    public List<AttachmentId> getAttachmentsIds() {
+        throw new NotImplementedException("Attachments Ids not implemented");
+    }
     
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java
index 41d04d0..7641a52 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import java.io.IOException;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import javax.mail.Flags;
@@ -46,6 +47,8 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableList;
+
 public abstract class AbstractMessageMapperTest {
 
     private final static char DELIMITER = ':';
@@ -59,6 +62,7 @@ public abstract class AbstractMessageMapperTest {
 
     private SimpleMailbox benwaInboxMailbox;
     private SimpleMailbox benwaWorkMailbox;
+    private SimpleMailbox attachmentsMailbox;
     
     private SimpleMailboxMessage message1;
     private SimpleMailboxMessage message2;
@@ -66,6 +70,8 @@ public abstract class AbstractMessageMapperTest {
     private SimpleMailboxMessage message4;
     private SimpleMailboxMessage message5;
     private SimpleMailboxMessage message6;
+    private SimpleMailboxMessage message7With1Attachment;
+    private SimpleMailboxMessage message8With2Attachments;
 
     public AbstractMessageMapperTest(MapperProvider mapperProvider) {
         this.mapperProvider = mapperProvider;
@@ -77,12 +83,15 @@ public abstract class AbstractMessageMapperTest {
         messageMapper = mapperProvider.createMessageMapper();
         benwaInboxMailbox = createMailbox(new MailboxPath("#private", "benwa", "INBOX"));
         benwaWorkMailbox = createMailbox( new MailboxPath("#private", "benwa", "INBOX"+DELIMITER+"work"));
+        attachmentsMailbox = createMailbox( new MailboxPath("#private", "benwa", "Attachments"));
         message1 = createMessage(benwaInboxMailbox, "Subject: Test1 \n\nBody1\n.\n", BODY_START,
new PropertyBuilder());
         message2 = createMessage(benwaInboxMailbox, "Subject: Test2 \n\nBody2\n.\n", BODY_START,
new PropertyBuilder());
         message3 = createMessage(benwaInboxMailbox, "Subject: Test3 \n\nBody3\n.\n", BODY_START,
new PropertyBuilder());
         message4 = createMessage(benwaInboxMailbox, "Subject: Test4 \n\nBody4\n.\n", BODY_START,
new PropertyBuilder());
         message5 = createMessage(benwaInboxMailbox, "Subject: Test5 \n\nBody5\n.\n", BODY_START,
new PropertyBuilder());
         message6 = createMessage(benwaWorkMailbox, "Subject: Test6 \n\nBody6\n.\n", BODY_START,
new PropertyBuilder());
+        message7With1Attachment = createMessage(attachmentsMailbox, "Subject: Test7 \n\nBody7\n.\n",
BODY_START, new PropertyBuilder(), ImmutableList.of(AttachmentId.from("123")));
+        message8With2Attachments = createMessage(attachmentsMailbox, "Subject: Test8 \n\nBody8\n.\n",
BODY_START, new PropertyBuilder(), ImmutableList.of(AttachmentId.from("123"), AttachmentId.from("456")));
     }
 
     @After
@@ -249,6 +258,54 @@ public abstract class AbstractMessageMapperTest {
     }
 
     @Test
+    public void messagesRetrievedUsingFetchTypeFullShouldHaveAttachmentsIdsEmptyWhenNoAttachment()
throws MailboxException, IOException{
+        saveMessages();
+        MessageMapper.FetchType fetchType = MessageMapper.FetchType.Full;
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(benwaInboxMailbox,
MessageRange.one(message1.getUid()), fetchType, LIMIT);
+        assertThat(retrievedMessageIterator.next().getAttachmentsIds()).isEmpty();
+    }
+
+    @Test
+    public void messagesRetrievedUsingFetchTypeFullShouldHaveAttachmentsIdsLoadedWhenOneAttachment()
throws MailboxException, IOException{
+        saveMessages();
+        MessageMapper.FetchType fetchType = MessageMapper.FetchType.Full;
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(attachmentsMailbox,
MessageRange.one(message7With1Attachment.getUid()), fetchType, LIMIT);
+        assertThat(retrievedMessageIterator.next().getAttachmentsIds()).isEqualTo(message7With1Attachment.getAttachmentsIds());
+    }
+
+    @Test
+    public void messagesRetrievedUsingFetchTypeFullShouldHaveAttachmentsIdsLoadedWhenTwoAttachments()
throws MailboxException, IOException{
+        saveMessages();
+        MessageMapper.FetchType fetchType = MessageMapper.FetchType.Full;
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(attachmentsMailbox,
MessageRange.one(message8With2Attachments.getUid()), fetchType, LIMIT);
+        assertThat(retrievedMessageIterator.next().getAttachmentsIds()).isEqualTo(message8With2Attachments.getAttachmentsIds());
+    }
+
+    @Test
+    public void messagesRetrievedUsingFetchTypeBodyShouldHaveAttachmentsIdsLoadedWhenOneAttachment()
throws MailboxException, IOException{
+        saveMessages();
+        MessageMapper.FetchType fetchType = MessageMapper.FetchType.Body;
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(attachmentsMailbox,
MessageRange.one(message7With1Attachment.getUid()), fetchType, LIMIT);
+        assertThat(retrievedMessageIterator.next().getAttachmentsIds()).isEqualTo(message7With1Attachment.getAttachmentsIds());
+    }
+
+    @Test
+    public void messagesRetrievedUsingFetchTypeHeadersShouldHaveAttachmentsIdsEmptyWhenOneAttachment()
throws MailboxException, IOException{
+        saveMessages();
+        MessageMapper.FetchType fetchType = MessageMapper.FetchType.Headers;
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(attachmentsMailbox,
MessageRange.one(message7With1Attachment.getUid()), fetchType, LIMIT);
+        assertThat(retrievedMessageIterator.next().getAttachmentsIds()).isEmpty();
+    }
+
+    @Test
+    public void messagesRetrievedUsingFetchTypeMetadataShouldHaveAttachmentsIdsEmptyWhenOneAttachment()
throws MailboxException, IOException{
+        saveMessages();
+        MessageMapper.FetchType fetchType = MessageMapper.FetchType.Metadata;
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(attachmentsMailbox,
MessageRange.one(message7With1Attachment.getUid()), fetchType, LIMIT);
+        assertThat(retrievedMessageIterator.next().getAttachmentsIds()).isEmpty();
+    }
+
+    @Test
     public void retrievingMessagesWithALimitShouldLimitTheNumberOfMessages() throws MailboxException
{
         int limit = 2;
         saveMessages();
@@ -663,12 +720,20 @@ public abstract class AbstractMessageMapperTest {
         message5.setModSeq(messageMapper.getHighestModSeq(benwaInboxMailbox));
         messageMapper.add(benwaWorkMailbox, message6);
         message6.setModSeq(messageMapper.getHighestModSeq(benwaWorkMailbox));
+        messageMapper.add(attachmentsMailbox, message7With1Attachment);
+        message7With1Attachment.setModSeq(messageMapper.getHighestModSeq(attachmentsMailbox));
+        messageMapper.add(attachmentsMailbox, message8With2Attachments);
+        message8With2Attachments.setModSeq(messageMapper.getHighestModSeq(attachmentsMailbox));
     }
 
     private MailboxMessage retrieveMessageFromStorage(MailboxMessage message) throws MailboxException
{
         return messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(message.getUid()),
MessageMapper.FetchType.Metadata, LIMIT).next();
     }
     
+    private SimpleMailboxMessage createMessage(Mailbox mailbox, String content, int bodyStart,
PropertyBuilder propertyBuilder, List<AttachmentId> attachmentsIds) {
+        return new SimpleMailboxMessage(new Date(), content.length(), bodyStart, new SharedByteArrayInputStream(content.getBytes()),
new Flags(), propertyBuilder, mailbox.getMailboxId(), attachmentsIds);
+    }
+    
     private SimpleMailboxMessage createMessage(Mailbox mailbox, String content, int bodyStart,
PropertyBuilder propertyBuilder) {
         return new SimpleMailboxMessage(new Date(), content.length(), bodyStart, new SharedByteArrayInputStream(content.getBytes()),
new Flags(), propertyBuilder, mailbox.getMailboxId());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f53d0eb9/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAssert.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAssert.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAssert.java
index a73904e..ab7a8bb 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAssert.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAssert.java
@@ -74,6 +74,11 @@ public class MessageAssert extends AbstractAssert<MessageAssert, MailboxMessage>
                 failWithMessage("Expected Body content to be <%s> but was <%s>",
IOUtils.toString(expected.getBodyContent()), IOUtils.toString(actual.getBodyContent()));
             }
         }
+        if (usedFetchType == MessageMapper.FetchType.Full || usedFetchType == MessageMapper.FetchType.Body)
{
+            if (!Objects.equal(actual.getAttachmentsIds(), expected.getAttachmentsIds()))
{
+                failWithMessage("Expected attachments ids to be <%s> but was <%s>",
expected.getAttachmentsIds(), actual.getAttachmentsIds());
+            }
+        }
         return this;
     }
 


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