james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [james-project] 03/06: JAMES-2761 get mailbox capabilities out of the loop on its messages
Date Wed, 12 Jun 2019 14:32:14 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 00438bf51efe0f804607c3e8f970c7faaced2a3f
Author: RĂ©mi Kowalski <rkowalski@linagora.com>
AuthorDate: Mon May 13 11:22:53 2019 +0200

    JAMES-2761 get mailbox capabilities out of the loop on its messages
---
 .../imap/processor/AbstractMailboxProcessor.java   | 44 ++++++++++++----------
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
index 08bef66..f6f1bab 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
@@ -52,7 +52,6 @@ import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageManager.MetaData;
-import org.apache.james.mailbox.MessageManager.MetaData.FetchGroup;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MessageRangeException;
@@ -201,12 +200,10 @@ public abstract class AbstractMailboxProcessor<M extends ImapRequest>
extends Ab
     }
     
     private void addFlagsResponses(ImapSession session, SelectedMailbox selected, ImapProcessor.Responder
responder, boolean useUid) {
-       
         try {
-  
             // To be lazily initialized only if needed, which is in minority of cases.
             MessageManager messageManager = null;
-
+            MetaData metaData = null;
             final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
 
             // Check if we need to send a FLAGS and PERMANENTFLAGS response before the FETCH
response
@@ -215,48 +212,55 @@ public abstract class AbstractMailboxProcessor<M extends ImapRequest>
extends Ab
             if (selected.hasNewApplicableFlags()) {
                 messageManager = getMailbox(session, selected);
                 flags(responder, selected);
-                permanentFlags(responder, messageManager.getMetaData(false, mailboxSession,
MessageManager.MetaData.FetchGroup.NO_COUNT), selected);
+                metaData = messageManager.getMetaData(false, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT);
+
+                permanentFlags(responder, metaData, selected);
                 selected.resetNewApplicableFlags();
             }
             
             final Collection<MessageUid> flagUpdateUids = selected.flagUpdateUids();
             if (!flagUpdateUids.isEmpty()) {
                 Iterator<MessageRange> ranges = MessageRange.toRanges(flagUpdateUids).iterator();
+                if (messageManager == null) {
+                    messageManager = getMailbox(session, selected);
+                }
+                if (metaData == null) {
+                    metaData = messageManager.getMetaData(false, mailboxSession, MessageManager.MetaData.FetchGroup.NO_COUNT);
+                }
+                boolean isModSeqPermanent = metaData.isModSeqPermanent();
                 while (ranges.hasNext()) {
-                 if (messageManager == null) {
-                     messageManager = getMailbox(session, selected);
-                 }
-                    addFlagsResponses(session, selected, responder, useUid, ranges.next(),
messageManager, mailboxSession);
+                    addFlagsResponses(session, selected, responder, useUid, ranges.next(),
messageManager, isModSeqPermanent, mailboxSession);
                 }
-
             }
-            
+
         } catch (MailboxException e) {
             handleResponseException(responder, e, HumanReadableText.FAILURE_TO_LOAD_FLAGS,
session);
         }
 
     }
     
-    protected void addFlagsResponses(ImapSession session, SelectedMailbox selected, ImapProcessor.Responder
responder, boolean useUid, MessageRange messageSet, MessageManager mailbox, MailboxSession
mailboxSession) throws MailboxException {
-
+    private void addFlagsResponses(ImapSession session,
+                                   SelectedMailbox selected,
+                                   ImapProcessor.Responder responder,
+                                   boolean useUid,
+                                   MessageRange messageSet, MessageManager mailbox,
+                                   boolean isModSeqPermanent,
+                                   MailboxSession mailboxSession) throws MailboxException
{
         final MessageResultIterator it = mailbox.getMessages(messageSet, FetchGroupImpl.MINIMAL,
 mailboxSession);
+        final boolean qresyncEnabled = EnableProcessor.getEnabledCapabilities(session).contains(ImapConstants.SUPPORTS_QRESYNC);
+        final boolean condstoreEnabled = EnableProcessor.getEnabledCapabilities(session).contains(ImapConstants.SUPPORTS_CONDSTORE);
         while (it.hasNext()) {
             MessageResult mr = it.next();
             final MessageUid uid = mr.getUid();
             int msn = selected.msn(uid);
             if (msn == SelectedMailbox.NO_SUCH_MESSAGE) {
-                LOGGER.debug("No message found with uid {} in the uid<->msn mapping
for mailbox {}. This may be because it was deleted by a concurrent session. So skip it..",
uid, selected.getPath().getFullName(mailboxSession.getPathDelimiter()));
-                    
-
+                LOGGER.debug("No message found with uid {} in the uid<->msn mapping
for mailbox {}. This may be because it was deleted by a concurrent session. So skip it..",
uid, selected.getPath().asString());
                 // skip this as it was not found in the mapping
                 // 
                 // See IMAP-346
                 continue;
             }
 
-            boolean qresyncEnabled = EnableProcessor.getEnabledCapabilities(session).contains(ImapConstants.SUPPORTS_QRESYNC);
-            boolean condstoreEnabled = EnableProcessor.getEnabledCapabilities(session).contains(ImapConstants.SUPPORTS_CONDSTORE);
-
             final Flags flags = mr.getFlags();
             final MessageUid uidOut;
             if (useUid || qresyncEnabled) {
@@ -273,7 +277,7 @@ public abstract class AbstractMailboxProcessor<M extends ImapRequest>
extends Ab
             
             // Check if we also need to return the MODSEQ in the response. This is true if
CONDSTORE or
             // if QRESYNC was enabled, and the mailbox supports the permant storage of mod-sequences
-            if ((condstoreEnabled || qresyncEnabled) && mailbox.getMetaData(false,
mailboxSession, FetchGroup.NO_COUNT).isModSeqPermanent()) {
+            if ((condstoreEnabled || qresyncEnabled) && isModSeqPermanent) {
                 response = new FetchResponse(msn, flags, uidOut, mr.getModSeq(), null, null,
null, null, null, null);
             } else {
                 response = new FetchResponse(msn, flags, uidOut, null, null, null, null,
null, null, null);


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


Mime
View raw message