This is an automated email from the ASF dual-hosted git repository.
rcordier 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 3797f3d7ab JAMES-3533 JMAP - Download - Fix extract blobId of
MessagePartBlobResolver
3797f3d7ab is described below
commit 3797f3d7abf4660eec6a7ca3d8473c8e1826079b
Author: vttran <[email protected]>
AuthorDate: Mon May 15 08:49:30 2023 +0700
JAMES-3533 JMAP - Download - Fix extract blobId of MessagePartBlobResolver
---
.../jmap/rfc8621/contract/DownloadContract.scala | 29 ++++++++++++++++++++++
.../apache/james/jmap/routes/DownloadRoutes.scala | 2 +-
2 files changed, 30 insertions(+), 1 deletion(-)
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/DownloadContract.scala
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DownloadContract.scala
index 650aad6e25..6c93b6427f 100644
---
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DownloadContract.scala
+++
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DownloadContract.scala
@@ -32,10 +32,12 @@ import
org.apache.james.jmap.rfc8621.contract.Fixture.{ACCEPT_RFC8621_VERSION_HE
import org.apache.james.mailbox.MessageManager.AppendCommand
import org.apache.james.mailbox.model.MailboxACL.Right
import org.apache.james.mailbox.model.{MailboxACL, MailboxPath, MessageId}
+import org.apache.james.mime4j.dom.Message
import org.apache.james.modules.{ACLProbeImpl, MailboxProbeImpl}
import org.apache.james.util.ClassLoaderUtils
import org.apache.james.utils.DataProbeImpl
import org.assertj.core.api.Assertions.assertThat
+import org.hamcrest.Matchers
import org.hamcrest.Matchers.{containsString, equalTo}
import org.junit.jupiter.api.{BeforeEach, Test}
@@ -620,4 +622,31 @@ trait DownloadContract {
assertThat(new
ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8)))
.hasContent(expectedResponse)
}
+
+ @Test
+ def downloadShouldFailWhenEmailPartInvalid(server: GuiceJamesServer): Unit =
{
+ val message: Message = Message.Builder
+ .of
+ .setSubject("test")
+ .setBody("testmail", StandardCharsets.UTF_8)
+ .build
+
+ val path = MailboxPath.inbox(BOB)
+ server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path)
+
+ val messageId = server.getProbe(classOf[MailboxProbeImpl])
+ .appendMessage(BOB.asString(), path, AppendCommand.from(message))
+ .getMessageId.serialize()
+
+ val messageAndInvalidPart: String = messageId + "_"
+
+ `given`
+ .basePath("")
+ .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+ .when
+ .get(s"/download/$accountId/$messageAndInvalidPart")
+ .`then`
+ .statusCode(404)
+ .body(Matchers.containsString("The resource could not be found"))
+ }
}
diff --git
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/DownloadRoutes.scala
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/DownloadRoutes.scala
index 2559866df9..63ca6c1ccd 100644
---
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/DownloadRoutes.scala
+++
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/DownloadRoutes.scala
@@ -192,7 +192,7 @@ class MessagePartBlobResolver @Inject()(val
messageIdFactory: MessageId.Factory,
val zoneIdSupplier: ZoneIdProvider)
extends BlobResolver {
private def asMessageAndPartIds(blobId: BlobId): Try[(MessageId,
List[BlobId])] = {
blobId.value.value.split('_').toList match {
- case messageIdString :: tail => for {
+ case messageIdString :: tail if tail.nonEmpty => for {
messageId <- Try(messageIdFactory.fromString(messageIdString))
} yield {
(messageId, partsToListOfBlobIds(messageIdString, tail))
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]