This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch 3.9.x
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/3.9.x by this push:
     new 84fa171783 JAMES-3872 Fix PG FetchGroup metadata ReadLevel (backport) 
(#2872)
84fa171783 is described below

commit 84fa171783decf12462ed1a4871217815d91d96a
Author: Benoit TELLIER <[email protected]>
AuthorDate: Tue Dec 2 03:14:24 2025 +0100

    JAMES-3872 Fix PG FetchGroup metadata ReadLevel (backport) (#2872)
    
    - Fetch headers onto attachment fetchGroup
    - Attachment charset case sensitivity caused the tests to fail
    - Attachment CID serialization null handling was done wrong
---
 .../postgres/mail/dao/PostgresMailboxMessageDAOUtils.java   | 13 ++++---------
 .../james/mailbox/postgres/mail/dto/AttachmentsDTO.java     |  7 ++++++-
 .../src/main/scala/org/apache/james/jmap/mail/Email.scala   |  2 +-
 .../scala/org/apache/james/jmap/mail/EmailBodyPart.scala    |  7 ++++---
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git 
a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxMessageDAOUtils.java
 
b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxMessageDAOUtils.java
index ba759875e6..820ee72aec 100644
--- 
a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxMessageDAOUtils.java
+++ 
b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxMessageDAOUtils.java
@@ -50,6 +50,7 @@ import java.io.InputStream;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.function.Function;
 
@@ -170,15 +171,9 @@ interface PostgresMailboxMessageDAOUtils {
     };
 
     Function<MessageMapper.FetchType, PostgresMailboxMessageFetchStrategy> 
FETCH_TYPE_TO_FETCH_STRATEGY = fetchType -> {
-        switch (fetchType) {
-            case METADATA:
-            case ATTACHMENTS_METADATA:
-                return PostgresMailboxMessageFetchStrategy.METADATA;
-            case HEADERS:
-            case FULL:
-                return PostgresMailboxMessageFetchStrategy.FULL;
-            default:
-                throw new RuntimeException("Unknown FetchType " + fetchType);
+        if (Objects.requireNonNull(fetchType) == 
MessageMapper.FetchType.METADATA) {
+            return PostgresMailboxMessageFetchStrategy.METADATA;
         }
+        return PostgresMailboxMessageFetchStrategy.FULL;
     };
 }
diff --git 
a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dto/AttachmentsDTO.java
 
b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dto/AttachmentsDTO.java
index 303f1c5cb3..8cadec64fd 100644
--- 
a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dto/AttachmentsDTO.java
+++ 
b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dto/AttachmentsDTO.java
@@ -97,7 +97,12 @@ public class AttachmentsDTO extends 
ArrayList<MessageRepresentation.AttachmentRe
         private MessageRepresentation.AttachmentRepresentation 
fromJsonNode(JsonNode jsonNode) {
             AttachmentId attachmentId = 
StringBackedAttachmentId.from(jsonNode.get(ATTACHMENT_ID_PROPERTY).asText());
             Optional<String> name = 
Optional.ofNullable(jsonNode.get(NAME_PROPERTY)).map(JsonNode::asText);
-            Optional<Cid> cid = 
Optional.ofNullable(jsonNode.get(CID_PROPERTY)).map(JsonNode::asText).map(Cid::from);
+            Optional<Cid> cid = 
Optional.ofNullable(jsonNode.get(CID_PROPERTY)).flatMap(node -> {
+                if (node.isNull()) {
+                    return Optional.empty();
+                }
+                return Optional.ofNullable(node.textValue());
+            }).map(Cid::from);
             boolean isInline = jsonNode.get(IN_LINE_PROPERTY).asBoolean();
 
             return new 
MessageRepresentation.AttachmentRepresentation(attachmentId, name, cid, 
isInline);
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala
index 0a77ab425e..c180a11d9d 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Email.scala
@@ -868,7 +868,7 @@ private class EmailFastViewWithAttachmentsMetadataReader 
@Inject()(messageIdMana
           preview = fastView.getPreview),
         header = EmailHeaders.from(zoneIdProvider.get())(mime4JMessage),
         specificHeaders = 
EmailHeaders.extractSpecificHeaders(request.properties)(zoneIdProvider.get(), 
mime4JMessage.getHeader),
-        attachments = 
AttachmentsMetadata(firstMessage.getLoadedAttachments.asScala.toList.map(EmailBodyPart.fromAttachment(request.bodyProperties,
 zoneIdProvider.get(), _, mime4JMessage))))
+        attachments = 
AttachmentsMetadata(firstMessage.getLoadedAttachments.asScala.toList.map(EmailBodyPart.fromAttachment(_,
 mime4JMessage))))
     }
   }
 }
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailBodyPart.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailBodyPart.scala
index 0986a84493..8546980034 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailBodyPart.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailBodyPart.scala
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.mail
 
 import java.time.ZoneId
+import java.util.Locale
 
 import cats.implicits._
 import eu.timepit.refined.api.Refined
@@ -32,7 +33,7 @@ import org.apache.james.jmap.api.model.Size.Size
 import org.apache.james.jmap.core.Properties
 import org.apache.james.jmap.mail.EmailBodyPart.{FILENAME_PREFIX, MDN_TYPE, 
MULTIPART_ALTERNATIVE, TEXT_HTML, TEXT_PLAIN, of}
 import org.apache.james.jmap.mail.PartId.PartIdValue
-import org.apache.james.jmap.mime4j. SizeUtils
+import org.apache.james.jmap.mime4j.SizeUtils
 import org.apache.james.mailbox.model.{Cid, MessageAttachmentMetadata}
 import org.apache.james.mime4j.Charsets.ISO_8859_1
 import org.apache.james.mime4j.codec.{DecodeMonitor, DecoderUtil}
@@ -74,7 +75,7 @@ object EmailBodyPart {
   val defaultProperties: Properties = Properties("partId", "blobId", "size", 
"name", "type", "charset", "disposition", "cid", "language", "location")
   val allowedProperties: Properties = defaultProperties ++ 
Properties("subParts", "headers")
 
-  def fromAttachment(properties: Option[Properties], zoneId: ZoneId, 
attachment: MessageAttachmentMetadata, entity: Message): EmailBodyPart = {
+  def fromAttachment(attachment: MessageAttachmentMetadata, entity: Message): 
EmailBodyPart = {
     def parseDisposition(attachment: MessageAttachmentMetadata): 
Option[Disposition] =
       if (attachment.isInline) {
         Option(Disposition.INLINE)
@@ -88,7 +89,7 @@ object EmailBodyPart {
       size = Size.sanitizeSize(attachment.getAttachment.getSize),
       name = attachment.getName.map(Name(_)).toScala,
       `type` = Type(attachment.getAttachment.getType.mimeType().asString()),
-      charset = attachment.getAttachment.getType.charset().map(charset => 
Charset(charset.name())).toScala,
+      charset = attachment.getAttachment.getType.charset().map(charset => 
Charset(charset.name().toUpperCase(Locale.US))).toScala,
       disposition = parseDisposition(attachment),
       cid = attachment.getCid.toScala,
       language = Option.empty,


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to