From 816dc3fcf574e5af5953fc39b9f83a2ea468b9ba Mon Sep 17 00:00:00 2001 From: Scott Wierschem Date: Thu, 7 Dec 2023 17:12:43 -0600 Subject: [PATCH] ! B Update to jakarta mail Closes #376 --- approvaltests-tests/pom.xml | 4 +- approvaltests-util/pom.xml | 4 +- .../com/spun/util/ByteArrayDataSource.java | 112 ------------------ .../java/com/spun/util/tests/EmailOpener.java | 2 +- 4 files changed, 5 insertions(+), 117 deletions(-) delete mode 100644 approvaltests-util/src/main/java/com/spun/util/ByteArrayDataSource.java diff --git a/approvaltests-tests/pom.xml b/approvaltests-tests/pom.xml index aae9b1561..6dfc6ee24 100644 --- a/approvaltests-tests/pom.xml +++ b/approvaltests-tests/pom.xml @@ -127,8 +127,8 @@ com.sun.mail - javax.mail - 1.6.2 + jakarta.mail + 2.0.1 diff --git a/approvaltests-util/pom.xml b/approvaltests-util/pom.xml index 7e171a434..860b2f8f0 100644 --- a/approvaltests-util/pom.xml +++ b/approvaltests-util/pom.xml @@ -32,8 +32,8 @@ com.sun.mail - javax.mail - 1.6.2 + jakarta.mail + 2.0.1 true diff --git a/approvaltests-util/src/main/java/com/spun/util/ByteArrayDataSource.java b/approvaltests-util/src/main/java/com/spun/util/ByteArrayDataSource.java deleted file mode 100644 index 52e694baa..000000000 --- a/approvaltests-util/src/main/java/com/spun/util/ByteArrayDataSource.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.spun.util; - -import javax.activation.DataSource; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; - -/** - * Comment By LLewellyn: This is a needed class for using mail. For some reason wasn't - * made as part of the standard mail package.

- * - * A simple DataSource for demonstration purposes. - * This class implements a DataSource from: - * an InputStream - * a byte array - * a String - * - * @author John Mani - * @author Bill Shannon - * @author Max Spivak - **/ -public class ByteArrayDataSource implements DataSource -{ - private byte[] data; // data - private String type; // content-type - private String name = "dummy"; - /* Create a DataSource from an input stream */ - public ByteArrayDataSource(InputStream is, String type) - { - this(is, type, null); - } - /* Create a DataSource from an input stream */ - public ByteArrayDataSource(InputStream is, String type, String name) - { - this.type = type; - setName(name); - try - { - try (ByteArrayOutputStream os = new ByteArrayOutputStream()) - { - int ch; - while ((ch = is.read()) != -1) - { - // XXX - must be made more efficient by - // doing buffered reads, rather than one byte reads - os.write(ch); - } - data = os.toByteArray(); - } - } - catch (IOException e) - { - throw ObjectUtils.throwAsError(e); - } - } - /* Create a DataSource from a byte array */ - public ByteArrayDataSource(byte[] data, String type) - { - this.data = data; - this.type = type; - } - public void setName(String name) - { - this.name = (name == null) ? "dummy" : name; - } - /* Create a DataSource from a String */ - public ByteArrayDataSource(String data, String type) - { - this(data, type, null); - } - /* Create a DataSource from a String */ - public ByteArrayDataSource(String data, String type, String name) - { - setName(name); - try - { - // Assumption that the string contains only ASCII - // characters! Otherwise just pass a charset into this - // constructor and use it in getBytes() - this.data = data.getBytes("iso-8859-1"); - } - catch (UnsupportedEncodingException uex) - { - } - this.type = type; - } - /** - * Return an InputStream for the data. - * Note - a new stream must be returned each time. - */ - public InputStream getInputStream() - { - if (data == null) - { throw new RuntimeException("no data"); } - return new ByteArrayInputStream(data); - } - public OutputStream getOutputStream() - { - throw new RuntimeException("cannot do this"); - } - public String getContentType() - { - return type; - } - public String getName() - { - return name; - } -} diff --git a/approvaltests-util/src/main/java/com/spun/util/tests/EmailOpener.java b/approvaltests-util/src/main/java/com/spun/util/tests/EmailOpener.java index a342ffd54..70d8189c4 100644 --- a/approvaltests-util/src/main/java/com/spun/util/tests/EmailOpener.java +++ b/approvaltests-util/src/main/java/com/spun/util/tests/EmailOpener.java @@ -1,8 +1,8 @@ package com.spun.util.tests; import com.spun.util.ObjectUtils; +import jakarta.mail.Message; -import javax.mail.Message; import java.io.File; import java.io.FileOutputStream;