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 a97d14088d JAMES-2586 blob resolvers should not throw an exception
when blob not found
a97d14088d is described below
commit a97d14088d69f321a91ff799be3bc5effe9268e9
Author: Rene Cordier <[email protected]>
AuthorDate: Thu Jan 23 17:05:50 2025 +0700
JAMES-2586 blob resolvers should not throw an exception when blob not found
---
.../apache/james/jmap/routes/DownloadRoutes.scala | 33 +++++++++++-----------
1 file changed, 16 insertions(+), 17 deletions(-)
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 99bc6f4951..cd590eed51 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
@@ -148,10 +148,9 @@ class MessageBlobResolver @Inject()(val messageIdFactory:
MessageId.Factory,
override def resolve(blobId: BlobId, mailboxSession: MailboxSession):
SMono[BlobResolutionResult] = {
Try(messageIdFactory.fromString(blobId.value.value)) match {
case Failure(_) => SMono.just(NonApplicable)
- case Success(messageId) => SMono.just(Applicable(SMono.fromPublisher(
- messageIdManager.getMessagesReactive(List(messageId).asJava,
FetchGroup.FULL_CONTENT, mailboxSession))
- .map[Blob](MessageBlob(blobId, _))
- .switchIfEmpty(SMono.error(BlobNotFoundException(blobId)))))
+ case Success(messageId) =>
SMono.fromPublisher(messageIdManager.getMessagesReactive(List(messageId).asJava,
FetchGroup.FULL_CONTENT, mailboxSession))
+ .map(message => Applicable(SMono.just(MessageBlob(blobId, message))))
+ .switchIfEmpty(SMono.just(NonApplicable))
}
}
}
@@ -164,23 +163,23 @@ class UploadResolver @Inject()(val uploadService:
UploadService) extends BlobRes
SMono.just(NonApplicable)
} else {
val uploadIdAsString = blobId.value.value.substring(prefix.length)
- SMono.just(Try(UploadId.from(uploadIdAsString)) match {
- case Failure(_) => NonApplicable
- case Success(uploadId) => Applicable(
- SMono(uploadService.retrieve(uploadId, mailboxSession.getUser))
- .map(upload => UploadedBlob(blobId, upload))
+ Try(UploadId.from(uploadIdAsString)) match {
+ case Failure(_) => SMono.just(NonApplicable)
+ case Success(uploadId) =>
SMono.fromPublisher(uploadService.retrieve(uploadId, mailboxSession.getUser))
+ .map(upload => Applicable(SMono.just(UploadedBlob(blobId,
upload))))
.onErrorResume {
- case _: UploadNotFoundException =>
SMono.error(BlobNotFoundException(blobId))
- })
- })
+ case _: UploadNotFoundException => SMono.just(NonApplicable)
+ case e => SMono.error[BlobResolutionResult](e)
+ }
+ }
}
}
}
class AttachmentBlobResolver @Inject()(val attachmentManager:
AttachmentManager, val attachmentIdFactory: AttachmentIdFactory) extends
BlobResolver {
override def resolve(blobId: BlobId, mailboxSession: MailboxSession):
SMono[BlobResolutionResult] =
- attachmentIdFactory.from(blobId.value.value) match {
- case attachmentId: StringBackedAttachmentId =>
+ Try(attachmentIdFactory.from(blobId.value.value)) match {
+ case Success(attachmentId) =>
SMono(attachmentManager.getAttachmentReactive(attachmentId,
mailboxSession))
.map(attachmentMetadata =>
Applicable(SMono(attachmentManager.loadReactive(attachmentMetadata,
mailboxSession))
.map(content => AttachmentBlob(attachmentMetadata, content))))
@@ -214,7 +213,7 @@ class MessagePartBlobResolver @Inject()(val
messageIdFactory: MessageId.Factory,
asMessageAndPartIds(blobId) match {
case Failure(_) => SMono.just(NonApplicable)
case Success((messageId, blobIds)) =>
- SMono.just(Applicable(SMono.fromPublisher(
+ SMono.fromPublisher(
messageIdManager.getMessagesReactive(List(messageId).asJava,
FetchGroup.FULL_CONTENT, mailboxSession))
.handle[MinimalEmailBodyPart] {
case (message, sink) => MinimalEmailBodyPart.ofMessage(None,
zoneIdSupplier.get(), BlobId.of(messageId).get, message)
@@ -229,8 +228,8 @@ class MessagePartBlobResolver @Inject()(val
messageIdFactory: MessageId.Factory,
}
.fold(sink.error(BlobNotFoundException(blobId)))(part =>
sink.next(part))
}
- .map[Blob](EmailBodyPartBlob(blobId, _))
- .switchIfEmpty(SMono.error(BlobNotFoundException(blobId)))))
+ .map(blob => Applicable(SMono.just(EmailBodyPartBlob(blobId, blob))))
+ .switchIfEmpty(SMono.just(NonApplicable))
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]