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/08 03:12:18 UTC

[james-project] 31/36: [REFACTORING] IMAPMDCContext Should rely on ImapSession, not IMAPSession

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 1047f874a5f83c8000672935d5a23173ea99168e
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Nov 7 12:16:25 2019 +0700

    [REFACTORING] IMAPMDCContext Should rely on ImapSession, not IMAPSession
    
    IMAPSession is unused outside of protocols.imap code, not linked to executed code.
---
 .../james/imapserver/netty/IMAPMDCContext.java     | 24 ++++++++++++++--------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java
index a0d5710..bb8799e 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java
@@ -24,8 +24,11 @@ import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.util.Optional;
 
+import org.apache.james.core.Username;
+import org.apache.james.imap.api.ImapSessionUtils;
+import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.api.process.SelectedMailbox;
-import org.apache.james.protocols.imap.IMAPSession;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.util.MDCBuilder;
 import org.jboss.netty.channel.ChannelHandlerContext;
 import org.jboss.netty.channel.ChannelLocal;
@@ -59,14 +62,17 @@ public class IMAPMDCContext {
     }
 
     private static MDCBuilder from(Object o) {
-        return Optional.ofNullable(o)
-            .filter(object -> object instanceof IMAPSession)
-            .map(object -> (IMAPSession) object)
-            .map(imapSession -> MDCBuilder.create()
-                .addContext(MDCBuilder.SESSION_ID, imapSession.getSessionID())
-                .addContext(MDCBuilder.USER, imapSession.getUser())
-                .addContext(from(Optional.ofNullable(imapSession.getSelected()))))
-            .orElse(MDCBuilder.create());
+        if (o instanceof ImapSession) {
+            ImapSession imapSession = (ImapSession) o;
+            MailboxSession mailboxSession = (MailboxSession) imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY);
+
+            return MDCBuilder.create()
+                .addContext(MDCBuilder.USER, Optional.ofNullable(mailboxSession)
+                    .map(MailboxSession::getUser)
+                    .map(Username::asString))
+                .addContext(from(Optional.ofNullable(imapSession.getSelected())));
+        }
+        return MDCBuilder.create();
     }
 
     private static MDCBuilder from(Optional<SelectedMailbox> selectedMailbox) {


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