You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/03/22 02:03:47 UTC

[james-project] 18/25: JAMES-3722 IMAP SELECT QRESYNC another small code extraction

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 389310bd1799de3cd750a0d18674e0ca07109ebb
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Mar 8 15:09:49 2022 +0700

    JAMES-3722 IMAP SELECT QRESYNC another small code extraction
---
 .../imap/processor/AbstractSelectionProcessor.java | 40 ++++++++++++----------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
index 735fbee..ed6293f 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
@@ -22,6 +22,7 @@ package org.apache.james.imap.processor;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
@@ -63,6 +64,7 @@ import org.apache.james.metrics.api.MetricFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.github.fge.lambdas.Throwing;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
 
@@ -168,23 +170,15 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ
                 //  The server sends the client any pending flag changes (using FETCH
                 //  responses that MUST contain UIDs) and expunges those that have
                 //  occurred in this mailbox since the provided modification sequence.
-                UidRange[] uidSet = request.getUidSet();
-
-                if (uidSet == null) {
-                    // See mailbox had some messages stored before, if not we don't need to query at all
-                    MessageUid uidNext = metaData.getUidNext();
-                    if (!uidNext.isFirst()) {
-                        // Use UIDNEXT -1 as max uid as stated in the QRESYNC RFC
-                        uidSet = new UidRange[] {new UidRange(MessageUid.MIN_VALUE, uidNext.previous())};
-                    }
-                }
-                
-                if (uidSet != null) {
-                    respondVanished(session, responder, knownSequences, knownUids, selected, uidSet);
-                }
+
+                uidSet(request, metaData)
+                    .ifPresent(Throwing.<UidRange[]>consumer(
+                        uidSet -> respondVanished(session, responder, knownSequences, knownUids, selected, uidSet))
+                        .sneakyThrow());
+
                 taggedOk(responder, request, metaData, HumanReadableText.SELECT);
             } else {
-                
+
                 taggedOk(responder, request, metaData, HumanReadableText.QRESYNC_UIDVALIDITY_MISMATCH);
             }
         } else {
@@ -196,6 +190,19 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ
         SearchResUtil.resetSavedSequenceSet(session);
     }
 
+    private Optional<UidRange[]> uidSet(AbstractMailboxSelectionRequest request, MailboxMetaData metaData) {
+        return Optional.ofNullable(request.getUidSet())
+            .or(() -> {
+                // See mailbox had some messages stored before, if not we don't need to query at all
+                MessageUid uidNext = metaData.getUidNext();
+                if (!uidNext.isFirst()) {
+                    // Use UIDNEXT -1 as max uid as stated in the QRESYNC RFC
+                    return Optional.of(new UidRange[] {new UidRange(MessageUid.MIN_VALUE, uidNext.previous())});
+                }
+                return Optional.empty();
+            });
+    }
+
     private void respondVanished(ImapSession session, Responder responder, IdRange[] knownSequences, UidRange[] knownUids, SelectedMailbox selected, UidRange[] uidSet) throws MailboxException {
         // RFC5162 3.1. QRESYNC Parameter to SELECT/EXAMINE
         //
@@ -342,8 +349,6 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ
             });
         }
         return true;
-
-
     }
 
     private void uidValidity(Responder responder, MailboxMetaData metaData) {
@@ -394,7 +399,6 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ
         return metaData;
     }
 
-
     private void addRecent(MailboxMetaData metaData, SelectedMailbox sessionMailbox) {
         final List<MessageUid> recentUids = metaData.getRecent();
         for (MessageUid uid : recentUids) {

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org