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 c377f81f38 JAMES-4059 MailetContainerModule should not do a strict check on RemoveMimeHeader with bcc name param (#2393) c377f81f38 is described below commit c377f81f38481a5f51937767c9c0c007d5947190 Author: Rene Cordier <rcord...@linagora.com> AuthorDate: Fri Aug 30 15:48:44 2024 +0700 JAMES-4059 MailetContainerModule should not do a strict check on RemoveMimeHeader with bcc name param (#2393) --- .../servers/pages/distributed/configure/jvm.adoc | 16 +++++++++ .../sample-configuration/jvm.properties | 5 ++- .../sample-configuration/jvm.properties | 5 ++- .../sample-configuration/jvm.properties | 5 ++- .../jpa-app/sample-configuration/jvm.properties | 5 ++- .../sample-configuration/jvm.properties | 5 ++- .../memory-app/sample-configuration/jvm.properties | 5 ++- .../sample-configuration/jvm.properties | 3 ++ .../modules/server/MailetContainerModule.java | 7 ++-- .../apache/james/jmap/MailetPreconditionTest.java | 42 ++++++++++++++++++++++ 10 files changed, 90 insertions(+), 8 deletions(-) diff --git a/docs/modules/servers/pages/distributed/configure/jvm.adoc b/docs/modules/servers/pages/distributed/configure/jvm.adoc index 170869594b..7aefd940bc 100644 --- a/docs/modules/servers/pages/distributed/configure/jvm.adoc +++ b/docs/modules/servers/pages/distributed/configure/jvm.adoc @@ -103,3 +103,19 @@ Ex in `jvm.properties` # james.reactor.inputstream.prefetch=4 ---- +== Disable mailet container check at James startup + +James is doing checks on startup for validating mailet container configuration against a set of +business rules, for instance making sure that the `bcc` header is being removed via +`RemoveMimeHeader` mailet in the mail processing pipeline defined in `mailetcontainer.xml` file. + +It could be useful for some administrators that know what they are doing to disable such checks +during James startup. + +Optional. Boolean. Defaults to true. + +Ex in `jvm.properties` +---- +james.mailet.container.check.enabled=false +---- +To disable the mailet container check at James startup. \ No newline at end of file diff --git a/server/apps/cassandra-app/sample-configuration/jvm.properties b/server/apps/cassandra-app/sample-configuration/jvm.properties index 03997ab5f5..7cef86567a 100644 --- a/server/apps/cassandra-app/sample-configuration/jvm.properties +++ b/server/apps/cassandra-app/sample-configuration/jvm.properties @@ -65,4 +65,7 @@ jmx.remote.x.mlet.allow.getMBeansFromURL=false # james.mime4j.buffered.body.factory.file.threshold=100K # Whether James should unzip JWTs. Default to false -# james.jwt.zip.allow=false \ No newline at end of file +# james.jwt.zip.allow=false + +# Enable/disable mailet container check at James startup. Defaults to true. +# james.mailet.container.check.enabled=true \ No newline at end of file diff --git a/server/apps/distributed-app/sample-configuration/jvm.properties b/server/apps/distributed-app/sample-configuration/jvm.properties index 804561f566..f55d3d20fe 100644 --- a/server/apps/distributed-app/sample-configuration/jvm.properties +++ b/server/apps/distributed-app/sample-configuration/jvm.properties @@ -81,4 +81,7 @@ jmx.remote.x.mlet.allow.getMBeansFromURL=false # Prefetch to use in Reactor to stream convertions (S3 => InputStream). Default to 1. # Higher values will tend to block less often at the price of higher memory consumptions. -# james.reactor.inputstream.prefetch=4 \ No newline at end of file +# james.reactor.inputstream.prefetch=4 + +# Enable/disable mailet container check at James startup. Defaults to true. +# james.mailet.container.check.enabled=true \ No newline at end of file diff --git a/server/apps/distributed-pop3-app/sample-configuration/jvm.properties b/server/apps/distributed-pop3-app/sample-configuration/jvm.properties index 181a7c302b..e7ece390c2 100644 --- a/server/apps/distributed-pop3-app/sample-configuration/jvm.properties +++ b/server/apps/distributed-pop3-app/sample-configuration/jvm.properties @@ -55,4 +55,7 @@ james.jmx.credential.generation=true jmx.remote.x.mlet.allow.getMBeansFromURL=false # Whether James should unzip JWTs. Default to false -# james.jwt.zip.allow=false \ No newline at end of file +# james.jwt.zip.allow=false + +# Enable/disable mailet container check at James startup. Defaults to true. +# james.mailet.container.check.enabled=true \ No newline at end of file diff --git a/server/apps/jpa-app/sample-configuration/jvm.properties b/server/apps/jpa-app/sample-configuration/jvm.properties index 4ebef369c5..04cfad0b6c 100644 --- a/server/apps/jpa-app/sample-configuration/jvm.properties +++ b/server/apps/jpa-app/sample-configuration/jvm.properties @@ -53,4 +53,7 @@ jmx.remote.x.mlet.allow.getMBeansFromURL=false openjpa.Multithreaded=true # Whether James should unzip JWTs. Default to false -# james.jwt.zip.allow=false \ No newline at end of file +# james.jwt.zip.allow=false + +# Enable/disable mailet container check at James startup. Defaults to true. +# james.mailet.container.check.enabled=true \ No newline at end of file diff --git a/server/apps/jpa-smtp-app/sample-configuration/jvm.properties b/server/apps/jpa-smtp-app/sample-configuration/jvm.properties index 4ebef369c5..04cfad0b6c 100644 --- a/server/apps/jpa-smtp-app/sample-configuration/jvm.properties +++ b/server/apps/jpa-smtp-app/sample-configuration/jvm.properties @@ -53,4 +53,7 @@ jmx.remote.x.mlet.allow.getMBeansFromURL=false openjpa.Multithreaded=true # Whether James should unzip JWTs. Default to false -# james.jwt.zip.allow=false \ No newline at end of file +# james.jwt.zip.allow=false + +# Enable/disable mailet container check at James startup. Defaults to true. +# james.mailet.container.check.enabled=true \ No newline at end of file diff --git a/server/apps/memory-app/sample-configuration/jvm.properties b/server/apps/memory-app/sample-configuration/jvm.properties index 1834ee9cbc..649b5fc3b1 100644 --- a/server/apps/memory-app/sample-configuration/jvm.properties +++ b/server/apps/memory-app/sample-configuration/jvm.properties @@ -55,4 +55,7 @@ jmx.remote.x.mlet.allow.getMBeansFromURL=false # james.jmap.default.charset=US-ASCII # Whether James should unzip JWTs. Default to false -# james.jwt.zip.allow=false \ No newline at end of file +# james.jwt.zip.allow=false + +# Enable/disable mailet container check at James startup. Defaults to true. +# james.mailet.container.check.enabled=true \ No newline at end of file diff --git a/server/apps/scaling-pulsar-smtp/sample-configuration/jvm.properties b/server/apps/scaling-pulsar-smtp/sample-configuration/jvm.properties index df272a165b..579b688dcb 100644 --- a/server/apps/scaling-pulsar-smtp/sample-configuration/jvm.properties +++ b/server/apps/scaling-pulsar-smtp/sample-configuration/jvm.properties @@ -46,3 +46,6 @@ # Whether James should unzip JWTs. Default to false # james.jwt.zip.allow=false + +# Enable/disable mailet container check at James startup. Defaults to true. +# james.mailet.container.check.enabled=true \ No newline at end of file diff --git a/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/MailetContainerModule.java b/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/MailetContainerModule.java index a1cab9b2bd..e6ef0a8e9b 100644 --- a/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/MailetContainerModule.java +++ b/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/MailetContainerModule.java @@ -80,12 +80,13 @@ import com.google.inject.multibindings.ProvidesIntoSet; public class MailetContainerModule extends AbstractModule { private static final Logger LOGGER = LoggerFactory.getLogger(MailetContainerModule.class); + private static final boolean MAILET_CONTAINER_CHECK_ENABLED = Boolean.parseBoolean(System.getProperty("james.mailet.container.check.enabled", "true")); public static final ProcessorsCheck.Impl BCC_Check = new ProcessorsCheck.Impl( "transport", All.class, RemoveMimeHeader.class, - pair -> pair.getMailet().getMailetConfig().getInitParameter("name").equals("bcc"), + pair -> Arrays.asList(pair.getMailet().getMailetConfig().getInitParameter("name").toLowerCase().split(",")).contains("bcc"), "Should be configured to remove Bcc header"); @Override @@ -179,7 +180,9 @@ public class MailetContainerModule extends AbstractModule { @Override public void initModule() throws Exception { configureProcessors(); - checkProcessors(); + if (MAILET_CONTAINER_CHECK_ENABLED) { + checkProcessors(); + } } private void configureProcessors() throws Exception { diff --git a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java index 252ab0c21d..f99e8bed48 100644 --- a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java +++ b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java @@ -191,5 +191,47 @@ class MailetPreconditionTest { assertThatCode(() -> MailetContainerModule.BCC_Check.check(pairs)) .doesNotThrowAnyException(); } + + @Test + void bccMailetCheckShouldNotThrowOnValidPairWithOtherNames() throws Exception { + RemoveMimeHeader removeMimeHeader = new RemoveMimeHeader(); + removeMimeHeader.init(FakeMailetConfig.builder() + .mailetName(BCC) + .mailetContext(MAILET_CONTEXT) + .setProperty("name", "header1,bcc,header2") + .build()); + + ImmutableMultimap<String, MatcherMailetPair> pairs = ImmutableMultimap.of("transport", new MatcherMailetPair(new All(), removeMimeHeader)); + assertThatCode(() -> MailetContainerModule.BCC_Check.check(pairs)) + .doesNotThrowAnyException(); + } + + @Test + void bccMailetCheckShouldThrowOnInvalidNameWithPairIncluded() throws Exception { + RemoveMimeHeader removeMimeHeader = new RemoveMimeHeader(); + removeMimeHeader.init(FakeMailetConfig.builder() + .mailetName(BCC) + .mailetContext(MAILET_CONTEXT) + .setProperty("name", "x-bcc-bug") + .build()); + + ImmutableMultimap<String, MatcherMailetPair> pairs = ImmutableMultimap.of("transport", new MatcherMailetPair(new All(), removeMimeHeader)); + assertThatThrownBy(() -> MailetContainerModule.BCC_Check.check(pairs)) + .isInstanceOf(ConfigurationException.class); + } + + @Test + void bccMailetCheckShouldNotThrowOnValidInsensitivePair() throws Exception { + RemoveMimeHeader removeMimeHeader = new RemoveMimeHeader(); + removeMimeHeader.init(FakeMailetConfig.builder() + .mailetName(BCC) + .mailetContext(MAILET_CONTEXT) + .setProperty("name", "BcC") + .build()); + + ImmutableMultimap<String, MatcherMailetPair> pairs = ImmutableMultimap.of("transport", new MatcherMailetPair(new All(), removeMimeHeader)); + assertThatCode(() -> MailetContainerModule.BCC_Check.check(pairs)) + .doesNotThrowAnyException(); + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org