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 2020/09/08 03:43:03 UTC
[james-project] 09/19: JAMES-3369 Review Email::from error handling
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
commit 57d5c8dd9e4aad070c1645b697a9c7bfbebff2d8
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Sep 7 16:11:55 2020 +0700
JAMES-3369 Review Email::from error handling
---
.../src/main/scala/org/apache/james/jmap/mail/Email.scala | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
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 61c59ef..5f499e9 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
@@ -65,17 +65,22 @@ object Email {
}
def from(message: (MessageId, Seq[MessageResult])): Try[Email] = {
- val firstMessage: MessageResult = message._2.head
val defaultMessageBuilder = new DefaultMessageBuilder
defaultMessageBuilder.setMimeEntityConfig(MimeConfig.PERMISSIVE)
defaultMessageBuilder.setDecodeMonitor(DecodeMonitor.SILENT)
- val mime4JMessage: Message = defaultMessageBuilder.parseMessage(firstMessage.getFullContent.getInputStream)
val messageId: MessageId = message._1
- val bodyStructureTry = EmailBodyPart.of(messageId, mime4JMessage)
-
- bodyStructureTry.map(bodyStructure => Email(messageId, sanitizeSize(firstMessage.getSize), bodyStructure))
+ for {
+ firstMessage <- message._2
+ .headOption
+ .map(Success(_))
+ .getOrElse(Failure(new IllegalArgumentException("No message supplied")))
+ mime4JMessage <- Try(defaultMessageBuilder.parseMessage(firstMessage.getFullContent.getInputStream))
+ bodyStructure <- EmailBodyPart.of(messageId, mime4JMessage)
+ } yield {
+ Email(messageId, sanitizeSize(firstMessage.getSize), bodyStructure)
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org