You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mime4j-dev@james.apache.org by ol...@apache.org on 2011/07/11 21:48:57 UTC
svn commit: r1145308 [3/7] - in /james/mime4j/trunk:
core/src/main/java/org/apache/james/mime4j/
core/src/main/java/org/apache/james/mime4j/codec/
core/src/main/java/org/apache/james/mime4j/io/
core/src/main/java/org/apache/james/mime4j/parser/ core/sr...
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMail.java Mon Jul 11 19:48:50 2011
@@ -25,114 +25,114 @@ import java.util.Locale;
import org.apache.james.mime4j.util.CharsetUtil;
public class ExampleMail {
-
- public static final String MIME_MULTIPART_EMBEDDED_MESSAGES_INNER_MULTIPART_MIXED = "--4.66920160910299\r\n" +
- "Content-Type: image/gif\r\n" +
- "Content-Transfer-Encoding: base64\r\n" +
- "MIME-Version: 1.0\r\n" +
- "Content-ID: 238478934723847238947892374\r\n" +
- "Content-Description: Bogus Image Data\r\n" +
- "\r\n" +
- "ABCDFEGHIJKLMNO\r\n" +
- "\r\n" +
- "--4.66920160910299\r\n" +
- "Content-Type: message/rfc822\r\n" +
- "\r\n" +
- "From: Timothy Tayler <ti...@example.org>\r\n" +
- "To: John Smith <jo...@example.org>\r\n" +
- "Date: Sat, 16 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
- "Subject: Another Example Email\r\n" +
- "Content-Type: multipart/mixed;boundary=2.50290787509\r\n" +
- "\r\n" +
- "Yet another preamble\r\n" +
- "\r\n" +
- "--2.50290787509\r\n" +
- "Content-Type: text/plain\r\n" +
- "\r\n" +
- "Rhubard AND Custard!\r\n" +
- "\r\n" +
- "--2.50290787509\r\n" +
- "Content-Type: multipart/alternative;boundary=3.243F6A8885A308D3\r\n" +
- "\r\n" +
- "--3.243F6A8885A308D3\r\n" +
- "Content-Type: text/plain\r\n" +
- "\r\n" +
- "Rhubard?Custard?\r\n" +
- "\r\n" +
- "--3.243F6A8885A308D3\r\n" +
- "\r\n" +
- "Content-Type: text/richtext\r\n" +
- "\r\n" +
- "Rhubard?Custard?\r\n" +
- "\r\n" +
- "--3.243F6A8885A308D3--\r\n" +
- "\r\n" +
- "--2.50290787509--\r\n" +
- "\r\n" +
+
+ public static final String MIME_MULTIPART_EMBEDDED_MESSAGES_INNER_MULTIPART_MIXED = "--4.66920160910299\r\n" +
+ "Content-Type: image/gif\r\n" +
+ "Content-Transfer-Encoding: base64\r\n" +
+ "MIME-Version: 1.0\r\n" +
+ "Content-ID: 238478934723847238947892374\r\n" +
+ "Content-Description: Bogus Image Data\r\n" +
+ "\r\n" +
+ "ABCDFEGHIJKLMNO\r\n" +
+ "\r\n" +
+ "--4.66920160910299\r\n" +
+ "Content-Type: message/rfc822\r\n" +
+ "\r\n" +
+ "From: Timothy Tayler <ti...@example.org>\r\n" +
+ "To: John Smith <jo...@example.org>\r\n" +
+ "Date: Sat, 16 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
+ "Subject: Another Example Email\r\n" +
+ "Content-Type: multipart/mixed;boundary=2.50290787509\r\n" +
+ "\r\n" +
+ "Yet another preamble\r\n" +
+ "\r\n" +
+ "--2.50290787509\r\n" +
+ "Content-Type: text/plain\r\n" +
+ "\r\n" +
+ "Rhubard AND Custard!\r\n" +
+ "\r\n" +
+ "--2.50290787509\r\n" +
+ "Content-Type: multipart/alternative;boundary=3.243F6A8885A308D3\r\n" +
+ "\r\n" +
+ "--3.243F6A8885A308D3\r\n" +
+ "Content-Type: text/plain\r\n" +
+ "\r\n" +
+ "Rhubard?Custard?\r\n" +
+ "\r\n" +
+ "--3.243F6A8885A308D3\r\n" +
+ "\r\n" +
+ "Content-Type: text/richtext\r\n" +
+ "\r\n" +
+ "Rhubard?Custard?\r\n" +
+ "\r\n" +
+ "--3.243F6A8885A308D3--\r\n" +
+ "\r\n" +
+ "--2.50290787509--\r\n" +
+ "\r\n" +
"--4.66920160910299--";
- public static final String MIME_MULTIPART_EMBEDDED_MESSAGES_INNER_MAIL = "From: Timothy Tayler <ti...@example.org>\r\n" +
- "To: Samual Smith <sa...@example.org>\r\n" +
- "Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
- "Subject: A Multipart Alternative Email\r\n" +
- "Content-Type: multipart/alternative;boundary=42\r\n" +
- "\r\n" +
- "This message has a premable\r\n" +
- "\r\n" +
- "--42\r\n" +
- "Content-Type: text/plain; charset=US-ASCII\r\n" +
- "\r\n" +
- "Custard!\r\n" +
- "\r\n" +
- "--42\r\n" +
- "Content-Type: application/octet-stream\r\n" +
- "\r\n" +
- "CUSTARDCUSTARDCUSTARD\r\n" +
- "\r\n" +
+ public static final String MIME_MULTIPART_EMBEDDED_MESSAGES_INNER_MAIL = "From: Timothy Tayler <ti...@example.org>\r\n" +
+ "To: Samual Smith <sa...@example.org>\r\n" +
+ "Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
+ "Subject: A Multipart Alternative Email\r\n" +
+ "Content-Type: multipart/alternative;boundary=42\r\n" +
+ "\r\n" +
+ "This message has a premable\r\n" +
+ "\r\n" +
+ "--42\r\n" +
+ "Content-Type: text/plain; charset=US-ASCII\r\n" +
+ "\r\n" +
+ "Custard!\r\n" +
+ "\r\n" +
+ "--42\r\n" +
+ "Content-Type: application/octet-stream\r\n" +
+ "\r\n" +
+ "CUSTARDCUSTARDCUSTARD\r\n" +
+ "\r\n" +
"--42--\r\n";
- public static final String MIME_MULTIPART_EMBEDDED_MESSAGES_BODY = "Start with a preamble\r\n" +
- "\r\n" +
- "--1729\r\n" +
- "Content-Type: text/plain; charset=US-ASCII\r\n" +
- "\r\n" +
- "Rhubarb!\r\n" +
- "\r\n" +
- "--1729\r\n" +
- "Content-Type: application/octet-stream\r\n" +
- "Content-Transfer-Encoding: base64\r\n" +
- "\r\n" +
- "987654321AHPLA\r\n" +
- "\r\n" +
- "--1729\r\n" +
- "Content-Type: message/rfc822\r\n" +
- "\r\n" +
- MIME_MULTIPART_EMBEDDED_MESSAGES_INNER_MAIL +
- "\r\n" +
- "--1729\r\n" +
- "Content-Type: multipart/mixed; boundary=4.66920160910299\r\n" +
- "\r\n" +
+ public static final String MIME_MULTIPART_EMBEDDED_MESSAGES_BODY = "Start with a preamble\r\n" +
+ "\r\n" +
+ "--1729\r\n" +
+ "Content-Type: text/plain; charset=US-ASCII\r\n" +
+ "\r\n" +
+ "Rhubarb!\r\n" +
+ "\r\n" +
+ "--1729\r\n" +
+ "Content-Type: application/octet-stream\r\n" +
+ "Content-Transfer-Encoding: base64\r\n" +
+ "\r\n" +
+ "987654321AHPLA\r\n" +
+ "\r\n" +
+ "--1729\r\n" +
+ "Content-Type: message/rfc822\r\n" +
+ "\r\n" +
+ MIME_MULTIPART_EMBEDDED_MESSAGES_INNER_MAIL +
+ "\r\n" +
+ "--1729\r\n" +
+ "Content-Type: multipart/mixed; boundary=4.66920160910299\r\n" +
+ "\r\n" +
MIME_MULTIPART_EMBEDDED_MESSAGES_INNER_MULTIPART_MIXED + "\r\n" +
- "--1729--\r\n" +
+ "--1729--\r\n" +
"\r\n";
-
+
public static final String MD5_CONTENT = "Q2hlY2sgSW50ZWdyaXR5IQ==";
public static final String CONTENT_DESCRIPTION = "Blah blah blah";
public static final String CONTENT_ID = "<f4...@mail.gmail.com>";
public static final Charset US_ASCII = CharsetUtil.US_ASCII;
public static final Charset LATIN1 = CharsetUtil.ISO_8859_1;
-
- public static final String MIME_MULTIPART_EMBEDDED_MESSAGES =
- "From: Timothy Tayler <ti...@example.org>\r\n" +
- "To: Samual Smith <sa...@example.org>\r\n" +
- "Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
- "Subject: A Multipart Email\r\n" +
- "Content-Type: multipart/mixed;boundary=1729\r\n" +
- "\r\n" +
- MIME_MULTIPART_EMBEDDED_MESSAGES_BODY;
-
- public static final String MULTIPART_WITH_CONTENT_LOCATION =
+ public static final String MIME_MULTIPART_EMBEDDED_MESSAGES =
+ "From: Timothy Tayler <ti...@example.org>\r\n" +
+ "To: Samual Smith <sa...@example.org>\r\n" +
+ "Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
+ "Subject: A Multipart Email\r\n" +
+ "Content-Type: multipart/mixed;boundary=1729\r\n" +
+ "\r\n" +
+ MIME_MULTIPART_EMBEDDED_MESSAGES_BODY;
+
+
+ public static final String MULTIPART_WITH_CONTENT_LOCATION =
"From: Timothy Tayler <ti...@example.org>\r\n" +
"To: Samual Smith <sa...@example.org>\r\n" +
"Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
@@ -166,7 +166,7 @@ public class ExampleMail {
"\r\n--1729--\r\n" +
"This is the epilogue\r\n";
- public static final String MULTIPART_WITH_BINARY_ATTACHMENTS_HEADER =
+ public static final String MULTIPART_WITH_BINARY_ATTACHMENTS_HEADER =
"Return-Path: <ro...@blueyonder.co.uk>\r\n" +
"Received: (qmail 18554 invoked from network); 25 May 2008 14:38:53 -0000\r\n" +
"Received: from unknown (HELO p3presmtp01-16.prod.phx3.secureserver.net)\r\n" +
@@ -217,7 +217,7 @@ public class ExampleMail {
"X-fetched-from: mail.xmlmapt.org\r\n" +
"X-Evolution-Source: imap://rob@thebes/\r\n" +
"\r\n";
-
+
public static final String MULTIPART_WITH_BINARY_ATTACHMENTS_BODY = "--=-tIdGYVstQJghyEDATnJ+\r\n" +
"Content-Type: text/plain\r\n" +
"Content-Transfer-Encoding: 7bit\r\n" +
@@ -332,11 +332,11 @@ public class ExampleMail {
public static final String ONE_PART_MIME_ASCII_BODY = "A single part MIME mail.\r\n";
public static final String RFC822_SIMPLE_BODY = "This is a very simple email.\r\n";
-
+
public static final String ONE_PART_MIME_8859_BODY = "M\u00F6nchengladbach\r\n";
-
+
public static final String ONE_PART_MIME_BASE64_LATIN1_BODY = "Hello Mo\u00F6nchengladbach\r\n";
-
+
public static final String ONE_PART_MIME_QUOTED_PRINTABLE_ASCII_BODY = "Sonnet LXXXI By William Shakespeare\r\n" +
"Or I shall live your epitaph to make,\r\n" +
"Or you survive when I in earth am rotten;\r\n" +
@@ -351,12 +351,12 @@ public class ExampleMail {
"And tongues to be, your being shall rehearse,\r\n" +
"When all the breathers of this world are dead;\r\n" +
" You still shall live,--such virtue hath my pen,--\r\n" +
- " Where breath most breathes, even in the mouths of men.\r\n";
-
+ " Where breath most breathes, even in the mouths of men.\r\n";
+
private static final byte[] ONE_PART_MIME_BASE64_LATIN1_ENCODED = EncodeUtils.toBase64(latin1(ONE_PART_MIME_BASE64_LATIN1_BODY));
-
+
public static final String ONE_PART_MIME_BASE64_ASCII_BODY = "Hello, World!\r\n";
-
+
public static final String ONE_PART_MIME_WITH_CONTENT_DISPOSITION_PARAMETERS =
"Message-ID: <f4...@mail.gmail.com>\r\n" +
"Date: Thu, 6 Mar 2008 18:02:03 +0000\r\n" +
@@ -387,7 +387,7 @@ public class ExampleMail {
"Delivered-To: robertburrelldonkin@gmail.com\r\n" +
"\r\n" +
ONE_PART_MIME_ASCII_BODY;
-
+
public static final String ONE_PART_MIME_ASCII_COMMENT_IN_MIME_VERSION = "Received: by 10.114.126.16 with HTTP; Thu, 6 Mar 2008 10:02:03 -0800 (PST)\r\n" +
"Message-ID: <f4...@mail.gmail.com>\r\n" +
"Date: Thu, 6 Mar 2008 18:02:03 +0000\r\n" +
@@ -400,7 +400,7 @@ public class ExampleMail {
"Content-Disposition: inline\r\n" +
"Delivered-To: robertburrelldonkin@gmail.com\r\n" +
"\r\n" + ONE_PART_MIME_ASCII_BODY;
-
+
public static final String ONE_PART_MIME_ASCII_MIME_VERSION_SPANS_TWO_LINES = "Received: by 10.114.126.16 with HTTP; Thu, 6 Mar 2008 10:02:03 -0800 (PST)\r\n" +
"Message-ID: <f4...@mail.gmail.com>\r\n" +
"Date: Thu, 6 Mar 2008 18:02:03 +0000\r\n" +
@@ -414,7 +414,7 @@ public class ExampleMail {
"Content-Disposition: inline\r\n" +
"Delivered-To: robertburrelldonkin@gmail.com\r\n" +
"\r\n" + ONE_PART_MIME_ASCII_BODY;
-
+
public static final String INNER_MAIL = "From: Timothy Tayler <ti...@example.org>\r\n" +
"To: Joshua Tetley <jo...@example.org>\r\n" +
"Date: Tue, 12 Feb 2008 17:34:09 +0000 (GMT)\r\n" +
@@ -448,7 +448,7 @@ public class ExampleMail {
"Last part is plain text\r\n" +
"--1729--\r\n" +
"The End";
-
+
public static final String ONE_PART_MIME_8859 = "Received: by 10.114.126.16 with HTTP; Thu, 6 Mar 2008 10:02:03 -0800 (PST)\r\n" +
"Message-ID: <f4...@mail.gmail.com>\r\n" +
"Date: Thu, 6 Mar 2008 18:02:03 +0000\r\n" +
@@ -464,7 +464,7 @@ public class ExampleMail {
"Delivered-To: robertburrelldonkin@gmail.com\r\n" +
"\r\n" +
ONE_PART_MIME_8859_BODY;
-
+
public static final String ONE_PART_MIME_BASE64_ASCII_HEADERS = "Received: by 10.114.126.16 with HTTP; Thu, 6 Mar 2008 10:02:03 -0800 (PST)\r\n" +
"Message-ID: <f4...@mail.gmail.com>\r\n" +
"Date: Thu, 6 Mar 2008 18:02:03 +0000\r\n" +
@@ -477,7 +477,7 @@ public class ExampleMail {
"Content-Disposition: inline\r\n" +
"Delivered-To: robertburrelldonkin@gmail.com\r\n" +
"\r\n";
-
+
public static final String ONE_PART_MIME_BASE64_LATIN1_HEADERS = "Received: by 10.114.126.16 with HTTP; Thu, 6 Mar 2008 10:02:03 -0800 (PST)\r\n" +
"Message-ID: <f4...@mail.gmail.com>\r\n" +
"Date: Thu, 6 Mar 2008 18:02:03 +0000\r\n" +
@@ -490,7 +490,7 @@ public class ExampleMail {
"Content-Disposition: inline\r\n" +
"Delivered-To: robertburrelldonkin@gmail.com\r\n" +
"\r\n";
-
+
public static final String ONE_PART_MIME_QUOTED_PRINTABLE_ASCII = "Received: by 10.114.126.16 with HTTP; Thu, 6 Mar 2008 10:02:03 -0800 (PST)\r\n" +
"Message-ID: <f4...@mail.gmail.com>\r\n" +
"Date: Thu, 6 Mar 2008 18:02:03 +0000\r\n" +
@@ -503,9 +503,9 @@ public class ExampleMail {
"Content-Disposition: inline\r\n" +
"Delivered-To: robertburrelldonkin@gmail.com\r\n" +
"\r\n" + breakLines(ONE_PART_MIME_QUOTED_PRINTABLE_ASCII_BODY.replaceAll("\r\n", "=0D=0A"));
-
-
- public static final String RFC_SIMPLE =
+
+
+ public static final String RFC_SIMPLE =
"From: Timothy Tayler <ti...@example.org>\r\n" +
"To: Samual Smith <sa...@example.org>\r\n" +
"Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
@@ -513,7 +513,7 @@ public class ExampleMail {
"\r\n" +
RFC822_SIMPLE_BODY;
- public static final String MIME_RFC822_SIMPLE =
+ public static final String MIME_RFC822_SIMPLE =
"From: Samual Smith <sa...@example.org>\r\n" +
"To: Joshua Tetley <jo...@example.org>\r\n" +
"Date: Thu, 14 Feb 2008 12:30:00 +0000 (GMT)\r\n" +
@@ -521,7 +521,7 @@ public class ExampleMail {
"MIME-Version: 1.0\r\n" +
"Content-Type: message/rfc822\r\n" +
"\r\n" + RFC_SIMPLE;
-
+
public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_7BIT = "Sonnet XXXIII By William Shakespeare\r\n" +
"\r\n" +
"Full many a glorious morning have I seen\r\n" +
@@ -538,7 +538,7 @@ public class ExampleMail {
"The region cloud hath mask'd him from me now.\r\n" +
" Yet him for this my love no whit disdaineth;\r\n" +
" Suns of the world may stain when heaven's sun staineth.\r\n";
-
+
public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_QUOTED_PRINTABLE = "Sonnet XXXV By William Shakespeare\r\n" +
"\r\n" +
"No more be griev'd at that which thou hast done:\r\n" +
@@ -554,8 +554,8 @@ public class ExampleMail {
"And 'gainst myself a lawful plea commence:\r\n" +
"Such civil war is in my love and hate,\r\n" +
" That I an accessary needs must be,\r\n" +
- " To that sweet thief which sourly robs from me.\r\n";
-
+ " To that sweet thief which sourly robs from me.\r\n";
+
public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BASE64 = "Sonnet XXXVIII By William Shakespeare\r\n" +
"\r\n" +
"How can my muse want subject to invent,\r\n" +
@@ -572,8 +572,8 @@ public class ExampleMail {
"Eternal numbers to outlive long date.\r\n" +
" If my slight muse do please these curious days,\r\n" +
" The pain be mine, but thine shall be the praise.\r\n";
-
- public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_ONE =
+
+ public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_ONE =
"From: Timothy Tayler <ti...@example.org>\r\n" +
"To: Samual Smith <sa...@example.org>\r\n" +
"Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
@@ -585,21 +585,21 @@ public class ExampleMail {
"--1729\r\n" +
"Content-Type: text/plain; charset=US-ASCII\r\n" +
"Content-Transfer-Encoding: 7bit\r\n\r\n";
-
- public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_TWO =
+
+ public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_TWO =
"\r\n--1729\r\n" +
"Content-Type: text/plain; charset=US-ASCII\r\n" +
"Content-Transfer-Encoding: Quoted-Printable\r\n\r\n";
-
- public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_THREE =
+
+ public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_THREE =
"\r\n--1729\r\n" +
"Content-Type: text/plain; charset=US-ASCII\r\n" +
"Content-Transfer-Encoding: base64\r\n\r\n";
-
- public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_END =
+
+ public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_END =
"\r\n--1729--\r\n";
-
- public static final String MIME_MULTIPART_ALTERNATIVE =
+
+ public static final String MIME_MULTIPART_ALTERNATIVE =
"From: Timothy Tayler <ti...@example.org>\r\n" +
"To: Samual Smith <sa...@example.org>\r\n" +
"Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
@@ -620,8 +620,8 @@ public class ExampleMail {
"<html><head><title>Rhubarb</title></head><body>Rhubarb!</body></html>\r\n" +
"\r\n--1729--\r\n" +
"This is the epilogue\r\n";
-
-
+
+
private static final byte[][] MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BYTE_ARRAYS = {
ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_ONE),
ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_7BIT),
@@ -631,7 +631,7 @@ public class ExampleMail {
EncodeUtils.toBase64(ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BASE64)),
ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_END),
};
-
+
public static final byte[] MIME_RFC822_SIMPLE_BYTES = ascii(MIME_RFC822_SIMPLE);
public static final byte[] MULTIPART_WITH_CONTENT_LOCATION_BYTES = ascii(MULTIPART_WITH_CONTENT_LOCATION);
public static final byte[] ONE_PART_MIME_WITH_CONTENT_DISPOSITION_PARAMETERS_BYTES = ascii(ONE_PART_MIME_WITH_CONTENT_DISPOSITION_PARAMETERS);
@@ -651,24 +651,24 @@ public class ExampleMail {
public static final byte[] ONE_PART_MIME_ASCII_MIME_VERSION_SPANS_TWO_LINES_BYTES = US_ASCII.encode(ONE_PART_MIME_ASCII_MIME_VERSION_SPANS_TWO_LINES).array();
public static final byte[] MAIL_WITH_RFC822_PART_BYTES = ascii(MAIL_WITH_RFC822_PART);
public static final byte[] MIME_MULTIPART_EMBEDDED_MESSAGES_BYTES = ascii(MIME_MULTIPART_EMBEDDED_MESSAGES);
-
+
public static final byte[] ascii(String text) {
-
+
return US_ASCII.encode(text).array();
}
-
+
public static final byte[] latin1(String text) {
-
+
return LATIN1.encode(text).array();
}
-
+
public static final byte[] join(byte[] one, byte[] two) {
byte[] results = new byte[one.length + two.length];
System.arraycopy(one, 0, results, 0, one.length);
System.arraycopy(two, 0, results, one.length, two.length);
return results;
}
-
+
public static final byte[] join(byte[][] byteArrays) {
int length = 0;
for (byte[] bytes : byteArrays) {
@@ -682,7 +682,7 @@ public class ExampleMail {
}
return results;
}
-
+
public static String breakLines(String original) {
StringBuilder buffer = new StringBuilder(original);
int count = 76;
@@ -690,10 +690,10 @@ public class ExampleMail {
if (buffer.charAt(count) == '=') {
count = count - 1;
} else if (buffer.charAt(count-1) == '=') {
- count = count - 4;
+ count = count - 4;
} else if (buffer.charAt(count-2) == '=') {
count = count - 3;
- }
+ }
buffer.insert(count, '\n');
buffer.insert(count, '\r');
buffer.insert(count, '=');
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/TestUtil.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/TestUtil.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/TestUtil.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/TestUtil.java Mon Jul 11 19:48:50 2011
@@ -56,18 +56,18 @@ public class TestUtil {
"uu-junk",
"uu-zeegee"
};
-
- public static String readResource(String resource, String charset)
+
+ public static String readResource(String resource, String charset)
throws IOException {
-
+
return IOUtils.toString(readResourceAsStream(resource), charset);
}
- public static InputStream readResourceAsStream(String resource)
+ public static InputStream readResourceAsStream(String resource)
throws IOException {
return new BufferedInputStream(
TestUtil.class.getResource(resource).openStream());
}
-
+
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64InputStreamTest.java Mon Jul 11 19:48:50 2011
@@ -36,7 +36,7 @@ public class Base64InputStreamTest exten
ByteArrayInputStream bis = null;
Base64InputStream decoder = null;
byte[] bytes = null;
-
+
/*
* Simple initial test.
*/
@@ -44,7 +44,7 @@ public class Base64InputStreamTest exten
fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlIQ=="));
decoder = new Base64InputStream(bis);
assertEquals("This is the plain text message!", toString(read(decoder)));
-
+
/*
* Test encoded text padded once, twice and not at all.
*/
@@ -63,7 +63,7 @@ public class Base64InputStreamTest exten
+ "YmUgcGFkZGVk"));
decoder = new Base64InputStream(bis);
assertEquals("This is a text which will not be padded", toString(read(decoder)));
-
+
/*
* Test that non base64 characters are ignored.
*/
@@ -72,7 +72,7 @@ public class Base64InputStreamTest exten
+ " \tdGV4dCBtZ?!XNzY*WdlIQ=="));
decoder = new Base64InputStream(bis);
assertEquals("This is the plain text message!", toString(read(decoder)));
-
+
/*
* Test that the bytes 0-255 shifted 0, 1 and 2 positions are
* decoded properly.
@@ -84,7 +84,7 @@ public class Base64InputStreamTest exten
+ "mZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6"
+ "/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5O"
+ "Xm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==";
-
+
String s2 = "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSY"
+ "nKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE"
+ "1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc"
@@ -92,7 +92,7 @@ public class Base64InputStreamTest exten
+ "mpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/"
+ "AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3N3e3+Dh4uPk5e"
+ "bn6Onq6+zt7u/w8fLz9PX29/j5+vv8/f7/AA==";
-
+
String s3 = "AgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQlJic"
+ "oKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU"
+ "5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzd"
@@ -100,27 +100,27 @@ public class Base64InputStreamTest exten
+ "m5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8D"
+ "BwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5u"
+ "fo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8AAQ==";
-
+
bis = new ByteArrayInputStream(fromString(s1));
decoder = new Base64InputStream(bis);
bytes = read(decoder);
-
+
for (int i = 0; i < bytes.length; i++) {
assertEquals("Position " + i, bytes[i], (byte) i);
}
-
+
bis = new ByteArrayInputStream(fromString(s2));
decoder = new Base64InputStream(bis);
bytes = read(decoder);
-
+
for (int i = 0; i < bytes.length; i++) {
assertEquals("Position " + i, bytes[i], (byte) (i + 1));
}
-
+
bis = new ByteArrayInputStream(fromString(s3));
decoder = new Base64InputStream(bis);
bytes = read(decoder);
-
+
for (int i = 0; i < bytes.length; i++) {
assertEquals("Position " + i, bytes[i], (byte) (i + 2));
}
@@ -129,14 +129,14 @@ public class Base64InputStreamTest exten
public void testDecodePrematureClose() throws IOException {
ByteArrayInputStream bis = null;
Base64InputStream decoder = null;
-
+
bis = new ByteArrayInputStream(
fromString("VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBtZXNzYWdlIQ=="));
decoder = new Base64InputStream(bis);
assertEquals('T', decoder.read());
assertEquals('h', decoder.read());
decoder.close();
-
+
try {
decoder.read();
fail();
@@ -256,7 +256,7 @@ public class Base64InputStreamTest exten
assertEquals("This is the plain text message", toString(out
.toByteArray()));
}
-
+
private byte[] read(InputStream is) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int b;
@@ -265,7 +265,7 @@ public class Base64InputStreamTest exten
}
return bos.toByteArray();
}
-
+
private byte[] fromString(String s) {
try {
return s.getBytes("US-ASCII");
@@ -274,7 +274,7 @@ public class Base64InputStreamTest exten
return null;
}
}
-
+
private String toString(byte[] b) {
try {
return new String(b, "US-ASCII");
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64OutputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64OutputStreamTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64OutputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/Base64OutputStreamTest.java Mon Jul 11 19:48:50 2011
@@ -31,7 +31,7 @@ public class Base64OutputStreamTest exte
public void testEncode() throws IOException {
ByteArrayOutputStream bos = null;
Base64OutputStream encoder = null;
-
+
/*
* Simple initial test.
*/
@@ -45,7 +45,7 @@ public class Base64OutputStreamTest exte
public void testEncodeUnderlyingStreamStaysOpen() throws IOException {
ByteArrayOutputStream bos = null;
Base64OutputStream encoder = null;
-
+
bos = new ByteArrayOutputStream();
encoder = new Base64OutputStream(bos);
encoder.write(fromString("This is the plain text message!"));
@@ -56,7 +56,7 @@ public class Base64OutputStreamTest exte
fail();
} catch (IOException expected) {
}
-
+
bos.write('y');
bos.write('a');
bos.write('d');
@@ -196,7 +196,7 @@ public class Base64OutputStreamTest exte
return toString(b.toByteArray());
}
-
+
private byte[] fromString(String s) {
try {
return s.getBytes("US-ASCII");
@@ -205,7 +205,7 @@ public class Base64OutputStreamTest exte
return null;
}
}
-
+
private String toString(byte[] b) {
try {
return new String(b, "US-ASCII");
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/CodecUtilTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/CodecUtilTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/CodecUtilTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/CodecUtilTest.java Mon Jul 11 19:48:50 2011
@@ -47,14 +47,14 @@ public class CodecUtilTest extends TestC
CodecUtil.copy(in, out);
assertEquals(content, out.toByteArray());
}
-
+
public void testEncodeQuotedPrintableLargeInput() throws Exception {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1024 * 5; i++) {
sb.append((char) ('0' + (i % 10)));
}
String expected = sb.toString().replaceAll("(\\d{75})", "$1=\r\n");
-
+
InputStream in = new ByteArrayInputStream(sb.toString().getBytes("US-ASCII"));
ByteArrayOutputStream out = new ByteArrayOutputStream();
CodecUtil.encodeQuotedPrintableBinary(in, out);
@@ -70,7 +70,7 @@ public class CodecUtilTest extends TestC
String actual = new String(out.toByteArray(), "US-ASCII");
assertEquals("7bit=20content=20with=20euro=20=A4=20symbol", actual);
}
-
+
public void testBase64OutputStream() throws Exception {
StringBuilder sb = new StringBuilder(2048);
for (int i = 0; i < 128; i++) {
@@ -87,14 +87,14 @@ public class CodecUtilTest extends TestC
CodecUtil.copy(new ByteArrayInputStream(input.getBytes()), outb64);
outb64.flush();
outb64.close();
-
+
InputStream is = new Base64InputStream(new ByteArrayInputStream(out2.toByteArray()));
ByteArrayOutputStream outRoundtrip = new ByteArrayOutputStream();
CodecUtil.copy(is, outRoundtrip);
String output = new String(outRoundtrip.toByteArray());
return output;
}
-
+
/**
* This test is a proof for MIME4J-67
*/
@@ -111,14 +111,14 @@ public class CodecUtilTest extends TestC
private String roundtripUsingEncoder(String input) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
CodecUtil.encodeBase64(new ByteArrayInputStream(input.getBytes()), out);
-
+
InputStream is = new Base64InputStream(new ByteArrayInputStream(out.toByteArray()));
ByteArrayOutputStream outRoundtrip = new ByteArrayOutputStream();
CodecUtil.copy(is, outRoundtrip);
String output = new String(outRoundtrip.toByteArray());
return output;
- }
-
+ }
+
/* performance test, not a unit test */
/*
public void testPerformance() throws Exception {
@@ -140,18 +140,18 @@ public class CodecUtilTest extends TestC
long time3 = System.currentTimeMillis();
roundtripUsingEncoder(input);
long time4 = System.currentTimeMillis();
-
+
totalEncoder1 += time2-time1;
totalStream1 += time3-time2;
totalEncoder2 += time4-time3;
}
-
+
System.out.println("Encoder 1st: "+totalEncoder1);
System.out.println("Encoder 2nd: "+totalEncoder2);
System.out.println("Stream 1st: "+totalStream1);
}
*/
-
+
private void assertEquals(byte[] expected, byte[] actual) {
StringBuilder buffer = new StringBuilder(expected.length);
assertEquals(expected.length, actual.length);
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java Mon Jul 11 19:48:50 2011
@@ -42,25 +42,25 @@ public class DecoderUtilTest extends Tes
}
public void testDecodeSomeEncodedWords() {
- assertEquals(" \u00e1\u00e2\u00e3\t\u00e4",
+ assertEquals(" \u00e1\u00e2\u00e3\t\u00e4",
DecoderUtil.decodeEncodedWords("=?iso-8859-1?Q?_=20=e1=e2=E3=09=E4?="));
- assertEquals("Word 1 ' \u00e2\u00e3\t\u00e4'. Word 2 ' \u00e2\u00e3\t\u00e4'",
+ assertEquals("Word 1 ' \u00e2\u00e3\t\u00e4'. Word 2 ' \u00e2\u00e3\t\u00e4'",
DecoderUtil.decodeEncodedWords("Word 1 '=?iso-8859-1?Q?_=20=e2=E3=09=E4?="
+ "'. Word 2 '=?iso-8859-1?q?_=20=e2=E3=09=E4?='"));
- assertEquals("=?iso-8859-YADA?Q?_=20=t1=e2=E3=09=E4?=",
+ assertEquals("=?iso-8859-YADA?Q?_=20=t1=e2=E3=09=E4?=",
DecoderUtil.decodeEncodedWords("=?iso-8859-YADA?Q?_=20=t1=e2=E3=09=E4?="));
- assertEquals("A short text",
+ assertEquals("A short text",
DecoderUtil.decodeEncodedWords("=?US-ASCII?B?QSBzaG9ydCB0ZXh0?="));
- assertEquals("A short text again!",
+ assertEquals("A short text again!",
DecoderUtil.decodeEncodedWords("=?US-ASCII?b?QSBzaG9ydCB0ZXh0IGFnYWluIQ==?="));
}
public void testDecodeJapaneseEncodedWords() {
String enc = "=?ISO-2022-JP?B?GyRCTCQbKEobJEI+NRsoShskQkJ6GyhKGyRCOS0bKEo=?= "
+ "=?ISO-2022-JP?B?GyRCOXAbKEobJEIiKBsoShskQiU1GyhKGyRCJSQbKEo=?= "
- + "=?ISO-2022-JP?B?GyRCJUkbKEobJEIlUxsoShskQiU4GyhKGyRCJU0bKEo=?= "
+ + "=?ISO-2022-JP?B?GyRCJUkbKEobJEIlUxsoShskQiU4GyhKGyRCJU0bKEo=?= "
+ "=?ISO-2022-JP?B?GyRCJTkbKEobJEIkThsoShskQjdoGyhKGyRCRGobKEo=?= "
- + "=?ISO-2022-JP?B?GyRCSEcbKEobJEIkRxsoShskQiQ5GyhKGyRCISobKEo=?=";
+ + "=?ISO-2022-JP?B?GyRCSEcbKEobJEIkRxsoShskQiQ5GyhKGyRCISobKEo=?=";
String dec = DecoderUtil.decodeEncodedWords(enc);
assertEquals("\u672A\u627F\u8AFE\u5E83\u544A\u203B\u30B5\u30A4\u30C9\u30D3"
@@ -120,5 +120,5 @@ public class DecoderUtilTest extends Tes
public void testFunnyInputDoesNotRaiseOutOfMemoryError() {
// Bug detected on June 7, 2005. Decoding the following string caused OutOfMemoryError.
assertEquals("=3?!!\\=?\"!g6P\"!Xp:\"!", DecoderUtil.decodeEncodedWords("=3?!!\\=?\"!g6P\"!Xp:\"!"));
- }
+ }
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableEncodeTest.java Mon Jul 11 19:48:50 2011
@@ -31,7 +31,7 @@ import org.apache.commons.io.IOUtils;
import org.apache.james.mime4j.util.CharsetUtil;
public class QuotedPrintableEncodeTest extends TestCase {
-
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -41,7 +41,7 @@ public class QuotedPrintableEncodeTest e
protected void tearDown() throws Exception {
super.tearDown();
}
-
+
public void testEscapedSoftBreak() throws Exception {
byte[] content = new byte[500];
Arrays.fill(content, (byte)0x20);
@@ -61,7 +61,7 @@ public class QuotedPrintableEncodeTest e
}
check(content, expected);
}
-
+
public void testPlainAsciiSoftBreak() throws Exception {
byte[] content = new byte[500];
Arrays.fill(content, (byte)0x29);
@@ -87,25 +87,25 @@ public class QuotedPrintableEncodeTest e
expected[467] = '\n';
check(content, expected);
}
-
+
public void testPlainASCII() throws Exception {
checkRoundtrip("Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage." +
"Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage." +
"Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage." +
"Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage.");
}
-
+
public void testEncodeSpace() throws Exception {
checkRoundtrip(" ");
}
-
+
public void testLetterEncoding() throws Exception {
for (byte b=0;b<Byte.MAX_VALUE;b++) {
byte[] content = {b};
checkRoundtrip(content);
}
}
-
+
private void checkRoundtrip(String content) throws Exception {
checkRoundtrip(content, CharsetUtil.US_ASCII);
}
@@ -113,7 +113,7 @@ public class QuotedPrintableEncodeTest e
private void checkRoundtrip(String content, Charset charset) throws Exception {
checkRoundtrip(charset.encode(content).array());
}
-
+
private void checkRoundtrip(byte[] content) throws Exception {
InputStream in = new ByteArrayInputStream(content);
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -124,14 +124,14 @@ public class QuotedPrintableEncodeTest e
IOUtils.copy(in, out);
assertEquals(content, out.toByteArray());
}
-
+
private void check(byte[] content, byte[] expected) throws Exception {
ByteArrayInputStream in = new ByteArrayInputStream(content);
ByteArrayOutputStream out = new ByteArrayOutputStream();
CodecUtil.encodeQuotedPrintableBinary(in, out);
assertEquals(expected, out.toByteArray());
}
-
+
private void assertEquals(byte[] expected, byte[] actual) {
assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i++) {
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableInputStreamTest.java Mon Jul 11 19:48:50 2011
@@ -67,25 +67,25 @@ public class QuotedPrintableInputStreamT
// TODO is this what we really expect from decoding a stream including CR with no LF?
assertEquals("Invalid=\rCR\rHard line\r\n", new String(read(decoder), "ISO8859-1"));
}
-
+
public void testSoftBreakLoneLFDecode() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("Soft line =\nHard line \r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
assertEquals("Soft line Hard line\r\n", new String(read(decoder), "ISO8859-1"));
}
-
+
public void testSoftBreakTrailingBalnksDecode() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("Soft line = \t \r\nHard line \r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
assertEquals("Soft line Hard line\r\n", new String(read(decoder), "ISO8859-1"));
}
-
+
public void testBrokenSoftBreakDecode() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("Soft line =\rHard line \r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
assertEquals("Soft line =\rHard line\r\n", new String(read(decoder), "ISO8859-1"));
}
-
+
public void testEscapedEQDecode() throws IOException, UnsupportedEncodingException {
ByteArrayInputStream bis = new ByteArrayInputStream("width==340 height=3d200\r\n".getBytes("US-ASCII"));
QuotedPrintableInputStream decoder = new QuotedPrintableInputStream(bis);
@@ -155,14 +155,14 @@ public class QuotedPrintableInputStreamT
assertEquals('\u00e1', decoder.read());
assertEquals('\u00e2', decoder.read());
decoder.close();
-
+
try {
decoder.read();
fail();
} catch (IOException expected) {
}
}
-
+
private byte[] read(InputStream is) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int b;
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableOutputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableOutputStreamTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableOutputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableOutputStreamTest.java Mon Jul 11 19:48:50 2011
@@ -30,7 +30,7 @@ public class QuotedPrintableOutputStream
public void testEncode() throws IOException {
ByteArrayOutputStream bos = null;
QuotedPrintableOutputStream encoder = null;
-
+
/*
* Simple initial test.
*/
@@ -45,7 +45,7 @@ public class QuotedPrintableOutputStream
public void testEncodeUnderlyingStreamStaysOpen() throws IOException {
ByteArrayOutputStream bos = null;
QuotedPrintableOutputStream encoder = null;
-
+
bos = new ByteArrayOutputStream();
encoder = new QuotedPrintableOutputStream(bos, false);
encoder.write(fromString("This is the plain text message containing a few euros: 100 \u20ac!"));
@@ -56,7 +56,7 @@ public class QuotedPrintableOutputStream
fail();
} catch (IOException expected) {
}
-
+
bos.write('y');
bos.write('a');
bos.write('d');
@@ -68,7 +68,7 @@ public class QuotedPrintableOutputStream
public void testEncodeSpecials() throws IOException {
ByteArrayOutputStream bos = null;
QuotedPrintableOutputStream encoder = null;
-
+
bos = new ByteArrayOutputStream();
encoder = new QuotedPrintableOutputStream(bos, false);
encoder.write(fromString("Testing \u20ac special . chars = also at the end ="));
@@ -80,7 +80,7 @@ public class QuotedPrintableOutputStream
public void testEncodeWrapping() throws IOException {
ByteArrayOutputStream bos = null;
QuotedPrintableOutputStream encoder = null;
-
+
bos = new ByteArrayOutputStream();
encoder = new QuotedPrintableOutputStream(bos, false);
encoder.write(fromString("This is a very very very very very very very very very very very very very very very long line"));
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/codec/QuotedPrintableTextEncodeTest.java Mon Jul 11 19:48:50 2011
@@ -41,7 +41,7 @@ public class QuotedPrintableTextEncodeTe
protected void tearDown() throws Exception {
super.tearDown();
}
-
+
public void testEscapedSoftBreak() throws Exception {
byte[] content = new byte[500];
Arrays.fill(content, (byte)0x18);
@@ -61,7 +61,7 @@ public class QuotedPrintableTextEncodeTe
}
check(content, expected);
}
-
+
public void testPlainAsciiSoftBreak() throws Exception {
byte[] content = new byte[500];
Arrays.fill(content, (byte)0x29);
@@ -87,28 +87,28 @@ public class QuotedPrintableTextEncodeTe
expected[467] = '\n';
check(content, expected);
}
-
+
public void testPlainASCII() throws Exception {
checkRoundtrip("Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage." +
"Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage." +
"Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage." +
"Thisisaverysimplemessage.Thisisaverysimplemessage.Thisisaverysimplemessage.");
}
-
+
public void testEncodeSpace() throws Exception {
checkRoundtrip(" A");
}
-
+
public void testLetterEncoding() throws Exception {
for (byte b=0;b<Byte.MAX_VALUE;b++) {
byte[] content = {b};
// White space is only escaped when followed by CRLF
- if (b != 10 && b != 13 && b != 32 && b != 9) {
+ if (b != 10 && b != 13 && b != 32 && b != 9) {
checkRoundtrip(content);
}
}
}
-
+
public void testCRLFShouldResetLineCount() throws Exception {
StringBuilder buffer = new StringBuilder(4096);
for (int i=0;i<1000;i++) {
@@ -117,31 +117,31 @@ public class QuotedPrintableTextEncodeTe
String longLine = buffer.toString();
check(longLine, longLine);
}
-
+
public void testDontEscapeLF() throws Exception {
check("Ready\nFor\n", "Ready\nFor\n");
}
-
+
public void testDontEscapeCR() throws Exception {
check("Ready\rFor\r", "Ready\rFor\r");
}
-
+
public void testEscapeSpaceAtLineEnd() throws Exception {
check(" \r\n", " =20\r\n");
}
-
+
public void testDontEscapeSpaceBeforeLineEnd() throws Exception {
check(" ", " ");
}
-
+
public void testDontEscapeTabsBeforeLineEnd() throws Exception {
check("\t\t\t\t", "\t\t\t\t");
}
-
+
public void testDontWhiteSpaceBeforeLineEnd() throws Exception {
check(" \t\t \t", " \t\t \t");
}
-
+
private void checkRoundtrip(String content) throws Exception {
checkRoundtrip(content, CharsetUtil.US_ASCII);
}
@@ -149,7 +149,7 @@ public class QuotedPrintableTextEncodeTe
private void checkRoundtrip(String content, Charset charset) throws Exception {
checkRoundtrip(charset.encode(content).array());
}
-
+
private void checkRoundtrip(byte[] content) throws Exception {
InputStream in = new ByteArrayInputStream(content);
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -160,20 +160,20 @@ public class QuotedPrintableTextEncodeTe
IOUtils.copy(in, out);
assertEquals(content, out.toByteArray());
}
-
+
private void check(String content, String expected) throws Exception {
Charset ascii = CharsetUtil.US_ASCII;
check(ascii.encode(content).array(), ascii.encode(expected).array());
}
-
+
private void check(byte[] content, byte[] expected) throws Exception {
ByteArrayInputStream in = new ByteArrayInputStream(content);
ByteArrayOutputStream out = new ByteArrayOutputStream();
CodecUtil.encodeQuotedPrintable(in, out);
assertEquals(expected, out.toByteArray());
}
-
+
private void assertEquals(byte[] expected, byte[] actual) {
assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i++) {
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamBufferTest.java Mon Jul 11 19:48:50 2011
@@ -34,10 +34,10 @@ public class BufferedLineReaderInputStre
byte[] b2 = pattern.getBytes("US-ASCII");
BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
inbuffer.fillBuffer();
-
+
assertEquals('b', inbuffer.read());
assertEquals('l', inbuffer.read());
-
+
try {
inbuffer.byteAt(1);
fail("IndexOutOfBoundsException should have been thrown");
@@ -91,7 +91,7 @@ public class BufferedLineReaderInputStre
}
assertEquals(10, inbuffer.indexOf((byte)'y', 2, 17));
}
-
+
public void testBasicOperations() throws Exception {
String text = "bla bla yada yada haha haha";
byte[] b1 = text.getBytes("US-ASCII");
@@ -107,14 +107,14 @@ public class BufferedLineReaderInputStre
assertEquals(2, inbuffer.pos());
assertEquals(27, inbuffer.limit());
assertEquals(25, inbuffer.length());
-
+
byte[] tmp1 = new byte[3];
assertEquals(3, inbuffer.read(tmp1));
assertEquals(5, inbuffer.pos());
assertEquals(27, inbuffer.limit());
assertEquals(22, inbuffer.length());
-
+
byte[] tmp2 = new byte[22];
assertEquals(22, inbuffer.read(tmp2));
@@ -138,7 +138,7 @@ public class BufferedLineReaderInputStre
int i = inbuffer.indexOf(b2);
assertEquals(7, i);
}
-
+
public void testPatternMatching2() throws Exception {
String text = "disddisdissdsidsidsiid";
String pattern = "siid";
@@ -149,7 +149,7 @@ public class BufferedLineReaderInputStre
int i = inbuffer.indexOf(b2);
assertEquals(18, i);
}
-
+
public void testPatternMatching3() throws Exception {
String text = "bla bla yada yada haha haha";
String pattern = "blah";
@@ -160,7 +160,7 @@ public class BufferedLineReaderInputStre
int i = inbuffer.indexOf(b2);
assertEquals(-1, i);
}
-
+
public void testPatternMatching4() throws Exception {
String text = "bla bla yada yada haha haha";
String pattern = "bla";
@@ -199,7 +199,7 @@ public class BufferedLineReaderInputStre
i = inbuffer.indexOf((byte)'g', inbuffer.pos(), inbuffer.length() - 3);
assertEquals(-1, i);
}
-
+
public void test0xFFInBinaryStream() throws Exception {
byte[] b1 = new byte[] {1, 2, 3, (byte) 0xff, 10, 1, 2, 3};
byte[] b2 = new byte[] {10};
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/BufferedLineReaderInputStreamTest.java Mon Jul 11 19:48:50 2011
@@ -35,7 +35,7 @@ public class BufferedLineReaderInputStre
String text = "ah blahblah";
byte[] b1 = text.getBytes("US-ASCII");
BufferedLineReaderInputStream instream = new BufferedLineReaderInputStream(new ByteArrayInputStream(b1), 4096);
-
+
assertEquals((byte)'a', instream.read());
assertEquals((byte)'h', instream.read());
assertEquals((byte)' ', instream.read());
@@ -51,7 +51,7 @@ public class BufferedLineReaderInputStre
}
public void testBasicReadLine() throws Exception {
-
+
String[] teststrs = new String[5];
teststrs[0] = "Hello\r\n";
teststrs[1] = "This string should be much longer than the size of the input buffer " +
@@ -66,15 +66,15 @@ public class BufferedLineReaderInputStre
teststrs[4] = "And goodbye\r\n";
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
-
+
for (String teststr : teststrs) {
outstream.write(teststr.getBytes("US-ASCII"));
}
byte[] raw = outstream.toByteArray();
-
- BufferedLineReaderInputStream instream = new BufferedLineReaderInputStream(new ByteArrayInputStream(raw), 16);
-
- ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
+
+ BufferedLineReaderInputStream instream = new BufferedLineReaderInputStream(new ByteArrayInputStream(raw), 16);
+
+ ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
for (String teststr : teststrs) {
linebuf.clear();
instream.readLine(linebuf);
@@ -84,25 +84,25 @@ public class BufferedLineReaderInputStre
assertEquals(-1, instream.readLine(linebuf));
assertEquals(-1, instream.readLine(linebuf));
}
-
+
public void testReadEmptyLine() throws Exception {
-
+
String teststr = "\n\n\r\n\r\r\n\n\n\n\n\n";
byte[] raw = teststr.getBytes("US-ASCII");
-
- LineReaderInputStream instream = new BufferedLineReaderInputStream(new ByteArrayInputStream(raw), 4);
-
- ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
+
+ LineReaderInputStream instream = new BufferedLineReaderInputStream(new ByteArrayInputStream(raw), 4);
+
+ ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
linebuf.clear();
instream.readLine(linebuf);
String s = new String(linebuf.toByteArray(), "US-ASCII");
assertEquals("\n", s);
-
+
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
assertEquals("\n", s);
-
+
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
@@ -143,18 +143,18 @@ public class BufferedLineReaderInputStre
}
public void testReadEmptyLineMaxLimit() throws Exception {
-
+
String teststr = "1234567890\r\n";
byte[] raw = teststr.getBytes("US-ASCII");
-
+
LineReaderInputStream instream1 = new BufferedLineReaderInputStream(
- new ByteArrayInputStream(raw), 1024, 13);
- ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
+ new ByteArrayInputStream(raw), 1024, 13);
+ ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
linebuf.clear();
instream1.readLine(linebuf);
LineReaderInputStream instream2 = new BufferedLineReaderInputStream(
- new ByteArrayInputStream(raw), 1024, 12);
+ new ByteArrayInputStream(raw), 1024, 12);
linebuf.clear();
try {
instream2.readLine(linebuf);
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/EOLConvertingInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/EOLConvertingInputStreamTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/EOLConvertingInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/EOLConvertingInputStreamTest.java Mon Jul 11 19:48:50 2011
@@ -34,31 +34,31 @@ public class EOLConvertingInputStreamTes
testConvertBoth("Line 1\r\nLine 2\r\n", "Line 1\r\nLine 2\r\n");
testConvertCR("Line 1\r\nLine 2\r\n", "Line 1\r\nLine 2\r\n");
testConvertLF("Line 1\r\nLine 2\r\n", "Line 1\r\nLine 2\r\n");
-
+
testConvertBoth("Line 1\n\rLine 2\n\r", "Line 1\r\n\r\nLine 2\r\n\r\n");
testConvertCR("Line 1\n\rLine 2\n\r", "Line 1\n\r\nLine 2\n\r\n");
testConvertLF("Line 1\n\rLine 2\n\r", "Line 1\r\n\rLine 2\r\n\r");
-
+
testConvertBoth("Line 1\nLine 2\n", "Line 1\r\nLine 2\r\n");
testConvertCR("Line 1\nLine 2\n", "Line 1\nLine 2\n");
testConvertLF("Line 1\nLine 2\n", "Line 1\r\nLine 2\r\n");
-
+
testConvertBoth("Line 1\rLine 2\r", "Line 1\r\nLine 2\r\n");
testConvertCR("Line 1\rLine 2\r", "Line 1\r\nLine 2\r\n");
testConvertLF("Line 1\rLine 2\r", "Line 1\rLine 2\r");
-
+
testConvertBoth("\r\n", "\r\n");
testConvertCR("\r\n", "\r\n");
testConvertLF("\r\n", "\r\n");
-
+
testConvertBoth("\n", "\r\n");
testConvertCR("\n", "\n");
testConvertLF("\n", "\r\n");
-
+
testConvertBoth("\r", "\r\n");
testConvertCR("\r", "\r\n");
testConvertLF("\r", "\r");
-
+
testConvertBoth("", "");
testConvertCR("", "");
testConvertLF("", "");
@@ -66,37 +66,37 @@ public class EOLConvertingInputStreamTes
private void testConvertBoth(String s1, String s2) throws IOException {
byte[] bytes = new byte[1024];
-
+
ByteArrayInputStream bais = new ByteArrayInputStream(fromString(s1));
- EOLConvertingInputStream in =
- new EOLConvertingInputStream(bais,
+ EOLConvertingInputStream in =
+ new EOLConvertingInputStream(bais,
EOLConvertingInputStream.CONVERT_BOTH);
int n = in.read(bytes);
assertEquals(s2, toString(bytes, n));
}
-
+
private void testConvertCR(String s1, String s2) throws IOException {
byte[] bytes = new byte[1024];
-
+
ByteArrayInputStream bais = new ByteArrayInputStream(fromString(s1));
- EOLConvertingInputStream in =
- new EOLConvertingInputStream(bais,
+ EOLConvertingInputStream in =
+ new EOLConvertingInputStream(bais,
EOLConvertingInputStream.CONVERT_CR);
int n = in.read(bytes);
assertEquals(s2, toString(bytes, n));
}
-
+
private void testConvertLF(String s1, String s2) throws IOException {
byte[] bytes = new byte[1024];
-
+
ByteArrayInputStream bais = new ByteArrayInputStream(fromString(s1));
- EOLConvertingInputStream in =
- new EOLConvertingInputStream(bais,
+ EOLConvertingInputStream in =
+ new EOLConvertingInputStream(bais,
EOLConvertingInputStream.CONVERT_LF);
int n = in.read(bytes);
assertEquals(s2, toString(bytes, n));
}
-
+
private String toString(byte[] b, int len) {
try {
if (len == -1) {
@@ -107,8 +107,8 @@ public class EOLConvertingInputStreamTes
fail(e.getMessage());
return null;
}
- }
-
+ }
+
private byte[] fromString(String s) {
try {
return s.getBytes("US-ASCII");
@@ -116,5 +116,5 @@ public class EOLConvertingInputStreamTes
fail(e.getMessage());
return null;
}
- }
+ }
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LimitedInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LimitedInputStreamTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LimitedInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LimitedInputStreamTest.java Mon Jul 11 19:48:50 2011
@@ -52,5 +52,5 @@ public class LimitedInputStreamTest exte
} catch (IOException ex) {
}
}
-
+
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptorTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptorTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptorTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptorTest.java Mon Jul 11 19:48:50 2011
@@ -33,10 +33,10 @@ public class LineReaderInputStreamAdapto
public void testBasicOperations() throws Exception {
String text = "ah blahblah";
byte[] b1 = text.getBytes("US-ASCII");
-
+
LineReaderInputStreamAdaptor instream = new LineReaderInputStreamAdaptor(
- new ByteArrayInputStream(b1));
-
+ new ByteArrayInputStream(b1));
+
assertEquals((byte)'a', instream.read());
assertEquals((byte)'h', instream.read());
assertEquals((byte)' ', instream.read());
@@ -52,7 +52,7 @@ public class LineReaderInputStreamAdapto
}
public void testBasicReadLine() throws Exception {
-
+
String[] teststrs = new String[5];
teststrs[0] = "Hello\r\n";
teststrs[1] = "This string should be much longer than the size of the input buffer " +
@@ -67,16 +67,16 @@ public class LineReaderInputStreamAdapto
teststrs[4] = "And goodbye\r\n";
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
-
+
for (String teststr : teststrs) {
outstream.write(teststr.getBytes("US-ASCII"));
}
byte[] raw = outstream.toByteArray();
-
+
LineReaderInputStreamAdaptor instream = new LineReaderInputStreamAdaptor(
- new ByteArrayInputStream(raw));
-
- ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
+ new ByteArrayInputStream(raw));
+
+ ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
for (String teststr : teststrs) {
linebuf.clear();
instream.readLine(linebuf);
@@ -86,26 +86,26 @@ public class LineReaderInputStreamAdapto
assertEquals(-1, instream.readLine(linebuf));
assertEquals(-1, instream.readLine(linebuf));
}
-
+
public void testReadEmptyLine() throws Exception {
-
+
String teststr = "\n\n\r\n\r\r\n\n\n\n\n\n";
byte[] raw = teststr.getBytes("US-ASCII");
-
+
LineReaderInputStreamAdaptor instream = new LineReaderInputStreamAdaptor(
- new ByteArrayInputStream(raw));
-
- ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
+ new ByteArrayInputStream(raw));
+
+ ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
linebuf.clear();
instream.readLine(linebuf);
String s = new String(linebuf.toByteArray(), "US-ASCII");
assertEquals("\n", s);
-
+
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
assertEquals("\n", s);
-
+
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
@@ -146,18 +146,18 @@ public class LineReaderInputStreamAdapto
}
public void testReadEmptyLineMaxLimit() throws Exception {
-
+
String teststr = "1234567890\r\n";
byte[] raw = teststr.getBytes("US-ASCII");
-
+
LineReaderInputStreamAdaptor instream1 = new LineReaderInputStreamAdaptor(
- new ByteArrayInputStream(raw), 13);
- ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
+ new ByteArrayInputStream(raw), 13);
+ ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
linebuf.clear();
instream1.readLine(linebuf);
LineReaderInputStreamAdaptor instream2 = new LineReaderInputStreamAdaptor(
- new ByteArrayInputStream(raw), 12);
+ new ByteArrayInputStream(raw), 12);
linebuf.clear();
try {
instream2.readLine(linebuf);
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/MimeBoundaryInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/MimeBoundaryInputStreamTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/MimeBoundaryInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/MimeBoundaryInputStreamTest.java Mon Jul 11 19:48:50 2011
@@ -37,103 +37,103 @@ public class MimeBoundaryInputStreamTest
public void testBasicReading() throws IOException {
String text = "Line 1\r\nLine 2\r\n--boundary\r\n" +
"Line 3\r\nLine 4\r\n--boundary--";
-
+
ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes("US-ASCII"));
-
- BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
-
+
+ BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
+
MimeBoundaryInputStream mime1 = new MimeBoundaryInputStream(buffer, "boundary");
assertEquals("Line 1\r\nLine 2", read(mime1, 5));
-
+
assertFalse(mime1.isLastPart());
-
+
MimeBoundaryInputStream mime2 = new MimeBoundaryInputStream(buffer, "boundary");
assertEquals("Line 3\r\nLine 4", read(mime2, 5));
assertTrue(mime2.isLastPart());
}
-
+
public void testLenientLineDelimiterReading() throws IOException {
String text = "Line 1\r\nLine 2\n--boundary\n" +
"Line 3\r\nLine 4\n--boundary--\n";
-
+
ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes("US-ASCII"));
-
- BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
-
+
+ BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
+
MimeBoundaryInputStream mime1 = new MimeBoundaryInputStream(buffer, "boundary");
assertEquals("Line 1\r\nLine 2", read(mime1, 5));
-
+
assertFalse(mime1.isLastPart());
-
+
MimeBoundaryInputStream mime2 = new MimeBoundaryInputStream(buffer, "boundary");
assertEquals("Line 3\r\nLine 4", read(mime2, 5));
assertTrue(mime2.isLastPart());
}
-
+
public void testBasicReadingSmallBuffer1() throws IOException {
String text = "yadayadayadayadayadayadayadayadayadayadayadayadayadayadayadayada\r\n--boundary\r\n" +
"blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah\r\n--boundary--";
-
+
ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes("US-ASCII"));
-
- BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 20);
-
+
+ BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 20);
+
MimeBoundaryInputStream mime1 = new MimeBoundaryInputStream(buffer, "boundary");
- assertEquals("yadayadayadayadayadayadayadayadayadayadayadayadayadayadayadayada",
+ assertEquals("yadayadayadayadayadayadayadayadayadayadayadayadayadayadayadayada",
read(mime1, 10));
-
+
assertFalse(mime1.isLastPart());
-
+
MimeBoundaryInputStream mime2 = new MimeBoundaryInputStream(buffer, "boundary");
- assertEquals("blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah",
+ assertEquals("blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah",
read(mime2, 10));
assertTrue(mime2.isLastPart());
}
-
+
public void testBasicReadingSmallBuffer2() throws IOException {
String text = "yadayadayadayadayadayadayadayadayadayadayadayadayadayadayadayada\r\n--boundary\r\n" +
"blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah\r\n--boundary--";
-
+
ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes("US-ASCII"));
-
- BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 20);
-
+
+ BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 20);
+
MimeBoundaryInputStream mime1 = new MimeBoundaryInputStream(buffer, "boundary");
-
- assertEquals("yadayadayadayadayadayadayadayadayadayadayadayadayadayadayadayada",
+
+ assertEquals("yadayadayadayadayadayadayadayadayadayadayadayadayadayadayadayada",
read(mime1, 25));
-
+
assertFalse(mime1.isLastPart());
-
+
MimeBoundaryInputStream mime2 = new MimeBoundaryInputStream(buffer, "boundary");
- assertEquals("blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah",
+ assertEquals("blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah",
read(mime2, 25));
assertTrue(mime2.isLastPart());
}
-
+
public void testBasicReadingByOneByte() throws IOException {
String text = "Line 1\r\nLine 2\r\n--boundary\r\n" +
"Line 3\r\nLine 4\r\n--boundary--";
-
+
ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes("US-ASCII"));
-
- BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
-
+
+ BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
+
MimeBoundaryInputStream mime1 = new MimeBoundaryInputStream(buffer, "boundary");
assertEquals("Line 1\r\nLine 2", readByOneByte(mime1));
-
+
assertFalse(mime1.isLastPart());
-
+
MimeBoundaryInputStream mime2 = new MimeBoundaryInputStream(buffer, "boundary");
assertEquals("Line 3\r\nLine 4", readByOneByte(mime2));
assertTrue(mime2.isLastPart());
}
-
+
/**
* Tests that a CRLF immediately preceding a boundary isn't included in
* the stream.
@@ -141,22 +141,22 @@ public class MimeBoundaryInputStreamTest
public void testCRLFPrecedingBoundary() throws IOException {
String text = "Line 1\r\nLine 2\r\n--boundary\r\n" +
"Line 3\r\nLine 4\r\n\r\n--boundary\r\n";
-
+
ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes("US-ASCII"));
-
- BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
-
+
+ BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
+
MimeBoundaryInputStream mime1 = new MimeBoundaryInputStream(buffer, "boundary");
assertEquals("Line 1\r\nLine 2", read(mime1, 5));
-
+
assertFalse(mime1.isLastPart());
-
+
MimeBoundaryInputStream mime2 = new MimeBoundaryInputStream(buffer, "boundary");
assertEquals("Line 3\r\nLine 4\r\n", read(mime2, 5));
assertFalse(mime2.isLastPart());
}
-
+
private String readByOneByte(InputStream is) throws IOException {
StringBuilder sb = new StringBuilder();
int b = 0;
@@ -177,66 +177,66 @@ public class MimeBoundaryInputStreamTest
}
return sb.toString();
}
-
+
/**
* Tests that a stream containing only a boundary is empty.
*/
public void testImmediateBoundary() throws IOException {
String text = "--boundary\r\n";
-
+
ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes());
- BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
-
- MimeBoundaryInputStream stream =
+ BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
+
+ MimeBoundaryInputStream stream =
new MimeBoundaryInputStream(buffer, "boundary");
assertEquals(-1, stream.read());
-
+
text = "\r\n--boundary\r\n";
-
+
bis = new ByteArrayInputStream(text.getBytes());
- buffer = new BufferedLineReaderInputStream(bis, 4096);
- stream =
+ buffer = new BufferedLineReaderInputStream(bis, 4096);
+ stream =
new MimeBoundaryInputStream(buffer, "boundary");
assertEquals(-1, stream.read());
}
-
+
/**
* Tests that hasMoreParts behave as expected.
*/
public void testHasMoreParts() throws IOException {
String text = "--boundary--\r\n";
-
+
ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes());
- BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
- MimeBoundaryInputStream stream =
+ BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
+ MimeBoundaryInputStream stream =
new MimeBoundaryInputStream(buffer, "boundary");
assertEquals(-1, stream.read());
assertTrue(stream.isLastPart());
}
-
+
/**
* Tests that a stream containing only a boundary is empty.
*/
public void testPrefixIsBoundary() throws IOException {
String text = "Line 1\r\n\r\n--boundary\r\n";
-
+
ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes());
- BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
- MimeBoundaryInputStream stream =
+ BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);
+ MimeBoundaryInputStream stream =
new MimeBoundaryInputStream(buffer, "boundary");
assertEquals("Line 1\r\n", read(stream, 100));
-
+
text = "--boundary\r\n";
-
+
bis = new ByteArrayInputStream(text.getBytes());
- buffer = new BufferedLineReaderInputStream(bis, 4096);
+ buffer = new BufferedLineReaderInputStream(bis, 4096);
stream = new MimeBoundaryInputStream(buffer, "boundary");
assertEquals(-1, stream.read());
}
-
-
+
+
public void testBasicReadLine() throws Exception {
-
+
String[] teststrs = new String[5];
teststrs[0] = "Hello\r\n";
teststrs[1] = "This string should be much longer than the size of the input buffer " +
@@ -251,19 +251,19 @@ public class MimeBoundaryInputStreamTest
teststrs[4] = "And goodbye\r\n";
String term = "\r\n--1234\r\n";
-
+
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
-
+
for (String teststr : teststrs) {
outstream.write(teststr.getBytes("US-ASCII"));
}
outstream.write(term.getBytes("US-ASCII"));
byte[] raw = outstream.toByteArray();
-
- BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(raw), 20);
- LineReaderInputStream instream = new MimeBoundaryInputStream(inbuffer, "1234");
-
- ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
+
+ BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(raw), 20);
+ LineReaderInputStream instream = new MimeBoundaryInputStream(inbuffer, "1234");
+
+ ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
for (String teststr : teststrs) {
linebuf.clear();
instream.readLine(linebuf);
@@ -273,26 +273,26 @@ public class MimeBoundaryInputStreamTest
assertEquals(-1, instream.readLine(linebuf));
assertEquals(-1, instream.readLine(linebuf));
}
-
+
public void testReadEmptyLine() throws Exception {
-
+
String teststr = "01234567890123456789\n\n\r\n\r\r\n\n\n\n\n\n--1234\r\n";
byte[] raw = teststr.getBytes("US-ASCII");
-
- BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(raw), 20);
- LineReaderInputStream instream = new MimeBoundaryInputStream(inbuffer, "1234");
-
- ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
+
+ BufferedLineReaderInputStream inbuffer = new BufferedLineReaderInputStream(new ByteArrayInputStream(raw), 20);
+ LineReaderInputStream instream = new MimeBoundaryInputStream(inbuffer, "1234");
+
+ ByteArrayBuffer linebuf = new ByteArrayBuffer(8);
linebuf.clear();
instream.readLine(linebuf);
String s = new String(linebuf.toByteArray(), "US-ASCII");
assertEquals("01234567890123456789\n", s);
-
+
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
assertEquals("\n", s);
-
+
linebuf.clear();
instream.readLine(linebuf);
s = new String(linebuf.toByteArray(), "US-ASCII");
@@ -326,5 +326,5 @@ public class MimeBoundaryInputStreamTest
assertEquals(-1, instream.readLine(linebuf));
assertEquals(-1, instream.readLine(linebuf));
}
-
+
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/PositionInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/PositionInputStreamTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/PositionInputStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/PositionInputStreamTest.java Mon Jul 11 19:48:50 2011
@@ -49,5 +49,5 @@ public class PositionInputStreamTest ext
assertTrue(countingStream.read(tmp) == -1);
assertEquals(7, countingStream.getPosition());
}
-
+
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java?rev=1145308&r1=1145307&r2=1145308&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java Mon Jul 11 19:48:50 2011
@@ -64,22 +64,22 @@ public class MimeStreamParserExampleMess
config.setMaxLineLen(-1);
parser = new MimeStreamParser(config);
handler = new TestHandler();
-
+
parser.setContentHandler(handler);
parser.parse(url.openStream());
-
+
String result = handler.sb.toString();
-
+
String s = url.toString();
String prefix = s.substring(0, s.lastIndexOf('.'));
URL xmlFileUrl = new URL(prefix + ".xml");
try {
- InputStream openStream = xmlFileUrl.openStream();
- String expected = IOUtils.toString(openStream, "ISO8859-1");
- assertEquals(expected, result);
+ InputStream openStream = xmlFileUrl.openStream();
+ String expected = IOUtils.toString(openStream, "ISO8859-1");
+ assertEquals(expected, result);
} catch (FileNotFoundException e) {
- IOUtils.write(result, new FileOutputStream(xmlFileUrl.getPath()+".expected"));
- fail("Expected file created.");
+ IOUtils.write(result, new FileOutputStream(xmlFileUrl.getPath()+".expected"));
+ fail("Expected file created.");
}
}
@@ -94,17 +94,17 @@ public class MimeStreamParserExampleMess
addTests("/mimetools-testmsgs");
}
- private void addTests(String testsFolder) throws URISyntaxException,
- MalformedURLException, IOException {
- URL resource = MimeStreamParserExampleMessagesTestSuite.class.getResource(testsFolder);
+ private void addTests(String testsFolder) throws URISyntaxException,
+ MalformedURLException, IOException {
+ URL resource = MimeStreamParserExampleMessagesTestSuite.class.getResource(testsFolder);
if (resource != null) {
if (resource.getProtocol().equalsIgnoreCase("file")) {
File dir = new File(resource.toURI());
File[] files = dir.listFiles();
-
+
for (File f : files) {
if (f.getName().endsWith(".msg")) {
- addTest(new MimeStreamParserExampleMessagesTest(f.getName(),
+ addTest(new MimeStreamParserExampleMessagesTest(f.getName(),
f.toURI().toURL()));
}
}
@@ -116,13 +116,13 @@ public class MimeStreamParserExampleMess
String s = "/" + entry.toString();
File f = new File(s);
if (s.startsWith(testsFolder) && s.endsWith(".msg")) {
- addTest(new MimeStreamParserExampleMessagesTest(f.getName(),
+ addTest(new MimeStreamParserExampleMessagesTest(f.getName(),
new URL("jar:file:" + jar.getName() + "!" + s)));
}
}
}
}
- }
+ }
}
}