From 5b14cb439865036f2df266067e3731491ed21dc7 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 31 Jul 2023 17:18:28 +0200 Subject: [PATCH] Use jakarta mail instead of javax mail and use Jakarta mail API without apache commons email --- distro/src/notice.txt | 6 +- modules/flowable-app-engine/pom.xml | 4 +- .../src/test/resources/log4j.properties | 1 - .../src/test/resources/log4j.properties | 1 - .../src/test/resources/log4j.properties | 2 +- modules/flowable-cmmn-engine/pom.xml | 8 +- .../cmmn/test/task/CmmnMailTaskTest.java | 15 +- .../src/test/resources/log4j.properties | 2 +- .../cfg/mail/FlowableMailClientCreator.java | 4 +- .../src/test/resources/log4j.properties | 2 +- modules/flowable-engine/pom.xml | 8 +- .../test/bpmn/mail/AttachmentsBean.java | 2 +- .../test/bpmn/mail/EmailSendTaskTest.java | 8 +- .../EmailSendTaskWithContentItemsTest.java | 2 +- .../test/bpmn/mail/EmailServiceTaskTest.java | 8 +- .../engine/test/bpmn/mail/EmailTestCase.java | 3 +- .../examples/bpmn/mail/EmailSendTaskTest.java | 5 +- .../bpmn/mail/EmailServiceTaskTest.java | 5 +- .../src/test/resources/log4j.properties | 1 - modules/flowable-event-registry/pom.xml | 4 +- .../src/test/resources/log4j.properties | 1 - .../src/test/resources/log4j.properties | 1 - .../src/test/resources/log4j.properties | 1 - .../src/test/resources/log4j.properties | 1 - .../src/test/resources/log4j.properties | 1 - .../src/test/resources/log4j.properties | 1 - .../src/test/resources/log4j.properties | 1 - modules/flowable-mail/pom.xml | 4 +- .../flowable/mail/common/api/MailMessage.java | 2 +- .../common/impl/BaseMailActivityDelegate.java | 4 +- .../ApacheCommonsEmailFlowableMailClient.java | 313 ------------ .../mail/JakartaMailFlowableMailClient.java | 450 ++++++++++++++++++ .../src/test/resources/log4j.properties | 2 +- .../src/test/resources/log4j.properties | 1 - modules/flowable-spring/pom.xml | 10 +- .../spring/test/email/JndiEmailTest.java | 8 +- .../spring/test/email/MockEmailTransport.java | 12 +- .../src/test/resources/log4j.properties | 1 - .../src/test/resources/log4j.properties | 1 - .../src/test/resources/log4j.properties | 2 +- .../src/main/resources/log4j.properties | 2 +- modules/flowable5-engine/pom.xml | 6 +- modules/flowable5-spring-test/pom.xml | 4 +- modules/flowable5-test/pom.xml | 4 +- .../engine/test/bpmn/mail/EmailTestCase.java | 9 +- .../examples/bpmn/mail/EmailSendTaskTest.java | 3 +- .../bpmn/mail/EmailServiceTaskTest.java | 3 +- .../src/test/resources/log4j.properties | 2 +- pom.xml | 25 +- qa/logging/log4j.properties | 2 +- .../src/test/resources/log4j.properties | 1 - 51 files changed, 535 insertions(+), 434 deletions(-) delete mode 100644 modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/apache/commons/ApacheCommonsEmailFlowableMailClient.java create mode 100644 modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/jakarta/mail/JakartaMailFlowableMailClient.java diff --git a/distro/src/notice.txt b/distro/src/notice.txt index c011bfdf6ee..7c007b88b20 100644 --- a/distro/src/notice.txt +++ b/distro/src/notice.txt @@ -77,7 +77,6 @@ com.fasterxml.jackson.datatype jackson-datatype-joda 2.15.2 The com.google.guava guava 31.0.1-jre The Apache Software License, Version 2.0 com.h2database h2 2.1.214 The H2 License, Version 1.0 com.fasterxml.uuid java-uuid-generator 3.3.0 The Apache Software License, Version 2.0 -com.sun.mail javax.mail 1.6.2 CDDL/GPLv2+CE commons-beanutils commons-beanutils 1.8.3 The Apache Software License, Version 2.0 commons-codec commons-codec 1.15 Apache License, Version 2.0 commons-digester commons-digester 1.8 The Apache Software License, Version 2.0 @@ -91,10 +90,10 @@ de.odysseus.juel juel-impl 2.2.7 The de.odysseus.juel juel-spi 2.2.7 The Apache Software License, Version 2.0 io.swagger swagger-annotations 1.6.2 Apache License 2.0 io.swagger swagger-models 1.6.2 Apache License 2.0 -javax.activation activation 1.1.1 COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 +jakarta.activation jakarta.activation-api 2.1.2 EDL 1.0 +jakarta.mail jakarta.mail.api 2.1.2 EDL 1.0 joda-time joda-time 2.10.13 Apache 2 log4j log4j 1.2.17 The Apache Software License, Version 2.0 -org.apache.commons commons-email 1.5 Apache License, Version 2.0 org.apache.commons commons-lang3 3.12.0 The Apache Software License, Version 2.0 org.apache.httpcomponents httpclient 4.5.13 Apache License, Version 2.0 org.apache.httpcomponents httpcore 4.4.15 Apache License, Version 2.0 @@ -102,6 +101,7 @@ org.apache.httpcomponents httpmime 4.5.13 Apac org.apache.geronimo.bundles json 20090211_1 The Apache Software License, Version 2.0 org.apache.groovy groovy 4.0.13 The Apache Software License, Version 2.0 org.apache.groovy groovy-jsr223 4.0.13 The Apache Software License, Version 2.0 +org.eclipse.angus angus-mail 2.0.2 EDL 1.0 / EPL 2.0 org.liquibase liquibase-core 4.5.0 Apache License, Version 2.0 org.mybatis mybatis 3.5.11 The Apache Software License, Version 2.0 org.mybatis mybatis-spring 3.0.0 The Apache Software License, Version 2.0 diff --git a/modules/flowable-app-engine/pom.xml b/modules/flowable-app-engine/pom.xml index d47b38ac897..12c8d40b70b 100644 --- a/modules/flowable-app-engine/pom.xml +++ b/modules/flowable-app-engine/pom.xml @@ -154,9 +154,9 @@ junit*;resolution:=optional, org.junit*;resolution:=optional, com.sun*;resolution:=optional, - javax.activation*;resolution:=optional, + jakarta.activation*;resolution:=optional, jakarta.persistence*;resolution:=optional, - org.apache.commons.mail*;resolution:=optional, + jakarta.mail*;resolution:=optional, org.apache.xerces*;resolution:=optional, org.springframework*;resolution:=optional, com.fasterxml*;resolution:=optional, diff --git a/modules/flowable-app-engine/src/test/resources/log4j.properties b/modules/flowable-app-engine/src/test/resources/log4j.properties index 41ea6e69349..8846a883e23 100644 --- a/modules/flowable-app-engine/src/test/resources/log4j.properties +++ b/modules/flowable-app-engine/src/test/resources/log4j.properties @@ -7,6 +7,5 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO log4j.logger.org.flowable.cmmn.engine.impl.agenda=DEBUG diff --git a/modules/flowable-batch-service/src/test/resources/log4j.properties b/modules/flowable-batch-service/src/test/resources/log4j.properties index 3b88061e97b..61e34f49c61 100644 --- a/modules/flowable-batch-service/src/test/resources/log4j.properties +++ b/modules/flowable-batch-service/src/test/resources/log4j.properties @@ -7,6 +7,5 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO log4j.logger.org.flowable.engine.impl.agenda=DEBUG diff --git a/modules/flowable-cmmn-engine-configurator/src/test/resources/log4j.properties b/modules/flowable-cmmn-engine-configurator/src/test/resources/log4j.properties index 3b88061e97b..03610eebf68 100644 --- a/modules/flowable-cmmn-engine-configurator/src/test/resources/log4j.properties +++ b/modules/flowable-cmmn-engine-configurator/src/test/resources/log4j.properties @@ -7,6 +7,6 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO +log4j.logger.jakarta.activation=INFO log4j.logger.org.flowable.engine.impl.agenda=DEBUG diff --git a/modules/flowable-cmmn-engine/pom.xml b/modules/flowable-cmmn-engine/pom.xml index 28d2dc62bfb..e8ab3284aa6 100644 --- a/modules/flowable-cmmn-engine/pom.xml +++ b/modules/flowable-cmmn-engine/pom.xml @@ -190,8 +190,8 @@ test - org.subethamail - subethasmtp-wiser + com.github.davidmoten + subethasmtp test @@ -222,9 +222,9 @@ junit*;resolution:=optional, org.junit*;resolution:=optional, com.sun*;resolution:=optional, - javax.activation*;resolution:=optional, + jakarta.activation*;resolution:=optional, jakarta.persistence*;resolution:=optional, - org.apache.commons.mail*;resolution:=optional, + jakarta.mail*;resolution:=optional, org.apache.xerces*;resolution:=optional, org.springframework*;resolution:=optional, com.fasterxml*;resolution:=optional, diff --git a/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/task/CmmnMailTaskTest.java b/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/task/CmmnMailTaskTest.java index 32216d16840..888afabdcb0 100644 --- a/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/task/CmmnMailTaskTest.java +++ b/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/task/CmmnMailTaskTest.java @@ -26,17 +26,16 @@ import java.util.Collections; import java.util.List; -import javax.activation.DataHandler; -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; +import jakarta.activation.DataHandler; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMultipart; import org.apache.commons.lang3.Validate; import org.flowable.cmmn.engine.test.CmmnDeployment; import org.flowable.cmmn.engine.test.FlowableCmmnTestCase; import org.flowable.common.engine.impl.cfg.mail.FlowableMailClientCreator; import org.flowable.common.engine.impl.cfg.mail.MailServerInfo; -import org.flowable.mail.common.api.client.FlowableMailClient; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -58,15 +57,13 @@ public class CmmnMailTaskTest extends FlowableCmmnTestCase { @BeforeClass public static void setupWiser() throws Exception { - wiser = new Wiser(); - wiser.setPort(5025); + wiser = Wiser.port(5025); int counter = 0; boolean serverUpAndRunning = false; while (!serverUpAndRunning && counter++ < 11) { - wiser = new Wiser(); - wiser.setPort(5025); + wiser = Wiser.port(5025); try { wiser.start(); diff --git a/modules/flowable-cmmn-engine/src/test/resources/log4j.properties b/modules/flowable-cmmn-engine/src/test/resources/log4j.properties index 10a9a3c44f2..af13413e8dc 100644 --- a/modules/flowable-cmmn-engine/src/test/resources/log4j.properties +++ b/modules/flowable-cmmn-engine/src/test/resources/log4j.properties @@ -7,7 +7,7 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=DEBUG -log4j.logger.javax.activation=INFO +log4j.logger.jakarta.activation=INFO log4j.logger.org.springframework=INFO log4j.logger.liquibase=INFO diff --git a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/cfg/mail/FlowableMailClientCreator.java b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/cfg/mail/FlowableMailClientCreator.java index 5a6f16097ab..1ba1420a63b 100644 --- a/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/cfg/mail/FlowableMailClientCreator.java +++ b/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/cfg/mail/FlowableMailClientCreator.java @@ -25,7 +25,7 @@ import org.flowable.mail.common.impl.MailHostServerConfiguration; import org.flowable.mail.common.impl.MailJndiServerConfiguration; import org.flowable.mail.common.impl.MailServerConfiguration; -import org.flowable.mail.common.impl.apache.commons.ApacheCommonsEmailFlowableMailClient; +import org.flowable.mail.common.impl.jakarta.mail.JakartaMailFlowableMailClient; /** * @author Filip Hrisafov @@ -53,7 +53,7 @@ public static FlowableMailClient createHostClient(String host, MailServerInfo se protected static FlowableMailClient createMailClient(MailServerConfiguration serverConfiguration, MailServerInfo serverInfo, MailServerInfo fallbackServerInfo) { MailDefaultsConfiguration defaultsConfiguration = createMailDefaultsConfiguration(serverInfo, fallbackServerInfo); - return new ApacheCommonsEmailFlowableMailClient(serverConfiguration, defaultsConfiguration); + return new JakartaMailFlowableMailClient(serverConfiguration, defaultsConfiguration); } protected static MailHostServerConfiguration createMailHostServerConfiguration(String host, MailServerInfo mailServer) { diff --git a/modules/flowable-engine-configurator/src/test/resources/log4j.properties b/modules/flowable-engine-configurator/src/test/resources/log4j.properties index 3b88061e97b..03610eebf68 100644 --- a/modules/flowable-engine-configurator/src/test/resources/log4j.properties +++ b/modules/flowable-engine-configurator/src/test/resources/log4j.properties @@ -7,6 +7,6 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO +log4j.logger.jakarta.activation=INFO log4j.logger.org.flowable.engine.impl.agenda=DEBUG diff --git a/modules/flowable-engine/pom.xml b/modules/flowable-engine/pom.xml index 686d16385f5..2c8e7682649 100755 --- a/modules/flowable-engine/pom.xml +++ b/modules/flowable-engine/pom.xml @@ -208,8 +208,8 @@ test - org.subethamail - subethasmtp-wiser + com.github.davidmoten + subethasmtp test @@ -308,9 +308,9 @@ junit*;resolution:=optional, org.junit*;resolution:=optional, com.sun*;resolution:=optional, - javax.activation*;resolution:=optional, + jakarta.activation*;resolution:=optional, jakarta.persistence*;resolution:=optional, - org.apache.commons.mail*;resolution:=optional, + jakarta.mail*;resolution:=optional, org.apache.xerces*;resolution:=optional, org.flowable.camel;resolution:=optional, org.flowable.camel.impl;resolution:=optional, diff --git a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/AttachmentsBean.java b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/AttachmentsBean.java index 5e1b525a2d0..ab15dc9038a 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/AttachmentsBean.java +++ b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/AttachmentsBean.java @@ -20,7 +20,7 @@ import java.io.Serializable; import java.nio.charset.StandardCharsets; -import javax.activation.DataSource; +import jakarta.activation.DataSource; import org.apache.commons.lang3.Validate; diff --git a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailSendTaskTest.java b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailSendTaskTest.java index 58c4a65278d..8206cc6430e 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailSendTaskTest.java +++ b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailSendTaskTest.java @@ -26,10 +26,10 @@ import java.util.List; import java.util.Map; -import javax.activation.DataHandler; -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; +import jakarta.activation.DataHandler; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMultipart; import org.flowable.common.engine.api.FlowableException; import org.flowable.common.engine.impl.history.HistoryLevel; diff --git a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailSendTaskWithContentItemsTest.java b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailSendTaskWithContentItemsTest.java index 869e63b63cd..97a9fd7b184 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailSendTaskWithContentItemsTest.java +++ b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailSendTaskWithContentItemsTest.java @@ -23,7 +23,7 @@ import java.util.Map; import java.util.Set; -import javax.mail.internet.MimeMultipart; +import jakarta.mail.internet.MimeMultipart; import org.flowable.common.engine.impl.interceptor.EngineConfigurationConstants; import org.flowable.content.api.ContentEngineConfigurationApi; diff --git a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailServiceTaskTest.java b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailServiceTaskTest.java index 15906a4cf05..d9ca0ec3d91 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailServiceTaskTest.java +++ b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailServiceTaskTest.java @@ -30,10 +30,10 @@ import java.util.Map; import java.util.stream.Stream; -import javax.activation.DataHandler; -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; +import jakarta.activation.DataHandler; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMultipart; import org.flowable.common.engine.api.FlowableException; import org.flowable.common.engine.impl.cfg.mail.FlowableMailClientCreator; diff --git a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailTestCase.java b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailTestCase.java index be7e820ca38..8c49f175ed8 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailTestCase.java +++ b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/mail/EmailTestCase.java @@ -41,8 +41,7 @@ protected void setUp() throws Exception { initialMailServers = mailServers == null ? null : new HashMap<>(mailServers); boolean serverUpAndRunning = false; while (!serverUpAndRunning) { - wiser = new Wiser(); - wiser.setPort(5025); + wiser = Wiser.port(5025); try { wiser.start(); diff --git a/modules/flowable-engine/src/test/java/org/flowable/examples/bpmn/mail/EmailSendTaskTest.java b/modules/flowable-engine/src/test/java/org/flowable/examples/bpmn/mail/EmailSendTaskTest.java index 75751e6698f..d5c9d05db24 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/examples/bpmn/mail/EmailSendTaskTest.java +++ b/modules/flowable-engine/src/test/java/org/flowable/examples/bpmn/mail/EmailSendTaskTest.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Map; -import javax.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMessage; import org.flowable.engine.impl.test.PluggableFlowableTestCase; import org.flowable.engine.test.Deployment; @@ -46,8 +46,7 @@ public class EmailSendTaskTest extends PluggableFlowableTestCase { protected void setUp() throws Exception { boolean serverUpAndRunning = false; while (!serverUpAndRunning) { - wiser = new Wiser(); - wiser.setPort(5025); + wiser = Wiser.port(5025); try { wiser.start(); diff --git a/modules/flowable-engine/src/test/java/org/flowable/examples/bpmn/mail/EmailServiceTaskTest.java b/modules/flowable-engine/src/test/java/org/flowable/examples/bpmn/mail/EmailServiceTaskTest.java index 705abd537b4..e7c26c6b0ed 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/examples/bpmn/mail/EmailServiceTaskTest.java +++ b/modules/flowable-engine/src/test/java/org/flowable/examples/bpmn/mail/EmailServiceTaskTest.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Map; -import javax.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMessage; import org.flowable.engine.impl.test.PluggableFlowableTestCase; import org.flowable.engine.test.Deployment; @@ -43,8 +43,7 @@ public class EmailServiceTaskTest extends PluggableFlowableTestCase { protected void setUp() throws Exception { boolean serverUpAndRunning = false; while (!serverUpAndRunning) { - wiser = new Wiser(); - wiser.setPort(5025); + wiser = Wiser.port(5025); try { wiser.start(); diff --git a/modules/flowable-entitylink-service/src/test/resources/log4j.properties b/modules/flowable-entitylink-service/src/test/resources/log4j.properties index 3b88061e97b..61e34f49c61 100644 --- a/modules/flowable-entitylink-service/src/test/resources/log4j.properties +++ b/modules/flowable-entitylink-service/src/test/resources/log4j.properties @@ -7,6 +7,5 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO log4j.logger.org.flowable.engine.impl.agenda=DEBUG diff --git a/modules/flowable-event-registry/pom.xml b/modules/flowable-event-registry/pom.xml index 33efa9d11cc..9194dc30047 100644 --- a/modules/flowable-event-registry/pom.xml +++ b/modules/flowable-event-registry/pom.xml @@ -137,9 +137,9 @@ org.junit.jupiter*;resolution:=optional, com.sun*;resolution:=optional, liquibase*;resolution:=optional, - javax.activation*;resolution:=optional, + jakarta.activation*;resolution:=optional, jakarta.persistence*;resolution:=optional, - org.apache.commons.mail*;resolution:=optional, + jakarta.mail*;resolution:=optional, org.apache.xerces*;resolution:=optional, org.springframework*;resolution:=optional, com.fasterxml*;resolution:=optional, diff --git a/modules/flowable-eventsubscription-service/src/test/resources/log4j.properties b/modules/flowable-eventsubscription-service/src/test/resources/log4j.properties index 3b88061e97b..61e34f49c61 100644 --- a/modules/flowable-eventsubscription-service/src/test/resources/log4j.properties +++ b/modules/flowable-eventsubscription-service/src/test/resources/log4j.properties @@ -7,6 +7,5 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO log4j.logger.org.flowable.engine.impl.agenda=DEBUG diff --git a/modules/flowable-groovy-script-static-engine/src/test/resources/log4j.properties b/modules/flowable-groovy-script-static-engine/src/test/resources/log4j.properties index 93ca471ee27..2cadd9879a0 100644 --- a/modules/flowable-groovy-script-static-engine/src/test/resources/log4j.properties +++ b/modules/flowable-groovy-script-static-engine/src/test/resources/log4j.properties @@ -7,4 +7,3 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO diff --git a/modules/flowable-identitylink-service/src/test/resources/log4j.properties b/modules/flowable-identitylink-service/src/test/resources/log4j.properties index 3b88061e97b..61e34f49c61 100644 --- a/modules/flowable-identitylink-service/src/test/resources/log4j.properties +++ b/modules/flowable-identitylink-service/src/test/resources/log4j.properties @@ -7,6 +7,5 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO log4j.logger.org.flowable.engine.impl.agenda=DEBUG diff --git a/modules/flowable-jms-spring-executor/src/test/resources/log4j.properties b/modules/flowable-jms-spring-executor/src/test/resources/log4j.properties index 680ad366c2e..b380a5f72d1 100644 --- a/modules/flowable-jms-spring-executor/src/test/resources/log4j.properties +++ b/modules/flowable-jms-spring-executor/src/test/resources/log4j.properties @@ -7,6 +7,5 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO log4j.logger.org.flowable.engine.impl.agenda=DEBUG \ No newline at end of file diff --git a/modules/flowable-jmx/src/test/resources/log4j.properties b/modules/flowable-jmx/src/test/resources/log4j.properties index 395fff2e876..873432d37ba 100644 --- a/modules/flowable-jmx/src/test/resources/log4j.properties +++ b/modules/flowable-jmx/src/test/resources/log4j.properties @@ -7,5 +7,4 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO diff --git a/modules/flowable-job-service/src/test/resources/log4j.properties b/modules/flowable-job-service/src/test/resources/log4j.properties index 3b88061e97b..61e34f49c61 100644 --- a/modules/flowable-job-service/src/test/resources/log4j.properties +++ b/modules/flowable-job-service/src/test/resources/log4j.properties @@ -7,6 +7,5 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO log4j.logger.org.flowable.engine.impl.agenda=DEBUG diff --git a/modules/flowable-ldap-configurator/src/test/resources/log4j.properties b/modules/flowable-ldap-configurator/src/test/resources/log4j.properties index 313b65874ef..ee53342ab7e 100644 --- a/modules/flowable-ldap-configurator/src/test/resources/log4j.properties +++ b/modules/flowable-ldap-configurator/src/test/resources/log4j.properties @@ -7,5 +7,4 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO diff --git a/modules/flowable-mail/pom.xml b/modules/flowable-mail/pom.xml index 8c4d77bc73f..6cf88fbd98d 100644 --- a/modules/flowable-mail/pom.xml +++ b/modules/flowable-mail/pom.xml @@ -128,8 +128,8 @@ slf4j-api - org.apache.commons - commons-email + org.eclipse.angus + angus-mail diff --git a/modules/flowable-mail/src/main/java/org/flowable/mail/common/api/MailMessage.java b/modules/flowable-mail/src/main/java/org/flowable/mail/common/api/MailMessage.java index 212b0abd882..0f70cbd72a3 100644 --- a/modules/flowable-mail/src/main/java/org/flowable/mail/common/api/MailMessage.java +++ b/modules/flowable-mail/src/main/java/org/flowable/mail/common/api/MailMessage.java @@ -18,7 +18,7 @@ import java.util.LinkedHashMap; import java.util.Map; -import javax.activation.DataSource; +import jakarta.activation.DataSource; /** * @author Filip Hrisafov diff --git a/modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/BaseMailActivityDelegate.java b/modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/BaseMailActivityDelegate.java index 97c1a45c4ee..b11bc96c377 100644 --- a/modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/BaseMailActivityDelegate.java +++ b/modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/BaseMailActivityDelegate.java @@ -22,8 +22,8 @@ import java.util.Collection; import java.util.Collections; -import javax.activation.DataSource; -import javax.activation.FileDataSource; +import jakarta.activation.DataSource; +import jakarta.activation.FileDataSource; import org.apache.commons.lang3.StringUtils; import org.flowable.common.engine.api.FlowableException; diff --git a/modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/apache/commons/ApacheCommonsEmailFlowableMailClient.java b/modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/apache/commons/ApacheCommonsEmailFlowableMailClient.java deleted file mode 100644 index ee26daa73c1..00000000000 --- a/modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/apache/commons/ApacheCommonsEmailFlowableMailClient.java +++ /dev/null @@ -1,313 +0,0 @@ -/* Licensed 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.flowable.mail.common.impl.apache.commons; - -import java.nio.charset.Charset; -import java.util.Collection; -import java.util.Map; - -import javax.activation.DataSource; -import javax.naming.NamingException; - -import org.apache.commons.mail.Email; -import org.apache.commons.mail.EmailException; -import org.apache.commons.mail.HtmlEmail; -import org.apache.commons.mail.MultiPartEmail; -import org.apache.commons.mail.SimpleEmail; -import org.flowable.common.engine.api.FlowableException; -import org.flowable.common.engine.api.FlowableIllegalArgumentException; -import org.flowable.mail.common.impl.MailDefaultsConfiguration; -import org.flowable.mail.common.impl.MailHostServerConfiguration; -import org.flowable.mail.common.impl.MailJndiServerConfiguration; -import org.flowable.mail.common.api.MailMessage; -import org.flowable.mail.common.api.MailResponse; -import org.flowable.mail.common.impl.MailServerConfiguration; -import org.flowable.mail.common.api.SendMailRequest; -import org.flowable.mail.common.api.client.ExecutableSendMailRequest; -import org.flowable.mail.common.api.client.FlowableMailClient; -import org.flowable.mail.common.impl.FlowableMailException; -import org.flowable.mail.common.impl.SimpleMailResponse; - -/** - * @author Filip Hrisafov - */ -public class ApacheCommonsEmailFlowableMailClient implements FlowableMailClient { - - protected final MailServerConfiguration serverConfiguration; - protected final MailDefaultsConfiguration defaultsConfiguration; - - public ApacheCommonsEmailFlowableMailClient(MailServerConfiguration serverConfiguration, MailDefaultsConfiguration defaultsConfiguration) { - this.serverConfiguration = serverConfiguration; - this.defaultsConfiguration = defaultsConfiguration; - } - - @Override - public ExecutableSendMailRequest prepareRequest(SendMailRequest request) { - MailMessage message = request.message(); - String text = message.getPlainContent(); - String html = message.getHtmlContent(); - Collection attachments = message.getAttachments(); - - boolean attachmentsExist = attachments != null && !attachments.isEmpty(); - Email email = createEmail(text, html, attachmentsExist); - addHeaders(email, message.getHeaders()); - addTo(email, message.getTo()); - setFrom(email, message.getFrom()); - addCc(email, message.getCc()); - addBcc(email, message.getBcc()); - setSubject(email, message.getSubject()); - setCharset(email, message.getCharset()); - if (attachmentsExist) { - attach(email, attachments); - } - setMailServerProperties(email); - - return new ApacheCommonsEmailMailRequest(email); - } - - protected Email createEmail(String text, String html, boolean attachmentsExist) { - if (html != null) { - return createHtmlEmail(text, html); - } else if (text != null) { - if (!attachmentsExist) { - return createTextOnlyEmail(text); - } else { - return createMultiPartEmail(text); - } - } else { - throw new FlowableIllegalArgumentException("'html' or 'text' is required to be defined when using the mail activity"); - } - } - - protected HtmlEmail createHtmlEmail(String text, String html) { - HtmlEmail email = new HtmlEmail(); - try { - email.setHtmlMsg(html); - if (text != null) { // for email clients that don't support html - email.setTextMsg(text); - } - return email; - } catch (EmailException e) { - throw new FlowableMailException("Could not create HTML email", e); - } - } - - protected SimpleEmail createTextOnlyEmail(String text) { - SimpleEmail email = new SimpleEmail(); - try { - email.setMsg(text); - return email; - } catch (EmailException e) { - throw new FlowableException("Could not create text-only email", e); - } - } - - protected MultiPartEmail createMultiPartEmail(String text) { - MultiPartEmail email = new MultiPartEmail(); - try { - email.setMsg(text); - return email; - } catch (EmailException e) { - throw new FlowableMailException("Could not create text-only email", e); - } - } - - protected void addHeaders(Email email, Map headers) { - if (headers != null && !headers.isEmpty()) { - headers.forEach(email::addHeader); - } - } - - protected void addTo(Email email, Collection to) { - if (to == null || to.isEmpty()) { - return; - } - Collection newTo = to; - Collection forceTo = defaultsConfiguration.forceTo(); - if (forceTo != null && !forceTo.isEmpty()) { - newTo = forceTo; - } - if (!newTo.isEmpty()) { - for (String t : newTo) { - try { - email.addTo(t); - } catch (EmailException e) { - throw new FlowableMailException("Could not add " + t + " as recipient", e); - } - } - } else { - throw new FlowableException("No recipient could be found for sending email"); - } - } - - protected void setFrom(Email email, String from) { - String fromAddress; - - if (from != null) { - fromAddress = from; - } else { // use default configured from address in defaults configuration - fromAddress = defaultsConfiguration.defaultFrom(); - } - - try { - email.setFrom(fromAddress); - } catch (EmailException e) { - throw new FlowableMailException("Could not set " + fromAddress + " as from address in email", e); - } - } - - protected void addCc(Email email, Collection cc) { - if (cc == null || cc.isEmpty()) { - return; - } - Collection newCc = cc; - - Collection forceTo = defaultsConfiguration.forceTo(); - if (forceTo != null && !forceTo.isEmpty()) { - newCc = forceTo; - } - if (!newCc.isEmpty()) { - for (String c : newCc) { - try { - email.addCc(c); - } catch (EmailException e) { - throw new FlowableMailException("Could not add " + c + " as cc recipient", e); - } - } - } - } - - protected void addBcc(Email email, Collection bcc) { - if (bcc == null || bcc.isEmpty()) { - return; - } - Collection newBcc = bcc; - Collection forceTo = defaultsConfiguration.forceTo(); - if (forceTo != null && !forceTo.isEmpty()) { - newBcc = forceTo; - } - if (!newBcc.isEmpty()) { - for (String b : newBcc) { - try { - email.addBcc(b); - } catch (EmailException e) { - throw new FlowableMailException("Could not add " + b + " as bcc recipient", e); - } - } - } - } - - protected void setSubject(Email email, String subject) { - email.setSubject(subject != null ? subject : ""); - } - - protected void setCharset(Email email, Charset charset) { - if (charset != null) { - email.setCharset(charset.name()); - } else { - Charset defaultCharset = defaultsConfiguration.defaultCharset(); - if (defaultCharset != null) { - email.setCharset(defaultCharset.name()); - } - } - } - - protected void attach(Email email, Collection attachments) { - if (email instanceof MultiPartEmail multiPartEmail) { - for (DataSource attachment : attachments) { - try { - multiPartEmail.attach(attachment, attachment.getName(), null); - } catch (EmailException e) { - throw new FlowableMailException("Failed to attach " + attachment, e); - } - } - - } - } - - protected void setMailServerProperties(Email email) { - if (serverConfiguration instanceof MailJndiServerConfiguration jndiServerConfiguration) { - setMailServerProperties(email, jndiServerConfiguration); - } else if (serverConfiguration instanceof MailHostServerConfiguration hostServerConfiguration) { - setMailServerProperties(email, hostServerConfiguration); - } else { - throw new FlowableException("Unsupported server configuration " + serverConfiguration); - } - } - - protected void setMailServerProperties(Email email, MailJndiServerConfiguration serverConfiguration) { - String sessionJndi = serverConfiguration.getSessionJndi(); - if (sessionJndi == null) { - throw new FlowableIllegalArgumentException("sessionJndi has to be set for " + serverConfiguration); - } - setEmailSession(email, sessionJndi); - } - - protected void setMailServerProperties(Email email, MailHostServerConfiguration serverConfiguration) { - String host = serverConfiguration.host(); - if (host == null) { - throw new FlowableException("Could not send email: no SMTP host is configured"); - } - - email.setHostName(host); - - MailHostServerConfiguration.Transport transport = serverConfiguration.transport(); - switch (transport) { - case SMTP -> email.setSmtpPort(serverConfiguration.port()); - case SMTPS -> { - email.setSslSmtpPort(Integer.toString(serverConfiguration.port())); - email.setSSLOnConnect(true); - } - case SMTPS_TLS -> { - email.setSslSmtpPort(Integer.toString(serverConfiguration.port())); - email.setSSLOnConnect(true); - email.setSSLOnConnect(true); - } - default -> throw new FlowableIllegalArgumentException("Unknown transport " + transport); - } - - String user = serverConfiguration.user(); - String password = serverConfiguration.password(); - if (user != null && password != null) { - email.setAuthentication(user, password); - } - - } - - protected void setEmailSession(Email email, String mailSessionJndi) { - try { - email.setMailSessionFromJNDI(mailSessionJndi); - } catch (NamingException e) { - throw new FlowableException("Could not send email: Incorrect JNDI configuration", e); - } - } - - protected static class ApacheCommonsEmailMailRequest implements ExecutableSendMailRequest { - - protected final Email email; - - protected ApacheCommonsEmailMailRequest(Email email) { - this.email = email; - } - - @Override - public MailResponse send() { - try { - String messageId = email.send(); - return new SimpleMailResponse(messageId); - } catch (EmailException e) { - throw new FlowableMailException("Sending email failed", e); - } - } - } -} diff --git a/modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/jakarta/mail/JakartaMailFlowableMailClient.java b/modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/jakarta/mail/JakartaMailFlowableMailClient.java new file mode 100644 index 00000000000..4df67a2709d --- /dev/null +++ b/modules/flowable-mail/src/main/java/org/flowable/mail/common/impl/jakarta/mail/JakartaMailFlowableMailClient.java @@ -0,0 +1,450 @@ +/* Licensed 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.flowable.mail.common.impl.jakarta.mail; + +import java.io.UnsupportedEncodingException; +import java.net.IDN; +import java.nio.charset.Charset; +import java.time.Duration; +import java.util.Collection; +import java.util.Date; +import java.util.Map; +import java.util.Properties; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import jakarta.activation.DataHandler; +import jakarta.activation.DataSource; +import jakarta.mail.Authenticator; +import jakarta.mail.BodyPart; +import jakarta.mail.Message; +import jakarta.mail.MessagingException; +import jakarta.mail.Part; +import jakarta.mail.PasswordAuthentication; +import jakarta.mail.Session; +import jakarta.mail.Transport; +import jakarta.mail.internet.AddressException; +import jakarta.mail.internet.InternetAddress; +import jakarta.mail.internet.MimeBodyPart; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMultipart; +import jakarta.mail.internet.MimeUtility; + +import org.apache.commons.lang3.StringUtils; +import org.flowable.common.engine.api.FlowableException; +import org.flowable.common.engine.api.FlowableIllegalArgumentException; +import org.flowable.mail.common.api.MailMessage; +import org.flowable.mail.common.api.MailResponse; +import org.flowable.mail.common.api.SendMailRequest; +import org.flowable.mail.common.api.client.ExecutableSendMailRequest; +import org.flowable.mail.common.api.client.FlowableMailClient; +import org.flowable.mail.common.impl.FlowableMailException; +import org.flowable.mail.common.impl.MailDefaultsConfiguration; +import org.flowable.mail.common.impl.MailHostServerConfiguration; +import org.flowable.mail.common.impl.MailJndiServerConfiguration; +import org.flowable.mail.common.impl.MailServerConfiguration; +import org.flowable.mail.common.impl.SimpleMailResponse; + +/** + * @author Filip Hrisafov + */ +public class JakartaMailFlowableMailClient implements FlowableMailClient { + // The creation of the Jakarta MimeMessage is inspired by Apache Commons Email + + private static final String MAIL_TRANSPORT_PROTOCOL = "mail.transport.protocol"; + private static final String MAIL_TRANSPORT_STARTTLS_ENABLE = "mail.smtp.starttls.enable"; + private static final String MAIL_TRANSPORT_STARTTLS_REQUIRED = "mail.smtp.starttls.false"; + private static final String MAIL_HOST = "mail.smtp.host"; + private static final String MAIL_PORT = "mail.smtp.port"; + + private static final String MAIL_SMTP_AUTH = "mail.smtp.auth"; + private static final String MAIL_SMTP_TIMEOUT = "mail.smtp.timeout"; + private static final String MAIL_SMTP_CONNECTIONTIMEOUT = "mail.smtp.connectiontimeout"; + private static final String MAIL_SMTP_SEND_PARTIAL = "mail.smtp.sendpartial"; + private static final String MAIL_SMTPS_SEND_PARTIAL = "mail.smtps.sendpartial"; + + private static final String MAIL_SMTP_SOCKET_FACTORY_PORT = "mail.smtp.socketFactory.port"; + private static final String MAIL_SMTP_SOCKET_FACTORY_CLASS = "mail.smtp.socketFactory.class"; + private static final String MAIL_SMTP_SOCKET_FACTORY_FALLBACK = "mail.smtp.socketFactory.fallback"; + + private static final String CONTENT_TYPE_TEXT_HTML = "text/html"; + + private static final Duration SOCKET_TIMEOUT = Duration.ofSeconds(60); + private static final Duration SOCKET_CONNECTION_TIMEOUT = Duration.ofSeconds(60); + + protected final MailServerConfiguration serverConfiguration; + protected final MailDefaultsConfiguration defaultsConfiguration; + + public JakartaMailFlowableMailClient(MailServerConfiguration serverConfiguration, MailDefaultsConfiguration defaultsConfiguration) { + this.serverConfiguration = serverConfiguration; + this.defaultsConfiguration = defaultsConfiguration; + } + + @Override + public ExecutableSendMailRequest prepareRequest(SendMailRequest request) { + Session session = createSession(); + try { + MimeMessage mimeMessage = createMimeMessage(request, session); + return new JakartaMailSendMailRequest(mimeMessage); + } catch (MessagingException e) { + throw new FlowableMailException("Failed to create mime message", e); + } + } + + protected MimeMessage createMimeMessage(SendMailRequest request, Session session) throws MessagingException { + MimeMessage mimeMessage = new MimeMessage(session); + + MailMessage message = request.message(); + Charset charset = getCharset(message); + setContent(mimeMessage, message, charset != null ? charset.name() : null); + setSubject(mimeMessage, message.getSubject(), charset); + addHeaders(mimeMessage, message.getHeaders(), charset); + addTo(mimeMessage, message.getTo()); + addCc(mimeMessage, message.getCc()); + addBcc(mimeMessage, message.getBcc()); + + setFrom(mimeMessage, message.getFrom()); + setSentDate(mimeMessage); + + return mimeMessage; + } + + protected Charset getCharset(MailMessage message) { + Charset charset = message.getCharset(); + if (charset == null) { + charset = defaultsConfiguration.defaultCharset(); + } + + return charset; + } + + protected void setSubject(MimeMessage message, String subject, Charset charset) throws MessagingException { + if (StringUtils.isNotEmpty(subject)) { + if (charset != null) { + message.setSubject(subject, charset.name()); + } else { + message.setSubject(subject); + } + } + } + + protected void addHeaders(MimeMessage message, Map headers, Charset charset) throws MessagingException { + if (headers != null && !headers.isEmpty()) { + for (Map.Entry entry : headers.entrySet()) { + + String name = entry.getKey(); + String value = entry.getValue(); + + if (StringUtils.isEmpty(name)) { + throw new FlowableMailException("header name cannot be null or empty"); + } + + if (StringUtils.isEmpty(value)) { + throw new FlowableMailException("header value cannot be null or empty"); + } + + String foldedHeaderValue = createFoldedHeaderValue(name, value, charset); + message.addHeader(name, foldedHeaderValue); + } + } + + } + + protected String createFoldedHeaderValue(String name, String value, Charset charset) { + try { + return MimeUtility.fold(name.length() + 2, MimeUtility.encodeText(value, charset != null ? charset.name() : null, null)); + } catch (UnsupportedEncodingException e) { + return value; + } + } + + protected void addTo(MimeMessage message, Collection to) { + addRecipient(message, to, Message.RecipientType.TO); + } + + protected void addCc(MimeMessage message, Collection cc) { + addRecipient(message, cc, Message.RecipientType.CC); + } + + protected void addBcc(MimeMessage message, Collection bcc) { + addRecipient(message, bcc, Message.RecipientType.BCC); + } + + protected void addRecipient(MimeMessage message, Collection recipients, Message.RecipientType recipientType) { + if (recipients == null || recipients.isEmpty()) { + return; + } + Collection newRecipients = recipients; + Collection forceRecipients = defaultsConfiguration.forceTo(); + if (forceRecipients != null && !forceRecipients.isEmpty()) { + newRecipients = forceRecipients; + } + if (!newRecipients.isEmpty()) { + for (String t : newRecipients) { + try { + message.addRecipient(recipientType, createInternetAddress(t)); + } catch (MessagingException e) { + throw new FlowableMailException("Could not add " + t + " as " + recipientType + " recipient", e); + } + } + } + } + + protected InternetAddress createInternetAddress(String email) { + try { + InternetAddress address = new InternetAddress(toASCIIEmail(email)); + address.validate(); + return address; + } catch (AddressException e) { + throw new FlowableMailException("Invalid email", e); + } + } + + protected String toASCIIEmail(String email) { + int atIndex = email.indexOf('@'); + if (atIndex < 0) { + return email; + } + + // localPart@domainPart + return email.substring(0, atIndex) + '@' + IDN.toASCII(email.substring(atIndex + 1)); + + } + + protected void setFrom(MimeMessage message, String from) { + String fromAddress; + + if (from != null) { + fromAddress = from; + } else { // use default configured from address in defaults configuration + fromAddress = defaultsConfiguration.defaultFrom(); + } + + try { + message.setFrom(createInternetAddress(fromAddress)); + } catch (MessagingException e) { + throw new FlowableMailException("Could not set " + fromAddress + " as from address in email", e); + } + } + + protected void setSentDate(MimeMessage message) { + try { + if (message.getSentDate() == null) { + message.setSentDate(new Date()); + } + } catch (MessagingException e) { + throw new FlowableMailException("Failed to set send date", e); + } + } + + protected void setContent(MimeMessage mimeMessage, MailMessage message, String charset) { + String text = message.getPlainContent(); + String html = message.getHtmlContent(); + Collection attachments = message.getAttachments(); + boolean attachmentsExists = attachments != null && !attachments.isEmpty(); + if (html == null && text == null) { + throw new FlowableIllegalArgumentException("'html' or 'text' is required to be defined when sending an email"); + } + if (html == null && !attachmentsExists) { + try { + mimeMessage.setText(text, charset); + } catch (MessagingException e) { + throw new FlowableMailException("Could not create text-only email", e); + } + } else { + try { + mimeMessage.setContent(createMultiPartContent(text, html, charset, attachments)); + } catch (MessagingException e) { + throw new FlowableMailException("Failed to create multi part email", e); + } + } + } + + protected MimeMultipart createMultiPartContent(String text, String html, String charset, Collection attachments) throws MessagingException { + boolean attachmentsExists = attachments != null && !attachments.isEmpty(); + + MimeMultipart rootContainer = new MimeMultipart(); + MimeMultipart bodyContainer = rootContainer; + + rootContainer.setSubType("mixed"); + + if (StringUtils.isNotEmpty(text) && StringUtils.isNotEmpty(html)) { + if (attachmentsExists) { + // If both HTML and TEXT bodies are provided, create an alternative + // container and add it to the root container + bodyContainer = new MimeMultipart("alternative"); + MimeBodyPart bodyPart = new MimeBodyPart(); + try { + bodyPart.setContent(bodyContainer); + rootContainer.addBodyPart(bodyPart); + } catch (MessagingException ex) { + throw new FlowableMailException("Failed to add body part", ex); + } + } else { + // no attachments present, change the mimetype + // of the root container (= body container) + rootContainer.setSubType("alternative"); + } + } + + if (StringUtils.isNotEmpty(html)) { + MimeBodyPart msgHtml = new MimeBodyPart(); + bodyContainer.addBodyPart(msgHtml, 0); + msgHtml.setText(html, charset, "html"); + + String contentType = msgHtml.getContentType(); + if (contentType == null || !contentType.equals(CONTENT_TYPE_TEXT_HTML)) { + if (StringUtils.isNotEmpty(charset)) { + msgHtml.setContent(html, CONTENT_TYPE_TEXT_HTML + "; charset=" + charset); + } else { + msgHtml.setContent(html, CONTENT_TYPE_TEXT_HTML); + } + } + } + + if (StringUtils.isNotEmpty(text)) { + MimeBodyPart msgText = new MimeBodyPart(); + bodyContainer.addBodyPart(msgText, 0); + msgText.setText(text, charset); + } + + if (attachmentsExists) { + for (DataSource attachment : attachments) { + BodyPart bodyPart = new MimeBodyPart(); + bodyPart.setDisposition(Part.ATTACHMENT); + try { + bodyPart.setFileName(MimeUtility.encodeText(attachment.getName(), charset, null)); + } catch (UnsupportedEncodingException e) { + throw new FlowableMailException("Could not encode attachment file name", e); + } + bodyPart.setDataHandler(new DataHandler(attachment)); + rootContainer.addBodyPart(bodyPart); + } + } + + return rootContainer; + } + + protected Session createSession() { + if (serverConfiguration instanceof MailJndiServerConfiguration jndiServerConfiguration) { + return createSession(jndiServerConfiguration); + } else if (serverConfiguration instanceof MailHostServerConfiguration hostServerConfiguration) { + return createSession(hostServerConfiguration); + } else { + throw new FlowableException("Unsupported server configuration " + serverConfiguration); + } + } + + protected Session createSession(MailJndiServerConfiguration serverConfiguration) { + String sessionJndi = serverConfiguration.getSessionJndi(); + if (sessionJndi == null) { + throw new FlowableIllegalArgumentException("sessionJndi has to be set for " + serverConfiguration); + } + try { + Context ctx; + if (sessionJndi.startsWith("java:")) { + ctx = new InitialContext(); + } else { + ctx = (Context) new InitialContext().lookup("java:comp/env"); + + } + + return (Session) ctx.lookup(sessionJndi); + } catch (NamingException e) { + throw new FlowableException("Could not send email: Incorrect JNDI configuration", e); + } + } + + protected Session createSession(MailHostServerConfiguration serverConfiguration) { + String host = serverConfiguration.host(); + if (host == null) { + throw new FlowableException("Could not send email: no SMTP host is configured"); + } + + Properties properties = new Properties(System.getProperties()); + properties.setProperty(MAIL_TRANSPORT_PROTOCOL, "smtp"); + properties.setProperty(MAIL_PORT, String.valueOf(serverConfiguration.port())); + properties.setProperty(MAIL_HOST, host); + + MailHostServerConfiguration.Transport transport = serverConfiguration.transport(); + properties.setProperty(MAIL_TRANSPORT_STARTTLS_ENABLE, transport == MailHostServerConfiguration.Transport.SMTPS_TLS ? "true" : "false"); + properties.setProperty(MAIL_TRANSPORT_STARTTLS_REQUIRED, "false"); + + properties.setProperty(MAIL_SMTP_SEND_PARTIAL, "false"); + properties.setProperty(MAIL_SMTPS_SEND_PARTIAL, "false"); + + Authenticator authenticator = getAuthenticator(serverConfiguration); + if (authenticator != null) { + properties.setProperty(MAIL_SMTP_AUTH, "true"); + } + + if (transport == MailHostServerConfiguration.Transport.SMTPS || transport == MailHostServerConfiguration.Transport.SMTPS_TLS) { + properties.setProperty(MAIL_SMTP_SOCKET_FACTORY_PORT, String.valueOf(serverConfiguration.port())); + properties.setProperty(MAIL_SMTP_SOCKET_FACTORY_CLASS, "javax.net.ssl.SSLSocketFactory"); + properties.setProperty(MAIL_SMTP_SOCKET_FACTORY_FALLBACK, "false"); + } + + properties.setProperty(MAIL_SMTP_TIMEOUT, Long.toString(SOCKET_TIMEOUT.toMillis())); + properties.setProperty(MAIL_SMTP_CONNECTIONTIMEOUT, Long.toString(SOCKET_CONNECTION_TIMEOUT.toMillis())); + + customizeProperties(properties, authenticator); + + return Session.getInstance(properties, authenticator); + + } + + protected void customizeProperties(Properties properties, Authenticator authenticator) { + // Nothing to do + } + + protected Authenticator getAuthenticator(MailHostServerConfiguration serverConfiguration) { + String user = serverConfiguration.user(); + String password = serverConfiguration.password(); + if (user != null && password != null) { + PasswordAuthentication passwordAuthentication = new PasswordAuthentication(user, password); + return new Authenticator() { + + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return passwordAuthentication; + } + }; + } + + return null; + } + + protected static class JakartaMailSendMailRequest implements ExecutableSendMailRequest { + + protected final MimeMessage message; + + protected JakartaMailSendMailRequest(MimeMessage message) { + this.message = message; + } + + @Override + public MailResponse send() { + try { + Transport.send(message); + return new SimpleMailResponse(message.getMessageID()); + } catch (MessagingException e) { + Session session = message.getSession(); + String host = session.getProperty("mail.smtp.host"); + String port = session.getProperty("mail.smtp.port"); + throw new FlowableMailException("Sending the email to the following server failed : " + host + ":" + port, e); + } + } + } +} diff --git a/modules/flowable-osgi/src/test/resources/log4j.properties b/modules/flowable-osgi/src/test/resources/log4j.properties index 44e229d8406..055c4a126cb 100644 --- a/modules/flowable-osgi/src/test/resources/log4j.properties +++ b/modules/flowable-osgi/src/test/resources/log4j.properties @@ -6,4 +6,4 @@ log4j.appender.CA.layout=org.apache.log4j.PatternLayout log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO +log4j.logger.jakarta.activation=INFO diff --git a/modules/flowable-secure-javascript/src/test/resources/log4j.properties b/modules/flowable-secure-javascript/src/test/resources/log4j.properties index a057a421448..d3e729838c4 100644 --- a/modules/flowable-secure-javascript/src/test/resources/log4j.properties +++ b/modules/flowable-secure-javascript/src/test/resources/log4j.properties @@ -7,4 +7,3 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO diff --git a/modules/flowable-spring/pom.xml b/modules/flowable-spring/pom.xml index 1f0fd31fcac..8814f0dfdcf 100644 --- a/modules/flowable-spring/pom.xml +++ b/modules/flowable-spring/pom.xml @@ -198,15 +198,9 @@ true - org.subethamail - subethasmtp-wiser + com.github.davidmoten + subethasmtp test - - - javax.mail - mail - - com.zaxxer diff --git a/modules/flowable-spring/src/test/java/org/flowable/spring/test/email/JndiEmailTest.java b/modules/flowable-spring/src/test/java/org/flowable/spring/test/email/JndiEmailTest.java index 2ffe17d2125..1edb130375e 100644 --- a/modules/flowable-spring/src/test/java/org/flowable/spring/test/email/JndiEmailTest.java +++ b/modules/flowable-spring/src/test/java/org/flowable/spring/test/email/JndiEmailTest.java @@ -18,10 +18,10 @@ import java.util.Map; import java.util.Properties; -import javax.mail.NoSuchProviderException; -import javax.mail.Provider; -import javax.mail.Provider.Type; -import javax.mail.Session; +import jakarta.mail.NoSuchProviderException; +import jakarta.mail.Provider; +import jakarta.mail.Provider.Type; +import jakarta.mail.Session; import javax.naming.InitialContext; import javax.naming.NamingException; diff --git a/modules/flowable-spring/src/test/java/org/flowable/spring/test/email/MockEmailTransport.java b/modules/flowable-spring/src/test/java/org/flowable/spring/test/email/MockEmailTransport.java index 1c15534c944..188b2274e79 100644 --- a/modules/flowable-spring/src/test/java/org/flowable/spring/test/email/MockEmailTransport.java +++ b/modules/flowable-spring/src/test/java/org/flowable/spring/test/email/MockEmailTransport.java @@ -14,12 +14,12 @@ import java.io.IOException; -import javax.mail.Address; -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.URLName; +import jakarta.mail.Address; +import jakarta.mail.Message; +import jakarta.mail.MessagingException; +import jakarta.mail.Session; +import jakarta.mail.Transport; +import jakarta.mail.URLName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/modules/flowable-task-service/src/test/resources/log4j.properties b/modules/flowable-task-service/src/test/resources/log4j.properties index 3b88061e97b..61e34f49c61 100644 --- a/modules/flowable-task-service/src/test/resources/log4j.properties +++ b/modules/flowable-task-service/src/test/resources/log4j.properties @@ -7,6 +7,5 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO log4j.logger.org.flowable.engine.impl.agenda=DEBUG diff --git a/modules/flowable-variable-service/src/test/resources/log4j.properties b/modules/flowable-variable-service/src/test/resources/log4j.properties index 3b88061e97b..61e34f49c61 100644 --- a/modules/flowable-variable-service/src/test/resources/log4j.properties +++ b/modules/flowable-variable-service/src/test/resources/log4j.properties @@ -7,6 +7,5 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO log4j.logger.org.flowable.engine.impl.agenda=DEBUG diff --git a/modules/flowable5-compatibility-test/src/test/resources/log4j.properties b/modules/flowable5-compatibility-test/src/test/resources/log4j.properties index a057a421448..4c5941e0d50 100644 --- a/modules/flowable5-compatibility-test/src/test/resources/log4j.properties +++ b/modules/flowable5-compatibility-test/src/test/resources/log4j.properties @@ -7,4 +7,4 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO +log4j.logger.jakarta.activation=INFO diff --git a/modules/flowable5-compatibility-testdata/src/main/resources/log4j.properties b/modules/flowable5-compatibility-testdata/src/main/resources/log4j.properties index a057a421448..4c5941e0d50 100644 --- a/modules/flowable5-compatibility-testdata/src/main/resources/log4j.properties +++ b/modules/flowable5-compatibility-testdata/src/main/resources/log4j.properties @@ -7,4 +7,4 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO +log4j.logger.jakarta.activation=INFO diff --git a/modules/flowable5-engine/pom.xml b/modules/flowable5-engine/pom.xml index 11fa0ccc13b..f43eb1b20cf 100644 --- a/modules/flowable5-engine/pom.xml +++ b/modules/flowable5-engine/pom.xml @@ -93,8 +93,8 @@ test - org.subethamail - subethasmtp-wiser + com.github.davidmoten + subethasmtp test @@ -168,7 +168,7 @@ org.junit*;resolution:=optional, com.sun*;resolution:=optional, jakarta.persistence*;resolution:=optional, - org.apache.commons.mail*;resolution:=optional, + jakarta.mail*;resolution:=optional, org.apache.xerces*;resolution:=optional, org.activiti.camel;resolution:=optional, org.activiti.camel.impl;resolution:=optional, diff --git a/modules/flowable5-spring-test/pom.xml b/modules/flowable5-spring-test/pom.xml index 01c51bd967a..02406485ab3 100644 --- a/modules/flowable5-spring-test/pom.xml +++ b/modules/flowable5-spring-test/pom.xml @@ -153,8 +153,8 @@ test - org.subethamail - subethasmtp-wiser + com.github.davidmoten + subethasmtp test diff --git a/modules/flowable5-test/pom.xml b/modules/flowable5-test/pom.xml index d6124fdd233..391157c2ae3 100755 --- a/modules/flowable5-test/pom.xml +++ b/modules/flowable5-test/pom.xml @@ -101,8 +101,8 @@ test - org.subethamail - subethasmtp-wiser + com.github.davidmoten + subethasmtp test diff --git a/modules/flowable5-test/src/test/java/org/activiti/engine/test/bpmn/mail/EmailTestCase.java b/modules/flowable5-test/src/test/java/org/activiti/engine/test/bpmn/mail/EmailTestCase.java index 4bbe9ddf08e..981f5f7840f 100644 --- a/modules/flowable5-test/src/test/java/org/activiti/engine/test/bpmn/mail/EmailTestCase.java +++ b/modules/flowable5-test/src/test/java/org/activiti/engine/test/bpmn/mail/EmailTestCase.java @@ -29,8 +29,7 @@ protected void setUp() throws Exception { boolean serverUpAndRunning = false; while (!serverUpAndRunning) { - wiser = new Wiser(); - wiser.setPort(5025); + wiser = Wiser.port(5025); try { wiser.start(); @@ -53,4 +52,10 @@ protected void tearDown() throws Exception { super.tearDown(); } + protected void reinitilizeMailClients() { + processEngineConfiguration.setDefaultMailClient(null); + processEngineConfiguration.getMailClients().clear(); + processEngineConfiguration.initMailClients(); + } + } diff --git a/modules/flowable5-test/src/test/java/org/activiti/examples/bpmn/mail/EmailSendTaskTest.java b/modules/flowable5-test/src/test/java/org/activiti/examples/bpmn/mail/EmailSendTaskTest.java index 2b904285dc4..5f1c3f991bc 100644 --- a/modules/flowable5-test/src/test/java/org/activiti/examples/bpmn/mail/EmailSendTaskTest.java +++ b/modules/flowable5-test/src/test/java/org/activiti/examples/bpmn/mail/EmailSendTaskTest.java @@ -40,8 +40,7 @@ protected void setUp() throws Exception { boolean serverUpAndRunning = false; while (!serverUpAndRunning) { - wiser = new Wiser(); - wiser.setPort(5025); + wiser = Wiser.port(5025); try { wiser.start(); diff --git a/modules/flowable5-test/src/test/java/org/activiti/examples/bpmn/mail/EmailServiceTaskTest.java b/modules/flowable5-test/src/test/java/org/activiti/examples/bpmn/mail/EmailServiceTaskTest.java index 74037ed8141..61805c5cba6 100644 --- a/modules/flowable5-test/src/test/java/org/activiti/examples/bpmn/mail/EmailServiceTaskTest.java +++ b/modules/flowable5-test/src/test/java/org/activiti/examples/bpmn/mail/EmailServiceTaskTest.java @@ -36,8 +36,7 @@ public class EmailServiceTaskTest extends PluggableFlowableTestCase { @Override protected void setUp() throws Exception { super.setUp(); - wiser = new Wiser(); - wiser.setPort(5025); + wiser = Wiser.port(5025); wiser.start(); } diff --git a/modules/flowable5-test/src/test/resources/log4j.properties b/modules/flowable5-test/src/test/resources/log4j.properties index a057a421448..4c5941e0d50 100644 --- a/modules/flowable5-test/src/test/resources/log4j.properties +++ b/modules/flowable5-test/src/test/resources/log4j.properties @@ -7,4 +7,4 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO +log4j.logger.jakarta.activation=INFO diff --git a/pom.xml b/pom.xml index 944a05e7342..2ec5e338f17 100644 --- a/pom.xml +++ b/pom.xml @@ -183,9 +183,9 @@ 2.0.1 - com.sun.mail - javax.mail - 1.6.2 + org.eclipse.angus + angus-mail + 2.0.2 jakarta.persistence @@ -253,12 +253,6 @@ jcc 11.5.8.0 - - - org.apache.commons - commons-email - 1.5 - org.apache.cxf @@ -364,16 +358,9 @@ import - org.subethamail - subethasmtp-wiser - 1.2 - test - - - commons-logging - commons-logging - - + com.github.davidmoten + subethasmtp + 6.0.6 org.liquibase diff --git a/qa/logging/log4j.properties b/qa/logging/log4j.properties index 6077b8d1c79..606d9b030f8 100644 --- a/qa/logging/log4j.properties +++ b/qa/logging/log4j.properties @@ -7,6 +7,6 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=ERROR -log4j.logger.javax.activation=ERROR +log4j.logger.jakarta.activation=ERROR log4j.logger.org.flowable.engine.impl.agenda=ERROR diff --git a/tooling/archetypes/flowable-archetype-unittest/src/main/resources/archetype-resources/src/test/resources/log4j.properties b/tooling/archetypes/flowable-archetype-unittest/src/main/resources/archetype-resources/src/test/resources/log4j.properties index e58bd4c74e0..4d0abda9f77 100644 --- a/tooling/archetypes/flowable-archetype-unittest/src/main/resources/archetype-resources/src/test/resources/log4j.properties +++ b/tooling/archetypes/flowable-archetype-unittest/src/main/resources/archetype-resources/src/test/resources/log4j.properties @@ -7,4 +7,3 @@ log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - % log4j.logger.org.apache.ibatis=INFO -log4j.logger.javax.activation=INFO