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 eb9bd9c77ebfce6e439d7308235c34c70ea229e3
Author: Benoit Tellier <[email protected]>
AuthorDate: Sun May 2 06:46:03 2021 +0700

    JAMES-3575 [REFACTORING] Flatten EmailSubmissionSet for/yield
---
 .../jmap/method/EmailSubmissionSetMethod.scala     | 54 ++++++++++------------
 1 file changed, 25 insertions(+), 29 deletions(-)

diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala
index e5f3bb8..4c9edd3 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/EmailSubmissionSetMethod.scala
@@ -241,35 +241,31 @@ class EmailSubmissionSetMethod @Inject()(serializer: 
EmailSubmissionSetSerialize
 
   private def sendEmail(mailboxSession: MailboxSession,
                         request: EmailSubmissionCreationRequest): 
Either[Throwable, (EmailSubmissionCreationResponse, MessageId)] = {
-    val message: Either[Exception, MessageResult] = 
messageIdManager.getMessage(request.emailId, FetchGroup.FULL_CONTENT, 
mailboxSession)
-      .asScala
-      .toList
-      .headOption
-      .toRight(MessageNotFoundException(request.emailId))
-
-    message.flatMap(m => {
-      val submissionId = EmailSubmissionId.generate
-
-      val result: Try[EmailSubmissionCreationResponse] = for {
-        message <- toMimeMessage(submissionId.value, m)
-        envelope <- resolveEnvelope(message, request.envelope)
-        validation <- validate(mailboxSession)(message, envelope)
-        mail <- Try({
-          val mailImpl = MailImpl.builder()
-            .name(submissionId.value)
-            .addRecipients(envelope.rcptTo.map(_.email).asJava)
-            .sender(envelope.mailFrom.email)
-            .addAttribute(new Attribute(MAIL_METADATA_USERNAME_ATTRIBUTE, 
AttributeValue.of(mailboxSession.getUser.asString())))
-            .build()
-          mailImpl.setMessageNoCopy(message)
-          mailImpl
-        })
-        enqueue <- Try(queue.enQueue(mail))
-      } yield {
-        EmailSubmissionCreationResponse(submissionId)
-      }
-      result.toEither.map(response => (response, request.emailId))
-    })
+   val result = for {
+      message <- messageIdManager.getMessage(request.emailId, 
FetchGroup.FULL_CONTENT, mailboxSession)
+        .asScala
+        .toList
+        .headOption
+        .toRight(MessageNotFoundException(request.emailId))
+      submissionId = EmailSubmissionId.generate
+      message <- toMimeMessage(submissionId.value, message).toEither
+      envelope <- resolveEnvelope(message, request.envelope).toEither
+      validation <- validate(mailboxSession)(message, envelope).toEither
+      mail <- Try({
+        val mailImpl = MailImpl.builder()
+          .name(submissionId.value)
+          .addRecipients(envelope.rcptTo.map(_.email).asJava)
+          .sender(envelope.mailFrom.email)
+          .addAttribute(new Attribute(MAIL_METADATA_USERNAME_ATTRIBUTE, 
AttributeValue.of(mailboxSession.getUser.asString())))
+          .build()
+        mailImpl.setMessageNoCopy(message)
+        mailImpl
+      }).toEither
+      enqueue <- Try(queue.enQueue(mail)).toEither
+    } yield {
+      EmailSubmissionCreationResponse(submissionId)
+    }
+     result.map(response => (response, request.emailId))
   }
 
   private def toMimeMessage(name: String, message: MessageResult): 
Try[MimeMessageWrapper] = {

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

Reply via email to