Skip to content

Commit

Permalink
Migrate to Jakarta Mail (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Jul 19, 2022
1 parent c0e3195 commit f669030
Show file tree
Hide file tree
Showing 39 changed files with 102 additions and 101 deletions.
1 change: 0 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ buildPlugin(useContainerAgent: true, configurations: [
[ platform: 'linux', jdk: '8' ],
[ platform: 'linux', jdk: '11' ],
[ platform: 'windows', jdk: '11' ],
[ platform: 'linux', jdk: '17' ],
])
4 changes: 2 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ This section allows you to specify recipients for each type of email trigger as

=== Pre-send scripts and post-send scripts

This feature allows you to write a script that can modify the https://docs.oracle.com/javaee/7/api/javax/mail/internet/MimeMessage.html[`MimeMessage`] object before or after sending the email.
This feature allows you to write a script that can modify the https://eclipse-ee4j.github.io/mail/docs/api/jakarta.mail/jakarta/mail/internet/MimeMessage.html[`MimeMessage`] object before or after sending the email.
This allows adding custom headers, modifying the body, etc.
Predefined variables include:

`msg` (https://docs.oracle.com/javaee/7/api/javax/mail/internet/MimeMessage.html[`javax.mail.internet.MimeMessage`]):: The MIME email message object, which can be modified.
`msg` (https://eclipse-ee4j.github.io/mail/docs/api/jakarta.mail/jakarta/mail/internet/MimeMessage.html[`jakarta.mail.internet.MimeMessage`]):: The MIME email message object, which can be modified.
`logger` (https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html[`java.io.PrintStream`]):: A `PrintStream` that can be used to log messages to the build log.
`build` (https://javadoc.jenkins.io/hudson/model/AbstractBuild.html[`hudson.model.AbstractBuild`]):: The build this message belongs to (only use with Freestyle projects).
`run` (https://javadoc.jenkins.io/hudson/model/Run.html[`hudson.model.Run`]):: The build this message belongs to (may be used with Freestyle projects or Pipeline).
Expand Down
8 changes: 4 additions & 4 deletions docs/recipes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ To filter out the recipients that *do not* contain `@example.com`:
.Filtering recipients on a domain
[source,groovy]
----
recipients = msg.getRecipients(javax.mail.Message.RecipientType.TO)
recipients = msg.getRecipients(jakarta.mail.Message.RecipientType.TO)
filtered = recipients.findAll { addr -> addr.toString().endsWith('@example.com') }
msg.setRecipients(javax.mail.Message.RecipientType.TO, filtered as javax.mail.Address[])
msg.setRecipients(jakarta.mail.Message.RecipientType.TO, filtered as jakarta.mail.Address[])
----

==== Filtering recipients on a whitelist
Expand All @@ -72,9 +72,9 @@ def includedInWhitelist(addr) {
return 0
}
recipients = msg.getRecipients(javax.mail.Message.RecipientType.TO)
recipients = msg.getRecipients(jakarta.mail.Message.RecipientType.TO)
filtered = recipients.findAll { addr -> includedInWhitelist(addr) > 0 }
msg.setRecipients(javax.mail.Message.RecipientType.TO, filtered as javax.mail.Address[])
msg.setRecipients(jakarta.mail.Message.RecipientType.TO, filtered as jakarta.mail.Address[])
----

== Post-send scripts
Expand Down
12 changes: 7 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<revision>2.90</revision>
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/email-ext-plugin</gitHubRepo>
<jenkins.version>2.346.1</jenkins.version>
<jenkins.version>2.332.1</jenkins.version>
<hpi.compatibleSinceVersion>2.57.2</hpi.compatibleSinceVersion>
<concurrency>1</concurrency>
<!-- To be removed once Jenkins.MANAGE gets out of beta -->
Expand Down Expand Up @@ -104,7 +104,7 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.346.x</artifactId>
<artifactId>bom-2.332.x</artifactId>
<version>1478.v81d3dc4f9a_43</version>
<scope>import</scope>
<type>pom</type>
Expand Down Expand Up @@ -141,6 +141,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mailer</artifactId>
<version>435.v79ef3972b_5c7</version> <!-- TODO until in BOM -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down Expand Up @@ -214,20 +215,21 @@
<scope>test</scope>
</dependency>
<!--
This must come before javax-mail-api in the class path in order to avoid eclipse-ee4j/mail#350.
This must come before jakarta-mail-api in the class path in order to avoid eclipse-ee4j/mail#350.
-->
<dependency>
<groupId>org.jvnet.mock-javamail</groupId>
<artifactId>mock-javamail</artifactId>
<version>1.12</version>
<version>2.0</version>
<scope>test</scope>
</dependency>
<!--
This must come after mock-javamail in the class path in order to avoid eclipse-ee4j/mail#350.
-->
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>javax-mail-api</artifactId>
<artifactId>jakarta-mail-api</artifactId>
<version>2.0.0-5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/hudson/plugins/emailext/AttachmentUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileTypeMap;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeUtility;
import jakarta.activation.DataHandler;
import jakarta.activation.DataSource;
import jakarta.activation.FileTypeMap;
import jakarta.mail.MessagingException;
import jakarta.mail.Multipart;
import jakarta.mail.internet.MimeBodyPart;
import jakarta.mail.internet.MimeUtility;
import org.apache.commons.lang.StringUtils;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.InternetAddress;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.AddressException;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import jakarta.mail.Address;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import jakarta.mail.Multipart;
import jakarta.mail.SendFailedException;
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 jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.codehaus.groovy.control.CompilerConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import jakarta.mail.Authenticator;
import jakarta.mail.PasswordAuthentication;
import jakarta.mail.Session;
import jakarta.mail.internet.AddressException;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;
import net.sf.json.JSONObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hudson.plugins.emailext;

import hudson.model.TaskListener;
import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;

class RecipientListStringAnalyser {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/emailext/SizedDataSource.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hudson.plugins.emailext;

import javax.activation.DataSource;
import jakarta.activation.DataSource;

public interface SizedDataSource extends DataSource {
long getSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import edu.umd.cs.findbugs.annotations.NonNull;
import java.lang.reflect.Method;
import javax.mail.internet.MimeMessage;
import jakarta.mail.internet.MimeMessage;

/**
* {@link org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist} of explicit {@link MimeMessage} instances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
//TODO should probably be moved into default lists in script-security
@Restricted(NoExternalUse.class)
@Extension
public class StaticJavaxMailWhitelist extends ProxyWhitelist {
public StaticJavaxMailWhitelist() throws IOException {
super(StaticWhitelist.from(StaticJavaxMailWhitelist.class.getResource("javax.mail.whitelist")));
public class StaticJakartaMailWhitelist extends ProxyWhitelist {
public StaticJakartaMailWhitelist() throws IOException {
super(StaticWhitelist.from(StaticJakartaMailWhitelist.class.getResource("jakarta.mail.whitelist")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.io.PrintStream;
import java.util.Collections;
import java.util.Set;
import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.Collections;
import java.util.Set;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.AddressException;
import jakarta.mail.internet.InternetAddress;

import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.Symbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import jenkins.scm.RunWithSCM;
import org.jenkinsci.Symbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.io.PrintStream;
import java.util.Collections;
import java.util.Set;
import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Set;
import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.HashSet;
import java.util.Set;

import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.InternetAddress;

import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import jenkins.scm.RunWithSCM;
import org.springframework.security.core.Authentication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.io.PrintStream;
import java.util.Collections;
import java.util.Set;
import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.mail.internet.InternetAddress;
import jakarta.mail.internet.InternetAddress;
import jenkins.model.Jenkins;
import jenkins.scm.RunWithSCM;
import org.jenkinsci.Symbol;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
staticField jakarta.mail.Message$RecipientType BCC
staticField jakarta.mail.Message$RecipientType CC
staticField jakarta.mail.Message$RecipientType TO

This file was deleted.

10 changes: 5 additions & 5 deletions src/test/java/hudson/plugins/emailext/AttachmentUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;
import jakarta.mail.BodyPart;
import jakarta.mail.Message;
import jakarta.mail.internet.MimeMessage;
import jakarta.mail.internet.MimeMultipart;
import jakarta.mail.internet.MimeUtility;
import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.Rule;
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/hudson/plugins/emailext/EmailExtStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import java.net.URL;
import java.util.Collections;
import java.util.Set;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import jakarta.mail.BodyPart;
import jakarta.mail.Message;
import jakarta.mail.internet.MimeMessage;
import jakarta.mail.internet.MimeMultipart;
import org.apache.commons.lang.StringEscapeUtils;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import org.junit.rules.TestName;
import org.mockito.Mockito;

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import jakarta.mail.Authenticator;
import jakarta.mail.PasswordAuthentication;

public class ExtendedEmailPublisherDescriptorJCasCTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction;
import javax.mail.Authenticator;
import jakarta.mail.Authenticator;
import jenkins.model.Jenkins;
import org.apache.xpath.Arg;
import org.junit.Rule;
Expand Down
Loading

0 comments on commit f669030

Please sign in to comment.