You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/06/29 09:06:06 UTC

[GitHub] [james-project] quantranhong1999 opened a new pull request #515: Plug threadIdGuessingAlgorithm to MessageManager

quantranhong1999 opened a new pull request #515:
URL: https://github.com/apache/james-project/pull/515


   I have some questions:
   - Am I supporting threadId for other protocols beside JMAP also? I am interacting with how James store threadId generally.
   - Should we have CassandraThreadIdGuessingAlgorithm and InMemoryThreadIdGuessingAlgorithm... separately in the future?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r661177934



##########
File path: mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
##########
@@ -144,6 +144,7 @@ void setUp() throws Exception {
         this.subscriptionManager = provideSubscriptionManager();
 
         this.message = Message.Builder.of()
+            .setMessageId("MimeMessageId")

Review comment:
       We should IMO accept messages without MimeMessageId

##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -87,11 +91,14 @@ public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Facto
         }
 
         @Override
-        public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
+        public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session, HeaderImpl headers) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            // TODO get mime message header fields
-            ThreadId threadId = threadIdGuessingAlgorithm.guessThreadId(session.getUser(), messageId, null, null, null, null);
+            MimeMessageId mimeMessageId = MimeMessageHeadersUtil.parseMimeMessageId(headers);

Review comment:
       Optional IMO

##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/utils/MimeMessageHeadersUtil.java
##########
@@ -0,0 +1,58 @@
+/******************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one     *
+ * or more contributor license agreements.  See the NOTICE file   *
+ * distributed with this work for additional information          *
+ * regarding copyright ownership.  The ASF licenses this file     *
+ * to you under the Apache License, Version 2.0 (the              *
+ * "License"); you may not use this file except in compliance     *
+ * with the License.  You may obtain a copy of the License at     *
+ *                                                                *
+ * http://www.apache.org/licenses/LICENSE-2.0                     *
+ *                                                                *
+ * Unless required by applicable law or agreed to in writing,     *
+ * software distributed under the License is distributed on an    *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY         *
+ * KIND, either express or implied.  See the License for the      *
+ * specific language governing permissions and limitations        *
+ * under the License.                                             *
+ ******************************************************************/
+
+package org.apache.james.mailbox.store.mail.utils;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import org.apache.james.mailbox.store.mail.model.MimeMessageId;
+import org.apache.james.mailbox.store.mail.model.Subject;
+import org.apache.james.mime4j.message.HeaderImpl;
+import org.apache.james.mime4j.stream.Field;
+
+public class MimeMessageHeadersUtil {
+    public static MimeMessageId parseMimeMessageId(HeaderImpl headers) {
+        return new MimeMessageId(headers.getField("Message-ID").getBody());
+    }
+
+    public static Optional<MimeMessageId> parseInReplyTo(HeaderImpl headers) {
+        Field inReplyToField = headers.getField("In-Reply-To");
+        if (inReplyToField != null) {
+            return Optional.of(new MimeMessageId(inReplyToField.getBody()));
+        }
+        return Optional.empty();
+    }
+
+    public static Optional<List<MimeMessageId>> parseReferences(HeaderImpl headers) {
+        List<Field> mimeMessageIdFields = headers.getFields("References");
+        if (!mimeMessageIdFields.isEmpty()) {
+            List<MimeMessageId> mimeMessageIdList = mimeMessageIdFields.stream()
+                .map(mimeMessageIdField -> new MimeMessageId(mimeMessageIdField.getBody()))
+                .collect(Collectors.toList());

Review comment:
       Guavate.toImmutableList()

##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -147,11 +154,15 @@ public WithoutAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Fa
         }
 
         @Override
-        public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
+        public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session, HeaderImpl headers) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            // TODO get mime message header fields
-            ThreadId threadId = threadIdGuessingAlgorithm.guessThreadId(session.getUser(), messageId, null, null, null, null);
+            MimeMessageId mimeMessageId = MimeMessageHeadersUtil.parseMimeMessageId(headers);
+            Optional<MimeMessageId> inReplyTo = MimeMessageHeadersUtil.parseInReplyTo(headers);
+            Optional<List<MimeMessageId>> references = MimeMessageHeadersUtil.parseReferences(headers);
+            Subject subject = MimeMessageHeadersUtil.parseSubject(headers);

Review comment:
       Idem, what if for any reason a message do not have a subject?

##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/utils/MimeMessageHeadersUtil.java
##########
@@ -0,0 +1,58 @@
+/******************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one     *
+ * or more contributor license agreements.  See the NOTICE file   *
+ * distributed with this work for additional information          *
+ * regarding copyright ownership.  The ASF licenses this file     *
+ * to you under the Apache License, Version 2.0 (the              *
+ * "License"); you may not use this file except in compliance     *
+ * with the License.  You may obtain a copy of the License at     *
+ *                                                                *
+ * http://www.apache.org/licenses/LICENSE-2.0                     *
+ *                                                                *
+ * Unless required by applicable law or agreed to in writing,     *
+ * software distributed under the License is distributed on an    *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY         *
+ * KIND, either express or implied.  See the License for the      *
+ * specific language governing permissions and limitations        *
+ * under the License.                                             *
+ ******************************************************************/
+
+package org.apache.james.mailbox.store.mail.utils;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import org.apache.james.mailbox.store.mail.model.MimeMessageId;
+import org.apache.james.mailbox.store.mail.model.Subject;
+import org.apache.james.mime4j.message.HeaderImpl;
+import org.apache.james.mime4j.stream.Field;
+
+public class MimeMessageHeadersUtil {
+    public static MimeMessageId parseMimeMessageId(HeaderImpl headers) {
+        return new MimeMessageId(headers.getField("Message-ID").getBody());
+    }
+
+    public static Optional<MimeMessageId> parseInReplyTo(HeaderImpl headers) {
+        Field inReplyToField = headers.getField("In-Reply-To");
+        if (inReplyToField != null) {

Review comment:
       Use Optional.ofNullable(...).map(...)

##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/utils/MimeMessageHeadersUtil.java
##########
@@ -0,0 +1,58 @@
+/******************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one     *
+ * or more contributor license agreements.  See the NOTICE file   *
+ * distributed with this work for additional information          *
+ * regarding copyright ownership.  The ASF licenses this file     *
+ * to you under the Apache License, Version 2.0 (the              *
+ * "License"); you may not use this file except in compliance     *
+ * with the License.  You may obtain a copy of the License at     *
+ *                                                                *
+ * http://www.apache.org/licenses/LICENSE-2.0                     *
+ *                                                                *
+ * Unless required by applicable law or agreed to in writing,     *
+ * software distributed under the License is distributed on an    *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY         *
+ * KIND, either express or implied.  See the License for the      *
+ * specific language governing permissions and limitations        *
+ * under the License.                                             *
+ ******************************************************************/
+
+package org.apache.james.mailbox.store.mail.utils;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import org.apache.james.mailbox.store.mail.model.MimeMessageId;
+import org.apache.james.mailbox.store.mail.model.Subject;
+import org.apache.james.mime4j.message.HeaderImpl;
+import org.apache.james.mime4j.stream.Field;
+
+public class MimeMessageHeadersUtil {
+    public static MimeMessageId parseMimeMessageId(HeaderImpl headers) {
+        return new MimeMessageId(headers.getField("Message-ID").getBody());
+    }
+
+    public static Optional<MimeMessageId> parseInReplyTo(HeaderImpl headers) {
+        Field inReplyToField = headers.getField("In-Reply-To");
+        if (inReplyToField != null) {
+            return Optional.of(new MimeMessageId(inReplyToField.getBody()));
+        }
+        return Optional.empty();
+    }
+
+    public static Optional<List<MimeMessageId>> parseReferences(HeaderImpl headers) {
+        List<Field> mimeMessageIdFields = headers.getFields("References");
+        if (!mimeMessageIdFields.isEmpty()) {
+            List<MimeMessageId> mimeMessageIdList = mimeMessageIdFields.stream()
+                .map(mimeMessageIdField -> new MimeMessageId(mimeMessageIdField.getBody()))
+                .collect(Collectors.toList());
+            return Optional.of(mimeMessageIdList);
+        }
+        return Optional.empty();
+    }
+
+    public static Subject parseSubject(HeaderImpl headers) {
+        return new Subject(headers.getField("Subject").getBody());

Review comment:
       `UnstructuredFieldImpl::getValue`
   
   (We need to handle possible encoded characters IMO cf HeaderCollectionTest::getHeadersShouldDecodeValues)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] quantranhong1999 edited a comment on pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
quantranhong1999 edited a comment on pull request #515:
URL: https://github.com/apache/james-project/pull/515#issuecomment-872087789


   Rebased on master + squash fixups.
   Tests are still green local, let's hope the CI the same :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] quantranhong1999 edited a comment on pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
quantranhong1999 edited a comment on pull request #515:
URL: https://github.com/apache/james-project/pull/515#issuecomment-872003860


   The related JPA tests fail is real. But these cassandra tests fail seems weird... they are green on local.
   
   ![image](https://user-images.githubusercontent.com/55171818/124084617-64aeb000-da79-11eb-92f1-66f787321c6d.png)
   
   ![image](https://user-images.githubusercontent.com/55171818/124085106-e1418e80-da79-11eb-8b8b-30e3101d598d.png)
   
   I am doing invalidate caches and build project again to see what happen.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r660437287



##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       I think you need a hint there...
   
   MaximalBodyDescriptor do held a list of fields CF this debugging session:
   
   ![Screenshot from 2021-06-29 16-17-11](https://user-images.githubusercontent.com/6928740/123771846-95fe7300-d8f5-11eb-841a-b0fb0aa600ae.png)
   
   We can contribute a `MaximalBodyDescriptor::getFiled(String name)` method in mime4J ?
   
   Then we would likely be able to do threadId guessing easily in `StoreMessageManager::appendMessage` (the one with the big try catch...) Then we can pass the threadId as a parameter to other methods just like properties...

##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       Likely even better (and less hacky) in arseProperties there is a header isntance we do not use...
   
   ```
   private PropertyBuilder parseProperties(BodyOffsetInputStream bIn) throws IOException, MimeException {
           // Disable line length... This should be handled by the smtp server
           // component and not the parser itself
           // https://issues.apache.org/jira/browse/IMAP-122
           final MimeTokenStream parser = getParser(bIn);
           final HeaderImpl fields = readHeader(parser);
           
           // All we need for threadId guessing <3
           fields.getFields("Message-Id")
           
           final MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser.getBodyDescriptor();
           final MediaType mediaType = getMediaType(descriptor);
           final PropertyBuilder propertyBuilder = getPropertyBuilder(descriptor, mediaType.mediaType, mediaType.subType);
           setTextualLinesCount(parser, mediaType.mediaType, propertyBuilder);
           return propertyBuilder;
       }
    ```

##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       Likely even better (and less hacky) in arseProperties there is a header isntance we do not use...
   
   ```
   private PropertyBuilder parseProperties(BodyOffsetInputStream bIn) throws IOException, MimeException {
           // Disable line length... This should be handled by the smtp server
           // component and not the parser itself
           // https://issues.apache.org/jira/browse/IMAP-122
           final MimeTokenStream parser = getParser(bIn);
           final HeaderImpl fields = readHeader(parser);
           
           // All we need for threadId guessing <3
           fields.getFields("Message-Id")
           
           final MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser.getBodyDescriptor();
           final MediaType mediaType = getMediaType(descriptor);
           final PropertyBuilder propertyBuilder = getPropertyBuilder(descriptor, mediaType.mediaType, mediaType.subType);
           setTextualLinesCount(parser, mediaType.mediaType, propertyBuilder);
           return propertyBuilder;
       }
    ```
    
    That method can then return an object combining properties and threadId....

##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       Likely even better (and less hacky) in parseProperties there is a header isntance we do not use...
   
   ```
   private PropertyBuilder parseProperties(BodyOffsetInputStream bIn) throws IOException, MimeException {
           // Disable line length... This should be handled by the smtp server
           // component and not the parser itself
           // https://issues.apache.org/jira/browse/IMAP-122
           final MimeTokenStream parser = getParser(bIn);
           final HeaderImpl fields = readHeader(parser);
           
           // All we need for threadId guessing <3
           fields.getFields("Message-Id")
           
           final MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser.getBodyDescriptor();
           final MediaType mediaType = getMediaType(descriptor);
           final PropertyBuilder propertyBuilder = getPropertyBuilder(descriptor, mediaType.mediaType, mediaType.subType);
           setTextualLinesCount(parser, mediaType.mediaType, propertyBuilder);
           return propertyBuilder;
       }
    ```
    
    That method can then return an object combining properties and threadId....




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] quantranhong1999 commented on a change in pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
quantranhong1999 commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r660484180



##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       How about using this header instance to get headers fields needed for ThreadIdGuessingAlgorithm, and still place ThreadIdGuessingAlgorithm at MessageStorer::appendMessageToStore as I am doing now? Because I think threadId should go with messageId. Otherwise we should messageId generate out of MessageStorer::appendMessageToStore.

##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       How about using this header instance to get headers fields needed for ThreadIdGuessingAlgorithm, and still place ThreadIdGuessingAlgorithm at MessageStorer::appendMessageToStore as I am doing now? Because I think threadId should go with messageId. Otherwise we should move messageIdFactory.generate out of MessageStorer::appendMessageToStore.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #515:
URL: https://github.com/apache/james-project/pull/515#issuecomment-871890253


   ```
   [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project apache-james-mailbox-cassandra: There are test failures.
   
   java.lang.NullPointerException: threadId is required (252 occurence...)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r660439882



##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       Likely even better (and less hacky) in arseProperties there is a header isntance we do not use...
   
   ```
   private PropertyBuilder parseProperties(BodyOffsetInputStream bIn) throws IOException, MimeException {
           // Disable line length... This should be handled by the smtp server
           // component and not the parser itself
           // https://issues.apache.org/jira/browse/IMAP-122
           final MimeTokenStream parser = getParser(bIn);
           final HeaderImpl fields = readHeader(parser);
           
           // All we need for threadId guessing <3
           fields.getFields("Message-Id")
           
           final MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser.getBodyDescriptor();
           final MediaType mediaType = getMediaType(descriptor);
           final PropertyBuilder propertyBuilder = getPropertyBuilder(descriptor, mediaType.mediaType, mediaType.subType);
           setTextualLinesCount(parser, mediaType.mediaType, propertyBuilder);
           return propertyBuilder;
       }
    ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] Arsnael merged pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
Arsnael merged pull request #515:
URL: https://github.com/apache/james-project/pull/515


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r660437287



##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       I think you need a hint there...
   
   MaximalBodyDescriptor do held a list of fields CF this debugging session:
   
   ![Screenshot from 2021-06-29 16-17-11](https://user-images.githubusercontent.com/6928740/123771846-95fe7300-d8f5-11eb-841a-b0fb0aa600ae.png)
   
   We can contribute a `MaximalBodyDescriptor::getFiled(String name)` method in mime4J ?
   
   Then we would likely be able to do threadId guessing easily in `StoreMessageManager::appendMessage` (the one with the big try catch...) Then we can pass the threadId as a parameter to other methods just like properties...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r661913863



##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/utils/MimeMessageHeadersUtil.java
##########
@@ -21,38 +21,39 @@
 
 import java.util.List;
 import java.util.Optional;
-import java.util.stream.Collectors;
 
 import org.apache.james.mailbox.store.mail.model.MimeMessageId;
 import org.apache.james.mailbox.store.mail.model.Subject;
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.field.UnstructuredFieldImpl;
 import org.apache.james.mime4j.message.HeaderImpl;
 import org.apache.james.mime4j.stream.Field;
 
+import com.github.steveash.guavate.Guavate;
+
 public class MimeMessageHeadersUtil {
-    public static MimeMessageId parseMimeMessageId(HeaderImpl headers) {
-        return new MimeMessageId(headers.getField("Message-ID").getBody());
+    public static Optional<MimeMessageId> parseMimeMessageId(HeaderImpl headers) {
+        return Optional.ofNullable(headers.getField("Message-ID")).map(field -> new MimeMessageId(field.getBody()));
     }
 
     public static Optional<MimeMessageId> parseInReplyTo(HeaderImpl headers) {
-        Field inReplyToField = headers.getField("In-Reply-To");
-        if (inReplyToField != null) {
-            return Optional.of(new MimeMessageId(inReplyToField.getBody()));
-        }
-        return Optional.empty();
+        return Optional.ofNullable(headers.getField("In-Reply-To")).map(field -> new MimeMessageId(field.getBody()));
     }
 
     public static Optional<List<MimeMessageId>> parseReferences(HeaderImpl headers) {
         List<Field> mimeMessageIdFields = headers.getFields("References");
         if (!mimeMessageIdFields.isEmpty()) {
             List<MimeMessageId> mimeMessageIdList = mimeMessageIdFields.stream()
                 .map(mimeMessageIdField -> new MimeMessageId(mimeMessageIdField.getBody()))
-                .collect(Collectors.toList());
+                .collect(Guavate.toImmutableList());
             return Optional.of(mimeMessageIdList);
         }
         return Optional.empty();
     }
 
-    public static Subject parseSubject(HeaderImpl headers) {
-        return new Subject(headers.getField("Subject").getBody());
+    public static Optional<Subject> parseSubject(HeaderImpl headers) {
+        return Optional.ofNullable(headers.getField("Subject"))
+            .map(field -> UnstructuredFieldImpl.PARSER.parse(field, DecodeMonitor.SILENT))

Review comment:
       We do not need to parse the field if it is already a `UnstructuredFieldImpl`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #515:
URL: https://github.com/apache/james-project/pull/515#issuecomment-872025105


   Pro-tip: git rebase master & rerun ;-)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] quantranhong1999 commented on pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
quantranhong1999 commented on pull request #515:
URL: https://github.com/apache/james-project/pull/515#issuecomment-872087789


   Rebased on master + squash fixups


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] quantranhong1999 edited a comment on pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
quantranhong1999 edited a comment on pull request #515:
URL: https://github.com/apache/james-project/pull/515#issuecomment-872087789


   Rebased on master + squash fixups.
   Tests are still green local, let's hope the CI the same :)
   
   Oops after rebase, it's actually failing ( because of this: https://github.com/apache/james-project/pull/464). At least I found out why :D 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] quantranhong1999 commented on a change in pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
quantranhong1999 commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r661944266



##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/utils/MimeMessageHeadersUtil.java
##########
@@ -21,38 +21,39 @@
 
 import java.util.List;
 import java.util.Optional;
-import java.util.stream.Collectors;
 
 import org.apache.james.mailbox.store.mail.model.MimeMessageId;
 import org.apache.james.mailbox.store.mail.model.Subject;
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.field.UnstructuredFieldImpl;
 import org.apache.james.mime4j.message.HeaderImpl;
 import org.apache.james.mime4j.stream.Field;
 
+import com.github.steveash.guavate.Guavate;
+
 public class MimeMessageHeadersUtil {
-    public static MimeMessageId parseMimeMessageId(HeaderImpl headers) {
-        return new MimeMessageId(headers.getField("Message-ID").getBody());
+    public static Optional<MimeMessageId> parseMimeMessageId(HeaderImpl headers) {
+        return Optional.ofNullable(headers.getField("Message-ID")).map(field -> new MimeMessageId(field.getBody()));
     }
 
     public static Optional<MimeMessageId> parseInReplyTo(HeaderImpl headers) {
-        Field inReplyToField = headers.getField("In-Reply-To");
-        if (inReplyToField != null) {
-            return Optional.of(new MimeMessageId(inReplyToField.getBody()));
-        }
-        return Optional.empty();
+        return Optional.ofNullable(headers.getField("In-Reply-To")).map(field -> new MimeMessageId(field.getBody()));
     }
 
     public static Optional<List<MimeMessageId>> parseReferences(HeaderImpl headers) {
         List<Field> mimeMessageIdFields = headers.getFields("References");
         if (!mimeMessageIdFields.isEmpty()) {
             List<MimeMessageId> mimeMessageIdList = mimeMessageIdFields.stream()
                 .map(mimeMessageIdField -> new MimeMessageId(mimeMessageIdField.getBody()))
-                .collect(Collectors.toList());
+                .collect(Guavate.toImmutableList());
             return Optional.of(mimeMessageIdList);
         }
         return Optional.empty();
     }
 
-    public static Subject parseSubject(HeaderImpl headers) {
-        return new Subject(headers.getField("Subject").getBody());
+    public static Optional<Subject> parseSubject(HeaderImpl headers) {
+        return Optional.ofNullable(headers.getField("Subject"))
+            .map(field -> UnstructuredFieldImpl.PARSER.parse(field, DecodeMonitor.SILENT))

Review comment:
       ![image](https://user-images.githubusercontent.com/55171818/124060122-8cd8e780-da56-11eb-8743-6f6c0a004576.png)
   
   Actually we don't parse until we using .getValue, and in that if statement handle the situation you said.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] quantranhong1999 commented on a change in pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
quantranhong1999 commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r660484180



##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       How about using this header instance to get headers fields needed for ThreadIdGuessingAlgorithm, and still place ThreadIdGuessingAlgorithm at MessageStorer::appendMessageToStore as I am doing now? Because I think threadId should go with messageId. Otherwise we should messageId generate out of MessageStorer::appendMessageToStore.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r660439882



##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       Likely even better (and less hacky) in arseProperties there is a header isntance we do not use...
   
   ```
   private PropertyBuilder parseProperties(BodyOffsetInputStream bIn) throws IOException, MimeException {
           // Disable line length... This should be handled by the smtp server
           // component and not the parser itself
           // https://issues.apache.org/jira/browse/IMAP-122
           final MimeTokenStream parser = getParser(bIn);
           final HeaderImpl fields = readHeader(parser);
           
           // All we need for threadId guessing <3
           fields.getFields("Message-Id")
           
           final MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser.getBodyDescriptor();
           final MediaType mediaType = getMediaType(descriptor);
           final PropertyBuilder propertyBuilder = getPropertyBuilder(descriptor, mediaType.mediaType, mediaType.subType);
           setTextualLinesCount(parser, mediaType.mediaType, propertyBuilder);
           return propertyBuilder;
       }
    ```
    
    That method can then return an object combining properties and threadId....




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] quantranhong1999 commented on pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
quantranhong1999 commented on pull request #515:
URL: https://github.com/apache/james-project/pull/515#issuecomment-871140436


   It's failing somewhere else related to JPA, still working on this.
   Look like we are missing threadId at JPAMailboxMessage...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #515:
URL: https://github.com/apache/james-project/pull/515#issuecomment-871145615


   > Look like we are missing threadId at JPAMailboxMessage...
   
   Use the messageId there then ;-)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r660647641



##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       This sounds like a good proposal to me ;-)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] quantranhong1999 commented on pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
quantranhong1999 commented on pull request #515:
URL: https://github.com/apache/james-project/pull/515#issuecomment-872003860


   The related JPA tests fail is real. But these cassandra tests fail seems weird... they are green on local.
   
   ![image](https://user-images.githubusercontent.com/55171818/124084617-64aeb000-da79-11eb-92f1-66f787321c6d.png)
   
   ![image](https://user-images.githubusercontent.com/55171818/124085106-e1418e80-da79-11eb-8b8b-30e3101d598d.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] quantranhong1999 commented on a change in pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
quantranhong1999 commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r660484180



##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       How about using this header instance to get headers fields needed for ThreadIdGuessingAlgorithm, and still place ThreadIdGuessingAlgorithm at MessageStorer::appendMessageToStore as I am doing now? Because I think threadId should go with messageId. Otherwise we should move messageIdFactory.generate out of MessageStorer::appendMessageToStore.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] chibenwa commented on a change in pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r660439882



##########
File path: mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -72,22 +73,25 @@
         private final MessageFactory messageFactory;
         private final AttachmentMapperFactory attachmentMapperFactory;
         private final MessageParser messageParser;
+        private final ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm;
 
         public WithAttachment(MailboxSessionMapperFactory mapperFactory, MessageId.Factory messageIdFactory,
                               MessageFactory messageFactory, AttachmentMapperFactory attachmentMapperFactory,
-                              MessageParser messageParser) {
+                              MessageParser messageParser, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm) {
             this.mapperFactory = mapperFactory;
             this.messageIdFactory = messageIdFactory;
             this.messageFactory = messageFactory;
             this.attachmentMapperFactory = attachmentMapperFactory;
             this.messageParser = messageParser;
+            this.threadIdGuessingAlgorithm = threadIdGuessingAlgorithm;
         }
 
         @Override
         public Mono<Pair<MessageMetaData, Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox mailbox, Date internalDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage, MailboxSession session) throws MailboxException {
             MessageMapper messageMapper = mapperFactory.getMessageMapper(session);
             MessageId messageId = messageIdFactory.generate();
-            ThreadId threadId = ThreadId.fromBaseMessageId(messageId);
+            // TODO get mime message header fields

Review comment:
       Likely even better (and less hacky) in parseProperties there is a header isntance we do not use...
   
   ```
   private PropertyBuilder parseProperties(BodyOffsetInputStream bIn) throws IOException, MimeException {
           // Disable line length... This should be handled by the smtp server
           // component and not the parser itself
           // https://issues.apache.org/jira/browse/IMAP-122
           final MimeTokenStream parser = getParser(bIn);
           final HeaderImpl fields = readHeader(parser);
           
           // All we need for threadId guessing <3
           fields.getFields("Message-Id")
           
           final MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) parser.getBodyDescriptor();
           final MediaType mediaType = getMediaType(descriptor);
           final PropertyBuilder propertyBuilder = getPropertyBuilder(descriptor, mediaType.mediaType, mediaType.subType);
           setTextualLinesCount(parser, mediaType.mediaType, propertyBuilder);
           return propertyBuilder;
       }
    ```
    
    That method can then return an object combining properties and threadId....




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [james-project] quantranhong1999 edited a comment on pull request #515: JAMES-3516 Plug threadIdGuessingAlgorithm to MessageManager

Posted by GitBox <gi...@apache.org>.
quantranhong1999 edited a comment on pull request #515:
URL: https://github.com/apache/james-project/pull/515#issuecomment-872087789


   Rebased on master + squash fixups.
   
   Oops after rebase, it's actually failing ( because of this: https://github.com/apache/james-project/pull/464). At least I found out why :D 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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