chibenwa commented on a change in pull request #385:
URL: https://github.com/apache/james-project/pull/385#discussion_r616374148
##########
File path:
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNSendMethod.scala
##########
@@ -212,21 +212,17 @@ class MDNSendMethod @Inject()(serializer: MDNSerializer,
.map(mailbox => mailbox.getAddress)
.toRight(MDNSendNotFoundException("Invalid
\"Disposition-Notification-To\" header field."))
- private def getMDNFinalRecipient(requestEntry: MDNSendCreateRequest,
identity: Identity): Either[MDNSendForbiddenFromException, FinalRecipient] = {
- if (requestEntry.finalRecipient.isEmpty) {
- scala.Right(FinalRecipient.builder()
- .finalRecipient(Text.fromRawText(identity.email.asString()))
- .build())
- }
- else {
- val tryMailAddress: Try[MailAddress] =
requestEntry.finalRecipient.get.getMailAddress
- if (tryMailAddress.isSuccess &&
tryMailAddress.get.equals(identity.email)) {
- scala.Right(requestEntry.finalRecipient.get.asJava.get)
- } else {
- Left(MDNSendForbiddenFromException("The user is not allowed to use the
given \"finalRecipient\" property"))
+ private def getMDNFinalRecipient(requestEntry: MDNSendCreateRequest,
identity: Identity): Either[MDNSendForbiddenFromException, FinalRecipient] =
+ requestEntry.finalRecipient
+ .map(finalRecipient => finalRecipient.getMailAddress)
+ .map(mayBeMailAddress => (mayBeMailAddress.isSuccess &&
mayBeMailAddress.get.equals(identity.email)))
Review comment:
We should be able to do some kind more advanced map here;
```
.map {
case scala.Right(finalRecipient) if finalRecipient.equals(identity.email)
=> scala.Right(finalRecipient.asJava.get)
case scala.Right(finalRecipient) =>
Left(MDNSendForbiddenFromException("The user is not allowed to use the given
\"finalRecipient\" property"))
case Left(e) => Left(e)
}
.getOrElse(scala.Right(FinalRecipient.builder()
.finalRecipient(Text.fromRawText(identity.email.asString()))
.build()))
```
Yes scala is super expressive!
##########
File path:
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/method/MDNSendMethod.scala
##########
@@ -59,7 +59,7 @@ class MDNSendMethod @Inject()(serializer: MDNSerializer,
mailQueueFactory: MailQueueFactory[_ <:
MailQueue],
messageIdManager: MessageIdManager,
emailSetMethod: EmailSetMethod,
- val identifyStore: IdentifyStore,
+ val identifyResolver: IdentifyResolver,
Review comment:
identifyResolver -> identityResolver
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]