james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject james-project git commit: JAMES-1796 Unwrap Cid
Date Mon, 11 Jul 2016 12:32:56 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 0cad05775 -> b87c93905


JAMES-1796 Unwrap Cid


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

Branch: refs/heads/master
Commit: b87c93905cd3e0c79e8d859bc4e49ebc59db2a4b
Parents: 0cad057
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Mon Jul 11 11:50:57 2016 +0200
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Mon Jul 11 14:32:26 2016 +0200

----------------------------------------------------------------------
 .../cassandra/mail/CassandraMessageMapper.java  |  5 +-
 .../store/mail/model/MessageAttachment.java     | 19 +++--
 .../mailbox/store/mail/model/impl/Cid.java      | 72 +++++++++++++++++++
 .../store/mail/model/impl/MessageParser.java    | 19 +++--
 .../store/mail/model/MessageAttachmentTest.java |  7 +-
 .../store/mail/model/MessageMapperTest.java     |  7 +-
 .../mailbox/store/mail/model/impl/CidTest.java  | 74 ++++++++++++++++++++
 .../mail/model/impl/MessageParserTest.java      |  2 +-
 .../test/resources/cucumber/GetMessages.feature |  2 +-
 .../jmap/methods/MIMEMessageConverter.java      |  2 +-
 .../methods/SetMessagesCreationProcessor.java   |  3 +-
 .../apache/james/jmap/model/MessageFactory.java |  3 +-
 .../jmap/methods/MIMEMessageConverterTest.java  |  9 +--
 .../james/jmap/model/MailboxMessageTest.java    |  3 +-
 14 files changed, 198 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/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 1d1bc16..6bd1e5a 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
@@ -98,6 +98,7 @@ 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.MessageAttachment;
+import org.apache.james.mailbox.store.mail.model.impl.Cid;
 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.mail.model.impl.SimpleProperty;
@@ -354,7 +355,7 @@ public class CassandraMessageMapper implements MessageMapper {
                         MessageAttachment.builder()
                             .attachment(attachmentsById.get(attachmentIdFrom(x)))
                             .name(x.getString(Attachments.NAME))
-                            .cid(x.getString(Attachments.CID))
+                            .cid(com.google.common.base.Optional.fromNullable(x.getString(Attachments.CID)).transform(Cid::from))
                             .isInline(x.getBool(Attachments.IS_INLINE))
                             .build()))
                     .collect(ImmutableCollectors.toImmutableList());
@@ -424,7 +425,7 @@ public class CassandraMessageMapper implements MessageMapper {
             .newValue()
             .setString(Attachments.ID, messageAttachment.getAttachmentId().getId())
             .setString(Attachments.NAME, messageAttachment.getName().orNull())
-            .setString(Attachments.CID, messageAttachment.getCid().orNull())
+            .setString(Attachments.CID, messageAttachment.getCid().transform(Cid::getValue).orNull())
             .setBool(Attachments.IS_INLINE, messageAttachment.isInline());
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/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 23cfc55..2fb9b78 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
@@ -19,6 +19,8 @@
 
 package org.apache.james.mailbox.store.mail.model;
 
+import org.apache.james.mailbox.store.mail.model.impl.Cid;
+
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
@@ -35,7 +37,7 @@ public class MessageAttachment {
 
         private Attachment attachment;
         private Optional<String> name;
-        private Optional<String> cid;
+        private Optional<Cid> cid;
         private Boolean isInline;
 
         private Builder() {
@@ -54,7 +56,14 @@ public class MessageAttachment {
             return this;
         }
 
-        public Builder cid(String cid) {
+        public Builder cid(Optional<Cid> cid) {
+            Preconditions.checkNotNull(cid);
+            this.cid = cid;
+            return this;
+        }
+
+        
+        public Builder cid(Cid cid) {
             this.cid = Optional.fromNullable(cid);
             return this;
         }
@@ -78,10 +87,10 @@ public class MessageAttachment {
 
     private final Attachment attachment;
     private final Optional<String> name;
-    private final Optional<String> cid;
+    private final Optional<Cid> cid;
     private final boolean isInline;
 
-    @VisibleForTesting MessageAttachment(Attachment attachment, Optional<String> name,
Optional<String> cid, boolean isInline) {
+    @VisibleForTesting MessageAttachment(Attachment attachment, Optional<String> name,
Optional<Cid> cid, boolean isInline) {
         this.attachment = attachment;
         this.name = name;
         this.cid = cid;
@@ -100,7 +109,7 @@ public class MessageAttachment {
         return name;
     }
 
-    public Optional<String> getCid() {
+    public Optional<Cid> getCid() {
         return cid;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/Cid.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/Cid.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/Cid.java
new file mode 100644
index 0000000..23c43fd
--- /dev/null
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/Cid.java
@@ -0,0 +1,72 @@
+/****************************************************************
+ * 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.store.mail.model.impl;
+
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+
+public class Cid {
+
+    public static Cid from(String cidAsString) {
+        Preconditions.checkNotNull(cidAsString);
+        Preconditions.checkArgument(!cidAsString.isEmpty(), "'cidAsString' is mandatory");
+        return new Cid(normalizedCid(cidAsString));
+    }
+
+    private static String normalizedCid(String input) {
+        if (isWrappedWithAngleBrackets(input)) {
+            return unwrap(input);
+        }
+        return input;
+    }
+    
+    private static String unwrap(String cidAsString) {
+        return cidAsString.substring(1, cidAsString.length() - 1);
+    }
+
+    private static boolean isWrappedWithAngleBrackets(String cidAsString) {
+        return cidAsString.startsWith("<") && cidAsString.endsWith(">");
+    }
+
+    private final String value;
+
+    private Cid(String value) {
+        this.value = value;
+    }
+
+    public String getValue() {
+        return value;
+    }
+    
+    @Override
+    public final boolean equals(Object obj) {
+        if (obj instanceof Cid) {
+            Cid other = (Cid) obj;
+            return Objects.equal(this.value, other.value);
+        }
+        return false;
+    }
+    
+    @Override
+    public final int hashCode() {
+        return Objects.hashCode(this.value);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/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 7e3f2fd..ff4e28c 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
@@ -88,7 +88,7 @@ public class MessageParser {
         Optional<ContentTypeField> contentTypeField = getContentTypeField(entity);
         Optional<String> contentType = contentType(contentTypeField);
         Optional<String> name = name(contentTypeField);
-        Optional<String> cid = cid(castField(entity.getHeader().getField(CONTENT_ID),
ContentIdField.class));
+        Optional<Cid> cid = cid(castField(entity.getHeader().getField(CONTENT_ID),
ContentIdField.class));
         boolean isInline = isInline(castField(entity.getHeader().getField(CONTENT_DISPOSITION),
ContentDispositionField.class));
 
         return MessageAttachment.builder()
@@ -132,13 +132,20 @@ public class MessageParser {
         }).or(Optional.<String> absent());
     }
 
-    private Optional<String> cid(Optional<ContentIdField> contentIdField) {
-        return contentIdField.transform(new Function<ContentIdField, Optional<String>>()
{
+    private Optional<Cid> cid(Optional<ContentIdField> contentIdField) {
+        return contentIdField.transform(new Function<ContentIdField, Optional<Cid>>()
{
             @Override
-            public Optional<String> apply(ContentIdField field) {
-                return Optional.fromNullable(field.getId());
+            public Optional<Cid> apply(ContentIdField field) {
+                return Optional.fromNullable(field.getId())
+                        .transform(new Function<String, Cid>() {
+
+                            @Override
+                            public Cid apply(String cid) {
+                                return Cid.from(cid);
+                            }
+                        });
             }
-        }).or(Optional.<String> absent());
+        }).or(Optional.<Cid> absent());
     }
 
     private boolean isMultipart(Entity entity) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/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 115a568..f29c116 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
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.store.mail.model;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import org.apache.james.mailbox.store.mail.model.impl.Cid;
 import org.junit.Test;
 
 import com.google.common.base.Optional;
@@ -45,7 +46,7 @@ public class MessageAttachmentTest {
                 .bytes("content".getBytes())
                 .type("type")
                 .build();
-        MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.<String>
absent(), Optional.<String> absent(), false);
+        MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.<String>
absent(), Optional.<Cid> absent(), false);
 
         MessageAttachment messageAttachment = MessageAttachment.builder()
             .attachment(attachment)
@@ -87,12 +88,12 @@ public class MessageAttachmentTest {
                 .bytes("content".getBytes())
                 .type("type")
                 .build();
-        MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.of("name"),
Optional.of("cid"), true);
+        MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.of("name"),
Optional.of(Cid.from("cid")), true);
 
         MessageAttachment messageAttachment = MessageAttachment.builder()
             .attachment(attachment)
             .name("name")
-            .cid("cid")
+            .cid(Cid.from("cid"))
             .isInline(true)
             .build();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
index 82ac2a3..f93936d 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
@@ -41,6 +41,7 @@ import org.apache.james.mailbox.store.FlagsUpdateCalculator;
 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.model.impl.Cid;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
@@ -118,19 +119,19 @@ public class MessageMapperTest<T extends MapperProvider> {
         message7With1Attachment = createMessage(attachmentsMailbox, "Subject: Test7 \n\nBody7\n.\n",
BODY_START, new PropertyBuilder(), 
                 ImmutableList.of(MessageAttachment.builder()
                         .attachment(attachment)
-                        .cid("cid")
+                        .cid(Cid.from("cid"))
                         .isInline(true)
                         .build()));
         message8With2Attachments = createMessage(attachmentsMailbox, "Subject: Test8 \n\nBody8\n.\n",
BODY_START, new PropertyBuilder(), 
                 ImmutableList.of(
                         MessageAttachment.builder()
                             .attachment(attachment)
-                            .cid("cid")
+                            .cid(Cid.from("cid"))
                             .isInline(true)
                             .build(),
                         MessageAttachment.builder()
                             .attachment(attachment2)
-                            .cid("cid2")
+                            .cid(Cid.from("cid2"))
                             .isInline(false)
                             .build()));
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/CidTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/CidTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/CidTest.java
new file mode 100644
index 0000000..1028614
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/CidTest.java
@@ -0,0 +1,74 @@
+/****************************************************************
+ * 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.store.mail.model.impl;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class CidTest {
+
+    @Rule public ExpectedException expectedException = ExpectedException.none();
+    
+    @Test
+    public void fromShouldThrowWhenNull() {
+        expectedException.expect(NullPointerException.class);
+        Cid.from(null);
+    }
+    
+    @Test
+    public void fromShouldThrowWhenEmpty() {
+        expectedException.expect(IllegalArgumentException.class);
+        Cid.from("");
+    }
+    
+    @Test
+    public void fromShouldRemoveTagsWhenExists() {
+        Cid cid = Cid.from("<123>");
+        assertThat(cid.getValue()).isEqualTo("123");
+    }
+    
+    @Test
+    public void fromShouldNotRemoveTagsWhenNone() {
+        Cid cid = Cid.from("123");
+        assertThat(cid.getValue()).isEqualTo("123");
+    }
+    
+    @Test
+    public void fromShouldNotRemoveTagsWhenNotEndTag() {
+        Cid cid = Cid.from("<123");
+        assertThat(cid.getValue()).isEqualTo("<123");
+    }
+    
+    @Test
+    public void fromShouldNotRemoveTagsWhenNotStartTag() {
+        Cid cid = Cid.from("123>");
+        assertThat(cid.getValue()).isEqualTo("123>");
+    }
+    
+    @Test
+    public void shouldRespectJavaBeanContract() {
+        EqualsVerifier.forClass(Cid.class).verify();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/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 054ebd0..b5d0f5c 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
@@ -144,7 +144,7 @@ public class MessageParserTest {
         List<MessageAttachment> attachments = testee.retrieveAttachments(ClassLoader.getSystemResourceAsStream("eml/oneInlinedAttachment.eml"));
 
         assertThat(attachments).hasSize(1);
-        assertThat(attachments.get(0).getCid()).isEqualTo(Optional.of("<part1.37A15C92.A7C3488D@linagora.com>"));
+        assertThat(attachments.get(0).getCid()).isEqualTo(Optional.of(Cid.from("part1.37A15C92.A7C3488D@linagora.com")));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
index 9b77a3f..0cf3fb7 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
@@ -153,7 +153,7 @@ Feature: GetMessages method
       |blobId   |"58aa22c2ec5770fb9e574ba19008dbfc647eba43" |
       |type     |"image/jpeg"                               |
       |size     |597                                        |
-      |cid      |"<part1.37A15C92.A7C3488D@linagora.com>"   |
+      |cid      |"part1.37A15C92.A7C3488D@linagora.com"     |
       |isInline |true                                       |
 
   Scenario: Retrieving message should return attachments and html body when some attachments
and html message

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MIMEMessageConverter.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MIMEMessageConverter.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MIMEMessageConverter.java
index 4be01ee..7a50287 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MIMEMessageConverter.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MIMEMessageConverter.java
@@ -246,7 +246,7 @@ public class MIMEMessageConverter {
 
     private void contentId(BodyPartBuilder builder, MessageAttachment att) {
         if (att.getCid().isPresent()) {
-            builder.setField(new RawField("Content-ID", att.getCid().get()));
+            builder.setField(new RawField("Content-ID", att.getCid().get().getValue()));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
index 9d6210e..124658c 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
@@ -70,6 +70,7 @@ import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxId;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.MessageAttachment;
+import org.apache.james.mailbox.store.mail.model.impl.Cid;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 import org.apache.james.util.streams.ImmutableCollectors;
@@ -327,7 +328,7 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor
{
             return MessageAttachment.builder()
                     .attachment(attachmentMapper.getAttachment(AttachmentId.from(attachment.getBlobId().getRawValue())))
                     .name(attachment.getName().orElse(null))
-                    .cid(attachment.getCid().orElse(null))
+                    .cid(attachment.getCid().map(Cid::from).orElse(null))
                     .isInline(attachment.isIsInline())
                     .build();
         } catch (AttachmentNotFoundException e) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/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 d23215e..1c592bf 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
@@ -34,6 +34,7 @@ import org.apache.james.jmap.model.message.IndexableMessage;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.MessageAttachment;
+import org.apache.james.mailbox.store.mail.model.impl.Cid;
 import org.apache.james.util.streams.ImmutableCollectors;
 
 import com.google.common.base.Strings;
@@ -163,7 +164,7 @@ public class MessageFactory {
                     .type(attachment.getAttachment().getType())
                     .size(attachment.getAttachment().getSize())
                     .name(attachment.getName().orNull())
-                    .cid(attachment.getCid().orNull())
+                    .cid(attachment.getCid().transform(Cid::getValue).orNull())
                     .isInline(attachment.isInline())
                     .build();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
index 08e8625..b898aff 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
@@ -32,6 +32,7 @@ import org.apache.james.jmap.model.CreationMessage.DraftEmailer;
 import org.apache.james.jmap.model.CreationMessageId;
 import org.apache.james.mailbox.store.mail.model.AttachmentId;
 import org.apache.james.mailbox.store.mail.model.MessageAttachment;
+import org.apache.james.mailbox.store.mail.model.impl.Cid;
 import org.apache.james.mime4j.Charsets;
 import org.apache.james.mime4j.dom.Entity;
 import org.apache.james.mime4j.dom.Message;
@@ -335,7 +336,7 @@ public class MIMEMessageConverterTest {
                 .htmlBody("Hello <b>all<b>!")
                 .build();
 
-        String expectedCID = "<cid>";
+        String expectedCID = "cid";
         String expectedMimeType = "image/png";
         String text = "123456";
         TextBody expectedBody = new BasicBodyFactory().textBody(text.getBytes(), Charsets.UTF_8);
@@ -345,7 +346,7 @@ public class MIMEMessageConverterTest {
                     .bytes(text.getBytes())
                     .type(expectedMimeType)
                     .build())
-                .cid(expectedCID)
+                .cid(Cid.from(expectedCID))
                 .isInline(true)
                 .build();
 
@@ -380,7 +381,7 @@ public class MIMEMessageConverterTest {
         TextBody expectedTextBody = new BasicBodyFactory().textBody("Hello all!".getBytes(),
Charsets.UTF_8);
         TextBody expectedHtmlBody = new BasicBodyFactory().textBody("Hello <b>all<b>!".getBytes(),
Charsets.UTF_8);
 
-        String expectedCID = "<cid>";
+        String expectedCID = "cid";
         String expectedMimeType = "image/png";
         String text = "123456";
         TextBody expectedAttachmentBody = new BasicBodyFactory().textBody(text.getBytes(),
Charsets.UTF_8);
@@ -390,7 +391,7 @@ public class MIMEMessageConverterTest {
                     .bytes(text.getBytes())
                     .type(expectedMimeType)
                     .build())
-                .cid(expectedCID)
+                .cid(Cid.from(expectedCID))
                 .isInline(true)
                 .build();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b87c9390/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
index 0293808..ac8e736 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
@@ -36,6 +36,7 @@ import org.apache.james.mailbox.store.TestId;
 import org.apache.james.mailbox.store.mail.model.AttachmentId;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.MessageAttachment;
+import org.apache.james.mailbox.store.mail.model.impl.Cid;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 import org.junit.Before;
@@ -422,7 +423,7 @@ public class MailboxMessageTest {
                             .bytes(payload.getBytes())
                             .type(type)
                             .build())
-                        .cid("cid")
+                        .cid(Cid.from("cid"))
                         .isInline(true)
                         .build()), 
                 x -> MessageId.of("user|box|" + x));


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