james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [5/5] james-project git commit: JAMES-1791 Move attachment name from Attachment to MessageAttachment
Date Fri, 08 Jul 2016 10:59:19 GMT
JAMES-1791 Move attachment name from Attachment to MessageAttachment


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

Branch: refs/heads/master
Commit: 1c294ddc02e008f57de3451ac72fb6e404847c46
Parents: 2d1fe09
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Thu Jul 7 11:12:41 2016 +0200
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Fri Jul 8 12:02:06 2016 +0200

----------------------------------------------------------------------
 .../mail/CassandraAttachmentMapper.java         |  4 ---
 .../cassandra/mail/CassandraMessageMapper.java  | 10 +++++---
 .../modules/CassandraAttachmentModule.java      |  1 -
 .../modules/CassandraMessageModule.java         |  1 +
 .../table/CassandraAttachmentTable.java         |  3 +--
 .../cassandra/table/CassandraMessageTable.java  |  1 +
 .../mailbox/store/mail/model/Attachment.java    | 26 +++-----------------
 .../store/mail/model/MessageAttachment.java     | 21 +++++++++++++---
 .../store/mail/model/impl/MessageParser.java    |  2 +-
 .../AbstractMailboxManagerAttachmentTest.java   |  2 +-
 .../store/mail/model/AttachmentTest.java        | 21 ----------------
 .../store/mail/model/MessageAttachmentTest.java |  5 ++--
 .../mail/model/impl/MessageParserTest.java      |  4 +--
 .../apache/james/jmap/model/MessageFactory.java |  2 +-
 14 files changed, 39 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
index 0cceb19..bd764c3 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
@@ -25,7 +25,6 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto;
 import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
 import static org.apache.james.mailbox.cassandra.table.CassandraAttachmentTable.FIELDS;
 import static org.apache.james.mailbox.cassandra.table.CassandraAttachmentTable.ID;
-import static org.apache.james.mailbox.cassandra.table.CassandraAttachmentTable.NAME;
 import static org.apache.james.mailbox.cassandra.table.CassandraAttachmentTable.PAYLOAD;
 import static org.apache.james.mailbox.cassandra.table.CassandraAttachmentTable.SIZE;
 import static org.apache.james.mailbox.cassandra.table.CassandraAttachmentTable.TABLE_NAME;
@@ -51,7 +50,6 @@ import com.datastax.driver.core.Row;
 import com.datastax.driver.core.Session;
 import com.github.fge.lambdas.Throwing;
 import com.github.fge.lambdas.ThrownByLambdaException;
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableList.Builder;
@@ -90,7 +88,6 @@ public class CassandraAttachmentMapper implements AttachmentMapper {
                 .attachmentId(AttachmentId.from(row.getString(ID)))
                 .bytes(row.getBytes(PAYLOAD).array())
                 .type(row.getString(TYPE))
-                .name(Optional.fromNullable(row.getString(NAME)))
                 .build();
     }
 
@@ -129,7 +126,6 @@ public class CassandraAttachmentMapper implements AttachmentMapper {
                 .value(ID, attachment.getAttachmentId().getId())
                 .value(PAYLOAD, ByteBuffer.wrap(IOUtils.toByteArray(attachment.getStream())))
                 .value(TYPE, attachment.getType())
-                .value(NAME, attachment.getName().orNull())
                 .value(SIZE, attachment.getSize())
         );
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/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 0232cfb..1d1bc16 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
@@ -59,12 +59,12 @@ import java.io.InputStream;
 import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 
 import javax.mail.Flags;
@@ -353,6 +353,7 @@ public class CassandraMessageMapper implements MessageMapper {
                     .map(Throwing.function(x -> 
                         MessageAttachment.builder()
                             .attachment(attachmentsById.get(attachmentIdFrom(x)))
+                            .name(x.getString(Attachments.NAME))
                             .cid(x.getString(Attachments.CID))
                             .isInline(x.getBool(Attachments.IS_INLINE))
                             .build()))
@@ -363,8 +364,10 @@ public class CassandraMessageMapper implements MessageMapper {
     }
 
     private Map<AttachmentId,Attachment> attachmentsById(Row row, List<UDTValue>
udtValues) {
-        return attachmentMapper.getAttachments(attachmentIds(udtValues)).stream()
-            .collect(ImmutableCollectors.toImmutableMap(Attachment::getAttachmentId, Function.identity()));
+        Map<AttachmentId, Attachment> map = new HashMap<>();
+        attachmentMapper.getAttachments(attachmentIds(udtValues)).stream()
+                .forEach(att -> map.put(att.getAttachmentId(), att));
+        return map;
     }
 
     private List<AttachmentId> attachmentIds(List<UDTValue> udtValues) {
@@ -420,6 +423,7 @@ public class CassandraMessageMapper implements MessageMapper {
         return typesProvider.getDefinedUserType(ATTACHMENTS)
             .newValue()
             .setString(Attachments.ID, messageAttachment.getAttachmentId().getId())
+            .setString(Attachments.NAME, messageAttachment.getName().orNull())
             .setString(Attachments.CID, messageAttachment.getCid().orNull())
             .setBool(Attachments.IS_INLINE, messageAttachment.isInline());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraAttachmentModule.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraAttachmentModule.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraAttachmentModule.java
index b26fe71..0108161 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraAttachmentModule.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/modules/CassandraAttachmentModule.java
@@ -48,7 +48,6 @@ public class CassandraAttachmentModule implements CassandraModule {
                     .addPartitionKey(CassandraAttachmentTable.ID, text())
                     .addColumn(CassandraAttachmentTable.PAYLOAD, blob())
                     .addColumn(CassandraAttachmentTable.TYPE, text())
-                    .addColumn(CassandraAttachmentTable.NAME, text())
                     .addColumn(CassandraAttachmentTable.SIZE, bigint())));
         index = Collections.emptyList();
         types = Collections.emptyList();

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/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 03494e9..2e9c3b9 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
@@ -98,6 +98,7 @@ public class CassandraMessageModule implements CassandraModule {
                     SchemaBuilder.createType(CassandraMessageTable.ATTACHMENTS)
                         .ifNotExists()
                         .addColumn(CassandraMessageTable.Attachments.ID, text())
+                        .addColumn(CassandraMessageTable.Attachments.NAME, text())
                         .addColumn(CassandraMessageTable.Attachments.CID, text())
                         .addColumn(CassandraMessageTable.Attachments.IS_INLINE, cboolean())));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraAttachmentTable.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraAttachmentTable.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraAttachmentTable.java
index 17158d1..a7115eb 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraAttachmentTable.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/table/CassandraAttachmentTable.java
@@ -25,8 +25,7 @@ public interface CassandraAttachmentTable {
     String ID = "id";
     String PAYLOAD = "payload";
     String TYPE = "type";
-    String NAME = "name";
     String SIZE = "size";
-    String[] FIELDS = { ID, PAYLOAD, TYPE, NAME, SIZE };
+    String[] FIELDS = { ID, PAYLOAD, TYPE, SIZE };
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/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 cbd89bf..8566881 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
@@ -74,6 +74,7 @@ public interface CassandraMessageTable {
 
     interface Attachments {
         String ID = "id";
+        String NAME = "name";
         String CID = "cid";
         String IS_INLINE = "isInline";
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Attachment.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Attachment.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Attachment.java
index 6205647..441b690 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Attachment.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Attachment.java
@@ -26,7 +26,6 @@ import java.util.Arrays;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 
@@ -41,11 +40,6 @@ public class Attachment {
         private AttachmentId attachmentId;
         private byte[] bytes;
         private String type;
-        private Optional<String> name;
-
-        private Builder() {
-            name = Optional.absent();
-        }
 
         public Builder attachmentId(AttachmentId attachmentId) {
             Preconditions.checkArgument(attachmentId != null);
@@ -65,18 +59,12 @@ public class Attachment {
             return this;
         }
 
-        public Builder name(Optional<String> name) {
-            Preconditions.checkArgument(name != null);
-            this.name = name;
-            return this;
-        }
-
         public Attachment build() {
             Preconditions.checkState(bytes != null, "'bytes' is mandatory");
             AttachmentId builtAttachmentId = attachmentId();
             Preconditions.checkState(builtAttachmentId != null, "'attachmentId' is mandatory");
             Preconditions.checkState(type != null, "'type' is mandatory");
-            return new Attachment(bytes, builtAttachmentId, type, name, size());
+            return new Attachment(bytes, builtAttachmentId, type, size());
         }
 
         private AttachmentId attachmentId() {
@@ -94,14 +82,12 @@ public class Attachment {
     private final byte[] bytes;
     private final AttachmentId attachmentId;
     private final String type;
-    private final Optional<String> name;
     private final long size;
 
-    private Attachment(byte[] bytes, AttachmentId attachmentId, String type, Optional<String>
name, long size) {
+    private Attachment(byte[] bytes, AttachmentId attachmentId, String type, long size) {
         this.bytes = bytes;
         this.attachmentId = attachmentId;
         this.type = type;
-        this.name = name;
         this.size = size;
     }
 
@@ -113,10 +99,6 @@ public class Attachment {
         return type;
     }
 
-    public Optional<String> getName() {
-        return name;
-    }
-
     public long getSize() {
         return size;
     }
@@ -132,7 +114,6 @@ public class Attachment {
             return Objects.equal(attachmentId, other.attachmentId)
                 && Arrays.equals(bytes, other.bytes)
                 && Objects.equal(type, other.type)
-                && Objects.equal(name, other.name)
                 && Objects.equal(size, other.size);
         }
         return false;
@@ -140,7 +121,7 @@ public class Attachment {
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(attachmentId, bytes, type, name, size);
+        return Objects.hashCode(attachmentId, bytes, type, size);
     }
 
     @Override
@@ -150,7 +131,6 @@ public class Attachment {
                 .add("attachmentId", attachmentId)
                 .add("bytes", bytes)
                 .add("type", type)
-                .add("name", name)
                 .add("size", size)
                 .toString();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java
index 6004e92..23cfc55 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java
@@ -34,10 +34,12 @@ public class MessageAttachment {
     public static class Builder {
 
         private Attachment attachment;
+        private Optional<String> name;
         private Optional<String> cid;
         private Boolean isInline;
 
         private Builder() {
+            name = Optional.absent();
             cid = Optional.absent();
         }
 
@@ -47,6 +49,11 @@ public class MessageAttachment {
             return this;
         }
 
+        public Builder name(String name) {
+            this.name = Optional.fromNullable(name);
+            return this;
+        }
+
         public Builder cid(String cid) {
             this.cid = Optional.fromNullable(cid);
             return this;
@@ -65,16 +72,18 @@ public class MessageAttachment {
             if (isInline && !cid.isPresent()) {
                 throw new IllegalStateException("'cid' is mandatory for inline attachments");
             }
-            return new MessageAttachment(attachment, cid, isInline);
+            return new MessageAttachment(attachment, name, cid, isInline);
         }
     }
 
     private final Attachment attachment;
+    private final Optional<String> name;
     private final Optional<String> cid;
     private final boolean isInline;
 
-    @VisibleForTesting MessageAttachment(Attachment attachment, Optional<String> cid,
boolean isInline) {
+    @VisibleForTesting MessageAttachment(Attachment attachment, Optional<String> name,
Optional<String> cid, boolean isInline) {
         this.attachment = attachment;
+        this.name = name;
         this.cid = cid;
         this.isInline = isInline;
     }
@@ -87,6 +96,10 @@ public class MessageAttachment {
         return attachment.getAttachmentId();
     }
 
+    public Optional<String> getName() {
+        return name;
+    }
+
     public Optional<String> getCid() {
         return cid;
     }
@@ -100,6 +113,7 @@ public class MessageAttachment {
         if (obj instanceof MessageAttachment) {
             MessageAttachment other = (MessageAttachment) obj;
             return Objects.equal(attachment, other.attachment)
+                && Objects.equal(name, other.name)
                 && Objects.equal(cid, other.cid)
                 && Objects.equal(isInline, other.isInline);
         }
@@ -108,7 +122,7 @@ public class MessageAttachment {
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(attachment, cid, isInline);
+        return Objects.hashCode(attachment, name, cid, isInline);
     }
 
     @Override
@@ -116,6 +130,7 @@ public class MessageAttachment {
         return MoreObjects
                 .toStringHelper(this)
                 .add("attachment", attachment)
+                .add("name", name)
                 .add("cid", cid)
                 .add("isInline", isInline)
                 .toString();

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
index dd99f29..9096efa 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
@@ -95,8 +95,8 @@ public class MessageParser {
                 .attachment(Attachment.builder()
                     .bytes(getBytes(messageWriter, entity.getBody()))
                     .type(contentType.or(DEFAULT_CONTENT_TYPE))
-                    .name(name)
                     .build())
+                .name(name.orNull())
                 .cid(cid.orNull())
                 .isInline(isInline)
                 .build();

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMailboxManagerAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMailboxManagerAttachmentTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMailboxManagerAttachmentTest.java
index 9527afa..025df51 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMailboxManagerAttachmentTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMailboxManagerAttachmentTest.java
@@ -118,7 +118,7 @@ public abstract class AbstractMailboxManagerAttachmentTest {
 
         Iterator<MailboxMessage> messages = messageMapper.findInMailbox(inbox, MessageRange.all(),
FetchType.Full, 1);
         List<MessageAttachment> attachments = messages.next().getAttachments();
-        assertThat(attachmentMapper.getAttachment(attachments.get(0).getAttachmentId()).getName()).isEqualTo(expectedName);
+        assertThat(attachments.get(0).getName()).isEqualTo(expectedName);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentTest.java
index f3505f4..a0018ba 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentTest.java
@@ -27,8 +27,6 @@ import java.io.InputStream;
 import org.apache.commons.io.IOUtils;
 import org.junit.Test;
 
-import com.google.common.base.Optional;
-
 public class AttachmentTest {
 
     @Test
@@ -82,12 +80,6 @@ public class AttachmentTest {
             .type("");
     }
 
-    @Test (expected = IllegalArgumentException.class)
-    public void builderShouldThrowWhenNameIsNull() {
-        Attachment.builder()
-            .name(null);
-    }
-
     @Test (expected = IllegalStateException.class)
     public void buildShouldThrowWhenAttachmentIdIsNotProvided() {
         Attachment.builder().build();
@@ -130,17 +122,4 @@ public class AttachmentTest {
 
         assertThat(attachment.getSize()).isEqualTo(input.getBytes().length);
     }
-
-    @Test
-    public void buildShouldSetTheName() throws Exception {
-        String input = "mystream";
-        Optional<String> expectedName = Optional.of("myName");
-        Attachment attachment = Attachment.builder()
-                .bytes(input.getBytes())
-                .type("content")
-                .name(expectedName)
-                .build();
-
-        assertThat(attachment.getName()).isEqualTo(expectedName);
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java
index 5d8ebcd..115a568 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java
@@ -45,7 +45,7 @@ public class MessageAttachmentTest {
                 .bytes("content".getBytes())
                 .type("type")
                 .build();
-        MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.<String>
absent(), false);
+        MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.<String>
absent(), Optional.<String> absent(), false);
 
         MessageAttachment messageAttachment = MessageAttachment.builder()
             .attachment(attachment)
@@ -87,10 +87,11 @@ public class MessageAttachmentTest {
                 .bytes("content".getBytes())
                 .type("type")
                 .build();
-        MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.of("cid"),
true);
+        MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.of("name"),
Optional.of("cid"), true);
 
         MessageAttachment messageAttachment = MessageAttachment.builder()
             .attachment(attachment)
+            .name("name")
             .cid("cid")
             .isInline(true)
             .build();

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
index 2512123..2e3a15e 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
@@ -59,7 +59,7 @@ public class MessageParserTest {
 
         assertThat(attachments).hasSize(1);
         Optional<String> expectedName = Optional.of("exploits_of_a_mom.png");
-        assertThat(attachments.get(0).getAttachment().getName()).isEqualTo(expectedName);
+        assertThat(attachments.get(0).getName()).isEqualTo(expectedName);
     }
 
     @Test
@@ -67,7 +67,7 @@ public class MessageParserTest {
         List<MessageAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneAttachmentWithoutName.eml"));
 
         assertThat(attachments).hasSize(1);
-        assertThat(attachments.get(0).getAttachment().getName()).isEqualTo(Optional.absent());
+        assertThat(attachments.get(0).getName()).isEqualTo(Optional.absent());
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/1c294ddc/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
index 126dcb9..a430627 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
@@ -161,8 +161,8 @@ public class MessageFactory {
         return Attachment.builder()
                     .blobId(attachment.getAttachmentId().getId())
                     .type(attachment.getAttachment().getType())
-                    .name(attachment.getAttachment().getName().orNull())
                     .size(attachment.getAttachment().getSize())
+                    .name(attachment.getName().orNull())
                     .cid(attachment.getCid().orNull())
                     .isInline(attachment.isInline())
                     .build();


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