This is an automated email from the ASF dual-hosted git repository. rcordier 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 8a7f9e9f7d [IMPROVEMENT] mock-smtp-server (parameters without values) (#2489) 8a7f9e9f7d is described below commit 8a7f9e9f7d06d21fabea3633944cc123b60552a9 Author: Maksim <85022218+maxxx...@users.noreply.github.com> AuthorDate: Fri Nov 8 07:02:42 2024 +0300 [IMPROVEMENT] mock-smtp-server (parameters without values) (#2489) --- server/mailet/mock-smtp-server/pom.xml | 4 +-- .../mock/smtp/server/HTTPConfigurationServer.java | 11 ++++--- .../james/mock/smtp/server/model/Condition.java | 3 +- .../apache/james/mock/smtp/server/model/Mail.java | 37 +++++++++++----------- .../apache/james/mock/smtp/server/model/Mails.java | 3 +- .../mock/smtp/server/model/MockSMTPBehavior.java | 6 ++-- .../server/model/MockSMTPBehaviorInformation.java | 3 +- .../mock/smtp/server/model/MockSmtpBehaviors.java | 3 +- .../james/mock/smtp/server/model/Response.java | 3 +- .../mock/smtp/server/model/SMTPExtension.java | 3 +- .../mock/smtp/server/model/SMTPExtensions.java | 3 +- .../server/testing/MockSmtpServerExtension.java | 2 +- .../james/mock/smtp/server/MockSMTPServerTest.java | 8 ++++- 13 files changed, 44 insertions(+), 45 deletions(-) diff --git a/server/mailet/mock-smtp-server/pom.xml b/server/mailet/mock-smtp-server/pom.xml index 6cf256746f..ea7bf15f71 100644 --- a/server/mailet/mock-smtp-server/pom.xml +++ b/server/mailet/mock-smtp-server/pom.xml @@ -123,12 +123,12 @@ <artifactId>jib-maven-plugin</artifactId> <configuration> <from> - <image>eclipse-temurin:11-jre-jammy</image> + <image>eclipse-temurin:21-jre-jammy</image> </from> <to> <image>linagora/mock-smtp-server</image> <tags> - <tag>0.6</tag> + <tag>0.7</tag> </tags> </to> <container> diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/HTTPConfigurationServer.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/HTTPConfigurationServer.java index de7aba12ad..86230652f4 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/HTTPConfigurationServer.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/HTTPConfigurationServer.java @@ -99,6 +99,7 @@ public class HTTPConfigurationServer { static final String VERSION = "/version"; static final String SMTP_MAILS = "/smtpMails"; static final String SMTP_MAILS_COUNT = "/smtpMailsCount"; + static final String JSON_SERIALIZATION_ERROR_MESSAGE = "Could not serialize JSON "; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() .registerModule(new Jdk8Module()) @@ -156,7 +157,7 @@ public class HTTPConfigurationServer { .header(CONTENT_TYPE, APPLICATION_JSON) .sendString(Mono.just(OBJECT_MAPPER.writeValueAsString(mockSmtpBehaviors))); } catch (JsonProcessingException e) { - LOGGER.error("Could not serialize JSON", e); + LOGGER.error(JSON_SERIALIZATION_ERROR_MESSAGE, e); return res.status(INTERNAL_SERVER_ERROR).send(); } } @@ -169,7 +170,7 @@ public class HTTPConfigurationServer { .header(CONTENT_TYPE, APPLICATION_JSON) .sendString(Mono.just(OBJECT_MAPPER.writeValueAsString(extensions))); } catch (JsonProcessingException e) { - LOGGER.error("Could not serialize JSON", e); + LOGGER.error(JSON_SERIALIZATION_ERROR_MESSAGE, e); return res.status(INTERNAL_SERVER_ERROR).send(); } } @@ -225,7 +226,7 @@ public class HTTPConfigurationServer { .header(CONTENT_TYPE, APPLICATION_JSON) .sendString(Mono.just(OBJECT_MAPPER.writeValueAsString(mailsRemoved))); } catch (JsonProcessingException e) { - LOGGER.error("Could not serialize JSON", e); + LOGGER.error(JSON_SERIALIZATION_ERROR_MESSAGE, e); return res.status(INTERNAL_SERVER_ERROR).send(); } } @@ -238,7 +239,7 @@ public class HTTPConfigurationServer { .header(CONTENT_TYPE, APPLICATION_JSON) .sendString(Mono.just(OBJECT_MAPPER.writeValueAsString(mails))); } catch (JsonProcessingException e) { - LOGGER.error("Could not serialize JSON", e); + LOGGER.error(JSON_SERIALIZATION_ERROR_MESSAGE, e); return res.status(INTERNAL_SERVER_ERROR).send(); } } @@ -251,7 +252,7 @@ public class HTTPConfigurationServer { .header(CONTENT_TYPE, APPLICATION_JSON) .sendString(Mono.just(OBJECT_MAPPER.writeValueAsString(count))); } catch (JsonProcessingException e) { - LOGGER.error("Could not serialize JSON", e); + LOGGER.error(JSON_SERIALIZATION_ERROR_MESSAGE, e); return res.status(INTERNAL_SERVER_ERROR).send(); } } diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Condition.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Condition.java index 96a91ab3b6..6f42bdc9e5 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Condition.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Condition.java @@ -104,8 +104,7 @@ public interface Condition { @Override public final boolean equals(Object o) { - if (o instanceof OperatorCondition) { - OperatorCondition condition = (OperatorCondition) o; + if (o instanceof OperatorCondition condition) { return Objects.equals(this.operator, condition.operator) && Objects.equals(this.matchingValue, condition.matchingValue); diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Mail.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Mail.java index 110ddd84cf..72bc48dc10 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Mail.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Mail.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.stream.Stream; @@ -41,15 +42,16 @@ import com.google.common.collect.ImmutableSet; @JsonDeserialize(builder = Mail.Builder.class) public class Mail { + @JsonDeserialize(builder = Parameter.Builder.class) public static class Parameter { @JsonPOJOBuilder(withPrefix = "") public static class Builder { private String name; - private String value; + private Optional<String> value; public Builder() { - + this.value = Optional.empty(); } public Builder name(String name) { @@ -58,15 +60,13 @@ public class Mail { } public Builder value(String value) { - this.value = value; + this.value = Optional.ofNullable(value); return this; } public Parameter build() { Preconditions.checkState(name != null, "'name' field cannot be omitted"); - Preconditions.checkState(value != null, "'value' field cannot be omitted"); - - return new Parameter(name, value); + return new Parameter(name, value.orElse("")); } } @@ -76,12 +76,17 @@ public class Mail { public static Collection<Mail.Parameter> fromArgLine(String argLine) { return Splitter.on(' ').splitToStream(argLine) - .filter(argString -> argString.contains("=")) + .filter(argString -> !argString.contains(":")) .map(Parameter::fromString) .collect(ImmutableList.toImmutableList()); } public static Parameter fromString(String argString) { + if (!argString.contains("=")) { + return Mail.Parameter.builder() + .name(argString) + .build(); + } Preconditions.checkArgument(argString.contains("=")); int index = argString.indexOf('='); @@ -109,8 +114,7 @@ public class Mail { @Override public final boolean equals(Object o) { - if (o instanceof Parameter) { - Parameter that = (Parameter) o; + if (o instanceof Parameter that) { return Objects.equals(this.name, that.name) && Objects.equals(this.value, that.value); @@ -170,7 +174,7 @@ public class Mail { } public static Recipient of(MailAddress address) { - return new Recipient(address, ImmutableList.of()); + return new Recipient(address, List.of()); } private final MailAddress address; @@ -191,8 +195,7 @@ public class Mail { @Override public final boolean equals(Object o) { - if (o instanceof Recipient) { - Recipient that = (Recipient) o; + if (o instanceof Recipient that) { return Objects.equals(this.address, that.address) && Objects.equals(this.parameters, that.parameters); @@ -283,11 +286,11 @@ public class Mail { public static Envelope ofAddresses(MailAddress from, MailAddress... recipients) { return new Envelope(from, Stream.of(recipients) .map(Recipient::of) - .collect(ImmutableSet.toImmutableSet()), ImmutableSet.of()); + .collect(ImmutableSet.toImmutableSet()), Set.of()); } public static Envelope of(MailAddress from, Recipient... recipients) { - return new Envelope(from, ImmutableSet.copyOf(Arrays.asList(recipients)), ImmutableSet.of()); + return new Envelope(from, ImmutableSet.copyOf(Arrays.asList(recipients)), Set.of()); } private final MailAddress from; @@ -318,8 +321,7 @@ public class Mail { @Override public final boolean equals(Object o) { - if (o instanceof Envelope) { - Envelope envelope = (Envelope) o; + if (o instanceof Envelope envelope) { return Objects.equals(this.from, envelope.from) && Objects.equals(this.recipients, envelope.recipients) @@ -386,8 +388,7 @@ public class Mail { @Override public final boolean equals(Object o) { - if (o instanceof Mail) { - Mail mail = (Mail) o; + if (o instanceof Mail mail) { return Objects.equals(this.envelope, mail.envelope) && Objects.equals(this.message, mail.message); diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Mails.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Mails.java index cc29c121e1..3d4b725714 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Mails.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Mails.java @@ -40,8 +40,7 @@ public class Mails { @Override public final boolean equals(Object o) { - if (o instanceof Mails) { - Mails that = (Mails) o; + if (o instanceof Mails that) { return Objects.equals(this.mailList, that.mailList); } diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/MockSMTPBehavior.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/MockSMTPBehavior.java index 9dbb66c96d..0c811fa338 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/MockSMTPBehavior.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/MockSMTPBehavior.java @@ -55,8 +55,7 @@ public class MockSMTPBehavior { @Override public final boolean equals(Object o) { - if (o instanceof NumberOfAnswersPolicy) { - NumberOfAnswersPolicy that = (NumberOfAnswersPolicy) o; + if (o instanceof NumberOfAnswersPolicy that) { return Objects.equals(this.numberOfAnswers, that.numberOfAnswers); } @@ -147,8 +146,7 @@ public class MockSMTPBehavior { @Override public final boolean equals(Object o) { - if (o instanceof MockSMTPBehavior) { - MockSMTPBehavior that = (MockSMTPBehavior) o; + if (o instanceof MockSMTPBehavior that) { return Objects.equals(this.smtpCommand, that.smtpCommand) && Objects.equals(this.condition, that.condition) diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/MockSMTPBehaviorInformation.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/MockSMTPBehaviorInformation.java index baa0d5044f..69bbe22eca 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/MockSMTPBehaviorInformation.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/MockSMTPBehaviorInformation.java @@ -132,8 +132,7 @@ public class MockSMTPBehaviorInformation { @Override public final boolean equals(Object o) { - if (o instanceof MockSMTPBehaviorInformation) { - MockSMTPBehaviorInformation that = (MockSMTPBehaviorInformation) o; + if (o instanceof MockSMTPBehaviorInformation that) { return Objects.equals(this.behavior, that.behavior) && Objects.equals(this.remainingAnswersCounter(), that.remainingAnswersCounter()); diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/MockSmtpBehaviors.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/MockSmtpBehaviors.java index 27a1633b93..db5ae65fc0 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/MockSmtpBehaviors.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/MockSmtpBehaviors.java @@ -47,8 +47,7 @@ public class MockSmtpBehaviors { @Override public final boolean equals(Object o) { - if (o instanceof MockSmtpBehaviors) { - MockSmtpBehaviors that = (MockSmtpBehaviors) o; + if (o instanceof MockSmtpBehaviors that) { return Objects.equals(this.behaviorList, that.behaviorList); } diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Response.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Response.java index bde5f183d8..542c57b411 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Response.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/Response.java @@ -102,8 +102,7 @@ public class Response { @Override public final boolean equals(Object o) { - if (o instanceof Response) { - Response response = (Response) o; + if (o instanceof Response response) { return Objects.equals(this.code, response.code) && Objects.equals(this.message, response.message); diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/SMTPExtension.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/SMTPExtension.java index 781f403bf9..392eedeb2d 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/SMTPExtension.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/SMTPExtension.java @@ -46,8 +46,7 @@ public class SMTPExtension { @Override public final boolean equals(Object o) { - if (o instanceof SMTPExtension) { - SMTPExtension that = (SMTPExtension) o; + if (o instanceof SMTPExtension that) { return Objects.equals(this.name, that.name); } diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/SMTPExtensions.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/SMTPExtensions.java index 39cf2cbd4c..f88c85c912 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/SMTPExtensions.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/model/SMTPExtensions.java @@ -45,8 +45,7 @@ public class SMTPExtensions { @Override public final boolean equals(Object o) { - if (o instanceof SMTPExtensions) { - SMTPExtensions that = (SMTPExtensions) o; + if (o instanceof SMTPExtensions that) { return Objects.equals(this.smtpExtensions, that.smtpExtensions); } diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/testing/MockSmtpServerExtension.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/testing/MockSmtpServerExtension.java index 639595c18b..69101937c8 100644 --- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/testing/MockSmtpServerExtension.java +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/testing/MockSmtpServerExtension.java @@ -46,7 +46,7 @@ public class MockSmtpServerExtension implements AfterEachCallback, BeforeAllCall DockerMockSmtp() { mockSmtpServer = DockerContainer.fromName(Images.MOCK_SMTP_SERVER) - .withLogConsumer(outputFrame -> LOGGER.debug("MockSMTP: " + outputFrame.getUtf8String())) + .withLogConsumer(outputFrame -> LOGGER.debug("MockSMTP: {}", outputFrame.getUtf8String())) .withExposedPorts(25, 8000) .waitingFor(Wait.forLogMessage(".*Mock SMTP server started.*", 1)) .withName("james-testing-mock-smtp-server-" + UUID.randomUUID()); diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPServerTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPServerTest.java index d758e43729..30bf1de6c6 100644 --- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPServerTest.java +++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPServerTest.java @@ -200,7 +200,7 @@ class MockSMTPServerTest { try { smtpClient.connect("localhost", mockServer.getPort().getValue()); smtpClient.ehlo("localhost"); - smtpClient.mail("<b...@james.org> MT-PRIORITY=3 RET=HDRS ENVID=gabouzomeuh"); + smtpClient.mail("<b...@james.org> MT-PRIORITY=3 REQUIRETLS RET=HDRS SMTPUTF8 ENVID=gabouzomeuh"); smtpClient.rcpt("<al...@james.org>"); smtpClient.sendShortMessageData("A short message..."); } finally { @@ -220,6 +220,12 @@ class MockSMTPServerTest { .name("MT-PRIORITY") .value("3") .build()) + .addMailParameter(Mail.Parameter.builder() + .name("REQUIRETLS") + .build()) + .addMailParameter(Mail.Parameter.builder() + .name("SMTPUTF8") + .build()) .from(new MailAddress(BOB)) .addRecipientMailAddress(new MailAddress(ALICE)) .build(); --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org