JAMES-1818 Move Cid and MessageAttachment to API
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/68dac05b Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/68dac05b Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/68dac05b Branch: refs/heads/master Commit: 68dac05b42dfa8627231396dae102c0a5f353b7f Parents: dc564ba Author: Raphael Ouazana <raphael.ouaz...@linagora.com> Authored: Mon Aug 22 17:28:49 2016 +0200 Committer: Raphael Ouazana <raphael.ouaz...@linagora.com> Committed: Mon Aug 29 15:15:43 2016 +0200 ---------------------------------------------------------------------- mailbox/api/pom.xml | 5 + .../org/apache/james/mailbox/model/Cid.java | 72 +++++++++ .../james/mailbox/model/MessageAttachment.java | 145 ++++++++++++++++++ .../org/apache/james/mailbox/model/CidTest.java | 75 ++++++++++ .../mailbox/model/MessageAttachmentTest.java | 104 +++++++++++++ .../cassandra/mail/CassandraMessageMapper.java | 4 +- .../mailbox/hbase/mail/HBaseMailboxMessage.java | 2 +- .../james/mailbox/jcr/JCRMessageManager.java | 2 +- .../jcr/mail/model/JCRMailboxMessage.java | 2 +- .../james/mailbox/jpa/JPAMessageManager.java | 2 +- .../openjpa/AbstractJPAMailboxMessage.java | 2 +- .../jpa/openjpa/OpenJPAMessageManager.java | 2 +- .../maildir/mail/model/MaildirMessage.java | 2 +- .../mailbox/store/StoreMessageManager.java | 2 +- .../mail/model/DelegatingMailboxMessage.java | 1 + .../james/mailbox/store/mail/model/Message.java | 2 + .../store/mail/model/MessageAttachment.java | 149 ------------------- .../mailbox/store/mail/model/impl/Cid.java | 72 --------- .../store/mail/model/impl/MessageParser.java | 3 +- .../mail/model/impl/SimpleMailboxMessage.java | 2 +- .../store/mail/model/impl/SimpleMessage.java | 2 +- .../AbstractMailboxManagerAttachmentTest.java | 2 +- .../mailbox/store/SimpleMailboxMembership.java | 2 +- .../store/mail/model/MessageAttachmentTest.java | 103 ------------- .../store/mail/model/MessageMapperTest.java | 3 +- .../mailbox/store/mail/model/impl/CidTest.java | 74 --------- .../mail/model/impl/MessageParserTest.java | 3 +- .../james/jmap/methods/GetMessagesMethod.java | 2 +- .../jmap/methods/MIMEMessageConverter.java | 2 +- .../methods/SetMessagesCreationProcessor.java | 4 +- .../apache/james/jmap/model/MessageFactory.java | 4 +- .../jmap/methods/MIMEMessageConverterTest.java | 4 +- .../james/jmap/model/MailboxMessageTest.java | 4 +- 33 files changed, 434 insertions(+), 425 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/api/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/api/pom.xml b/mailbox/api/pom.xml index 86b1f27..0092d05 100644 --- a/mailbox/api/pom.xml +++ b/mailbox/api/pom.xml @@ -63,6 +63,11 @@ <scope>test</scope> </dependency> <dependency> + <groupId>nl.jqno.equalsverifier</groupId> + <artifactId>equalsverifier</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>${assertj-1.version}</version> http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java new file mode 100644 index 0000000..bfaa6cc --- /dev/null +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/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.model; + + +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/68dac05b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageAttachment.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageAttachment.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageAttachment.java new file mode 100644 index 0000000..1c4c084 --- /dev/null +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageAttachment.java @@ -0,0 +1,145 @@ +/**************************************************************** + * 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.model; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.MoreObjects; +import com.google.common.base.Objects; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; + +public class MessageAttachment { + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private Attachment attachment; + private Optional<String> name; + private Optional<Cid> cid; + private Boolean isInline; + + private Builder() { + name = Optional.absent(); + cid = Optional.absent(); + } + + public Builder attachment(Attachment attachment) { + Preconditions.checkArgument(attachment != null); + this.attachment = attachment; + return this; + } + + public Builder name(String name) { + this.name = Optional.fromNullable(name); + return this; + } + + 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; + } + + public Builder isInline(boolean isInline) { + this.isInline = isInline; + return this; + } + + public MessageAttachment build() { + Preconditions.checkState(attachment != null, "'attachment' is mandatory"); + if (isInline == null) { + isInline = false; + } + if (isInline && !cid.isPresent()) { + throw new IllegalStateException("'cid' is mandatory for inline attachments"); + } + return new MessageAttachment(attachment, name, cid, isInline); + } + } + + private final Attachment attachment; + private final Optional<String> name; + private final Optional<Cid> cid; + private final boolean isInline; + + @VisibleForTesting MessageAttachment(Attachment attachment, Optional<String> name, Optional<Cid> cid, boolean isInline) { + this.attachment = attachment; + this.name = name; + this.cid = cid; + this.isInline = isInline; + } + + public Attachment getAttachment() { + return attachment; + } + + public AttachmentId getAttachmentId() { + return attachment.getAttachmentId(); + } + + public Optional<String> getName() { + return name; + } + + public Optional<Cid> getCid() { + return cid; + } + + public boolean isInline() { + return isInline; + } + + @Override + public boolean equals(Object obj) { + 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); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hashCode(attachment, name, cid, isInline); + } + + @Override + public String toString() { + 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/68dac05b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java new file mode 100644 index 0000000..c9c9459 --- /dev/null +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java @@ -0,0 +1,75 @@ +/**************************************************************** + * 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.model; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.james.mailbox.model.Cid; +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/68dac05b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java new file mode 100644 index 0000000..1fbe0ca --- /dev/null +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java @@ -0,0 +1,104 @@ +/**************************************************************** + * 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.model; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.james.mailbox.model.Attachment; +import org.apache.james.mailbox.model.Cid; +import org.apache.james.mailbox.model.MessageAttachment; +import org.junit.Test; + +import com.google.common.base.Optional; + +public class MessageAttachmentTest { + + @Test(expected=IllegalStateException.class) + public void buildShouldThrowWhenAttachmentIsNotGiven() { + MessageAttachment.builder() + .build(); + } + + @Test(expected=IllegalArgumentException.class) + public void builderShouldThrowWhenAttachmentIsNull() { + MessageAttachment.builder() + .attachment(null); + } + + @Test + public void buildShouldWorkWhenMandatoryAttributesAreGiven() { + Attachment attachment = Attachment.builder() + .bytes("content".getBytes()) + .type("type") + .build(); + MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.<String> absent(), Optional.<Cid> absent(), false); + + MessageAttachment messageAttachment = MessageAttachment.builder() + .attachment(attachment) + .build(); + + assertThat(messageAttachment).isEqualTo(expectedMessageAttachment); + } + + @Test + public void buildShouldSetIsInlineDefaultValueWhenNotGiven() { + Attachment attachment = Attachment.builder() + .bytes("content".getBytes()) + .type("type") + .build(); + + MessageAttachment messageAttachment = MessageAttachment.builder() + .attachment(attachment) + .build(); + + assertThat(messageAttachment.isInline()).isFalse(); + } + + @Test(expected=IllegalStateException.class) + public void buildShouldThrowWhenIsInlineAndNoCid() { + Attachment attachment = Attachment.builder() + .bytes("content".getBytes()) + .type("type") + .build(); + + MessageAttachment.builder() + .attachment(attachment) + .isInline(true) + .build(); + } + + @Test + public void buildShouldSetAttributesWhenAllAreGiven() { + Attachment attachment = Attachment.builder() + .bytes("content".getBytes()) + .type("type") + .build(); + MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.of("name"), Optional.of(Cid.from("cid")), true); + + MessageAttachment messageAttachment = MessageAttachment.builder() + .attachment(attachment) + .name("name") + .cid(Cid.from("cid")) + .isInline(true) + .build(); + + assertThat(messageAttachment).isEqualTo(expectedMessageAttachment); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 4818ed7..105cee8 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 @@ -86,6 +86,8 @@ import org.apache.james.mailbox.cassandra.table.CassandraMessageTable.Properties import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.Attachment; import org.apache.james.mailbox.model.AttachmentId; +import org.apache.james.mailbox.model.Cid; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.model.MessageMetaData; import org.apache.james.mailbox.model.MessageRange; import org.apache.james.mailbox.model.UpdatedFlags; @@ -97,8 +99,6 @@ import org.apache.james.mailbox.store.mail.ModSeqProvider; import org.apache.james.mailbox.store.mail.UidProvider; 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; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 8e8266c..6ff9cd1 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 @@ -38,10 +38,10 @@ 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.model.MessageAttachment; 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; -import org.apache.james.mailbox.store.mail.model.MessageAttachment; import org.apache.james.mailbox.store.mail.model.MessageId; import org.apache.james.mailbox.store.mail.model.Property; import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java ---------------------------------------------------------------------- diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java index 59448ca..b3daebe 100644 --- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java +++ b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java @@ -31,13 +31,13 @@ import org.apache.james.mailbox.acl.MailboxACLResolver; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.jcr.mail.model.JCRMailbox; import org.apache.james.mailbox.jcr.mail.model.JCRMailboxMessage; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.quota.QuotaManager; import org.apache.james.mailbox.quota.QuotaRootResolver; import org.apache.james.mailbox.store.MailboxSessionMapperFactory; import org.apache.james.mailbox.store.StoreMessageManager; import org.apache.james.mailbox.store.event.MailboxEventDispatcher; import org.apache.james.mailbox.store.mail.model.MailboxMessage; -import org.apache.james.mailbox.store.mail.model.MessageAttachment; import org.apache.james.mailbox.store.mail.model.impl.MessageParser; import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder; import org.apache.james.mailbox.store.search.MessageSearchIndex; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 eecb9e0..ec1bf07 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 @@ -42,10 +42,10 @@ 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.model.MessageAttachment; 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; -import org.apache.james.mailbox.store.mail.model.MessageAttachment; import org.apache.james.mailbox.store.mail.model.MessageId; import org.apache.james.mailbox.store.mail.model.Property; import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java ---------------------------------------------------------------------- diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java index 6dcb8c1..dbe718e 100644 --- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java +++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java @@ -31,6 +31,7 @@ import org.apache.james.mailbox.acl.MailboxACLResolver; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.jpa.mail.model.JPAMailbox; import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.quota.QuotaManager; import org.apache.james.mailbox.quota.QuotaRootResolver; import org.apache.james.mailbox.store.MailboxSessionMapperFactory; @@ -38,7 +39,6 @@ import org.apache.james.mailbox.store.StoreMessageManager; import org.apache.james.mailbox.store.event.MailboxEventDispatcher; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.MailboxMessage; -import org.apache.james.mailbox.store.mail.model.MessageAttachment; import org.apache.james.mailbox.store.mail.model.impl.MessageParser; import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder; import org.apache.james.mailbox.store.search.MessageSearchIndex; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 c1aa3fa..d98533b 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 @@ -46,11 +46,11 @@ 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.model.MessageAttachment; 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; 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.MessageId; import org.apache.james.mailbox.store.mail.model.Property; import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java ---------------------------------------------------------------------- diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java index 3ae70a3..7b60d43 100644 --- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java +++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java @@ -33,13 +33,13 @@ import org.apache.james.mailbox.jpa.JPAMessageManager; import org.apache.james.mailbox.jpa.mail.model.JPAMailbox; import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAEncryptedMailboxMessage; import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAStreamingMailboxMessage; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.quota.QuotaManager; import org.apache.james.mailbox.quota.QuotaRootResolver; import org.apache.james.mailbox.store.MailboxSessionMapperFactory; import org.apache.james.mailbox.store.event.MailboxEventDispatcher; import org.apache.james.mailbox.store.mail.model.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.MessageParser; import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder; import org.apache.james.mailbox.store.search.MessageSearchIndex; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 c537f96..9b4c7f9 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 @@ -31,8 +31,8 @@ import javax.mail.util.SharedFileInputStream; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.NotImplementedException; import org.apache.james.mailbox.maildir.MaildirMessageName; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.store.mail.model.Message; -import org.apache.james.mailbox.store.mail.model.MessageAttachment; import org.apache.james.mailbox.store.mail.model.MessageId; import org.apache.james.mailbox.store.mail.model.Property; import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java index 5bdb68c..1e6fb3c 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java @@ -53,6 +53,7 @@ import org.apache.james.mailbox.model.Attachment; import org.apache.james.mailbox.model.MailboxACL; import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights; import org.apache.james.mailbox.model.MailboxId; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.model.MessageMetaData; import org.apache.james.mailbox.model.MessageRange; import org.apache.james.mailbox.model.MessageResult.FetchGroup; @@ -68,7 +69,6 @@ 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.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.MessageParser; import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder; import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 828ba56..101c56b 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 @@ -25,6 +25,7 @@ import java.util.List; import javax.mail.Flags; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator; public abstract class DelegatingMailboxMessage implements MailboxMessage { http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 dbe2a04..430f1ec 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 @@ -23,6 +23,8 @@ import java.io.InputStream; import java.util.Date; import java.util.List; +import org.apache.james.mailbox.model.MessageAttachment; + public interface Message { MessageId getMessageId(); http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 deleted file mode 100644 index e59912c..0000000 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mailbox.store.mail.model; - -import org.apache.james.mailbox.model.Attachment; -import org.apache.james.mailbox.model.AttachmentId; -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; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; - -public class MessageAttachment { - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private Attachment attachment; - private Optional<String> name; - private Optional<Cid> cid; - private Boolean isInline; - - private Builder() { - name = Optional.absent(); - cid = Optional.absent(); - } - - public Builder attachment(Attachment attachment) { - Preconditions.checkArgument(attachment != null); - this.attachment = attachment; - return this; - } - - public Builder name(String name) { - this.name = Optional.fromNullable(name); - return this; - } - - 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; - } - - public Builder isInline(boolean isInline) { - this.isInline = isInline; - return this; - } - - public MessageAttachment build() { - Preconditions.checkState(attachment != null, "'attachment' is mandatory"); - if (isInline == null) { - isInline = false; - } - if (isInline && !cid.isPresent()) { - throw new IllegalStateException("'cid' is mandatory for inline attachments"); - } - return new MessageAttachment(attachment, name, cid, isInline); - } - } - - private final Attachment attachment; - private final Optional<String> name; - private final Optional<Cid> cid; - private final boolean isInline; - - @VisibleForTesting MessageAttachment(Attachment attachment, Optional<String> name, Optional<Cid> cid, boolean isInline) { - this.attachment = attachment; - this.name = name; - this.cid = cid; - this.isInline = isInline; - } - - public Attachment getAttachment() { - return attachment; - } - - public AttachmentId getAttachmentId() { - return attachment.getAttachmentId(); - } - - public Optional<String> getName() { - return name; - } - - public Optional<Cid> getCid() { - return cid; - } - - public boolean isInline() { - return isInline; - } - - @Override - public boolean equals(Object obj) { - 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); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hashCode(attachment, name, cid, isInline); - } - - @Override - public String toString() { - 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/68dac05b/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 deleted file mode 100644 index 23c43fd..0000000 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/Cid.java +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.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/68dac05b/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 c4d877a..1588302 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 @@ -25,7 +25,8 @@ import java.io.InputStream; import java.util.List; import org.apache.james.mailbox.model.Attachment; -import org.apache.james.mailbox.store.mail.model.MessageAttachment; +import org.apache.james.mailbox.model.Cid; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mime4j.MimeException; import org.apache.james.mime4j.dom.Body; import org.apache.james.mime4j.dom.Entity; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 2eac432..fd465d7 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 @@ -30,9 +30,9 @@ import javax.mail.util.SharedByteArrayInputStream; import org.apache.commons.io.IOUtils; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.MailboxId; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.store.mail.model.DelegatingMailboxMessage; import org.apache.james.mailbox.store.mail.model.MailboxMessage; -import org.apache.james.mailbox.store.mail.model.MessageAttachment; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 19c98d2..e6380e1 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 @@ -25,8 +25,8 @@ import java.util.List; import javax.mail.internet.SharedInputStream; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.store.mail.model.Message; -import org.apache.james.mailbox.store.mail.model.MessageAttachment; import org.apache.james.mailbox.store.mail.model.MessageId; import org.apache.james.mailbox.store.mail.model.Property; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 025df51..4c809fc 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 @@ -36,6 +36,7 @@ import org.apache.james.mailbox.MessageManager; import org.apache.james.mailbox.mock.MockMailboxSession; import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.model.MessageRange; import org.apache.james.mailbox.store.mail.AttachmentMapper; import org.apache.james.mailbox.store.mail.MailboxMapper; @@ -43,7 +44,6 @@ 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.Mailbox; import org.apache.james.mailbox.store.mail.model.MailboxMessage; -import org.apache.james.mailbox.store.mail.model.MessageAttachment; import org.junit.After; import org.junit.Before; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 28fad25..b053172 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 @@ -36,9 +36,9 @@ import java.util.Map.Entry; import javax.mail.Flags; import org.apache.commons.lang.NotImplementedException; +import org.apache.james.mailbox.model.MessageAttachment; 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.MessageAttachment; import org.apache.james.mailbox.store.mail.model.Property; public class SimpleMailboxMembership implements MailboxMessage { http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 deleted file mode 100644 index 7d13932..0000000 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mailbox.store.mail.model; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.james.mailbox.model.Attachment; -import org.apache.james.mailbox.store.mail.model.impl.Cid; -import org.junit.Test; - -import com.google.common.base.Optional; - -public class MessageAttachmentTest { - - @Test(expected=IllegalStateException.class) - public void buildShouldThrowWhenAttachmentIsNotGiven() { - MessageAttachment.builder() - .build(); - } - - @Test(expected=IllegalArgumentException.class) - public void builderShouldThrowWhenAttachmentIsNull() { - MessageAttachment.builder() - .attachment(null); - } - - @Test - public void buildShouldWorkWhenMandatoryAttributesAreGiven() { - Attachment attachment = Attachment.builder() - .bytes("content".getBytes()) - .type("type") - .build(); - MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.<String> absent(), Optional.<Cid> absent(), false); - - MessageAttachment messageAttachment = MessageAttachment.builder() - .attachment(attachment) - .build(); - - assertThat(messageAttachment).isEqualTo(expectedMessageAttachment); - } - - @Test - public void buildShouldSetIsInlineDefaultValueWhenNotGiven() { - Attachment attachment = Attachment.builder() - .bytes("content".getBytes()) - .type("type") - .build(); - - MessageAttachment messageAttachment = MessageAttachment.builder() - .attachment(attachment) - .build(); - - assertThat(messageAttachment.isInline()).isFalse(); - } - - @Test(expected=IllegalStateException.class) - public void buildShouldThrowWhenIsInlineAndNoCid() { - Attachment attachment = Attachment.builder() - .bytes("content".getBytes()) - .type("type") - .build(); - - MessageAttachment.builder() - .attachment(attachment) - .isInline(true) - .build(); - } - - @Test - public void buildShouldSetAttributesWhenAllAreGiven() { - Attachment attachment = Attachment.builder() - .bytes("content".getBytes()) - .type("type") - .build(); - MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.of("name"), Optional.of(Cid.from("cid")), true); - - MessageAttachment messageAttachment = MessageAttachment.builder() - .attachment(attachment) - .name("name") - .cid(Cid.from("cid")) - .isInline(true) - .build(); - - assertThat(messageAttachment).isEqualTo(expectedMessageAttachment); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 0bfda0c..956c8fb 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 @@ -35,8 +35,10 @@ import org.apache.james.mailbox.MessageManager.FlagsUpdateMode; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.Attachment; import org.apache.james.mailbox.model.AttachmentId; +import org.apache.james.mailbox.model.Cid; import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.model.MessageMetaData; import org.apache.james.mailbox.model.MessageRange; import org.apache.james.mailbox.model.UpdatedFlags; @@ -44,7 +46,6 @@ 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; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 deleted file mode 100644 index 1028614..0000000 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/CidTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.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/68dac05b/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 fa1edcd..6eb0584 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 @@ -24,7 +24,8 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; import org.apache.james.mailbox.model.Attachment; -import org.apache.james.mailbox.store.mail.model.MessageAttachment; +import org.apache.james.mailbox.model.Cid; +import org.apache.james.mailbox.model.MessageAttachment; import org.junit.Before; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java index 08ca4ac..8bc0a3e 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java @@ -41,13 +41,13 @@ import org.apache.james.jmap.model.MessageProperties.HeaderProperty; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.model.MessageRange; import org.apache.james.mailbox.store.mail.MailboxMapperFactory; import org.apache.james.mailbox.store.mail.MessageMapper; import org.apache.james.mailbox.store.mail.MessageMapperFactory; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.MailboxMessage; -import org.apache.james.mailbox.store.mail.model.MessageAttachment; import org.javatuples.Pair; import com.fasterxml.jackson.databind.ser.PropertyFilter; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 b802276..886fd4e 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 @@ -29,8 +29,8 @@ import java.util.stream.Collectors; import org.apache.james.jmap.model.CreationMessage; import org.apache.james.jmap.model.CreationMessage.DraftEmailer; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.jmap.model.CreationMessageId; -import org.apache.james.mailbox.store.mail.model.MessageAttachment; import org.apache.james.mime4j.Charsets; import org.apache.james.mime4j.codec.DecodeMonitor; import org.apache.james.mime4j.dom.FieldParser; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 ce8538d..ebd299d 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 @@ -62,14 +62,14 @@ import org.apache.james.mailbox.exception.AttachmentNotFoundException; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.exception.MailboxNotFoundException; import org.apache.james.mailbox.model.AttachmentId; +import org.apache.james.mailbox.model.Cid; import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.store.MailboxSessionMapperFactory; import org.apache.james.mailbox.store.mail.MessageMapper; 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.mailet.Mail; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 6eb9bda..8790df3 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 @@ -31,10 +31,10 @@ import javax.inject.Inject; import org.apache.james.jmap.model.message.EMailer; import org.apache.james.jmap.model.message.IndexableMessage; +import org.apache.james.mailbox.model.Cid; +import org.apache.james.mailbox.model.MessageAttachment; 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 com.github.steveash.guavate.Guavate; import com.google.common.base.Strings; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 5876bc3..a5f4556 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 @@ -31,8 +31,8 @@ import org.apache.james.jmap.model.CreationMessage; import org.apache.james.jmap.model.CreationMessage.DraftEmailer; import org.apache.james.jmap.model.CreationMessageId; import org.apache.james.mailbox.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.mailbox.model.Cid; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mime4j.Charsets; import org.apache.james.mime4j.dom.Entity; import org.apache.james.mime4j.dom.Message; http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 d42e539..4ad127c 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 @@ -33,10 +33,10 @@ import javax.mail.util.SharedByteArrayInputStream; import org.apache.commons.io.IOUtils; import org.apache.james.jmap.utils.HtmlTextExtractor; import org.apache.james.mailbox.model.AttachmentId; +import org.apache.james.mailbox.model.Cid; +import org.apache.james.mailbox.model.MessageAttachment; import org.apache.james.mailbox.store.TestId; 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; --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org