You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/11/28 02:12:18 UTC
[james-project] 01/23: JAMES-2989 StoreMessageIdManager should
comply to fetchGroup read level
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 <bt...@linagora.com>
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<MessageResult> getMessages(List<MessageId> messageIds, MessageResult.FetchGroup fetchGroup, MailboxSession mailboxSession) throws MailboxException {
MessageIdMapper messageIdMapper = mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession);
- List<MailboxMessage> messageList = messageIdMapper.find(messageIds, MessageMapper.FetchType.Full);
+
+ MessageMapper.FetchType fetchType = FetchGroupConverter.getFetchType(fetchGroup);
+ List<MailboxMessage> messageList = messageIdMapper.find(messageIds, fetchType);
ImmutableSet<MailboxId> 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 0000000..d280172
--- /dev/null
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
@@ -0,0 +1,69 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.mail;
+
+import org.apache.james.mailbox.model.MessageResult;
+
+public class FetchGroupConverter {
+ /**
+ * Use the passed {@link MessageResult.FetchGroup} and calculate the right
+ * {@link MessageMapper.FetchType} for it
+ */
+ public static MessageMapper.FetchType getFetchType(MessageResult.FetchGroup group) {
+ int content = group.content();
+ boolean headers = false;
+ boolean body = false;
+ boolean full = false;
+
+ if ((content & MessageResult.FetchGroup.HEADERS) > 0) {
+ headers = true;
+ content -= MessageResult.FetchGroup.HEADERS;
+ }
+ if (group.getPartContentDescriptors().size() > 0) {
+ full = true;
+ }
+ if ((content & MessageResult.FetchGroup.BODY_CONTENT) > 0) {
+ body = true;
+ content -= MessageResult.FetchGroup.BODY_CONTENT;
+ }
+
+ if ((content & MessageResult.FetchGroup.FULL_CONTENT) > 0) {
+ full = true;
+ content -= MessageResult.FetchGroup.FULL_CONTENT;
+ }
+
+ if ((content & MessageResult.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 -= MessageResult.FetchGroup.MIME_DESCRIPTOR;
+ }
+ if (full || (body && headers)) {
+ return MessageMapper.FetchType.Full;
+ } else if (body) {
+ return MessageMapper.FetchType.Body;
+ } else if (headers) {
+ return MessageMapper.FetchType.Headers;
+ } else {
+ return MessageMapper.FetchType.Metadata;
+ }
+ }
+}
diff --git a/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/MessageIdProbe.java b/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/MessageIdProbe.java
index e6703fe..a2ae27d 100644
--- a/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/MessageIdProbe.java
+++ b/server/container/guice/protocols/jmap-draft/src/main/java/org/apache/james/jmap/draft/MessageIdProbe.java
@@ -68,7 +68,7 @@ public class MessageIdProbe implements GuiceProbe {
MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
List<MessageResult> messages = messageIdManager.getMessages(
ImmutableList.of(messageId),
- FetchGroupImpl.MINIMAL,
+ FetchGroupImpl.FULL_CONTENT,
mailboxSession);
return messages.stream()
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org