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 <btell...@linagora.com> 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