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/07/01 03:26:54 UTC

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

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