You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/12/06 01:54:24 UTC

[james-project] branch master updated: [FIX] EmailBodyPart filename should fallback to Content-Disposition field (#1348)

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


The following commit(s) were added to refs/heads/master by this push:
     new 8f717f9c22 [FIX] EmailBodyPart filename should fallback to Content-Disposition field (#1348)
8f717f9c22 is described below

commit 8f717f9c227c3139b03d49bfa8583e5b4898c417
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Tue Dec 6 08:54:19 2022 +0700

    [FIX] EmailBodyPart filename should fallback to Content-Disposition field (#1348)
---
 .../james/jmap/rfc8621/contract/EmailGetMethodContract.scala  |  6 ++++--
 .../main/scala/org/apache/james/jmap/mail/EmailBodyPart.scala | 11 +++++++++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailGetMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailGetMethodContract.scala
index 26f977a5d5..2da1b0acd9 100644
--- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailGetMethodContract.scala
+++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailGetMethodContract.scala
@@ -4459,7 +4459,8 @@ trait EmailGetMethodContract {
          |                                "size": 102,
          |                                "partId": "3",
          |                                "blobId": "${messageId.serialize}_3",
-         |                                "type": "application/json"
+         |                                "type": "application/json",
+         |                                "name":"yyy.txt"
          |                            },
          |                            {
          |                                "charset": "us-ascii",
@@ -4467,7 +4468,8 @@ trait EmailGetMethodContract {
          |                                "size": 102,
          |                                "partId": "4",
          |                                "blobId": "${messageId.serialize}_4",
-         |                                "type": "application/json"
+         |                                "type": "application/json",
+         |                                "name":"xxx.txt"
          |                            }
          |                        ],
          |                        "bodyValues": {
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 b1fa6363a0..0824cf5fbe 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
@@ -19,6 +19,8 @@
 
 package org.apache.james.jmap.mail
 
+import java.io.OutputStream
+
 import cats.implicits._
 import com.google.common.io.CountingOutputStream
 import eu.timepit.refined.api.Refined
@@ -32,13 +34,12 @@ import org.apache.james.jmap.mail.EmailBodyPart.{FILENAME_PREFIX, MULTIPART_ALTE
 import org.apache.james.jmap.mail.PartId.PartIdValue
 import org.apache.james.mailbox.model.{Cid, MessageId, MessageResult}
 import org.apache.james.mime4j.codec.{DecodeMonitor, DecoderUtil}
-import org.apache.james.mime4j.dom.field.{ContentLanguageField, ContentTypeField, FieldName}
+import org.apache.james.mime4j.dom.field.{ContentDispositionField, ContentLanguageField, ContentTypeField, FieldName}
 import org.apache.james.mime4j.dom.{Entity, Message, Multipart, TextBody => Mime4JTextBody}
 import org.apache.james.mime4j.message.{DefaultMessageBuilder, DefaultMessageWriter}
 import org.apache.james.mime4j.stream.{Field, MimeConfig, RawField}
 import org.apache.james.util.html.HtmlTextExtractor
 
-import java.io.OutputStream
 import scala.jdk.CollectionConverters._
 import scala.util.{Failure, Success, Try}
 
@@ -164,6 +165,12 @@ object Name {
           .map(DecoderUtil.decodeEncodedWords(_, DecodeMonitor.SILENT))
       case _ => None
     }.map(Name(_))
+    .orElse(Option(entity.getHeader.getField(FieldName.CONTENT_DISPOSITION))
+      .flatMap {
+        case contentDispositionField: ContentDispositionField => Option(contentDispositionField.getFilename)
+          .map(DecoderUtil.decodeEncodedWords(_, DecodeMonitor.SILENT))
+        case _ => None
+      }.map(Name(_)))
 }
 
 case class Name(value: String) extends AnyVal


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