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 01:40:52 UTC

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

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