Author: pete.muir(a)jboss.org
Date: 2008-06-06 16:36:35 -0400 (Fri, 06 Jun 2008)
New Revision: 8342
Modified:
trunk/src/mail/org/jboss/seam/mail/ui/Header.java
trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/HeaderTest.java
Log:
Add line folding
Modified: trunk/src/mail/org/jboss/seam/mail/ui/Header.java
===================================================================
--- trunk/src/mail/org/jboss/seam/mail/ui/Header.java 2008-06-06 16:07:16 UTC (rev 8341)
+++ trunk/src/mail/org/jboss/seam/mail/ui/Header.java 2008-06-06 20:36:35 UTC (rev 8342)
@@ -4,6 +4,8 @@
import java.io.IOException;
import java.io.StringReader;
+import javax.mail.internet.MimeUtility;
+
public class Header
{
@@ -47,7 +49,7 @@
{
try
{
- sanitizedValue = sanitize(value);
+ sanitizedValue = sanitizeValue(value);
}
catch (IOException e)
{
@@ -66,5 +68,15 @@
BufferedReader reader = new BufferedReader(new StringReader(value));
return reader.readLine();
}
+
+ /**
+ * Remove any line feed/new line characters from a (possibly) folded header
+ * @throws IOException
+ */
+ public static String sanitizeValue(String value) throws IOException
+ {
+ // The user might have folded the header (stupid SMTP idiocy)
+ return sanitize(MimeUtility.unfold(value));
+ }
}
Modified: trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/HeaderTest.java
===================================================================
--- trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/HeaderTest.java 2008-06-06
16:07:16 UTC (rev 8341)
+++ trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/HeaderTest.java 2008-06-06
20:36:35 UTC (rev 8342)
@@ -61,4 +61,45 @@
assert "foo".equals(header.getSanitizedName());
assert "bar".equals(header.getSanitizedValue());
}
+
+ @Test
+ public void testHeaderWithFolding1()
+ {
+ String name = "header";
+ String value = "\"Joe & J. Harvey\" <ddd @ Org>,\n JJV @
BBN";
+ String sanitizedValue = "\"Joe & J. Harvey\" <ddd @ Org>,
JJV @ BBN";
+
+ Header header = new Header(name, value);
+
+ assert header.getSanitizedName().equals(name);
+ assert header.getSanitizedValue().equals(sanitizedValue);
+
+ }
+
+ @Test
+ public void testHeaderWithFolding2()
+ {
+ String name = "header";
+ String value = "\"Joe & J. Harvey\"\n <ddd @ Org>, JJV\n @
BBN";
+ String sanitizedValue = "\"Joe & J. Harvey\" <ddd @ Org>,
JJV @ BBN";
+
+ Header header = new Header(name, value);
+
+ assert header.getSanitizedName().equals(name);
+ assert header.getSanitizedValue().equals(sanitizedValue);
+
+ }
+
+ @Test
+ public void testHeaderWithFolding3()
+ {
+ String name = "header";
+ String value = "\"Joe &\n J. Harvey\" <ddd @ Org>, JJV @
BBN";
+ String sanitizedValue = "\"Joe & J. Harvey\" <ddd @ Org>,
JJV @ BBN";
+ Header header = new Header(name, value);
+
+ assert header.getSanitizedName().equals(name);
+ assert header.getSanitizedValue().equals(sanitizedValue);
+
+ }
}
Show replies by date