diff --git a/examples/pom.xml b/examples/pom.xml
index 8eb2dae9..b5054564 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -37,11 +37,6 @@
jakarta.servlet.jsp.jstl
3.0.1
-
- jakarta.mail
- jakarta.mail-api
- compile
-
commons-logging
commons-logging
diff --git a/pom.xml b/pom.xml
index 64789bfb..b5047c77 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,20 +78,6 @@
1.1.2
provided
-
- jakarta.mail
- jakarta.mail-api
- 2.1.2
- provided
- true
-
-
- jakarta.activation
- jakarta.activation-api
-
-
-
-
commons-logging
commons-logging
diff --git a/stripes/pom.xml b/stripes/pom.xml
index d270b524..34804c3e 100644
--- a/stripes/pom.xml
+++ b/stripes/pom.xml
@@ -40,10 +40,6 @@
5.0.1
provided
-
- jakarta.mail
- jakarta.mail-api
-
junit
junit
diff --git a/stripes/src/main/java/net/sourceforge/stripes/validation/EmailTypeConverter.java b/stripes/src/main/java/net/sourceforge/stripes/validation/EmailTypeConverter.java
index 50a6b466..73cba784 100644
--- a/stripes/src/main/java/net/sourceforge/stripes/validation/EmailTypeConverter.java
+++ b/stripes/src/main/java/net/sourceforge/stripes/validation/EmailTypeConverter.java
@@ -14,10 +14,9 @@
*/
package net.sourceforge.stripes.validation;
-import jakarta.mail.internet.AddressException;
-import jakarta.mail.internet.InternetAddress;
import java.util.Collection;
import java.util.Locale;
+import java.util.regex.Pattern;
/**
* A faux TypeConverter that validates that the String supplied is a valid email address. Relies on
@@ -42,6 +41,14 @@
* @since Stripes 1.2
*/
public class EmailTypeConverter implements TypeConverter {
+
+ /**
+ * This RegEx is taken from the HTML5 spec.
+ */
+ private static final Pattern EMAIL_VALIDATION_REGEX =
+ Pattern.compile(
+ "[ \\a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[[\\[]a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[]a-zA-Z0-9])?)*");
/** Accepts the Locale provided, but does nothing with it since emails are Locale-less. */
public void setLocale(Locale locale) {
/** Doesn't matter for email. */
@@ -59,19 +66,31 @@ public void setLocale(Locale locale) {
public String convert(
String input, Class extends String> targetType, Collection errors) {
- String result = null;
+ // Used to test for more than one @ symbol
+ int atSymbolOccurrences = (input.length() - input.replace("@", "").length());
+
+ // Used to test for no dots after the last @ sign
+ boolean noDotsAfterLastAtSign =
+ input.contains("@") && !input.substring(input.lastIndexOf("@")).contains(".");
+
+ // Used to test for starts with a dot
+ boolean startsWithDot = input.split("@")[0].startsWith(".");
+
+ // Used to test for ends with a dot
+ boolean endsWithDot = input.split("@")[0].endsWith(".");
+
+ // Used to test for two consecutive dots
+ boolean twoConsecutiveDots = input.split("@")[0].contains("..");
- try {
- InternetAddress address = new InternetAddress(input, true);
- result = address.getAddress();
- if (!result.contains("@")) {
- result = null;
- throw new AddressException();
- }
- } catch (AddressException ae) {
+ if (atSymbolOccurrences > 1
+ || noDotsAfterLastAtSign
+ || startsWithDot
+ || endsWithDot
+ || twoConsecutiveDots
+ || !EMAIL_VALIDATION_REGEX.matcher(input).matches()) {
errors.add(new ScopedLocalizableError("converter.email", "invalidEmail"));
}
- return result;
+ return input;
}
}
diff --git a/stripes/src/test/java/net/sourceforge/stripes/action/TestStreamingResolution.java b/stripes/src/test/java/net/sourceforge/stripes/action/TestStreamingResolution.java
index 01c015e9..9d0746f0 100644
--- a/stripes/src/test/java/net/sourceforge/stripes/action/TestStreamingResolution.java
+++ b/stripes/src/test/java/net/sourceforge/stripes/action/TestStreamingResolution.java
@@ -14,13 +14,13 @@
*/
package net.sourceforge.stripes.action;
-import jakarta.mail.internet.ContentDisposition;
-import jakarta.mail.internet.ParseException;
import java.io.ByteArrayInputStream;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
import net.sourceforge.stripes.mock.MockHttpServletResponse;
+import org.apache.commons.fileupload2.core.ParameterParser;
import org.junit.Assert;
import org.junit.Test;
@@ -34,7 +34,7 @@ public void testContentDisposition() throws Exception {
}
private void doTestContentDisposition(boolean attachment, String filename) throws Exception {
- byte[] data = UUID.randomUUID().toString().getBytes(Charset.forName("UTF-8"));
+ byte[] data = UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8);
ByteArrayInputStream is = new ByteArrayInputStream(data);
StreamingResolution resolution = new StreamingResolution("application/octet-stream", is);
@@ -48,32 +48,35 @@ private void doTestContentDisposition(boolean attachment, String filename) throw
resolution.stream(response);
Assert.assertArrayEquals(data, response.getOutputBytes());
- ContentDisposition disposition = getContentDisposition(response);
+ // Use commons-fileupload to parse the Content-Disposition header
+ String disposition = null;
+ String cdAttachment = null;
+ String cdFilename = null;
+ final List
-
- jakarta.mail
- jakarta.mail-api
- compile
-
commons-logging
commons-logging