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 ad...@apache.org on 2017/07/05 13:59:10 UTC

[03/34] james-project git commit: JAMES-2085 Log when mailbox can not be retrieved

JAMES-2085 Log when mailbox can not be retrieved


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/cb181cab
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/cb181cab
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/cb181cab

Branch: refs/heads/master
Commit: cb181cabffbc4dbf55d65477e9defe69f3ba9194
Parents: 1eaca58
Author: benwa <bt...@linagora.com>
Authored: Mon Jul 3 10:37:00 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jul 5 17:13:25 2017 +0700

----------------------------------------------------------------------
 .../mailbox/store/StoreMessageIdManager.java    | 37 ++++++--------------
 1 file changed, 11 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/cb181cab/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
----------------------------------------------------------------------
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 dcf812b..9964d6c 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
@@ -58,6 +58,7 @@ import org.apache.james.mailbox.store.quota.QuotaChecker;
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
@@ -158,7 +159,7 @@ public class StoreMessageIdManager implements MessageIdManager {
         allowOnMailboxSession(mailboxIds, mailboxSession, mailboxMapper);
 
         List<MailboxMessage> mailboxMessages = FluentIterable.from(messageIdMapper.find(ImmutableList.of(messageId), MessageMapper.FetchType.Full))
-            .filter(belongsToUser(mailboxSession, mailboxMapper))
+            .filter(messageBelongsToUser(mailboxSession, mailboxMapper))
             .toList();
 
         if (!mailboxMessages.isEmpty()) {
@@ -264,20 +265,6 @@ public class StoreMessageIdManager implements MessageIdManager {
         };
     }
 
-    private Predicate<MailboxMessage> belongsToUser(final MailboxSession mailboxSession, final MailboxMapper mailboxMapper) {
-        return new Predicate<MailboxMessage>() {
-            @Override
-            public boolean apply(MailboxMessage input) {
-                try {
-                    Mailbox currentMailbox = mailboxMapper.findMailboxById(input.getMailboxId());
-                    return belongsToCurrentUser(currentMailbox, mailboxSession);
-                } catch (MailboxException e) {
-                    return false;
-                }
-            }
-        };
-    }
-
     private Predicate<MailboxId> mailboxBelongsToUser(final MailboxSession mailboxSession, final MailboxMapper mailboxMapper) {
         return new Predicate<MailboxId>() {
             @Override
@@ -286,12 +273,19 @@ public class StoreMessageIdManager implements MessageIdManager {
                     Mailbox currentMailbox = mailboxMapper.findMailboxById(mailboxId);
                     return belongsToCurrentUser(currentMailbox, mailboxSession);
                 } catch (MailboxException e) {
+                    mailboxSession.getLog().error(String.format("Can not retrieve mailboxPath associated with %s", mailboxId.serialize()), e);
                     return false;
                 }
             }
         };
     }
 
+    private Predicate<MailboxMessage> messageBelongsToUser(MailboxSession mailboxSession, MailboxMapper mailboxMapper) {
+        return Predicates.compose(
+            mailboxBelongsToUser(mailboxSession, mailboxMapper),
+            EXTRACT_MAILBOX_ID_FUNCTION);
+    }
+
     private void allowOnMailboxSession(List<MailboxId> mailboxIds, MailboxSession mailboxSession, MailboxMapper mailboxMapper) throws MailboxNotFoundException {
         Optional<MailboxId> mailboxForbidden = FluentIterable.from(mailboxIds)
             .firstMatch(isMailboxOfOtherUser(mailboxSession, mailboxMapper))
@@ -302,17 +296,8 @@ public class StoreMessageIdManager implements MessageIdManager {
         }
     }
 
-    private Predicate<MailboxId> isMailboxOfOtherUser(final MailboxSession mailboxSession, final MailboxMapper mailboxMapper) {
-        return new Predicate<MailboxId>() {
-            @Override
-            public boolean apply(MailboxId mailboxId) {
-                try {
-                    return !belongsToCurrentUser(mailboxMapper.findMailboxById(mailboxId), mailboxSession);
-                } catch (MailboxException e) {
-                    return true;
-                }
-            }
-        };
+    private Predicate<MailboxId> isMailboxOfOtherUser(MailboxSession mailboxSession, MailboxMapper mailboxMapper) {
+        return Predicates.not(mailboxBelongsToUser(mailboxSession, mailboxMapper));
     }
 
     private boolean belongsToCurrentUser(Mailbox mailbox, MailboxSession session) {


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