[jira] [Commented] (JAMES-2988) JMAP GetMessages should use the smallest projection possible

2019-11-27 Thread Benoit Tellier (Jira)


[ 
https://issues.apache.org/jira/browse/JAMES-2988?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16984156#comment-16984156
 ] 

Benoit Tellier commented on JAMES-2988:
---

https://github.com/linagora/james-project/pull/2935 proposes the removal of 
bitewise operations within FetchGroup and upgrade it to an enumset.

This refactoring clearly makes the code easier to read.

> JMAP GetMessages should use the smallest projection possible
> 
>
> Key: JAMES-2988
> URL: https://issues.apache.org/jira/browse/JAMES-2988
> Project: James Server
>  Issue Type: Sub-task
>Reporter: Trần Tiến Đức
>Priority: Major
>
> ADR 12:
> [https://github.com/apache/james-project/pull/170]
>  
> After JAMES-2987
>  
> GetMessageMethod should select the appropriate factory, retrieve 
> MailboxMessage with the right fetch type.
> GetMessageResponse should return a generic "MessageProjection"
> You should be able to retrieve the model needed for the level of reads 
> requested and use the appropriate method introduced in Message(Id)Manager .
> You may need to fix some JMAP integration tests (specifying the read 
> properties in the incoming JMAP requests)
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Comment Edited] (JAMES-2988) JMAP GetMessages should use the smallest projection possible

2019-11-27 Thread Benoit Tellier (Jira)


[ 
https://issues.apache.org/jira/browse/JAMES-2988?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16984088#comment-16984088
 ] 

Benoit Tellier edited comment on JAMES-2988 at 11/28/19 2:20 AM:
-

https://github.com/linagora/james-project/pull/2920 MessageIdManager should 
comply with the use of fetch group

Fetch group -> mapper fetch type convertion is extracted and tested.

I did also rework the fetch API so that API parameters supplied by the API 
caller are no longer interfaces. This made:
 - the API harder to discover as you have to navigate several classes
 - the mailbox-store dependencie was needed to actually use the fetch API

Also I reworked fetchGroup related classes to actually be immutable which is a 
great win.

In the process I contributed tests for IMAP FetchData -> FetchGroup convertion.

https://github.com/linagora/james-project/pull/2928 ensured JMAP is choosing 
the appropriate fetchGroup given requested messages properties and is returning 
the appropriate messageView

These two pull requests are merged.

In that ongoing effort, Matthieu and I would like to further refactor 
FetchGroup to no longer rely on tricky low level bite masks but rather use a 
friendlier 'EnumSet'. I will rebase his work on the latest master changes. (See 
https://github.com/linagora/james-project/pull/2929 as a reference)


was (Author: btellier):
https://github.com/linagora/james-project/pull/2920 MessageIdManager should 
comply with the use of fetch group

Fetch group -> mapper fetch type convertion is extracted and tested.

I did also rework the fetch API so that API parameters supplied by the API 
caller are no longer interfaces. This made:
 - the API harder to discover as you have to navigate several classes
 - the mailbox-store dependencie was needed to actually use the fetch API

Also I reworked fetchGroup related classes to actually be immutable which is a 
great win.

In the process I contributed tests for IMAP FetchData -> FetchGroup convertion.

https://github.com/linagora/james-project/pull/2928 ensured JMAP is choosing 
the appropriate fetchGroup given requested messages properties and is returning 
the appropriate messageView

These two pull requests are merged.

In that ongoing effort, Matthieu and I would like to further refactor 
FetchGroup to no longer rely on tricky low level bite masks but rather use a 
friendlier 'EnumSet'. I will rebase his work on the latest master changes.

> JMAP GetMessages should use the smallest projection possible
> 
>
> Key: JAMES-2988
> URL: https://issues.apache.org/jira/browse/JAMES-2988
> Project: James Server
>  Issue Type: Sub-task
>Reporter: Trần Tiến Đức
>Priority: Major
>
> ADR 12:
> [https://github.com/apache/james-project/pull/170]
>  
> After JAMES-2987
>  
> GetMessageMethod should select the appropriate factory, retrieve 
> MailboxMessage with the right fetch type.
> GetMessageResponse should return a generic "MessageProjection"
> You should be able to retrieve the model needed for the level of reads 
> requested and use the appropriate method introduced in Message(Id)Manager .
> You may need to fix some JMAP integration tests (specifying the read 
> properties in the incoming JMAP requests)
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2988) JMAP GetMessages should use the smallest projection possible

2019-11-27 Thread Benoit Tellier (Jira)


[ 
https://issues.apache.org/jira/browse/JAMES-2988?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16984088#comment-16984088
 ] 

Benoit Tellier commented on JAMES-2988:
---

https://github.com/linagora/james-project/pull/2920 MessageIdManager should 
comply with the use of fetch group

Fetch group -> mapper fetch type convertion is extracted and tested.

I did also rework the fetch API so that API parameters supplied by the API 
caller are no longer interfaces. This made:
 - the API harder to discover as you have to navigate several classes
 - the mailbox-store dependencie was needed to actually use the fetch API

Also I reworked fetchGroup related classes to actually be immutable which is a 
great win.

In the process I contributed tests for IMAP FetchData -> FetchGroup convertion.

https://github.com/linagora/james-project/pull/2928 ensured JMAP is choosing 
the appropriate fetchGroup given requested messages properties and is returning 
the appropriate messageView

These two pull requests are merged.

In that ongoing effort, Matthieu and I would like to further refactor 
FetchGroup to no longer rely on tricky low level bite masks but rather use a 
friendlier 'EnumSet'. I will rebase his work on the latest master changes.

> JMAP GetMessages should use the smallest projection possible
> 
>
> Key: JAMES-2988
> URL: https://issues.apache.org/jira/browse/JAMES-2988
> Project: James Server
>  Issue Type: Sub-task
>Reporter: Trần Tiến Đức
>Priority: Major
>
> ADR 12:
> [https://github.com/apache/james-project/pull/170]
>  
> After JAMES-2987
>  
> GetMessageMethod should select the appropriate factory, retrieve 
> MailboxMessage with the right fetch type.
> GetMessageResponse should return a generic "MessageProjection"
> You should be able to retrieve the model needed for the level of reads 
> requested and use the appropriate method introduced in Message(Id)Manager .
> You may need to fix some JMAP integration tests (specifying the read 
> properties in the incoming JMAP requests)
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[james-project] 18/23: JAMES-2989 Rework toString for MimePathImpl

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit be28f6eb6be6783986d970515dfed63cf08770ed
Author: Benoit Tellier 
AuthorDate: Tue Nov 26 13:46:55 2019 +0700

JAMES-2989 Rework toString for MimePathImpl
---
 .../api/src/main/java/org/apache/james/mailbox/model/MimePath.java | 7 ++-
 .../src/test/java/org/apache/james/mailbox/model/MimePathTest.java | 6 +++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePath.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePath.java
index f77a5ea..b41301e 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePath.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePath.java
@@ -66,7 +66,12 @@ public final class MimePath {
 
 @Override
 public final String toString() {
+List parts = Arrays.stream(positions)
+.boxed()
+.collect(Guavate.toImmutableList());
+
 return "MIMEPath:"
-+ Arrays.toString(positions);
++ Joiner.on('.')
+.join(parts);
 }
 }
\ No newline at end of file
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathTest.java 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathTest.java
index 3715a40..91e2651 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathTest.java
@@ -36,20 +36,20 @@ class MimePathTest {
 void toStringWhenEmpty() {
 int[] empty = {};
 assertThat(new MimePath(empty).toString())
-.isEqualTo("MIMEPath:[]");
+.isEqualTo("MIMEPath:");
 }
 
 @Test
 void toStringWhenSingle() {
 int[] single = {1};
 assertThat(new MimePath(single).toString())
-.isEqualTo("MIMEPath:[1]");
+.isEqualTo("MIMEPath:1");
 }
 
 @Test
 void toStringWhenMany() {
 int[] many = {1, 2, 3};
 assertThat(new MimePath(many).toString())
-.isEqualTo("MIMEPath:[1, 2, 3]");
+.isEqualTo("MIMEPath:1.2.3");
 }
 }
\ No newline at end of file


-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[james-project] 12/23: JAMES-2989 POJOify FetchGroup

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 4a44dc857120f9d43eab97c6603b5fc9f5e29321
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 11:59:52 2019 +0700

JAMES-2989 POJOify FetchGroup
---
 .../listeners/SetCustomFlagOnBigMessagesTest.java  |   6 +-
 .../org/apache/james/mailbox/MessageIdManager.java |   2 +-
 .../org/apache/james/mailbox/MessageManager.java   |   2 +-
 .../model/{FetchGroupImpl.java => FetchGroup.java} |  53 ---
 .../org/apache/james/mailbox/model/Headers.java|   1 -
 .../apache/james/mailbox/model/MessageResult.java  |  51 ---
 .../james/mailbox/model/PartContentDescriptor.java |  14 +--
 .../apache/james/mailbox/MailboxManagerTest.java   |  10 +-
 .../james/mailbox/backup/DefaultMailboxBackup.java |   4 +-
 .../james/vault/DeletedMessageVaultHookTest.java   |   4 +-
 .../james/mailbox/store/MessageResultImpl.java |  11 ++-
 .../apache/james/mailbox/store/ResultUtils.java|  28 +++---
 .../james/mailbox/store/StoreBlobManager.java  |   4 +-
 .../james/mailbox/store/StoreMessageIdManager.java |   5 +-
 .../james/mailbox/store/StoreMessageManager.java   |   2 +-
 .../mailbox/store/StoreMessageResultIterator.java  |   4 +-
 .../mailbox/store/mail/FetchGroupConverter.java|  22 ++---
 .../store/AbstractCombinationManagerTest.java  |  45 +
 .../AbstractMessageIdManagerSideEffectTest.java|  18 ++--
 .../store/AbstractMessageIdManagerStorageTest.java | 102 ++---
 .../james/mailbox/store/StoreBlobManagerTest.java  |  18 ++--
 .../StoreMailboxMessageResultIteratorTest.java |  10 +-
 .../mailbox/tools/copier/MailboxCopierImpl.java|   4 +-
 .../imap/processor/AbstractMailboxProcessor.java   |   4 +-
 .../james/imap/processor/SearchProcessor.java  |   4 +-
 .../james/imap/processor/StoreProcessor.java   |  13 ++-
 .../james/imap/processor/fetch/FetchProcessor.java |  21 ++---
 .../apache/james/jmap/draft/MessageIdProbe.java|   6 +-
 .../mailets/delivery/MailboxAppenderTest.java  |  10 +-
 .../jmap/draft/methods/GetMessagesMethod.java  |   4 +-
 .../james/jmap/draft/methods/ReferenceUpdater.java |   4 +-
 .../james/jmap/draft/methods/SendMDNProcessor.java |   4 +-
 .../draft/methods/SetMessagesUpdateProcessor.java  |   6 +-
 .../jmap/draft/send/PostDequeueDecorator.java  |   4 +-
 .../message/view/MessageFullViewFactoryTest.java   |   6 +-
 .../message/view/MessageHeaderViewFactoryTest.java |   6 +-
 .../view/MessageMetadataViewFactoryTest.java   |   6 +-
 .../jmap/draft/send/PostDequeueDecoratorTest.java  |  24 ++---
 .../james/pop3server/mailbox/MailboxAdapter.java   |  11 +--
 .../routes/DeletedMessagesVaultRoutesTest.java |   4 +-
 40 files changed, 264 insertions(+), 293 deletions(-)

diff --git 
a/examples/custom-listeners/src/test/java/org/apache/james/examples/custom/listeners/SetCustomFlagOnBigMessagesTest.java
 
b/examples/custom-listeners/src/test/java/org/apache/james/examples/custom/listeners/SetCustomFlagOnBigMessagesTest.java
index be8f918..e3340d5 100644
--- 
a/examples/custom-listeners/src/test/java/org/apache/james/examples/custom/listeners/SetCustomFlagOnBigMessagesTest.java
+++ 
b/examples/custom-listeners/src/test/java/org/apache/james/examples/custom/listeners/SetCustomFlagOnBigMessagesTest.java
@@ -37,7 +37,7 @@ import org.apache.james.mailbox.events.Event;
 import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
 import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
 import org.apache.james.mailbox.model.ComposedMessageId;
-import org.apache.james.mailbox.model.FetchGroupImpl;
+import org.apache.james.mailbox.model.FetchGroup;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageMetaData;
@@ -125,7 +125,7 @@ class SetCustomFlagOnBigMessagesTest {
 mailboxSession);
 
 MessageResult addedMessage = inboxMessageManager
-.getMessages(MessageRange.one(composedIdOfSmallMessage.getUid()), 
FetchGroupImpl.MINIMAL, mailboxSession)
+.getMessages(MessageRange.one(composedIdOfSmallMessage.getUid()), 
FetchGroup.MINIMAL, mailboxSession)
 .next();
 MessageMetaData oneMBMetaData = new 
MessageMetaData(addedMessage.getUid(), addedMessage.getModSeq(),
 addedMessage.getFlags(), ONE_MB, addedMessage.getInternalDate(), 
addedMessage.getMessageId());
@@ -181,7 +181,7 @@ class SetCustomFlagOnBigMessagesTest {
 
 private Stream getMessageFlags(MessageUid messageUid) throws 
Exception {
 return Streams.stream(inboxMessageManager
-.getMessages(MessageRange.one(messageUid), FetchGroupImpl.MINIMAL, 
mailboxSession))
+.getMessages(MessageRange.one(messageUid), FetchGroup.MINIMAL, 
mailboxSession))
 

[james-project] 04/23: JAMES-2989 Rework equals & hashcode for MimePathImpl

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit b4d98b1daf9059475b7a61beb625cc8becd1a242
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 11:14:29 2019 +0700

JAMES-2989 Rework equals & hashcode for MimePathImpl
---
 .../apache/james/mailbox/model/MimePathImpl.java   | 28 +--
 .../james/mailbox/model/MimePathImplTest.java} | 56 +++---
 2 files changed, 18 insertions(+), 66 deletions(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
index d75020d..66c5fcf 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
@@ -37,25 +37,19 @@ public class MimePathImpl implements MessageResult.MimePath 
{
 return positions;
 }
 
-public int hashCode() {
-return positions.length;
-}
+@Override
+public final boolean equals(Object o) {
+if (o instanceof MimePathImpl) {
+MimePathImpl mimePath = (MimePathImpl) o;
 
-public boolean equals(Object obj) {
-if (this == obj) {
-return true;
-}
-if (obj == null) {
-return false;
-}
-if (getClass() != obj.getClass()) {
-return false;
+return Arrays.equals(this.positions, mimePath.positions);
 }
-final MimePathImpl other = (MimePathImpl) obj;
-if (!Arrays.equals(positions, other.positions)) {
-return false;
-}
-return true;
+return false;
+}
+
+@Override
+public final int hashCode() {
+return Arrays.hashCode(positions);
 }
 
 public String toString() {
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathImplTest.java
similarity index 50%
copy from 
mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
copy to 
mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathImplTest.java
index d75020d..0b1caf9 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
+++ 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathImplTest.java
@@ -17,58 +17,16 @@
  * under the License.   *
  /
 
-/**
- * 
- */
 package org.apache.james.mailbox.model;
 
-import java.util.Arrays;
+import org.junit.jupiter.api.Test;
 
-public class MimePathImpl implements MessageResult.MimePath {
-private final int[] positions;
+import nl.jqno.equalsverifier.EqualsVerifier;
 
-public MimePathImpl(int[] positions) {
-super();
-this.positions = positions;
-}
-
-@Override
-public int[] getPositions() {
-return positions;
-}
-
-public int hashCode() {
-return positions.length;
-}
-
-public boolean equals(Object obj) {
-if (this == obj) {
-return true;
-}
-if (obj == null) {
-return false;
-}
-if (getClass() != obj.getClass()) {
-return false;
-}
-final MimePathImpl other = (MimePathImpl) obj;
-if (!Arrays.equals(positions, other.positions)) {
-return false;
-}
-return true;
-}
-
-public String toString() {
-final StringBuilder builder = new StringBuilder("MIMEPath:");
-boolean isFirst = false;
-for (int position : positions) {
-if (isFirst) {
-isFirst = false;
-} else {
-builder.append('.');
-}
-builder.append(position);
-}
-return builder.toString();
+class MimePathImplTest {
+@Test
+void shouldMatchBeanContract() {
+EqualsVerifier.forClass(MimePathImpl.class)
+.verify();
 }
 }
\ No newline at end of file


-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[james-project] 15/23: JAMES-2989 Little refactor for FetchGroupConverter

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit c80a8521b662d9450e42c7d1955fd8848472cb45
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 13:01:06 2019 +0700

JAMES-2989 Little refactor for FetchGroupConverter
---
 .../mailbox/store/mail/FetchGroupConverter.java| 51 +-
 1 file changed, 20 insertions(+), 31 deletions(-)

diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
index 5bceef9..62b30e6 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
@@ -27,44 +27,29 @@ public class FetchGroupConverter {
  * {@link MessageMapper.FetchType} for it
  */
 public static MessageMapper.FetchType getFetchType(FetchGroup group) {
-int content = group.content();
-boolean headers = false;
-boolean body = false;
-boolean full = false;
-
-if ((content & FetchGroup.HEADERS_MASK) > 0) {
-headers = true;
-content -= FetchGroup.HEADERS_MASK;
-}
-if (group.getPartContentDescriptors().size() > 0) {
-full = true;
-}
-if ((content & FetchGroup.BODY_CONTENT_MASK) > 0) {
-body = true;
-content -= FetchGroup.BODY_CONTENT_MASK;
-}
-
-if ((content & FetchGroup.FULL_CONTENT_MASK) > 0) {
-full = true;
-content -= FetchGroup.FULL_CONTENT_MASK;
+if (hasMask(group, FetchGroup.FULL_CONTENT_MASK)) {
+return MessageMapper.FetchType.Full;
 }
-
-if ((content & FetchGroup.MIME_DESCRIPTOR_MASK) > 0) {
+if (hasMask(group, FetchGroup.MIME_DESCRIPTOR_MASK)) {
 // If we need the mimedescriptor we MAY need the full content later
 // too.
 // This gives us no other choice then request it
-full = true;
-content -= FetchGroup.MIME_DESCRIPTOR_MASK;
+return MessageMapper.FetchType.Full;
 }
-if ((content & FetchGroup.MIME_CONTENT_MASK) > 0) {
-full = true;
-content -= FetchGroup.MIME_CONTENT_MASK;
+if (hasMask(group, FetchGroup.MIME_CONTENT_MASK)) {
+return MessageMapper.FetchType.Full;
+}
+if (hasMask(group, FetchGroup.MIME_HEADERS_MASK)) {
+return MessageMapper.FetchType.Full;
 }
-if ((content & FetchGroup.MIME_HEADERS_MASK) > 0) {
-full = true;
-content -= FetchGroup.MIME_HEADERS_MASK;
+if (!group.getPartContentDescriptors().isEmpty()) {
+return MessageMapper.FetchType.Full;
 }
-if (full || (body && headers)) {
+
+boolean headers = hasMask(group, FetchGroup.HEADERS_MASK);
+boolean body = hasMask(group, FetchGroup.BODY_CONTENT_MASK);
+
+if (body && headers) {
 return MessageMapper.FetchType.Full;
 } else if (body) {
 return MessageMapper.FetchType.Body;
@@ -74,4 +59,8 @@ public class FetchGroupConverter {
 return MessageMapper.FetchType.Metadata;
 }
 }
+
+private static boolean hasMask(FetchGroup group, int mask) {
+return (group.content() & mask) > 0;
+}
 }


-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[james-project] 17/23: JAMES-2988 Move bitewise logic with FetchGroup models

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit b0dc0b3a70fa37d4c9f8ce89f7151e5263d8f115
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 18:11:31 2019 +0700

JAMES-2988 Move bitewise logic with FetchGroup models
---
 .../org/apache/james/mailbox/model/FetchGroup.java | 13 +
 .../james/mailbox/model/PartContentDescriptor.java | 12 -
 .../apache/james/mailbox/model/FetchGroupTest.java | 56 ++
 .../mailbox/model/PartContentDescriptorTest.java   | 55 +
 .../apache/james/mailbox/store/ResultUtils.java| 40 +---
 .../mailbox/store/mail/FetchGroupConverter.java| 16 +++
 6 files changed, 153 insertions(+), 39 deletions(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
index 10f9657..56c01ee 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.mailbox.model;
 
+import java.util.Arrays;
 import java.util.Objects;
 import java.util.Set;
 import java.util.stream.Stream;
@@ -35,6 +36,7 @@ public class FetchGroup {
  * For example: could have best performance when doing store and then
  * forget. UIDs are always returned
  */
+public static final int NO_MASK = 0;
 public static final int MINIMAL_MASK = 0x00;
 public static final int MIME_DESCRIPTOR_MASK = 0x01;
 public static final int HEADERS_MASK = 0x100;
@@ -120,6 +122,17 @@ public class FetchGroup {
 .or(content);
 }
 
+public boolean hasMask(int mask) {
+return (content & mask) > NO_MASK;
+}
+
+public boolean hasOnlyMasks(int... masks) {
+int allowedMask = Arrays.stream(masks)
+.reduce((a, b) -> a | b)
+.orElse(0);
+return (content & (~ allowedMask)) == 0;
+}
+
 @Override
 public String toString() {
 return "Fetch " + content;
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptor.java
 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptor.java
index 158a348..089d1fd 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptor.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptor.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.mailbox.model;
 
+import static org.apache.james.mailbox.model.FetchGroup.NO_MASK;
+
 import java.util.Objects;
 
 /**
@@ -68,11 +70,17 @@ public class PartContentDescriptor {
 return path;
 }
 
-public int hashCode() {
+public boolean hasMask(int mask) {
+return (content & mask) > NO_MASK;
+}
+
+@Override
+public final int hashCode() {
 return Objects.hash(path);
 }
 
-public boolean equals(Object obj) {
+@Override
+public final boolean equals(Object obj) {
 if (obj instanceof PartContentDescriptor) {
 PartContentDescriptor that = (PartContentDescriptor) obj;
 return Objects.equals(this.path, that.path);
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/FetchGroupTest.java 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/FetchGroupTest.java
index b3a4712..5ded8c0 100644
--- 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/FetchGroupTest.java
+++ 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/FetchGroupTest.java
@@ -72,4 +72,60 @@ class FetchGroupTest {
 .addPartContent(new MimePath(path), FetchGroup.HEADERS_MASK))
 .isEqualTo(new FetchGroup(FetchGroup.MINIMAL_MASK, 
ImmutableSet.of(new PartContentDescriptor(FetchGroup.MINIMAL_MASK, new 
MimePath(path)).or(FetchGroup.HEADERS_MASK;
 }
+
+@Test
+void hasMaskShouldReturnFalseWhenNotContained() {
+assertThat(FetchGroup.MINIMAL
+.or(FetchGroup.MIME_HEADERS_MASK)
+.or(FetchGroup.MIME_DESCRIPTOR_MASK)
+.hasMask(FetchGroup.HEADERS_MASK))
+.isFalse();
+}
+
+@Test
+void hasMaskShouldReturnTrueWhenContained() {
+assertThat(FetchGroup.MINIMAL
+.or(FetchGroup.MIME_HEADERS_MASK)
+.or(FetchGroup.MIME_DESCRIPTOR_MASK)
+.hasMask(FetchGroup.MIME_HEADERS_MASK))
+.isTrue();
+}
+
+@Test
+void hasOnlyMasksShouldReturnTrueWhenSuppliedEmpty() {
+assertThat(FetchGroup.MINIMAL
+.hasOnlyMasks())
+.isTrue();
+}
+
+@Test
+void hasOnlyMasksShouldReturnTrueWhenExactlyContainASingleValue() {
+assertThat(FetchGroup.HEADERS
+.hasOnlyMasks(FetchGroup.HEADERS_MASK))
+ 

[james-project] 01/23: JAMES-2989 StoreMessageIdManager should comply to fetchGroup read level

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 3d422bf11f2b596c69e3576a4a16c182659f27ed
Author: Benoit Tellier 
AuthorDate: Fri Nov 22 14:59:05 2019 +0700

JAMES-2989 StoreMessageIdManager should comply to fetchGroup read level
---
 .../james/mailbox/store/StoreMessageIdManager.java |  5 +-
 .../mailbox/store/StoreMessageResultIterator.java  | 47 +--
 .../mailbox/store/mail/FetchGroupConverter.java| 69 ++
 .../apache/james/jmap/draft/MessageIdProbe.java|  2 +-
 4 files changed, 76 insertions(+), 47 deletions(-)

diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
index bf3d810..229638e 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
@@ -55,6 +55,7 @@ import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.event.EventFactory;
+import org.apache.james.mailbox.store.mail.FetchGroupConverter;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.MessageIdMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper;
@@ -137,7 +138,9 @@ public class StoreMessageIdManager implements 
MessageIdManager {
 @Override
 public List getMessages(List messageIds, 
MessageResult.FetchGroup fetchGroup, MailboxSession mailboxSession) throws 
MailboxException {
 MessageIdMapper messageIdMapper = 
mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession);
-List messageList = messageIdMapper.find(messageIds, 
MessageMapper.FetchType.Full);
+
+MessageMapper.FetchType fetchType = 
FetchGroupConverter.getFetchType(fetchGroup);
+List messageList = messageIdMapper.find(messageIds, 
fetchType);
 
 ImmutableSet allowedMailboxIds = 
getAllowedMailboxIds(mailboxSession, messageList, Right.Read);
 
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
index f2cb048..c18d1f8 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
@@ -18,6 +18,8 @@
  /
 package org.apache.james.mailbox.store;
 
+import static 
org.apache.james.mailbox.store.mail.FetchGroupConverter.getFetchType;
+
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
@@ -76,51 +78,6 @@ public class StoreMessageResultIterator implements 
MessageResultIterator {
 LOGGER.debug("batchSizes used: {}", batchSizes);
 }
 
-/**
- * Use the passed {@link FetchGroup} and calculate the right
- * {@link FetchType} for it
- */
-private static FetchType getFetchType(FetchGroup group) {
-int content = group.content();
-boolean headers = false;
-boolean body = false;
-boolean full = false;
-
-if ((content & FetchGroup.HEADERS) > 0) {
-headers = true;
-content -= FetchGroup.HEADERS;
-}
-if (group.getPartContentDescriptors().size() > 0) {
-full = true;
-}
-if ((content & FetchGroup.BODY_CONTENT) > 0) {
-body = true;
-content -= FetchGroup.BODY_CONTENT;
-}
-
-if ((content & FetchGroup.FULL_CONTENT) > 0) {
-full = true;
-content -= FetchGroup.FULL_CONTENT;
-}
-
-if ((content & FetchGroup.MIME_DESCRIPTOR) > 0) {
-// If we need the mimedescriptor we MAY need the full content later
-// too.
-// This gives us no other choice then request it
-full = true;
-content -= FetchGroup.MIME_DESCRIPTOR;
-}
-if (full || (body && headers)) {
-return FetchType.Full;
-} else if (body) {
-return FetchType.Body;
-} else if (headers) {
-return FetchType.Headers;
-} else {
-return FetchType.Metadata;
-}
-}
-
 @Override
 public boolean hasNext() {
 if (cursor.compareTo(to) > 0) {
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
new file mode 100644
index 000..d280172
--- /dev/null
+++ 

[james-project] 22/23: JAMES-2988 Restrict MessageView to the minimal one in GetResponse

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit b9af21bced5e8f1478a0e2bd4186dc48e320b7bf
Author: Benoit Tellier 
AuthorDate: Tue Nov 26 16:54:55 2019 +0700

JAMES-2988 Restrict MessageView to the minimal one in GetResponse
---
 .../jmap/draft/methods/GetMessagesMethod.java  |  19 +--
 .../message/view/MessageHeaderViewFactory.java |   4 +-
 .../message/view/MessageMetadataViewFactory.java   |   5 +-
 ...iewFactory.java => MetaMessageViewFactory.java} |  47 
 .../jmap/draft/methods/GetMessagesMethodTest.java  | 129 +++--
 5 files changed, 160 insertions(+), 44 deletions(-)

diff --git 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
index 966ec40..01c2c25 100644
--- 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
+++ 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
@@ -33,8 +33,9 @@ import org.apache.james.jmap.draft.model.GetMessagesResponse;
 import org.apache.james.jmap.draft.model.MessageProperties;
 import org.apache.james.jmap.draft.model.MessageProperties.HeaderProperty;
 import org.apache.james.jmap.draft.model.MethodCallId;
-import org.apache.james.jmap.draft.model.message.view.MessageFullView;
-import org.apache.james.jmap.draft.model.message.view.MessageFullViewFactory;
+import org.apache.james.jmap.draft.model.message.view.MessageView;
+import org.apache.james.jmap.draft.model.message.view.MessageViewFactory;
+import org.apache.james.jmap.draft.model.message.view.MetaMessageViewFactory;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -59,16 +60,16 @@ public class GetMessagesMethod implements Method {
 private static final Logger LOGGER = 
LoggerFactory.getLogger(GetMessagesMethod.class);
 private static final Method.Request.Name METHOD_NAME = 
Method.Request.name("getMessages");
 private static final Method.Response.Name RESPONSE_NAME = 
Method.Response.name("messages");
-private final MessageFullViewFactory messageFullViewFactory;
+private final MetaMessageViewFactory messageViewFactory;
 private final MessageIdManager messageIdManager;
 private final MetricFactory metricFactory;
 
 @Inject
 @VisibleForTesting GetMessagesMethod(
-MessageFullViewFactory messageFullViewFactory,
+MetaMessageViewFactory messageViewFactory,
 MessageIdManager messageIdManager,
 MetricFactory metricFactory) {
-this.messageFullViewFactory = messageFullViewFactory;
+this.messageViewFactory = messageViewFactory;
 this.messageIdManager = messageIdManager;
 this.metricFactory = metricFactory;
 }
@@ -123,6 +124,8 @@ public class GetMessagesMethod implements Method {
 
 try {
 MessageProperties.ReadProfile readProfile = 
getMessagesRequest.getProperties().computeReadLevel();
+MessageViewFactory factory = 
messageViewFactory.getFactory(readProfile);
+
 return GetMessagesResponse.builder()
 .messages(
 messageIdManager.getMessages(getMessagesRequest.getIds(), 
FetchGroup.FULL_CONTENT, mailboxSession)
@@ -132,7 +135,7 @@ public class GetMessagesMethod implements Method {
 .values()
 .stream()
 .filter(collection -> !collection.isEmpty())
-.flatMap(toMessageViews())
+.flatMap(toMessageViews(factory))
 .collect(Guavate.toImmutableList()))
 .expectedMessageIds(getMessagesRequest.getIds())
 .build();
@@ -141,10 +144,10 @@ public class GetMessagesMethod implements Method {
 }
 }
 
-private Function, Stream> 
toMessageViews() {
+private Function, Stream> 
toMessageViews(MessageViewFactory factory) {
 return messageResults -> {
 try {
-return 
Stream.of(messageFullViewFactory.fromMessageResults(messageResults));
+return Stream.of(factory.fromMessageResults(messageResults));
 } catch (Exception e) {
 LOGGER.error("Can not convert MessageResults to Message for 
{}", messageResults.iterator().next().getMessageId().serialize(), e);
 return Stream.of();
diff --git 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java
 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactory.java

[james-project] 10/23: JAMES-2989 POJOify PartContentDescriptor

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit a19703b64d7c0917c4777355abe6574acb442131
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 11:42:28 2019 +0700

JAMES-2989 POJOify PartContentDescriptor
---
 .../apache/james/mailbox/model/FetchGroupImpl.java |  4 +--
 .../apache/james/mailbox/model/MessageResult.java  | 28 --
 ...criptorImpl.java => PartContentDescriptor.java} | 34 +-
 .../apache/james/mailbox/store/ResultUtils.java|  7 +++--
 4 files changed, 32 insertions(+), 41 deletions(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
index 7cafe91..c9dd1c7 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
@@ -78,11 +78,11 @@ public class FetchGroupImpl implements 
MessageResult.FetchGroup {
 if (partContentDescriptors == null) {
 partContentDescriptors = new HashSet<>();
 }
-PartContentDescriptorImpl currentDescriptor = 
(PartContentDescriptorImpl) partContentDescriptors.stream()
+PartContentDescriptor currentDescriptor = 
partContentDescriptors.stream()
 .filter(descriptor -> path.equals(descriptor.path()))
 .findFirst()
 .orElseGet(() -> {
-PartContentDescriptorImpl result = new 
PartContentDescriptorImpl(path);
+PartContentDescriptor result = new PartContentDescriptor(path);
 partContentDescriptors.add(result);
 return result;
 });
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
index 7ed64f5..12a4ae8 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
@@ -123,34 +123,6 @@ public interface MessageResult extends 
Comparable {
  * there is no part content to be fetched
  */
 Set getPartContentDescriptors();
-
-/**
- * Describes the contents to be fetched for a mail part. All
- * implementations MUST implement equals. Two implementations are equal
- * if and only if their paths are equal.
- */
-interface PartContentDescriptor {
-/**
- * Contents to be fetched. Composed bitwise.
- * 
- * @return bitwise descripion
- * @see #MINIMAL
- * @see #MIME_DESCRIPTOR
- * @see #HEADERS
- * @see #FULL_CONTENT
- * @see #BODY_CONTENT
- * @see #MIME_HEADERS
- * @see #MIME_CONTENT
- */
-int content();
-
-/**
- * Path describing the part to be fetched.
- * 
- * @return path describing the part, not null
- */
-MimePath path();
-}
 }
 
 MimeDescriptor getMimeDescriptor() throws MailboxException;
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptorImpl.java
 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptor.java
similarity index 64%
rename from 
mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptorImpl.java
rename to 
mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptor.java
index f7a8ccd..38a949c 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptorImpl.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptor.java
@@ -21,15 +21,18 @@ package org.apache.james.mailbox.model;
 
 import java.util.Objects;
 
-import 
org.apache.james.mailbox.model.MessageResult.FetchGroup.PartContentDescriptor;
-
-public class PartContentDescriptorImpl implements PartContentDescriptor {
+/**
+ * Describes the contents to be fetched for a mail part. All
+ * implementations MUST implement equals. Two implementations are equal
+ * if and only if their paths are equal.
+ */
+public class PartContentDescriptor {
 
 private int content = 0;
 
 private final MimePath path;
 
-public PartContentDescriptorImpl(MimePath path) {
+public PartContentDescriptor(MimePath path) {
 this.path = path;
 }
 
@@ -37,12 +40,27 @@ public class PartContentDescriptorImpl implements 
PartContentDescriptor {
 this.content = this.content | content;
 }
 
-@Override
+/**
+ * Contents to be fetched. Composed bitwise.
+ *
+ * @return bitwise descripion
+ * @see 

[james-project] 06/23: JAMES-2989 POJOify MimePath

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 11424cc5fe78504ab510266c0d2a2c4d6537ef80
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 11:28:04 2019 +0700

JAMES-2989 POJOify MimePath
---
 .../apache/james/mailbox/model/FetchGroupImpl.java |  2 --
 .../apache/james/mailbox/model/MessageResult.java  | 14 
 .../model/{MimePathImpl.java => MimePath.java} | 25 --
 .../mailbox/model/PartContentDescriptorImpl.java   |  2 --
 .../{MimePathImplTest.java => MimePathTest.java}   | 10 -
 .../james/mailbox/store/MessageResultImpl.java |  1 +
 .../apache/james/mailbox/store/ResultUtils.java|  2 +-
 .../mailbox/store/StoreMessageResultIterator.java  |  1 +
 .../james/imap/processor/fetch/FetchProcessor.java |  5 ++---
 .../imap/processor/fetch/FetchResponseBuilder.java | 10 -
 10 files changed, 34 insertions(+), 38 deletions(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
index d3b8d62..7cafe91 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
@@ -22,8 +22,6 @@ package org.apache.james.mailbox.model;
 import java.util.HashSet;
 import java.util.Set;
 
-import org.apache.james.mailbox.model.MessageResult.MimePath;
-
 /**
  * Specifies a fetch group.
  */
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
index 2cb24c1..7ed64f5 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
@@ -266,19 +266,5 @@ public interface MessageResult extends 
Comparable {
  * Indicates if the message have attachments, regardless of loaded 
attachments.
  */
 boolean hasAttachments() throws MailboxException;
-
-/**
- * Describes a path within a multipart MIME message. All implementations
- * must implement equals. Two paths are equal if and only if each position
- * is identical.
- */
-interface MimePath {
 
-/**
- * Gets the positions of each part in the path.
- * 
- * @return part positions describing the path
- */
-int[] getPositions();
-}
 }
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePath.java
similarity index 73%
rename from 
mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
rename to mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePath.java
index 0548429..f77a5ea 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePath.java
@@ -23,23 +23,36 @@
 package org.apache.james.mailbox.model;
 
 import java.util.Arrays;
+import java.util.List;
 
-public class MimePathImpl implements MessageResult.MimePath {
+import com.github.steveash.guavate.Guavate;
+import com.google.common.base.Joiner;
+
+/**
+ * Describes a path within a multipart MIME message. All implementations
+ * must implement equals. Two paths are equal if and only if each position
+ * is identical.
+ */
+public final class MimePath {
 private final int[] positions;
 
-public MimePathImpl(int[] positions) {
-this.positions = positions;
+public MimePath(int[] positions) {
+this.positions = Arrays.copyOf(positions, positions.length);
 }
 
-@Override
+/**
+ * Gets the positions of each part in the path.
+ *
+ * @return part positions describing the path
+ */
 public int[] getPositions() {
 return positions;
 }
 
 @Override
 public final boolean equals(Object o) {
-if (o instanceof MimePathImpl) {
-MimePathImpl mimePath = (MimePathImpl) o;
+if (o instanceof MimePath) {
+MimePath mimePath = (MimePath) o;
 
 return Arrays.equals(this.positions, mimePath.positions);
 }
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptorImpl.java
 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptorImpl.java
index 6072220..e0761f4 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptorImpl.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptorImpl.java
@@ -22,8 +22,6 @@ package org.apache.james.mailbox.model;
 import java.util.Objects;
 
 import 

[james-project] 11/23: JAMES-2989 StoreMailboxMessageResultIteratorTest should use FetchGroupImpl

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit ca808dc494153233d2f1e083770d0c719d133988
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 11:44:02 2019 +0700

JAMES-2989 StoreMailboxMessageResultIteratorTest should use FetchGroupImpl
---
 .../StoreMailboxMessageResultIteratorTest.java | 24 +-
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
index 1e4a787..a41d703 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
@@ -23,13 +23,11 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Optional;
-import java.util.Set;
 
 import javax.mail.Flags;
 import javax.mail.util.SharedByteArrayInputStream;
@@ -37,11 +35,11 @@ import javax.mail.util.SharedByteArrayInputStream;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.ModSeq;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.FetchGroupImpl;
 import org.apache.james.mailbox.model.Mailbox;
 import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
-import org.apache.james.mailbox.model.MessageResult.FetchGroup;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.mail.MessageMapper;
@@ -55,18 +53,6 @@ import com.google.common.collect.Iterables;
 
 public class StoreMailboxMessageResultIteratorTest {
 
-private final class TestFetchGroup implements FetchGroup {
-@Override
-public Set getPartContentDescriptors() {
-return new HashSet<>();
-}
-
-@Override
-public int content() {
-return FetchGroup.MINIMAL;
-}
-}
-
 private final class TestMessageMapper implements MessageMapper {
 private final MessageRange messageRange;
 
@@ -203,7 +189,7 @@ public class StoreMailboxMessageResultIteratorTest {
 public void testBatching() {
 MessageRange range = MessageRange.range(MessageUid.of(1), 
MessageUid.of(10));
 BatchSizes batchSize = BatchSizes.uniqueBatchSize(3);
-StoreMessageResultIterator it = new StoreMessageResultIterator(new 
TestMessageMapper(MessageRange.all()), null, range, batchSize, new 
TestFetchGroup());
+StoreMessageResultIterator it = new StoreMessageResultIterator(new 
TestMessageMapper(MessageRange.all()), null, range, batchSize, 
FetchGroupImpl.MINIMAL);
 
 assertThat(it).toIterable()
 .extracting(input -> input.getUid().asLong())
@@ -214,7 +200,7 @@ public class StoreMailboxMessageResultIteratorTest {
 public void nextShouldReturnFirstElement() {
 MessageRange range = MessageUid.of(1).toRange();
 BatchSizes batchSize = BatchSizes.uniqueBatchSize(42);
-StoreMessageResultIterator iterator = new 
StoreMessageResultIterator(new TestMessageMapper(range), null, range, 
batchSize, new TestFetchGroup());
+StoreMessageResultIterator iterator = new 
StoreMessageResultIterator(new TestMessageMapper(range), null, range, 
batchSize, FetchGroupImpl.MINIMAL);
 assertThat(iterator.next()).isNotNull();
 }
 
@@ -223,7 +209,7 @@ public class StoreMailboxMessageResultIteratorTest {
 MessageRange messages = MessageUid.of(1).toRange();
 MessageRange findRange = MessageUid.of(2).toRange();
 BatchSizes batchSize = BatchSizes.uniqueBatchSize(42);
-StoreMessageResultIterator iterator = new 
StoreMessageResultIterator(new TestMessageMapper(messages), null, findRange, 
batchSize, new TestFetchGroup());
+StoreMessageResultIterator iterator = new 
StoreMessageResultIterator(new TestMessageMapper(messages), null, findRange, 
batchSize, FetchGroupImpl.MINIMAL);
 iterator.next();
 }
 
@@ -232,7 +218,7 @@ public class StoreMailboxMessageResultIteratorTest {
 MessageRange messages = MessageUid.of(1).toRange();
 MessageRange findRange = MessageUid.of(2).toRange();
 BatchSizes batchSize = BatchSizes.uniqueBatchSize(42);
-StoreMessageResultIterator iterator = new 
StoreMessageResultIterator(new TestMessageMapper(messages), null, findRange, 
batchSize, new 

[james-project] 08/23: JAMES-2989 POP3 should rely on mailbox-api fetch groups

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 844c0adbe7d6941a0c3ce94f76c89bb86ef3bc1d
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 11:37:24 2019 +0700

JAMES-2989 POP3 should rely on mailbox-api fetch groups
---
 .../james/pop3server/mailbox/MailboxAdapter.java   | 48 +++---
 1 file changed, 5 insertions(+), 43 deletions(-)

diff --git 
a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
 
b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
index b6ca3b2..996e3b3 100644
--- 
a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
+++ 
b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/mailbox/MailboxAdapter.java
@@ -22,10 +22,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 import java.util.stream.Collectors;
 
 import org.apache.james.mailbox.MailboxManager;
@@ -33,6 +31,7 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.FetchGroupImpl;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.MessageResult.FetchGroup;
@@ -43,47 +42,10 @@ import com.github.steveash.guavate.Guavate;
 import com.google.common.collect.ImmutableList;
 
 public class MailboxAdapter implements Mailbox {
-
-private abstract static class POP3FetchGroup implements FetchGroup {
-@Override
-public Set getPartContentDescriptors() {
-return new HashSet<>();
-}
-}
-
-private static final FetchGroup FULL_GROUP = new POP3FetchGroup() {
-
-@Override
-public int content() {
-return BODY_CONTENT | HEADERS;
-}
-
-};
-
-private static final FetchGroup BODY_GROUP = new POP3FetchGroup() {
-
-@Override
-public int content() {
-return BODY_CONTENT;
-}
-
-};
-
-private static final FetchGroup HEADERS_GROUP = new POP3FetchGroup() {
-
-@Override
-public int content() {
-return HEADERS;
-}
-};
-
-private static final FetchGroup METADATA_GROUP = new POP3FetchGroup() {
-
-@Override
-public int content() {
-return MINIMAL;
-}
-};
+private static final FetchGroup FULL_GROUP = FetchGroupImpl.FULL_CONTENT;
+private static final FetchGroup BODY_GROUP = FetchGroupImpl.BODY_CONTENT;
+private static final FetchGroup HEADERS_GROUP = FetchGroupImpl.HEADERS;
+private static final FetchGroup METADATA_GROUP = FetchGroupImpl.MINIMAL;
 
 private final MessageManager manager;
 private final MailboxSession session;


-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[james-project] 19/23: JAMES-2988 Full unit test coverage for FetchGroup generation in IMAP

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 575cac3b4a2d1e5814fcf6f46512c92bc9ed5928
Author: Benoit Tellier 
AuthorDate: Wed Nov 27 10:08:53 2019 +0700

JAMES-2988 Full unit test coverage for FetchGroup generation in IMAP
---
 protocols/imap/pom.xml |  5 ++
 .../apache/james/imap/api/message/FetchData.java   | 33 ++---
 .../imap/processor/fetch/FetchDataConverter.java   | 83 ++
 .../james/imap/processor/fetch/FetchProcessor.java | 57 +--
 .../processor/fetch/FetchDataConverterTest.java| 79 
 5 files changed, 190 insertions(+), 67 deletions(-)

diff --git a/protocols/imap/pom.xml b/protocols/imap/pom.xml
index 000e30b..bf957e0 100644
--- a/protocols/imap/pom.xml
+++ b/protocols/imap/pom.xml
@@ -90,6 +90,11 @@
 commons-lang3
 
 
+org.junit.jupiter
+junit-jupiter-params
+test
+
+
 org.mockito
 mockito-core
 test
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/api/message/FetchData.java 
b/protocols/imap/src/main/java/org/apache/james/imap/api/message/FetchData.java
index 7e836b7..bc5095d 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/api/message/FetchData.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/api/message/FetchData.java
@@ -58,56 +58,63 @@ public class FetchData {
 return body;
 }
 
-public void setBody(boolean body) {
+public FetchData setBody(boolean body) {
 this.body = body;
+return this;
 }
 
 public boolean isBodyStructure() {
 return bodyStructure;
 }
 
-public void setBodyStructure(boolean bodyStructure) {
+public FetchData setBodyStructure(boolean bodyStructure) {
 this.bodyStructure = bodyStructure;
+return this;
 }
 
 public boolean isEnvelope() {
 return envelope;
 }
 
-public void setEnvelope(boolean envelope) {
+public FetchData setEnvelope(boolean envelope) {
 this.envelope = envelope;
+return this;
 }
 
 public boolean isFlags() {
 return flags;
 }
 
-public void setFlags(boolean flags) {
+public FetchData setFlags(boolean flags) {
 this.flags = flags;
+return this;
 }
 
 public boolean isInternalDate() {
 return internalDate;
 }
 
-public void setInternalDate(boolean internalDate) {
+public FetchData setInternalDate(boolean internalDate) {
 this.internalDate = internalDate;
+return this;
 }
 
 public boolean isSize() {
 return size;
 }
 
-public void setSize(boolean size) {
+public FetchData setSize(boolean size) {
 this.size = size;
+return this;
 }
 
 public boolean isUid() {
 return uid;
 }
 
-public void setUid(boolean uid) {
+public FetchData setUid(boolean uid) {
 this.uid = uid;
+return this;
 }
 
 public boolean isSetSeen() {
@@ -119,13 +126,15 @@ public class FetchData {
 return modSeq;
 }
 
-public void setModSeq(boolean modSeq) {
+public FetchData setModSeq(boolean modSeq) {
 this.modSeq = modSeq;
+return this;
 }
 
-public void setChangedSince(long changedSince) {
+public FetchData setChangedSince(long changedSince) {
 this.changedSince = changedSince;
 this.modSeq = true;
+return this;
 }
 
 public long getChangedSince() {
@@ -137,8 +146,9 @@ public class FetchData {
  * 
  * @param vanished
  */
-public void setVanished(boolean vanished) {
+public FetchData setVanished(boolean vanished) {
 this.vanished = vanished;
+return this;
 }
 
 /**
@@ -150,11 +160,12 @@ public class FetchData {
 return vanished;
 }
 
-public void add(BodyFetchElement element, boolean peek) {
+public FetchData add(BodyFetchElement element, boolean peek) {
 if (!peek) {
 setSeen = true;
 }
 bodyElements.add(element);
+return this;
 }
 
 public int hashCode() {
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchDataConverter.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchDataConverter.java
new file mode 100644
index 000..54d4b5e
--- /dev/null
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchDataConverter.java
@@ -0,0 +1,83 @@
+/
+ * 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*
+ * 

[james-project] 09/23: JAMES-2989 Mailbox copier should rely on mailbox-api fetch groups

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit f608394a91b888157916143f1d48a1ad0012a1b3
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 11:39:09 2019 +0700

JAMES-2989 Mailbox copier should rely on mailbox-api fetch groups
---
 .../mailbox/tools/copier/MailboxCopierImpl.java  | 20 ++--
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git 
a/mailbox/tools/copier/src/main/java/org/apache/james/mailbox/tools/copier/MailboxCopierImpl.java
 
b/mailbox/tools/copier/src/main/java/org/apache/james/mailbox/tools/copier/MailboxCopierImpl.java
index 4f04f4b..5955469 100644
--- 
a/mailbox/tools/copier/src/main/java/org/apache/james/mailbox/tools/copier/MailboxCopierImpl.java
+++ 
b/mailbox/tools/copier/src/main/java/org/apache/james/mailbox/tools/copier/MailboxCopierImpl.java
@@ -20,10 +20,8 @@ package org.apache.james.mailbox.tools.copier;
 
 import java.io.IOException;
 import java.util.Calendar;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
 
 import javax.mail.Flags.Flag;
 
@@ -34,10 +32,10 @@ import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.copier.MailboxCopier;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxExistsException;
+import org.apache.james.mailbox.model.FetchGroupImpl;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MessageResult;
-import org.apache.james.mailbox.model.MessageResult.FetchGroup;
 import org.apache.james.mailbox.store.streaming.InputStreamContent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,20 +47,6 @@ import org.slf4j.LoggerFactory;
 public class MailboxCopierImpl implements MailboxCopier {
 private static final Logger LOGGER = 
LoggerFactory.getLogger(MailboxCopierImpl.class.getName());
 
-private static final FetchGroup GROUP = new FetchGroup() {
-
-@Override
-public int content() {
-return FULL_CONTENT;
-}
-
-@Override
-public Set getPartContentDescriptors() {
-return new HashSet<>();
-}
-
-};
-
 @Override
 public void copyMailboxes(MailboxManager srcMailboxManager, MailboxManager 
dstMailboxManager) throws MailboxException, IOException {
 
@@ -115,7 +99,7 @@ public class MailboxCopierImpl implements MailboxCopier {
 MessageManager dstMessageManager = 
dstMailboxManager.getMailbox(mailboxPath, dstMailboxSession);
 
 int j = 0;
-Iterator messageResultIterator = 
srcMessageManager.getMessages(MessageRange.all(), GROUP, srcMailboxSession);
+Iterator messageResultIterator = 
srcMessageManager.getMessages(MessageRange.all(), FetchGroupImpl.FULL_CONTENT, 
srcMailboxSession);
 
 while (messageResultIterator.hasNext()) {
 


-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[james-project] 23/23: JAMES-2988 Use the smallest fetch group possible upon GetMessages

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit e8c2f63ac4ce7414db349cee066a2ea00511d23c
Author: Benoit Tellier 
AuthorDate: Wed Nov 27 03:16:04 2019 +0100

JAMES-2988 Use the smallest fetch group possible upon GetMessages
---
 .../james/jmap/draft/methods/GetMessagesMethod.java  |  3 +--
 .../apache/james/jmap/draft/model/MessageProperties.java | 16 
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
index 01c2c25..f4a8315 100644
--- 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
+++ 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/methods/GetMessagesMethod.java
@@ -39,7 +39,6 @@ import 
org.apache.james.jmap.draft.model.message.view.MetaMessageViewFactory;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.FetchGroup;
 import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.util.MDCBuilder;
@@ -128,7 +127,7 @@ public class GetMessagesMethod implements Method {
 
 return GetMessagesResponse.builder()
 .messages(
-messageIdManager.getMessages(getMessagesRequest.getIds(), 
FetchGroup.FULL_CONTENT, mailboxSession)
+messageIdManager.getMessages(getMessagesRequest.getIds(), 
readProfile.getFetchGroup(), mailboxSession)
 .stream()
 
.collect(Guavate.toImmutableListMultimap(MessageResult::getMessageId))
 .asMap()
diff --git 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/MessageProperties.java
 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/MessageProperties.java
index b2cadee..12fa16a 100644
--- 
a/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/MessageProperties.java
+++ 
b/server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/model/MessageProperties.java
@@ -24,6 +24,8 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.stream.Stream;
 
+import org.apache.james.mailbox.model.FetchGroup;
+
 import com.github.steveash.guavate.Guavate;
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Preconditions;
@@ -213,9 +215,9 @@ public class MessageProperties {
 }
 
 public enum ReadProfile {
-Metadata(0),
-Header(1),
-Full(2);
+Metadata(0, FetchGroup.MINIMAL),
+Header(1, FetchGroup.HEADERS),
+Full(2, FetchGroup.FULL_CONTENT);
 
 static ReadProfile combine(ReadProfile readProfile1, ReadProfile 
readProfile2) {
 if (readProfile1.priority > readProfile2.priority) {
@@ -225,9 +227,15 @@ public class MessageProperties {
 }
 
 private final int priority;
+private final FetchGroup fetchGroup;
 
-ReadProfile(int priority) {
+ReadProfile(int priority, FetchGroup fetchGroup) {
 this.priority = priority;
+this.fetchGroup = fetchGroup;
+}
+
+public FetchGroup getFetchGroup() {
+return fetchGroup;
 }
 }
 


-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[james-project] 21/23: JAMES-2988 Fix FetchGroup javadoc

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 77d5ad0bef96704c47bc4d4880c9f156f9f8f724
Author: Benoit Tellier 
AuthorDate: Wed Nov 27 10:25:05 2019 +0700

JAMES-2988 Fix FetchGroup javadoc
---
 .../api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java| 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
index 7ff2d70..7923774 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
@@ -67,7 +67,7 @@ public class FetchGroup {
 /**
  * Contents to be fetched. Composed bitwise.
  *
- * @return bitwise description
+ * @return masks to be used for bitewise operations.
  * @see #MINIMAL_MASK
  * @see #MIME_DESCRIPTOR_MASK
  * @see #HEADERS_MASK


-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[james-project] 07/23: JAMES-2989 Remove unused PartContentDescriptorImpl constructor

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 9401010c52d161751f66d6d5d243b493ebdea545
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 11:31:19 2019 +0700

JAMES-2989 Remove unused PartContentDescriptorImpl constructor
---
 .../org/apache/james/mailbox/model/PartContentDescriptorImpl.java  | 7 ---
 1 file changed, 7 deletions(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptorImpl.java
 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptorImpl.java
index e0761f4..f7a8ccd 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptorImpl.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptorImpl.java
@@ -30,13 +30,6 @@ public class PartContentDescriptorImpl implements 
PartContentDescriptor {
 private final MimePath path;
 
 public PartContentDescriptorImpl(MimePath path) {
-super();
-this.path = path;
-}
-
-public PartContentDescriptorImpl(int content, MimePath path) {
-super();
-this.content = content;
 this.path = path;
 }
 


-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[james-project] 13/23: JAMES-2989 FetchGroup & PartContentDescriptor should be immutable

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 19940b33a80d5e2d32d7de4712bf7f07261ffa63
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 12:49:05 2019 +0700

JAMES-2989 FetchGroup & PartContentDescriptor should be immutable
---
 .../org/apache/james/mailbox/model/FetchGroup.java | 78 ++
 .../james/mailbox/model/PartContentDescriptor.java | 13 ++--
 .../apache/james/mailbox/model/FetchGroupTest.java | 75 +
 .../james/imap/processor/fetch/FetchProcessor.java | 20 +++---
 4 files changed, 145 insertions(+), 41 deletions(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
index 40b5fae..10f9657 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
@@ -19,8 +19,13 @@
 
 package org.apache.james.mailbox.model;
 
-import java.util.HashSet;
+import java.util.Objects;
 import java.util.Set;
+import java.util.stream.Stream;
+
+import com.github.steveash.guavate.Guavate;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableSet;
 
 /**
  * Indicates the results fetched.
@@ -43,15 +48,16 @@ public class FetchGroup {
 public static final FetchGroup FULL_CONTENT = new 
FetchGroup(FULL_CONTENT_MASK);
 public static final FetchGroup BODY_CONTENT = new 
FetchGroup(BODY_CONTENT_MASK);
 
-private int content;
-
-private Set partContentDescriptors;
+private final int content;
+private final ImmutableSet partContentDescriptors;
 
-private FetchGroup(int content) {
-this(content, new HashSet<>());
+@VisibleForTesting
+FetchGroup(int content) {
+this(content, ImmutableSet.of());
 }
 
-private FetchGroup(int content, Set 
partContentDescriptors) {
+@VisibleForTesting
+FetchGroup(int content, ImmutableSet 
partContentDescriptors) {
 this.content = content;
 this.partContentDescriptors = partContentDescriptors;
 }
@@ -72,12 +78,8 @@ public class FetchGroup {
 return content;
 }
 
-public void or(int content) {
-this.content = this.content | content;
-}
-
-public String toString() {
-return "Fetch " + content;
+public FetchGroup or(int content) {
+ return new FetchGroup(this.content | content, partContentDescriptors);
 }
 
 /**
@@ -99,19 +101,43 @@ public class FetchGroup {
  * @param content
  *bitwise content constant
  */
-public void addPartContent(MimePath path, int content) {
-if (partContentDescriptors == null) {
-partContentDescriptors = new HashSet<>();
+public FetchGroup addPartContent(MimePath path, int content) {
+PartContentDescriptor newContent = 
retrieveUpdatedPartContentDescriptor(path, content);
+
+return new FetchGroup(this.content,
+Stream.concat(
+partContentDescriptors.stream()
+.filter(descriptor -> !descriptor.path().equals(path)),
+Stream.of(newContent))
+.collect(Guavate.toImmutableSet()));
+}
+
+private PartContentDescriptor 
retrieveUpdatedPartContentDescriptor(MimePath path, int content) {
+return partContentDescriptors.stream()
+.filter(descriptor -> path.equals(descriptor.path()))
+.findFirst()
+.orElse(new PartContentDescriptor(path))
+.or(content);
+}
+
+@Override
+public String toString() {
+return "Fetch " + content;
+}
+
+@Override
+public final boolean equals(Object o) {
+if (o instanceof FetchGroup) {
+FetchGroup that = (FetchGroup) o;
+
+return Objects.equals(this.content, that.content)
+&& Objects.equals(this.partContentDescriptors, 
that.partContentDescriptors);
 }
-PartContentDescriptor currentDescriptor = 
partContentDescriptors.stream()
-.filter(descriptor -> path.equals(descriptor.path()))
-.findFirst()
-.orElseGet(() -> {
-PartContentDescriptor result = new PartContentDescriptor(path);
-partContentDescriptors.add(result);
-return result;
-});
-
-currentDescriptor.or(content);
+return false;
+}
+
+@Override
+public final int hashCode() {
+return Objects.hash(content, partContentDescriptors);
 }
 }
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptor.java
 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/PartContentDescriptor.java
index 2a1b815..158a348 100644
--- 

[james-project] 05/23: JAMES-2989 Rework toString for MimePathImpl

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 95cb9dcf463e78782a6fd07d118bfb60d1ed8fc7
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 11:22:57 2019 +0700

JAMES-2989 Rework toString for MimePathImpl
---
 .../apache/james/mailbox/model/MimePathImpl.java   | 17 
 .../james/mailbox/model/MimePathImplTest.java  | 23 ++
 2 files changed, 27 insertions(+), 13 deletions(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
index 66c5fcf..0548429 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
@@ -28,7 +28,6 @@ public class MimePathImpl implements MessageResult.MimePath {
 private final int[] positions;
 
 public MimePathImpl(int[] positions) {
-super();
 this.positions = positions;
 }
 
@@ -52,17 +51,9 @@ public class MimePathImpl implements MessageResult.MimePath {
 return Arrays.hashCode(positions);
 }
 
-public String toString() {
-final StringBuilder builder = new StringBuilder("MIMEPath:");
-boolean isFirst = false;
-for (int position : positions) {
-if (isFirst) {
-isFirst = false;
-} else {
-builder.append('.');
-}
-builder.append(position);
-}
-return builder.toString();
+@Override
+public final String toString() {
+return "MIMEPath:"
++ Arrays.toString(positions);
 }
 }
\ No newline at end of file
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathImplTest.java
 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathImplTest.java
index 0b1caf9..ff649d2 100644
--- 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathImplTest.java
+++ 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MimePathImplTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.mailbox.model;
 
+import static org.assertj.core.api.Java6Assertions.assertThat;
+
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
@@ -29,4 +31,25 @@ class MimePathImplTest {
 EqualsVerifier.forClass(MimePathImpl.class)
 .verify();
 }
+
+@Test
+void toStringWhenEmpty() {
+int[] empty = {};
+assertThat(new MimePathImpl(empty).toString())
+.isEqualTo("MIMEPath:[]");
+}
+
+@Test
+void toStringWhenSingle() {
+int[] single = {1};
+assertThat(new MimePathImpl(single).toString())
+.isEqualTo("MIMEPath:[1]");
+}
+
+@Test
+void toStringWhenMany() {
+int[] many = {1, 2, 3};
+assertThat(new MimePathImpl(many).toString())
+.isEqualTo("MIMEPath:[1, 2, 3]");
+}
 }
\ No newline at end of file


-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[james-project] 02/23: JAMES-2989 FetchGroupImpl constructors should be private

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit a311e9e5caebece4157052c80e2368b3f9f5c7fb
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 11:07:18 2019 +0700

JAMES-2989 FetchGroupImpl constructors should be private

Encourage using base constants instead.
---
 .../org/apache/james/mailbox/model/FetchGroupImpl.java | 18 +++---
 .../james/imap/processor/fetch/FetchProcessor.java |  2 +-
 .../mailets/delivery/MailboxAppenderTest.java  |  9 -
 3 files changed, 12 insertions(+), 17 deletions(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
index c5d0430..d3b8d62 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroupImpl.java
@@ -29,27 +29,23 @@ import 
org.apache.james.mailbox.model.MessageResult.MimePath;
  */
 public class FetchGroupImpl implements MessageResult.FetchGroup {
 
-public static final MessageResult.FetchGroup MINIMAL = new 
FetchGroupImpl(MessageResult.FetchGroup.MINIMAL);
+public static final FetchGroupImpl MINIMAL = new 
FetchGroupImpl(MessageResult.FetchGroup.MINIMAL);
 
-public static final MessageResult.FetchGroup HEADERS = new 
FetchGroupImpl(MessageResult.FetchGroup.HEADERS);
+public static final FetchGroupImpl HEADERS = new 
FetchGroupImpl(MessageResult.FetchGroup.HEADERS);
 
-public static final MessageResult.FetchGroup FULL_CONTENT = new 
FetchGroupImpl(MessageResult.FetchGroup.FULL_CONTENT);
+public static final FetchGroupImpl FULL_CONTENT = new 
FetchGroupImpl(MessageResult.FetchGroup.FULL_CONTENT);
 
-public static final MessageResult.FetchGroup BODY_CONTENT = new 
FetchGroupImpl(MessageResult.FetchGroup.BODY_CONTENT);
+public static final FetchGroupImpl BODY_CONTENT = new 
FetchGroupImpl(MessageResult.FetchGroup.BODY_CONTENT);
 
-private int content = MessageResult.FetchGroup.MINIMAL;
+private int content;
 
 private Set partContentDescriptors;
 
-public FetchGroupImpl() {
-this(0, new HashSet<>());
-}
-
-public FetchGroupImpl(int content) {
+private FetchGroupImpl(int content) {
 this(content, new HashSet<>());
 }
 
-public FetchGroupImpl(int content, Set 
partContentDescriptors) {
+private FetchGroupImpl(int content, Set 
partContentDescriptors) {
 this.content = content;
 this.partContentDescriptors = partContentDescriptors;
 }
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
index d35b7bd..a75fd30 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
@@ -186,7 +186,7 @@ public class FetchProcessor extends 
AbstractMailboxProcessor {
 }
 
 protected FetchGroup getFetchGroup(FetchData fetch) {
-FetchGroupImpl result = new FetchGroupImpl();
+FetchGroupImpl result = FetchGroupImpl.MINIMAL;
 
 if (fetch.isEnvelope()) {
 result.or(FetchGroup.HEADERS);
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/MailboxAppenderTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/MailboxAppenderTest.java
index 5c1f626..58102dd 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/MailboxAppenderTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/MailboxAppenderTest.java
@@ -35,7 +35,6 @@ import 
org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
 import org.apache.james.mailbox.model.FetchGroupImpl;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageRange;
-import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.MessageResultIterator;
 import org.apache.james.util.concurrency.ConcurrentTestRunner;
 import org.junit.jupiter.api.BeforeEach;
@@ -72,7 +71,7 @@ public class MailboxAppenderTest {
 testee.append(mimeMessage, USER, FOLDER);
 
 MessageResultIterator messages = 
mailboxManager.getMailbox(MailboxPath.forUser(USER, FOLDER), session)
-.getMessages(MessageRange.all(), new 
FetchGroupImpl(MessageResult.FetchGroup.FULL_CONTENT), session);
+.getMessages(MessageRange.all(), FetchGroupImpl.FULL_CONTENT, 
session);
 
 assertThat(messages).toIterable()
 .hasSize(1);
@@ -86,7 +85,7 @@ public class MailboxAppenderTest {
 

[james-project] branch master updated (970357f -> e8c2f63)

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


from 970357f  [Refactoring] Correct ModSeq mailbox json serializer
 new 3d422bf  JAMES-2989 StoreMessageIdManager should comply to fetchGroup 
read level
 new a311e9e  JAMES-2989 FetchGroupImpl constructors should be private
 new 6ee07f3  JAMES-2989 MimePathImpl class should be located in mailbox-api
 new b4d98b1  JAMES-2989 Rework equals & hashcode for MimePathImpl
 new 95cb9dc  JAMES-2989 Rework toString for MimePathImpl
 new 11424cc  JAMES-2989 POJOify MimePath
 new 9401010  JAMES-2989 Remove unused PartContentDescriptorImpl constructor
 new 844c0ad  JAMES-2989 POP3 should rely on mailbox-api fetch groups
 new f608394  JAMES-2989 Mailbox copier should rely on mailbox-api fetch 
groups
 new a19703b  JAMES-2989 POJOify PartContentDescriptor
 new ca808dc  JAMES-2989 StoreMailboxMessageResultIteratorTest should use 
FetchGroupImpl
 new 4a44dc8  JAMES-2989 POJOify FetchGroup
 new 19940b3  JAMES-2989 FetchGroup & PartContentDescriptor should be 
immutable
 new 9e5ddfb  JAMES-2989 Tests for FetchGroupConverter
 new c80a852  JAMES-2989 Little refactor for FetchGroupConverter
 new 6c9350f  JAMES-2989 POJOify  mailbox-api headers
 new b0dc0b3  JAMES-2988 Move bitewise logic with FetchGroup models
 new be28f6e  JAMES-2989 Rework toString for MimePathImpl
 new 575cac3  JAMES-2988 Full unit test coverage for FetchGroup generation 
in IMAP
 new 362bc72  s/JAMES-2988 FetchGroup::or/FetchGroup::with
 new 77d5ad0  JAMES-2988 Fix FetchGroup javadoc
 new b9af21b  JAMES-2988 Restrict MessageView to the minimal one in 
GetResponse
 new e8c2f63  JAMES-2988 Use the smallest fetch group possible upon 
GetMessages

The 23 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../listeners/SetCustomFlagOnBigMessagesTest.java  |   6 +-
 .../org/apache/james/mailbox/MessageIdManager.java |   2 +-
 .../org/apache/james/mailbox/MessageManager.java   |   2 +-
 .../org/apache/james/mailbox/model/FetchGroup.java | 156 +
 .../apache/james/mailbox/model/FetchGroupImpl.java |  98 -
 .../org/apache/james/mailbox/model/Header.java}|  23 ++-
 .../org/apache/james/mailbox/model/Headers.java|   2 -
 .../apache/james/mailbox/model/MessageResult.java  | 113 ---
 .../model/{MessageIdDto.java => MimePath.java} |  61 
 ...criptorImpl.java => PartContentDescriptor.java} |  62 +---
 .../apache/james/mailbox/MailboxManagerTest.java   |  10 +-
 .../apache/james/mailbox/model/FetchGroupTest.java | 131 +
 .../apache/james/mailbox/model/MimePathTest.java   |  37 +++--
 .../PartContentDescriptorTest.java}|  36 ++---
 .../james/mailbox/backup/DefaultMailboxBackup.java |   4 +-
 .../james/vault/DeletedMessageVaultHookTest.java   |   4 +-
 .../james/mailbox/store/LazyMimeDescriptor.java|   2 +-
 .../james/mailbox/store/MessageResultImpl.java |  13 +-
 .../james/mailbox/store/MimeDescriptorImpl.java|  22 +--
 .../apache/james/mailbox/store/ResultUtils.java|  64 -
 .../james/mailbox/store/StoreBlobManager.java  |   4 +-
 .../james/mailbox/store/StoreMessageIdManager.java |  10 +-
 .../james/mailbox/store/StoreMessageManager.java   |   2 +-
 .../mailbox/store/StoreMessageResultIterator.java  |  53 +--
 .../mailbox/store/mail/FetchGroupConverter.java|  62 
 .../mailbox/store/search/MessageSearches.java  |   2 +-
 .../comparator/AbstractHeaderComparator.java   |   2 +-
 .../mailbox/store/streaming/FullByteContent.java   |   5 +-
 .../store/streaming/PartContentBuilder.java|  16 +--
 .../store/AbstractCombinationManagerTest.java  |  45 +++---
 .../AbstractMessageIdManagerSideEffectTest.java|  18 +--
 .../store/AbstractMessageIdManagerStorageTest.java | 102 +++---
 .../PartContentBuilderComplexMultipartTest.java|   4 +-
 ...PartContentBuilderMultipartAlternativeTest.java |   4 +-
 .../james/mailbox/store/StoreBlobManagerTest.java  |  18 +--
 .../StoreMailboxMessageResultIteratorTest.java |  24 +---
 .../store/mail/FetchGroupConverterTest.java| 121 
 .../mailbox/tools/copier/MailboxCopierImpl.java|  20 +--
 protocols/imap/pom.xml |   5 +
 .../apache/james/imap/api/message/FetchData.java   |  33 +++--
 .../imap/processor/AbstractMailboxProcessor.java   |   4 +-
 .../james/imap/processor/SearchProcessor.java  |   4 +-
 .../james/imap/processor/StoreProcessor.java   |  13 +-
 .../imap/processor/fetch/EnvelopeBuilder.java  |   6 +-
 

[james-project] 16/23: JAMES-2989 POJOify mailbox-api headers

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 6c9350f78b69201264a1b70c2d4e0313756e76d8
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 13:17:50 2019 +0700

JAMES-2989 POJOify  mailbox-api headers
---
 .../org/apache/james/mailbox/model/Header.java}| 23 ++---
 .../org/apache/james/mailbox/model/Headers.java|  1 -
 .../apache/james/mailbox/model/MessageResult.java  | 20 
 .../james/mailbox/store/LazyMimeDescriptor.java|  2 +-
 .../james/mailbox/store/MessageResultImpl.java |  1 +
 .../james/mailbox/store/MimeDescriptorImpl.java| 22 -
 .../apache/james/mailbox/store/ResultUtils.java| 13 +++---
 .../mailbox/store/StoreMessageResultIterator.java  |  1 +
 .../mailbox/store/search/MessageSearches.java  |  2 +-
 .../comparator/AbstractHeaderComparator.java   |  2 +-
 .../mailbox/store/streaming/FullByteContent.java   |  5 +-
 .../store/streaming/PartContentBuilder.java| 16 +++
 .../PartContentBuilderComplexMultipartTest.java|  4 +-
 ...PartContentBuilderMultipartAlternativeTest.java |  4 +-
 .../imap/processor/fetch/EnvelopeBuilder.java  |  6 +--
 .../imap/processor/fetch/FetchResponseBuilder.java | 25 +-
 .../imap/processor/fetch/HeaderBodyElement.java|  6 +--
 .../imap/processor/fetch/MessageResultUtils.java   | 46 +-
 .../imap/processor/fetch/MimeBodyElement.java  | 12 ++---
 .../fetch/MailboxMessageResultUtilsTest.java   | 54 --
 .../james/jmap/draft/methods/ReferenceUpdater.java |  2 +-
 21 files changed, 109 insertions(+), 158 deletions(-)

diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultHeader.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Header.java
similarity index 84%
rename from 
mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultHeader.java
rename to mailbox/api/src/main/java/org/apache/james/mailbox/model/Header.java
index f1424f2..71b2e4c 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultHeader.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Header.java
@@ -20,32 +20,41 @@
 /**
  * 
  */
-package org.apache.james.mailbox.store;
+package org.apache.james.mailbox.model;
 
 import static java.nio.charset.StandardCharsets.US_ASCII;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 
-import org.apache.james.mailbox.model.MessageResult;
-
-public final class ResultHeader implements MessageResult.Header {
+/**
+ * A header.
+ */
+public final class Header implements Content {
 private final String name;
 private final String value;
 private final long size;
 
-public ResultHeader(String name, String value) {
+public Header(String name, String value) {
 this.name = name;
 this.value = value;
 this.size = name.length() + value.length() + 2;
 }
 
-@Override
+/**
+ * Gets the name of this header.
+ *
+ * @return name of this header
+ */
 public String getName() {
 return name;
 }
 
-@Override
+/**
+ * Gets the (unparsed) value of this header.
+ *
+ * @return value of this header
+ */
 public String getValue() {
 return value;
 }
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Headers.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Headers.java
index 52b959b..16e715d 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Headers.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Headers.java
@@ -22,7 +22,6 @@ package org.apache.james.mailbox.model;
 import java.util.Iterator;
 
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MessageResult.Header;
 
 public interface Headers extends Content {
 /**
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
index c85df56..82894d6 100644
--- 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
+++ 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
@@ -101,26 +101,6 @@ public interface MessageResult extends 
Comparable {
 Iterator iterateMimeHeaders(MimePath path) throws MailboxException;
 
 /**
- * A header.
- */
-interface Header extends Content {
-
-/**
- * Gets the name of this header.
- * 
- * @return name of this header
- */
-String getName();
-
-/**
- * Gets the (unparsed) value of this header.
- * 
- * @return value of this header
- */
-String getValue();
-}
-
-/**
  * Gets the full message including headers and body. The 

[james-project] 03/23: JAMES-2989 MimePathImpl class should be located in mailbox-api

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 6ee07f309d900d2690a7e778e34b9a569cec2688
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 11:12:08 2019 +0700

JAMES-2989 MimePathImpl class should be located in mailbox-api

Or we don't have the tools in the api to actually be calling it...
---
 .../src/main/java/org/apache/james/mailbox/model}/MimePathImpl.java | 6 ++
 .../java/org/apache/james/imap/processor/fetch/FetchProcessor.java  | 1 +
 .../org/apache/james/imap/processor/fetch/FetchResponseBuilder.java | 1 +
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/MimePathImpl.java
 b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
similarity index 93%
rename from 
protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/MimePathImpl.java
rename to 
mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
index c695221..d75020d 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/MimePathImpl.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MimePathImpl.java
@@ -20,13 +20,11 @@
 /**
  * 
  */
-package org.apache.james.imap.processor.fetch;
+package org.apache.james.mailbox.model;
 
 import java.util.Arrays;
 
-import org.apache.james.mailbox.model.MessageResult;
-
-final class MimePathImpl implements MessageResult.MimePath {
+public class MimePathImpl implements MessageResult.MimePath {
 private final int[] positions;
 
 public MimePathImpl(int[] positions) {
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
index a75fd30..ebe12e5 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
@@ -49,6 +49,7 @@ import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.MessageResult.FetchGroup;
 import org.apache.james.mailbox.model.MessageResult.MimePath;
 import org.apache.james.mailbox.model.MessageResultIterator;
+import org.apache.james.mailbox.model.MimePathImpl;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.util.MDCBuilder;
 import org.slf4j.Logger;
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
index a56e0fc..29b9535 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
@@ -46,6 +46,7 @@ import 
org.apache.james.mailbox.exception.MessageRangeException;
 import org.apache.james.mailbox.model.Content;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MessageResult;
+import org.apache.james.mailbox.model.MimePathImpl;
 
 public final class FetchResponseBuilder {
 


-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[james-project] 20/23: s/JAMES-2988 FetchGroup::or/FetchGroup::with

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 362bc7222b547390195c342dedd4db9057a83a5c
Author: Benoit Tellier 
AuthorDate: Wed Nov 27 10:22:56 2019 +0700

s/JAMES-2988 FetchGroup::or/FetchGroup::with
---
 .../java/org/apache/james/mailbox/model/FetchGroup.java|  2 +-
 .../org/apache/james/mailbox/model/FetchGroupTest.java | 14 +++---
 .../james/mailbox/store/mail/FetchGroupConverterTest.java  |  8 
 .../james/imap/processor/fetch/FetchDataConverter.java |  6 +++---
 .../james/imap/processor/fetch/FetchDataConverterTest.java |  4 ++--
 5 files changed, 17 insertions(+), 17 deletions(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
index 56c01ee..7ff2d70 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/FetchGroup.java
@@ -80,7 +80,7 @@ public class FetchGroup {
 return content;
 }
 
-public FetchGroup or(int content) {
+public FetchGroup with(int content) {
  return new FetchGroup(this.content | content, partContentDescriptors);
 }
 
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/FetchGroupTest.java 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/FetchGroupTest.java
index 5ded8c0..1ad5baa 100644
--- 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/FetchGroupTest.java
+++ 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/FetchGroupTest.java
@@ -37,7 +37,7 @@ class FetchGroupTest {
 @Test
 void orShouldReturnAFetchGroupWithUpdatedContent() {
 int expected = FetchGroup.HEADERS_MASK | FetchGroup.FULL_CONTENT_MASK;
-assertThat(FetchGroup.HEADERS.or(FetchGroup.FULL_CONTENT_MASK))
+assertThat(FetchGroup.HEADERS.with(FetchGroup.FULL_CONTENT_MASK))
 .isEqualTo(new FetchGroup(expected));
 }
 
@@ -76,8 +76,8 @@ class FetchGroupTest {
 @Test
 void hasMaskShouldReturnFalseWhenNotContained() {
 assertThat(FetchGroup.MINIMAL
-.or(FetchGroup.MIME_HEADERS_MASK)
-.or(FetchGroup.MIME_DESCRIPTOR_MASK)
+.with(FetchGroup.MIME_HEADERS_MASK)
+.with(FetchGroup.MIME_DESCRIPTOR_MASK)
 .hasMask(FetchGroup.HEADERS_MASK))
 .isFalse();
 }
@@ -85,8 +85,8 @@ class FetchGroupTest {
 @Test
 void hasMaskShouldReturnTrueWhenContained() {
 assertThat(FetchGroup.MINIMAL
-.or(FetchGroup.MIME_HEADERS_MASK)
-.or(FetchGroup.MIME_DESCRIPTOR_MASK)
+.with(FetchGroup.MIME_HEADERS_MASK)
+.with(FetchGroup.MIME_DESCRIPTOR_MASK)
 .hasMask(FetchGroup.MIME_HEADERS_MASK))
 .isTrue();
 }
@@ -108,7 +108,7 @@ class FetchGroupTest {
 @Test
 void hasOnlyMasksShouldReturnTrueWhenExactlyContainMultipleValues() {
 assertThat(FetchGroup.HEADERS
-.or(FetchGroup.BODY_CONTENT_MASK)
+.with(FetchGroup.BODY_CONTENT_MASK)
 .hasOnlyMasks(FetchGroup.HEADERS_MASK, 
FetchGroup.BODY_CONTENT_MASK))
 .isTrue();
 }
@@ -116,7 +116,7 @@ class FetchGroupTest {
 @Test
 void hasOnlyMasksShouldReturnFalseWhenNotContained() {
 assertThat(FetchGroup.HEADERS
-.or(FetchGroup.BODY_CONTENT_MASK)
+.with(FetchGroup.BODY_CONTENT_MASK)
 .hasOnlyMasks(FetchGroup.FULL_CONTENT_MASK))
 .isFalse();
 }
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java
index 2c3f66f..07c92e9 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java
@@ -47,7 +47,7 @@ class FetchGroupConverterTest {
 @Test
 void getFetchTypeShouldReturnFullWhenBodyAndHeaders() {
 FetchGroup fetchGroup = FetchGroup.BODY_CONTENT
-.or(FetchGroup.HEADERS_MASK);
+.with(FetchGroup.HEADERS_MASK);
 
 assertThat(FetchGroupConverter.getFetchType(fetchGroup))
 .isEqualTo(MessageMapper.FetchType.Full);
@@ -62,7 +62,7 @@ class FetchGroupConverterTest {
 @Test
 void getFetchTypeShouldReturnFullWhenMimeContent() {
 FetchGroup fetchGroup = FetchGroup.MINIMAL
-.or(FetchGroup.MIME_CONTENT_MASK);
+.with(FetchGroup.MIME_CONTENT_MASK);
 assertThat(FetchGroupConverter.getFetchType(fetchGroup))
 .isEqualTo(MessageMapper.FetchType.Full);
 }
@@ -70,7 

[james-project] 14/23: JAMES-2989 Tests for FetchGroupConverter

2019-11-27 Thread btellier
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 9e5ddfba2a3f56a5e8014dea95b006322dc93b81
Author: Benoit Tellier 
AuthorDate: Mon Nov 25 12:50:57 2019 +0700

JAMES-2989 Tests for FetchGroupConverter
---
 .../mailbox/store/mail/FetchGroupConverter.java|   8 ++
 .../store/mail/FetchGroupConverterTest.java| 121 +
 2 files changed, 129 insertions(+)

diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
index cfd91fb..5bceef9 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
@@ -56,6 +56,14 @@ public class FetchGroupConverter {
 full = true;
 content -= FetchGroup.MIME_DESCRIPTOR_MASK;
 }
+if ((content & FetchGroup.MIME_CONTENT_MASK) > 0) {
+full = true;
+content -= FetchGroup.MIME_CONTENT_MASK;
+}
+if ((content & FetchGroup.MIME_HEADERS_MASK) > 0) {
+full = true;
+content -= FetchGroup.MIME_HEADERS_MASK;
+}
 if (full || (body && headers)) {
 return MessageMapper.FetchType.Full;
 } else if (body) {
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java
new file mode 100644
index 000..2c3f66f
--- /dev/null
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/FetchGroupConverterTest.java
@@ -0,0 +1,121 @@
+/
+ * 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: ww.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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.model.FetchGroup;
+import org.apache.james.mailbox.model.MimePath;
+import org.junit.jupiter.api.Test;
+
+class FetchGroupConverterTest {
+@Test
+void getFetchTypeShouldReturnMetadataWhenMinimal() {
+assertThat(FetchGroupConverter.getFetchType(FetchGroup.MINIMAL))
+.isEqualTo(MessageMapper.FetchType.Metadata);
+}
+
+@Test
+void getFetchTypeShouldReturnHeadersWhenHeaders() {
+assertThat(FetchGroupConverter.getFetchType(FetchGroup.HEADERS))
+.isEqualTo(MessageMapper.FetchType.Headers);
+}
+
+@Test
+void getFetchTypeShouldReturnBodyContentWhenBody() {
+assertThat(FetchGroupConverter.getFetchType(FetchGroup.BODY_CONTENT))
+.isEqualTo(MessageMapper.FetchType.Body);
+}
+
+@Test
+void getFetchTypeShouldReturnFullWhenBodyAndHeaders() {
+FetchGroup fetchGroup = FetchGroup.BODY_CONTENT
+.or(FetchGroup.HEADERS_MASK);
+
+assertThat(FetchGroupConverter.getFetchType(fetchGroup))
+.isEqualTo(MessageMapper.FetchType.Full);
+}
+
+@Test
+void getFetchTypeShouldReturnFullWhenFull() {
+assertThat(FetchGroupConverter.getFetchType(FetchGroup.FULL_CONTENT))
+.isEqualTo(MessageMapper.FetchType.Full);
+}
+
+@Test
+void getFetchTypeShouldReturnFullWhenMimeContent() {
+FetchGroup fetchGroup = FetchGroup.MINIMAL
+.or(FetchGroup.MIME_CONTENT_MASK);
+assertThat(FetchGroupConverter.getFetchType(fetchGroup))
+.isEqualTo(MessageMapper.FetchType.Full);
+}
+
+@Test
+void getFetchTypeShouldReturnFullWhenMimeDescriptor() {
+FetchGroup fetchGroup = FetchGroup.MINIMAL
+.or(FetchGroup.MIME_DESCRIPTOR_MASK);
+   

[jira] [Created] (JAMES-2996) Guice end up in zombie state when start fail

2019-11-27 Thread Benoit Tellier (Jira)
Benoit Tellier created JAMES-2996:
-

 Summary: Guice end up in zombie state when start fail
 Key: JAMES-2996
 URL: https://issues.apache.org/jira/browse/JAMES-2996
 Project: James Server
  Issue Type: Bug
  Components: guice
Affects Versions: 3.4.0
Reporter: Benoit Tellier


Currently when an error arise:
 - the exception is not catched and logged in stderr
 - James is started despite some failed components, and the initialization is 
not completed

I would expect:
 - that an error upon start leave the app in a clean stopped state
 - that the error is logged using slf4j in order to be caught by proper 
monitoring tools



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Closed] (JAMES-2972) Incorrect attribute name in the mailet configuration

2019-11-27 Thread Benoit Tellier (Jira)


 [ 
https://issues.apache.org/jira/browse/JAMES-2972?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Benoit Tellier closed JAMES-2972.
-
Fix Version/s: 3.5.0
   Resolution: Fixed

> Incorrect attribute name in the mailet configuration
> 
>
> Key: JAMES-2972
> URL: https://issues.apache.org/jira/browse/JAMES-2972
> Project: James Server
>  Issue Type: Bug
>Reporter: Trần Tiến Đức
>Priority: Minor
> Fix For: 3.5.0
>
>  Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> For example: 
> [https://github.com/apache/james-project/blob/master/server/app/src/main/resources/mailetcontainer.xml#L59-L65]
>  
> The "matcher" attribute should be "match" instead. There're several places in 
> James source code have this fault. And these miss configured mailet are 
> pointing to Null processor. To avoid this weird behavior, you will comment 
> these mailet out then write description/explanation for the usage of the 
> mailets/matchers
>  
> And the content of mailetcontainer.xml of spring product in dockerfiles/ is 
> not the same with another one in spring main source code. They should be 
> identical



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2972) Incorrect attribute name in the mailet configuration

2019-11-27 Thread ConSol


[ 
https://issues.apache.org/jira/browse/JAMES-2972?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16983334#comment-16983334
 ] 

Jörg Thomas (ConSol) commented on JAMES-2972:
-

...can be closed, yes (can't do it myself since i'm not the reporter)

> Incorrect attribute name in the mailet configuration
> 
>
> Key: JAMES-2972
> URL: https://issues.apache.org/jira/browse/JAMES-2972
> Project: James Server
>  Issue Type: Bug
>Reporter: Trần Tiến Đức
>Priority: Minor
>  Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> For example: 
> [https://github.com/apache/james-project/blob/master/server/app/src/main/resources/mailetcontainer.xml#L59-L65]
>  
> The "matcher" attribute should be "match" instead. There're several places in 
> James source code have this fault. And these miss configured mailet are 
> pointing to Null processor. To avoid this weird behavior, you will comment 
> these mailet out then write description/explanation for the usage of the 
> mailets/matchers
>  
> And the content of mailetcontainer.xml of spring product in dockerfiles/ is 
> not the same with another one in spring main source code. They should be 
> identical



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org