This is an automated email from the ASF dual-hosted git repository. jhelou 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 6440caab48 [JAMES-4127] Adds default implementations to Mailet 6440caab48 is described below commit 6440caab48cc3670a16cfe0c12c88ad03c47e376 Author: Jean Helou <j...@xn--gml-cma.com> AuthorDate: Tue Apr 1 16:09:33 2025 +0200 [JAMES-4127] Adds default implementations to Mailet The default behaviour for `init`, `destroy` and `getMailetInfo` is to do nothing (can be overriden by implementations as is done in GenericMailet. This change makes `service` and `getMailetConfig` the only methods to implement to build a mailet. Regarding `getMailetConfig` please refer to [JAMES-4128](https://issues.apache.org/jira/browse/JAMES-4128) --- .../api/src/main/java/org/apache/mailet/Mailet.java | 15 +++++++++++---- .../java/org/apache/mailet/base/GenericMailet.java | 21 --------------------- .../mailets/sub/ConstructorBoundTestMailet.java | 13 ------------- 3 files changed, 11 insertions(+), 38 deletions(-) diff --git a/mailet/api/src/main/java/org/apache/mailet/Mailet.java b/mailet/api/src/main/java/org/apache/mailet/Mailet.java index c4dc449c9d..f59fc8b9dd 100644 --- a/mailet/api/src/main/java/org/apache/mailet/Mailet.java +++ b/mailet/api/src/main/java/org/apache/mailet/Mailet.java @@ -80,7 +80,8 @@ public interface Mailet { * and initialization parameters * @throws MessagingException if an error occurs */ - void init(MailetConfig config) throws MessagingException; + default void init(MailetConfig config) throws MessagingException { + } /** * Services a mail message. @@ -109,7 +110,8 @@ public interface Mailet { * are being held (such as memory, file handles or threads) and make sure * that any persistent information is properly stored. */ - void destroy(); + default void destroy() { + } /** * Returns a MailetConfig object, which provides initialization parameters @@ -127,14 +129,19 @@ public interface Mailet { /** * Returns information about the mailet, such as author, version and * copyright. + * <p> + * By default, this method returns an empty string. Override this method + * to have it return a meaningful value. * * @return the Mailet information (as a plain text string) */ - String getMailetInfo(); + default String getMailetInfo() { + return ""; + } /** * @return the list of processors that needs to be present according to this mailet configuration. - * + * <p> * Needs to be called after {@link Mailet::init()} */ default Collection<ProcessingState> requiredProcessingState() { diff --git a/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java b/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java index 5aee0a39ab..3f12f4bf22 100644 --- a/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java +++ b/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java @@ -73,15 +73,6 @@ public abstract class GenericMailet implements Mailet, MailetConfig { public GenericMailet() { } - /** - * Called by the mailer container to indicate to a mailet that the - * mailet is being taken out of service. - */ - @Override - public void destroy() { - //Do nothing - } - /** * <p>Gets a boolean valued init parameter.</p> * <p>A convenience method. The result is parsed @@ -202,18 +193,6 @@ public abstract class GenericMailet implements Mailet, MailetConfig { return getMailetConfig().getMailetContext(); } - /** - * Returns information about the mailet, such as author, version, and - * copyright. By default, this method returns an empty string. Override - * this method to have it return a meaningful value. - * - * @return information about this mailet, by default an empty string - */ - @Override - public String getMailetInfo() { - return ""; - } - /** * Returns the name of this mailet instance. * diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/transport/mailets/sub/ConstructorBoundTestMailet.java b/server/container/guice/mailet/src/test/java/org/apache/james/transport/mailets/sub/ConstructorBoundTestMailet.java index fb06ab24ea..ed582c04c1 100644 --- a/server/container/guice/mailet/src/test/java/org/apache/james/transport/mailets/sub/ConstructorBoundTestMailet.java +++ b/server/container/guice/mailet/src/test/java/org/apache/james/transport/mailets/sub/ConstructorBoundTestMailet.java @@ -34,26 +34,13 @@ public class ConstructorBoundTestMailet implements Mailet { this.config = config; } - @Override - public void init(MailetConfig config) throws MessagingException { - } - @Override public void service(Mail mail) throws MessagingException { } - @Override - public void destroy() { - } - @Override public MailetConfig getMailetConfig() { return config; } - - @Override - public String getMailetInfo() { - return ""; - } } --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org