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 2fdff661da9b0073ee63fb2191322db07afe854e Author: Tung Tran <vtt...@linagora.com> AuthorDate: Sat Jun 24 07:51:04 2023 +0700 [CLEAN CODE] Scala code - Fix warning log --- .../cassandra/CassandraEventStoreExtension.scala | 4 +- .../cassandra/JsonEventSerializerTest.scala | 2 +- .../rfc8621/contract/CustomMethodContract.scala | 6 +- .../rfc8621/contract/EmailSetMethodContract.scala | 27 +-- .../contract/MailboxSetMethodContract.scala | 5 +- .../jmap/rfc8621/contract/WebSocketContract.scala | 185 +++++---------------- .../james/jmap/rfc8621/contract/package.scala | 35 ++++ .../james/jmap/json/DelegationSerializer.scala | 2 + .../james/jmap/json/EmailGetSerializer.scala | 6 +- .../james/jmap/json/EmailQuerySerializer.scala | 1 + .../james/jmap/json/EmailSetSerializer.scala | 1 + .../james/jmap/json/IdentitySerializer.scala | 1 + .../apache/james/jmap/json/MailboxSerializer.scala | 1 + .../jmap/json/PushSubscriptionSerializer.scala | 1 + .../apache/james/jmap/json/QuotaSerializer.scala | 1 + .../james/jmap/json/VacationSerializer.scala | 1 + .../scala/org/apache/james/jmap/json/package.scala | 2 + .../scala/org/apache/james/jmap/mail/Email.scala | 1 + .../org/apache/james/jmap/mail/EmailHeader.scala | 4 +- .../org/apache/james/jmap/mail/EmailSet.scala | 4 +- .../scala/org/apache/james/jmap/mail/Keyword.scala | 2 +- .../org/apache/james/jmap/mail/Keywords.scala | 4 +- .../james/jmap/routes/EventSourceRoutes.scala | 1 + .../org/apache/james/jmap/routes/JmapApi.scala | 2 +- .../apache/james/jmap/routes/UploadRoutes.scala | 2 +- .../james/queue/pulsar/PulsarMailQueue.scala | 1 + .../task/eventsourcing/DecisionProjection.scala | 1 + 27 files changed, 112 insertions(+), 191 deletions(-) diff --git a/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreExtension.scala b/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreExtension.scala index df5a0514f7..1adc17ff58 100644 --- a/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreExtension.scala +++ b/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreExtension.scala @@ -27,9 +27,7 @@ class CassandraEventStoreExtension(var cassandra: CassandraClusterExtension, val private var eventStoreDao : Option[EventStoreDao] = None - def this(eventSerializer: JsonEventSerializer) { - this(new CassandraClusterExtension(CassandraEventStoreModule.MODULE), eventSerializer) - } + def this(eventSerializer: JsonEventSerializer) = this(new CassandraClusterExtension(CassandraEventStoreModule.MODULE), eventSerializer) override def beforeAll(context: ExtensionContext): Unit = cassandra.beforeAll(context) diff --git a/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializerTest.scala b/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializerTest.scala index 6961ce55cc..7896527b89 100644 --- a/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializerTest.scala +++ b/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializerTest.scala @@ -43,7 +43,7 @@ class JsonEventSerializerTest { .isEqualTo(JsonEventSerializerTest.TEST_EVENT) @Test - def shouldThrowWhenDeserializeUnknownEvent() = + def shouldThrowWhenDeserializeUnknownEvent(): Unit = assertThatThrownBy(() => JsonEventSerializer .forModules() 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/CustomMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/CustomMethodContract.scala index cf474fe0ce..685ec1711b 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/CustomMethodContract.scala +++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/CustomMethodContract.scala @@ -307,8 +307,7 @@ trait CustomMethodContract { server.getProbe(classOf[JmapEventBusProbe]) .emitStateChange(stateChangeEvent, accountId) - ws.receive() - .map { case t: Text => t.payload } + ws.receive().asPayload }) .send(backend) .body @@ -348,8 +347,7 @@ trait CustomMethodContract { server.getProbe(classOf[JmapEventBusProbe]) .emitStateChange(stateChangeEvent, accountId) - ws.receive() - .map { case t: Text => t.payload } + ws.receive().asPayload }) .send(backend) .body 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/EmailSetMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSetMethodContract.scala index 03ae3905ff..d15444a64d 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSetMethodContract.scala +++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/EmailSetMethodContract.scala @@ -56,6 +56,7 @@ import org.apache.james.utils.DataProbeImpl import org.assertj.core.api.Assertions.assertThat import org.awaitility.Awaitility import org.awaitility.Durations.ONE_HUNDRED_MILLISECONDS +import org.hamcrest.Matchers import org.hamcrest.Matchers.{equalTo, not} import org.junit.jupiter.api.{BeforeEach, Test} import org.junit.jupiter.params.ParameterizedTest @@ -1511,7 +1512,7 @@ trait EmailSetMethodContract { | ] |}""".stripMargin - val response = `given` + `given` .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER) .body(request) .when @@ -1519,26 +1520,10 @@ trait EmailSetMethodContract { .`then` .statusCode(SC_OK) .contentType(JSON) - .extract - .body - .asString - - assertThatJson(response) - .whenIgnoringPaths("methodResponses[0][1].notCreated.aaaaaa.description") - .inPath("methodResponses[0][1].notCreated.aaaaaa") - .isEqualTo( - s"""{ - | "type": "tooLarge" - |}""".stripMargin) - - // Message size is date-time and matchine (Message-Id) dependant - val description = assertThatJson(response) - .withIgnorePlaceholder("@") - .inPath("methodResponses[0][1].notCreated.aaaaaa.description") - .asString() - description.endsWith(" bytes while the maximum allowed is 10485760") - description.startsWith("Attempt to create a message of ") - + .body("methodResponses[0][1].notCreated.aaaaaa.type", equalTo("tooLarge")) + .body("methodResponses[0][1].notCreated.aaaaaa.description", + Matchers.allOf(Matchers.startsWith("Attempt to create a message of "), + Matchers.endsWith(" bytes while the maximum allowed is 10485760"))) } @Test 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/MailboxSetMethodContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala index 632c3957da..6d925fb6c4 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala +++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/MailboxSetMethodContract.scala @@ -8042,10 +8042,7 @@ trait MailboxSetMethodContract { | }, "c1"]] |}""".stripMargin)) - List(ws.receive() - .map { case t: Text => - t.payload - }) + List(ws.receive().asPayload) }) .send(backend) .body 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/WebSocketContract.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/WebSocketContract.scala index cd5ea01246..0f04f7c453 100644 --- a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/WebSocketContract.scala +++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/WebSocketContract.scala @@ -52,8 +52,6 @@ import sttp.client3.okhttp.OkHttpSyncBackend import sttp.client3.{Identity, RequestT, SttpBackend, asWebSocket, basicRequest} import sttp.model.Uri import sttp.monad.MonadError -import sttp.monad.syntax.MonadErrorOps -import sttp.ws.WebSocketFrame.Text import sttp.ws.{WebSocket, WebSocketFrame} import scala.jdk.CollectionConverters._ @@ -102,8 +100,7 @@ trait WebSocketContract { | ] |}""".stripMargin)) - ws.receive() - .map { case t: Text => t.payload } + ws.receive().asPayload }) .send(backend) .body @@ -148,10 +145,7 @@ trait WebSocketContract { | ] | ] |}""".stripMargin)) - ws.receive() - .map { - case t: Text => t.payload - } + ws.receive().asPayload }, { Thread.sleep(200) @@ -172,10 +166,7 @@ trait WebSocketContract { | ] |}""".stripMargin)) - ws.receive() - .map { - case t: Text => t.payload - } + ws.receive().asPayload }) }) .send(backend) @@ -194,8 +185,7 @@ trait WebSocketContract { ws => ws.send(WebSocketFrame.text("The quick brown fox")) - ws.receive() - .map { case t: Text => t.payload } + ws.receive().asPayload }) .send(backend) .body @@ -219,8 +209,7 @@ trait WebSocketContract { ws => ws.send(WebSocketFrame.text("The quick brown fox")) - ws.receive() - .map { case t: Text => t.toString } + ws.receive().asPayload }) .send(backend) .body) @@ -250,8 +239,7 @@ trait WebSocketContract { | ] |}""".stripMargin)) - ws.receive() - .map { case t: Text => t.payload } + ws.receive().asPayload }) .send(backend) .body @@ -290,8 +278,7 @@ trait WebSocketContract { | ] |}""".stripMargin)) - ws.receive() - .map { case t: Text => t.payload } + ws.receive().asPayload }) .send(backend) .body @@ -330,8 +317,7 @@ trait WebSocketContract { | ] |}""".stripMargin)) - ws.receive() - .map { case t: Text => t.payload } + ws.receive().asPayload }) .send(backend) .body @@ -370,8 +356,7 @@ trait WebSocketContract { | ] |}""".stripMargin)) - ws.receive() - .map { case t: Text => t.payload } + ws.receive().asPayload }) .send(backend) .body @@ -408,8 +393,7 @@ trait WebSocketContract { | "c1"]] |}""".stripMargin)) - ws.receive() - .map { case t: Text => t.payload } + ws.receive().asPayload }) .send(backend) .body @@ -463,14 +447,8 @@ trait WebSocketContract { |}""".stripMargin)) List( - ws.receive() - .map { case t: Text => - t.payload - }, - ws.receive() - .map { case t: Text => - t.payload - }) + ws.receive().asPayload, + ws.receive().asPayload) }) .send(backend) .body @@ -516,10 +494,7 @@ trait WebSocketContract { sendEmailTo(server, DAVID) List( - ws.receive() - .map { case t: Text => - t.payload - }) + ws.receive().asPayload) }) .send(backend) .body @@ -561,10 +536,7 @@ trait WebSocketContract { sendEmailTo(server, BOB) List( - ws.receive() - .map { case t: Text => - t.payload - }) + ws.receive().asPayload) }) .send(backend) .body @@ -608,22 +580,10 @@ trait WebSocketContract { sendEmailTo(server, BOB) List( - ws.receive() - .map { case t: Text => - t.payload - }, - ws.receive() - .map { case t: Text => - t.payload - }, - ws.receive() - .map { case t: Text => - t.payload - }, - ws.receive() - .map { case t: Text => - t.payload - }) + ws.receive().asPayload, + ws.receive().asPayload, + ws.receive().asPayload, + ws.receive().asPayload) }) .send(backend) .body @@ -686,10 +646,7 @@ trait WebSocketContract { createEmail(ws) List.range(0, 10) - .map(i => ws.receive() - .map { case t: Text => - t.payload - }) + .map(i => ws.receive().asPayload) }) .send(backend) .body @@ -735,14 +692,8 @@ trait WebSocketContract { |}""".stripMargin)) List( - ws.receive() - .map { case t: Text => - t.payload - }, - ws.receive() - .map { case t: Text => - t.payload - }) + ws.receive().asPayload, + ws.receive().asPayload) }) .send(backend) .body @@ -794,14 +745,8 @@ trait WebSocketContract { |}""".stripMargin)) List( - ws.receive() - .map { case t: Text => - t.payload - }, - ws.receive() - .map { case t: Text => - t.payload - }) + ws.receive().asPayload, + ws.receive().asPayload) }) .send(backend) .body @@ -851,10 +796,7 @@ trait WebSocketContract { | }, "c1"]] |}""".stripMargin)) - val responseAsJson = Json.parse(ws.receive() - .map { case t: Text => - t.payload - }) + val responseAsJson = Json.parse(ws.receive().asPayload) .\("methodResponses") .\(0).\(1) .\("created") @@ -891,15 +833,8 @@ trait WebSocketContract { | }, "c1"]] |}""".stripMargin)) - val stateChange1 = ws.receive() - .map { case t: Text => - t.payload - } - val response1 = - ws.receive() - .map { case t: Text => - t.payload - } + val stateChange1 = ws.receive().asPayload + val response1 = ws.receive().asPayload Thread.sleep(100) @@ -916,15 +851,8 @@ trait WebSocketContract { Thread.sleep(100) - val stateChange2 = ws.receive() - .map { case t: Text => - t.payload - } - val response2 = - ws.receive() - .map { case t: Text => - t.payload - } + val stateChange2 = ws.receive().asPayload + val response2 = ws.receive().asPayload List(response1, response2, stateChange1, stateChange2) }) @@ -978,14 +906,8 @@ trait WebSocketContract { |}""".stripMargin)) List( - ws.receive() - .map { case t: Text => - t.payload - }, - ws.receive() - .map { case t: Text => - t.payload - }) + ws.receive().asPayload, + ws.receive().asPayload) }) .send(backend) .body @@ -1025,10 +947,7 @@ trait WebSocketContract { sendEmailTo(server, BOB) List( - ws.receive() - .map { case t: Text => - t.payload - }) + ws.receive().asPayload) }) .send(backend) .body @@ -1075,14 +994,8 @@ trait WebSocketContract { |}""".stripMargin)) List( - ws.receive() - .map { case t: Text => - t.payload - }, - ws.receive() - .map { case t: Text => - t.payload - }) + ws.receive().asPayload, + ws.receive().asPayload) }) .send(backend) .body @@ -1138,14 +1051,8 @@ trait WebSocketContract { | }, "c1"]] |}""".stripMargin)) - List(ws.receive() - .map { case t: Text => - t.payload - }, - ws.receive() - .map { case t: Text => - t.payload - }) + List(ws.receive().asPayload, + ws.receive().asPayload) }) .send(backend) .body @@ -1196,11 +1103,7 @@ trait WebSocketContract { Thread.sleep(100) - List( - ws.receive() - .map { case t: Text => - t.payload - }) + List(ws.receive().asPayload) }) .send(backend) .body @@ -1266,16 +1169,10 @@ trait WebSocketContract { | }, "c1"]] |}""".stripMargin)) - val response = ws.receive() - .map { case t: Text => - t.payload - } + val response = ws.receive().asPayload val maybeNotification: String = Try(SMono.fromCallable(() => - ws.receive() - .map { case t: Text => - t.payload - }) + ws.receive().asPayload) .subscribeOn(Schedulers.newSingle("test")) .block(scala.concurrent.duration.Duration.fromNanos(100000000))) .fold(e => "No notification received", s => s) @@ -1342,11 +1239,7 @@ trait WebSocketContract { Thread.sleep(100) - ws.receive() - .map { case t: Text => - t.payload - } - }) + ws.receive().asPayload}) .send(backend) .body 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/package.scala b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/package.scala new file mode 100644 index 0000000000..4b2a41999a --- /dev/null +++ b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/package.scala @@ -0,0 +1,35 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.jmap.rfc8621 + +import cats.implicits.toFunctorOps +import sttp.client3.Identity +import sttp.ws.WebSocketFrame +import sttp.ws.WebSocketFrame.Text + +package object contract { + + implicit class asPayload(val webSocketFrame: Identity[WebSocketFrame]) { + def asPayload: Identity[String] = webSocketFrame.map { + case t: Text => t.payload + case _ => throw new RuntimeException("Not a text frame") + } + } +} diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/DelegationSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/DelegationSerializer.scala index dd2e078426..4a19803a28 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/DelegationSerializer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/DelegationSerializer.scala @@ -88,6 +88,7 @@ object DelegationSerializer { .filter(jsonObject) case jsValue => jsValue })) + case jsValue => JsError(s"expected JsArray, got $jsValue") }).get def serialize(response: DelegatedAccountGetResponse, properties: Properties): JsValue = @@ -99,5 +100,6 @@ object DelegationSerializer { .filter(jsonObject) case jsValue => jsValue })) + case jsValue => JsError(s"expected JsArray, got $jsValue") }).get } \ No newline at end of file diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailGetSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailGetSerializer.scala index 33e63eb5e1..3da03d5c39 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailGetSerializer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailGetSerializer.scala @@ -89,7 +89,6 @@ object EmailGetSerializer { private implicit val hasAttachmentWrites: Writes[HasAttachment] = Json.valueWrites[HasAttachment] private implicit val headerNameWrites: Writes[EmailHeaderName] = Json.valueWrites[EmailHeaderName] private implicit val rawHeaderWrites: Writes[RawHeaderValue] = Json.valueWrites[RawHeaderValue] - private implicit val allHeaderWrites: Writes[AllHeaderValues] = Json.valueWrites[AllHeaderValues] private implicit val textHeaderWrites: Writes[TextHeaderValue] = Json.valueWrites[TextHeaderValue] private implicit val addressesHeaderWrites: Writes[AddressesHeaderValue] = Json.valueWrites[AddressesHeaderValue] private implicit val GroupNameWrites: Writes[GroupName] = Json.valueWrites[GroupName] @@ -103,7 +102,7 @@ object EmailGetSerializer { private implicit val headerURLWrites: Writes[HeaderURL] = Json.valueWrites[HeaderURL] private implicit val urlsHeaderWrites: Writes[URLsHeaderValue] = Json.valueWrites[URLsHeaderValue] private implicit val emailHeaderWrites: Writes[EmailHeaderValue] = { - case headerValue: AllHeaderValues => JsArray(headerValue.values.map(h => Json.toJson[EmailHeaderValue](h))) + case headerValue: AllHeaderValues => JsArray(headerValue.values.map(h => Json.toJson[EmailHeaderValue](h)(emailHeaderWrites))) case headerValue: RawHeaderValue => Json.toJson[RawHeaderValue](headerValue) case headerValue: TextHeaderValue => Json.toJson[TextHeaderValue](headerValue) case headerValue: AddressesHeaderValue => Json.toJson[AddressesHeaderValue](headerValue) @@ -112,6 +111,7 @@ object EmailGetSerializer { case headerValue: DateHeaderValue => Json.toJson[DateHeaderValue](headerValue) case headerValue: URLsHeaderValue => Json.toJson[URLsHeaderValue](headerValue) } + private implicit val allHeaderWrites: Writes[AllHeaderValues] = Json.valueWrites[AllHeaderValues] private implicit val headersWrites: Writes[EmailHeader] = Json.writes[EmailHeader] private implicit val bodyValueWrites: Writes[EmailBodyValue] = Json.writes[EmailBodyValue] private implicit val unparsedMessageIdWrites: Writes[UnparsedEmailId] = Json.valueWrites[UnparsedEmailId] @@ -149,7 +149,7 @@ object EmailGetSerializer { (__ \ "cid").writeNullable[Cid] and (__ \ "language").writeNullable[Languages] and (__ \ "location").writeNullable[Location] and - (__ \ "subParts").lazyWriteNullable(implicitly[Writes[List[EmailBodyPartToSerialize]]]) and + (__ \ "subParts").lazyWriteNullable(implicitly[Writes[List[EmailBodyPartToSerialize]]](list => new JsArray(list.map(bodyPartWritesToSerializeWrites.writes).toIndexedSeq) )) and JsPath.write[Map[String, Option[EmailHeaderValue]]] )(unlift(EmailBodyPartToSerialize.unapply)) diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailQuerySerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailQuerySerializer.scala index c41e255daa..02f0a353d0 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailQuerySerializer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailQuerySerializer.scala @@ -120,6 +120,7 @@ class EmailQuerySerializer @Inject()(mailboxIdFactory: MailboxId.Factory) { } private implicit val sortPropertyWrites: Writes[SortProperty] = { case ReceivedAtSortProperty => JsString("receivedAt") + case _ => throw new NotImplementedError() } private implicit val isAscendingFormat: Format[IsAscending] = Json.valueFormat[IsAscending] diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailSetSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailSetSerializer.scala index c11d46bf62..3ec0ea36ed 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailSetSerializer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/EmailSetSerializer.scala @@ -251,6 +251,7 @@ class EmailSetSerializer @Inject()(messageIdFactory: MessageId.Factory, mailboxI .sequence .fold(e => JsError(e), ids => JsSuccess(MessageIdsHeaderValue(Some(ids).filter(_.nonEmpty)))) + case jsValue => JsError(s"expected JsArray, got $jsValue") } private implicit val isTruncatedReads: Reads[IsTruncated] = Json.valueReads[IsTruncated] diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/IdentitySerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/IdentitySerializer.scala index daad8cc0a6..41139f143a 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/IdentitySerializer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/IdentitySerializer.scala @@ -103,6 +103,7 @@ object IdentitySerializer { case jsonObject: JsObject => propertiesFiltered(properties, capabilities).filter(jsonObject) case jsValue => jsValue })) + case jsValue => JsError(s"expected JsArray, got $jsValue") }).get diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MailboxSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MailboxSerializer.scala index 517e5d37d4..0acf331102 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MailboxSerializer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/MailboxSerializer.scala @@ -180,6 +180,7 @@ class MailboxSerializer @Inject()(mailboxIdFactory: MailboxId.Factory) { case jsonObject: JsObject => mailboxTransformation.filter(jsonObject) case jsValue => jsValue })) + case jsValue => JsError(s"expected JsArray, got $jsValue") }).get } diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/PushSubscriptionSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/PushSubscriptionSerializer.scala index aa23892582..db4d497c5a 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/PushSubscriptionSerializer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/PushSubscriptionSerializer.scala @@ -116,5 +116,6 @@ class PushSubscriptionSerializer @Inject()(typeStateFactory: TypeStateFactory) { properties.filter(jsonObject) case jsValue => jsValue })) + case jsValue => JsError(s"expected JsArray, got $jsValue") }).get } diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/QuotaSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/QuotaSerializer.scala index c9ee5512f2..c6fb5f90f5 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/QuotaSerializer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/QuotaSerializer.scala @@ -124,6 +124,7 @@ object QuotaSerializer { .filter(jsonObject) case jsValue => jsValue })) + case jsValue => JsError(s"expected JsArray, got $jsValue") }).get def serialize(response: QuotaGetResponse): JsValue = Json.toJson(response) diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/VacationSerializer.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/VacationSerializer.scala index 5f54cf5397..5862078152 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/VacationSerializer.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/VacationSerializer.scala @@ -91,6 +91,7 @@ object VacationSerializer { .filter(jsonObject) case jsValue => jsValue })) + case jsValue => JsError(s"expected JsArray, got $jsValue") }).get diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/package.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/package.scala index 9219314c75..75c0286b95 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/package.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/json/package.scala @@ -30,6 +30,7 @@ import org.apache.james.jmap.core.{AccountId, Properties, SetError, UTCDate, Uui import org.apache.james.jmap.mail.HasMoreChanges import play.api.libs.json._ +import scala.annotation.nowarn import scala.util.{Failure, Success, Try} package object json { @@ -44,6 +45,7 @@ package object json { case _ => JsError("Expecting mailboxId value to be a boolean") } + @nowarn def mapWrites[K, V](keyWriter: K => String, valueWriter: Writes[V]): OWrites[Map[K, V]] = (ids: Map[K, V]) => { ids.foldLeft(JsObject.empty)((jsObject, kv) => { 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 d19490a9dc..5037b417cf 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 @@ -174,6 +174,7 @@ object ReadLevel { case FastViewWithAttachmentsMetadataReadLevel => FastViewWithAttachmentsMetadataReadLevel case _ => FastViewReadLevel } + case _ => throw new NotImplementedError() } } diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailHeader.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailHeader.scala index a1f578c99a..6256d7c283 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailHeader.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailHeader.scala @@ -88,7 +88,7 @@ object MessageIdsHeaderValue { if(body.startsWith("<") && body.endsWith(">") && body.contains("@")) { scala.Right(HeaderMessageId.from(body)) } else { - Left() + Left((): Unit) } }.toOption) .toList @@ -113,7 +113,7 @@ object URLsHeaderValue { if(url.startsWith("<") && url.endsWith(">")) { scala.Right(HeaderURL.from(url)) } else { - Left() + Left((): Unit) } }.toOption)) diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailSet.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailSet.scala index da1e74e9d3..b223121a7a 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailSet.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/EmailSet.scala @@ -301,8 +301,8 @@ case class EmailCreationRequest(mailboxIds: MailboxIds, bodyValues.getOrElse(Map()) .get(partId) .map { - case part if part.isTruncated.isDefined && part.isTruncated.get.value.equals(true) => Left(new IllegalArgumentException("Expecting isTruncated to be false")) - case part if part.isEncodingProblem.isDefined && part.isEncodingProblem.get.value.equals(true) => Left(new IllegalArgumentException("Expecting isEncodingProblem to be false")) + case part if part.isTruncated.isDefined && part.isTruncated.get.value => Left(new IllegalArgumentException("Expecting isTruncated to be false")) + case part if part.isEncodingProblem.isDefined && part.isEncodingProblem.get.value => Left(new IllegalArgumentException("Expecting isEncodingProblem to be false")) case part => Right(Some(part.value)) } diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Keyword.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Keyword.scala index 002eb0cd4a..b1c23ce234 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Keyword.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Keyword.scala @@ -81,7 +81,7 @@ final case class Keyword(flagName: String) extends AnyVal { def isForbiddenImapKeyword: Boolean = Keyword.NON_EXPOSED_IMAP_KEYWORDS.contains(this) def asSystemFlag: Option[Flags.Flag] = Keyword.IMAP_SYSTEM_FLAGS - .filter(entry => entry._2.equals(this)) + .filter(entry => entry._2 == this) .keys .collectFirst(flag => flag) diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Keywords.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Keywords.scala index f48aa4d686..9967665b96 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Keywords.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/mail/Keywords.scala @@ -51,11 +51,11 @@ object KeywordsValidator { if (exposedKeywords.isEmpty || exposedKeywords.size != keywords.size) { Failure(new IllegalArgumentException("Does not allow to update 'Deleted' or 'Recent' flag")) } else { - Success() + Success((): Unit) } } - val IGNORE_NON_EXPOSED_IMAP_KEYWORDS: KeywordsValidator = _ => Success() + val IGNORE_NON_EXPOSED_IMAP_KEYWORDS: KeywordsValidator = _ => Success((): Unit) } object KeywordFilter { diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/EventSourceRoutes.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/EventSourceRoutes.scala index 9bc4d1ebc3..fafcc79897 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/EventSourceRoutes.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/EventSourceRoutes.scala @@ -216,6 +216,7 @@ class EventSourceRoutes@Inject() (@Named(InjectionKeys.RFC_8621) val authenticat val event: String = outboundMessage match { case _: PingMessage => "ping" case _: StateChange => "state" + case _ => throw new NotImplementedError() } s"event: $event\ndata: ${Json.stringify(pushSerializer.serializeSSE(outboundMessage))}\n\n" } diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JmapApi.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JmapApi.scala index d9c0ae4ce6..3e6f9262fc 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JmapApi.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/JmapApi.scala @@ -95,7 +95,7 @@ class JMAPApi (methods: Set[Method], defaultCapabilities: Set[CapabilityIdentifi if (missingCapabilities.nonEmpty) { Left(MissingCapabilityException(s"Missing capability(ies): ${missingCapabilities.mkString(", ")}")) } else { - Right() + Right((): Unit) } } } diff --git a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/UploadRoutes.scala b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/UploadRoutes.scala index 2c42f2a62b..fc9a976450 100644 --- a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/UploadRoutes.scala +++ b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/UploadRoutes.scala @@ -85,7 +85,7 @@ class UploadRoutes @Inject()(@Named(InjectionKeys.RFC_8621) val authenticator: A def post(request: HttpServerRequest, response: HttpServerResponse): Mono[Void] = { request.requestHeaders.get(CONTENT_TYPE) match { - case contentType => SMono.fromPublisher( + case contentType: String if contentType.nonEmpty => SMono.fromPublisher( authenticator.authenticate(request)) .flatMap(session => post(request, response, ContentType.of(contentType), session)) .onErrorResume { diff --git a/server/queue/queue-pulsar/src/main/scala/org/apache/james/queue/pulsar/PulsarMailQueue.scala b/server/queue/queue-pulsar/src/main/scala/org/apache/james/queue/pulsar/PulsarMailQueue.scala index 2d2ddb9af4..8f385b78fd 100644 --- a/server/queue/queue-pulsar/src/main/scala/org/apache/james/queue/pulsar/PulsarMailQueue.scala +++ b/server/queue/queue-pulsar/src/main/scala/org/apache/james/queue/pulsar/PulsarMailQueue.scala @@ -259,6 +259,7 @@ class PulsarMailQueue( .fromPublisher(readMimeMessage(partsId)) .collect { case Some(message) => message } .map(message => (readMail(metadata, message), partsId, committableMessage)) + case _ => throw new NotImplementedError() } } diff --git a/server/task/task-memory/src/main/scala/org/apache/james/task/eventsourcing/DecisionProjection.scala b/server/task/task-memory/src/main/scala/org/apache/james/task/eventsourcing/DecisionProjection.scala index 2d4b274529..602daeeef4 100644 --- a/server/task/task-memory/src/main/scala/org/apache/james/task/eventsourcing/DecisionProjection.scala +++ b/server/task/task-memory/src/main/scala/org/apache/james/task/eventsourcing/DecisionProjection.scala @@ -45,6 +45,7 @@ object DecisionProjection { taskEvent match { case _: Created => DecisionProjection(Status.WAITING, None) case updated: AdditionalInformationUpdated => DecisionProjection(Status.IN_PROGRESS, Some(updated.additionalInformation.timestamp)) + case _ => throw new NotImplementedError() } } } --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org