james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwiederk...@apache.org
Subject svn commit: r748583 [2/2] - in /james/mime4j/trunk/src: main/java/org/apache/james/mime4j/field/ main/java/org/apache/james/mime4j/message/ main/java/org/apache/james/mime4j/parser/ main/java/org/apache/james/mime4j/util/ test/java/org/apache/james/mim...
Date Fri, 27 Feb 2009 16:45:03 GMT
Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/field/FieldsTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/field/FieldsTest.java?rev=748583&r1=748582&r2=748583&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/field/FieldsTest.java (original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/field/FieldsTest.java Fri Feb
27 16:45:02 2009
@@ -30,6 +30,8 @@
 import org.apache.james.mime4j.field.address.Group;
 import org.apache.james.mime4j.field.address.Mailbox;
 import org.apache.james.mime4j.parser.Field;
+import org.apache.james.mime4j.util.ByteSequence;
+import org.apache.james.mime4j.util.ContentUtil;
 import org.apache.james.mime4j.util.MimeUtil;
 
 public class FieldsTest extends TestCase {
@@ -43,7 +45,7 @@
         String expectedRaw = "Content-Type: multipart/mixed;\r\n "
                 + "boundary=\"-=Part.0.37877968dd4f6595.11eccf0271c"
                 + ".2dce5678cbc933d5=-\"";
-        assertEquals(expectedRaw, field.getRaw());
+        assertEquals(expectedRaw, decode(field.getRaw()));
     }
 
     public void testContentTypeStringParameters() throws Exception {
@@ -57,7 +59,7 @@
         String expectedRaw = "Content-Type: multipart/mixed;\r\n "
                 + "boundary=\"-=Part.0.37877968dd4f6595.11eccf0271c"
                 + ".2dce5678cbc933d5=-\"";
-        assertEquals(expectedRaw, field.getRaw());
+        assertEquals(expectedRaw, decode(field.getRaw()));
     }
 
     public void testContentTypeStringParametersWithSpaces() throws Exception {
@@ -69,7 +71,7 @@
 
         String expectedRaw = "Content-Type: multipart/mixed; "
                 + "param=\"value with space chars\"";
-        assertEquals(expectedRaw, field.getRaw());
+        assertEquals(expectedRaw, decode(field.getRaw()));
     }
 
     public void testContentTypeStringNullParameters() throws Exception {
@@ -77,7 +79,7 @@
         assertTrue(field.isValidField());
 
         String expectedRaw = "Content-Type: text/plain";
-        assertEquals(expectedRaw, field.getRaw());
+        assertEquals(expectedRaw, decode(field.getRaw()));
     }
 
     public void testInvalidContentType() throws Exception {
@@ -94,7 +96,8 @@
                 .contentTransferEncoding("base64");
         assertTrue(field.isValidField());
 
-        assertEquals("Content-Transfer-Encoding: base64", field.getRaw());
+        assertEquals("Content-Transfer-Encoding: base64",
+                decode(field.getRaw()));
     }
 
     public void testContentDispositionString() throws Exception {
@@ -106,7 +109,7 @@
         String expectedRaw = "Content-Disposition: inline; filename="
                 + "\"testing 1 2.dat\"; size=12345;\r\n creation-date="
                 + "\"Thu, 1 Jan 1970 00:00:00 +0000\"";
-        assertEquals(expectedRaw, field.getRaw());
+        assertEquals(expectedRaw, decode(field.getRaw()));
     }
 
     public void testContentDispositionStringParameters() throws Exception {
@@ -119,7 +122,7 @@
 
         String expectedRaw = "Content-Disposition: attachment; "
                 + "creation-date=\"Thu, 1 Jan 1970 00:00:00\r\n +0000\"";
-        assertEquals(expectedRaw, field.getRaw());
+        assertEquals(expectedRaw, decode(field.getRaw()));
 
         assertEquals(new Date(0), field.getCreationDate());
     }
@@ -130,7 +133,7 @@
         assertTrue(field.isValidField());
 
         String expectedRaw = "Content-Disposition: inline";
-        assertEquals(expectedRaw, field.getRaw());
+        assertEquals(expectedRaw, decode(field.getRaw()));
     }
 
     public void testContentDispositionFilename() throws Exception {
@@ -154,7 +157,8 @@
 
     public void testContentDispositionFilenameSizeDate() throws Exception {
         ContentDispositionField field = Fields.contentDisposition("attachment",
-                "some file.dat", 300, new Date(1000), new Date(2000), new Date(3000));
+                "some file.dat", 300, new Date(1000), new Date(2000), new Date(
+                        3000));
         assertTrue(field.isValidField());
 
         assertEquals("attachment", field.getDispositionType());
@@ -178,15 +182,16 @@
                 .getTimeZone("GMT"));
         assertTrue(field.isValidField());
 
-        assertEquals("Date: Thu, 1 Jan 1970 00:00:00 +0000", field.getRaw());
+        assertEquals("Date: Thu, 1 Jan 1970 00:00:00 +0000", decode(field
+                .getRaw()));
         assertEquals(new Date(0), field.getDate());
 
         field = Fields.date("Resent-Date", new Date(0), TimeZone
                 .getTimeZone("GMT+1"));
         assertTrue(field.isValidField());
 
-        assertEquals("Resent-Date: Thu, 1 Jan 1970 01:00:00 +0100", field
-                .getRaw());
+        assertEquals("Resent-Date: Thu, 1 Jan 1970 01:00:00 +0100",
+                decode(field.getRaw()));
         assertEquals(new Date(0), field.getDate());
     }
 
@@ -196,38 +201,39 @@
                 .getTimeZone("CET"));
         assertTrue(field.isValidField());
 
-        assertEquals("Date: Wed, 16 Jul 2008 17:12:33 +0200", field.getRaw());
+        assertEquals("Date: Wed, 16 Jul 2008 17:12:33 +0200", decode(field
+                .getRaw()));
         assertEquals(new Date(millis), field.getDate());
     }
 
     public void testMessageId() throws Exception {
         Field messageId = Fields.messageId("acme.org");
 
-        String raw = messageId.getRaw();
+        String raw = ContentUtil.decode(messageId.getRaw());
         assertTrue(raw.startsWith("Message-ID: <Mime4j."));
         assertTrue(raw.endsWith("@acme.org>"));
     }
 
     public void testSubject() throws Exception {
-        assertEquals("Subject: ", Fields.subject("").getRaw());
-        assertEquals("Subject: test", Fields.subject("test").getRaw());
-        assertEquals("Subject: =?ISO-8859-1?Q?Sm=F8rebr=F8d?=", Fields.subject(
-                "Sm\370rebr\370d").getRaw());
+        assertEquals("Subject: ", decode(Fields.subject("").getRaw()));
+        assertEquals("Subject: test", decode(Fields.subject("test").getRaw()));
+        assertEquals("Subject: =?ISO-8859-1?Q?Sm=F8rebr=F8d?=", decode(Fields
+                .subject("Sm\370rebr\370d").getRaw()));
 
         String seventyEight = "12345678901234567890123456789012345678901234567890123456789012345678";
-        assertEquals("Subject:\r\n " + seventyEight, Fields.subject(
-                seventyEight).getRaw());
+        assertEquals("Subject:\r\n " + seventyEight, decode(Fields.subject(
+                seventyEight).getRaw()));
 
         String seventyNine = seventyEight + "9";
         String expected = "Subject: =?US-ASCII?Q?1234567890123456789012345678901234?="
                 + "\r\n =?US-ASCII?Q?56789012345678901234567890123456789?=";
-        assertEquals(expected, Fields.subject(seventyNine).getRaw());
+        assertEquals(expected, decode(Fields.subject(seventyNine).getRaw()));
     }
 
     public void testSender() throws Exception {
         MailboxField field = Fields.sender(Mailbox
                 .parse("JD <john.doe@acme.org>"));
-        assertEquals("Sender: JD <john.doe@acme.org>", field.getRaw());
+        assertEquals("Sender: JD <john.doe@acme.org>", decode(field.getRaw()));
     }
 
     public void testFrom() throws Exception {
@@ -235,15 +241,15 @@
         Mailbox mailbox2 = Mailbox.parse("Mary Smith <mary@example.net>");
 
         MailboxListField field = Fields.from(mailbox1);
-        assertEquals("From: JD <john.doe@acme.org>", field.getRaw());
+        assertEquals("From: JD <john.doe@acme.org>", decode(field.getRaw()));
 
         field = Fields.from(mailbox1, mailbox2);
         assertEquals("From: JD <john.doe@acme.org>, "
-                + "Mary Smith <mary@example.net>", field.getRaw());
+                + "Mary Smith <mary@example.net>", decode(field.getRaw()));
 
         field = Fields.from(Arrays.asList(mailbox1, mailbox2));
         assertEquals("From: JD <john.doe@acme.org>, "
-                + "Mary Smith <mary@example.net>", field.getRaw());
+                + "Mary Smith <mary@example.net>", decode(field.getRaw()));
     }
 
     public void testTo() throws Exception {
@@ -254,17 +260,17 @@
 
         AddressListField field = Fields.to(group);
         assertEquals("To: The Does: JD <john.doe@acme.org>, "
-                + "jane.doe@example.org;", field.getRaw());
+                + "jane.doe@example.org;", decode(field.getRaw()));
 
         field = Fields.to(group, mailbox3);
         assertEquals("To: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary Smith\r\n <mary@example.net>",
-                field.getRaw());
+                decode(field.getRaw()));
 
         field = Fields.to(Arrays.asList(group, mailbox3));
         assertEquals("To: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary Smith\r\n <mary@example.net>",
-                field.getRaw());
+                decode(field.getRaw()));
     }
 
     public void testCc() throws Exception {
@@ -275,17 +281,17 @@
 
         AddressListField field = Fields.cc(group);
         assertEquals("Cc: The Does: JD <john.doe@acme.org>, "
-                + "jane.doe@example.org;", field.getRaw());
+                + "jane.doe@example.org;", decode(field.getRaw()));
 
         field = Fields.cc(group, mailbox3);
         assertEquals("Cc: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary Smith\r\n <mary@example.net>",
-                field.getRaw());
+                decode(field.getRaw()));
 
         field = Fields.cc(Arrays.asList(group, mailbox3));
         assertEquals("Cc: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary Smith\r\n <mary@example.net>",
-                field.getRaw());
+                decode(field.getRaw()));
     }
 
     public void testBcc() throws Exception {
@@ -296,17 +302,17 @@
 
         AddressListField field = Fields.bcc(group);
         assertEquals("Bcc: The Does: JD <john.doe@acme.org>, "
-                + "jane.doe@example.org;", field.getRaw());
+                + "jane.doe@example.org;", decode(field.getRaw()));
 
         field = Fields.bcc(group, mailbox3);
         assertEquals("Bcc: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary Smith\r\n <mary@example.net>",
-                field.getRaw());
+                decode(field.getRaw()));
 
         field = Fields.bcc(Arrays.asList(group, mailbox3));
         assertEquals("Bcc: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary Smith\r\n <mary@example.net>",
-                field.getRaw());
+                decode(field.getRaw()));
     }
 
     public void testReplyTo() throws Exception {
@@ -317,23 +323,24 @@
 
         AddressListField field = Fields.replyTo(group);
         assertEquals("Reply-To: The Does: JD <john.doe@acme.org>, "
-                + "jane.doe@example.org;", field.getRaw());
+                + "jane.doe@example.org;", decode(field.getRaw()));
 
         field = Fields.replyTo(group, mailbox3);
         assertEquals("Reply-To: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary\r\n Smith <mary@example.net>",
-                field.getRaw());
+                decode(field.getRaw()));
 
         field = Fields.replyTo(Arrays.asList(group, mailbox3));
         assertEquals("Reply-To: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary\r\n Smith <mary@example.net>",
-                field.getRaw());
+                decode(field.getRaw()));
     }
 
     public void testMailbox() throws Exception {
         MailboxField field = Fields.mailbox("Resent-Sender", Mailbox
                 .parse("JD <john.doe@acme.org>"));
-        assertEquals("Resent-Sender: JD <john.doe@acme.org>", field.getRaw());
+        assertEquals("Resent-Sender: JD <john.doe@acme.org>", decode(field
+                .getRaw()));
     }
 
     public void testMailboxList() throws Exception {
@@ -343,7 +350,7 @@
         MailboxListField field = Fields.mailboxList("Resent-From", Arrays
                 .asList(mailbox1, mailbox2));
         assertEquals("Resent-From: JD <john.doe@acme.org>, "
-                + "Mary Smith <mary@example.net>", field.getRaw());
+                + "Mary Smith <mary@example.net>", decode(field.getRaw()));
     }
 
     public void testAddressList() throws Exception {
@@ -356,7 +363,7 @@
                 group, mailbox3));
         assertEquals("Resent-To: The Does: JD <john.doe@acme.org>, "
                 + "jane.doe@example.org;, Mary\r\n Smith <mary@example.net>",
-                field.getRaw());
+                decode(field.getRaw()));
     }
 
     public void testInvalidFieldName() throws Exception {
@@ -367,4 +374,8 @@
         }
     }
 
+    private String decode(ByteSequence byteSequence) {
+        return ContentUtil.decode(byteSequence);
+    }
+
 }

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/EntityTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/EntityTest.java?rev=748583&r1=748582&r2=748583&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/EntityTest.java (original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/EntityTest.java Fri Feb
27 16:45:02 2009
@@ -70,7 +70,7 @@
         assertNull(entity.getDispositionType());
 
         Header header = new Header();
-        header.setField(AbstractField.parse("Content-Disposition", "inline"));
+        header.setField(AbstractField.parse("Content-Disposition: inline"));
         entity.setHeader(header);
 
         assertEquals("inline", entity.getDispositionType());
@@ -100,8 +100,8 @@
         assertNull(entity.getFilename());
 
         Header header = new Header();
-        header.setField(AbstractField.parse("Content-Disposition",
-                "attachment; filename=\"some file.dat\""));
+        header.setField(AbstractField.parse("Content-Disposition: attachment; "
+                + "filename=\"some file.dat\""));
         entity.setHeader(header);
 
         assertEquals("some file.dat", entity.getFilename());

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/ExampleMessagesRoundtripTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/ExampleMessagesRoundtripTest.java?rev=748583&r1=748582&r2=748583&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/ExampleMessagesRoundtripTest.java
(original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/ExampleMessagesRoundtripTest.java
Fri Feb 27 16:45:02 2009
@@ -64,7 +64,7 @@
         config.setMaxLineLen(-1);
         Message inputMessage = new Message(new FileInputStream(file), config);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MessageWriter.LENIENT.writeEntity(inputMessage, out);
+        inputMessage.writeTo(out);
         
         String msgoutFile = file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf('.'))
+ ".out";
         String msgoutFileMime4j = file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf('.'))
+ ".mime4j.out";
@@ -73,17 +73,6 @@
             ByteArrayOutputStream expectedstream = new ByteArrayOutputStream();
             CodecUtil.copy(new FileInputStream(msgoutFile), expectedstream);
             assertEquals("Wrong Expected result", new String(expectedstream.toByteArray()),
new String(out.toByteArray()));
-            
-            Message roundtripMessage = new Message(new FileInputStream(msgoutFile), config);
-            ByteArrayOutputStream outRoundtrip = new ByteArrayOutputStream();
-            MessageWriter.LENIENT.writeEntity(roundtripMessage, outRoundtrip);
-            assertEquals("Failed LENIENT roundtrip", new String(out.toByteArray()), new String(outRoundtrip.toByteArray()));
-
-            roundtripMessage = new Message(new FileInputStream(msgoutFile), config);
-            outRoundtrip = new ByteArrayOutputStream();
-            MessageWriter.STRICT_ERROR.writeEntity(roundtripMessage, outRoundtrip);
-            assertEquals("Failed STRICT roundtrip", new String(out.toByteArray()), new String(outRoundtrip.toByteArray()));
-
         } catch (FileNotFoundException e) {
             FileOutputStream fos = new FileOutputStream(msgoutFileMime4j);
             fos.write(out.toByteArray());
@@ -91,8 +80,6 @@
             fos.close();
             fail("Expected file not found: generated a file with the expected result!");
         }
-        
-        
     }
 
     public static Test suite() throws IOException {

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/HeaderTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/HeaderTest.java?rev=748583&r1=748582&r2=748583&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/HeaderTest.java (original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/HeaderTest.java Fri Feb
27 16:45:02 2009
@@ -22,7 +22,6 @@
 import junit.framework.TestCase;
 
 import org.apache.commons.io.output.ByteArrayOutputStream;
-import org.apache.james.mime4j.MimeIOException;
 import org.apache.james.mime4j.field.AbstractField;
 import org.apache.james.mime4j.parser.Field;
 import org.apache.james.mime4j.util.CharsetUtil;
@@ -47,7 +46,7 @@
     
     private static final String SWISS_GERMAN_HELLO = "Gr\374ezi_z\344m\344";
 
-    public void testWriteInStrictMode() throws Exception {
+    public void testWriteSpecialCharacters() throws Exception {
         String hello = SWISS_GERMAN_HELLO;
         Header header = new Header();
         header.addField(AbstractField.parse("Hello: " + hello));
@@ -58,40 +57,12 @@
         
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
         
-        MessageWriter.STRICT_IGNORE.writeHeader(header, buffer);
+        MessageWriter.DEFAULT.writeHeader(header, buffer);
         String s = buffer.toString(CharsetUtil.US_ASCII.name());
         
         assertEquals("Hello: Gr?ezi_z?m?\r\n\r\n", s);
-
-        buffer.reset();
-        
-        try {
-            MessageWriter.STRICT_ERROR.writeHeader(header, buffer);
-            fail("MimeIOException should have been thrown");
-        } catch (MimeIOException expected) {
-        }
     }
-    
-    public void testWriteInLenientMode() throws Exception {
-        String hello = SWISS_GERMAN_HELLO;
-        Header header = new Header();
-        header.addField(AbstractField.parse("Hello: " + hello));
-        header.addField(AbstractField.parse("Content-type: text/plain; charset=" + 
-                CharsetUtil.ISO_8859_1.name()));
-        
-        Field field = header.getField("Hello");
-        assertNotNull(field);
-        assertEquals(hello, field.getBody());
-        
-        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-        
-        MessageWriter.LENIENT.writeHeader(header, buffer);
-        String s = buffer.toString(CharsetUtil.ISO_8859_1.name());
-        
-        assertEquals("Hello: " + hello + "\r\n" +
-                "Content-type: text/plain; charset=ISO-8859-1\r\n\r\n", s);
-    }
-    
+
     public void testRemoveFields() throws Exception {
         Header header = new Header();
         header.addField(AbstractField.parse("Received: from foo by bar for james"));

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java?rev=748583&r1=748582&r2=748583&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
(original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
Fri Feb 27 16:45:02 2009
@@ -22,6 +22,7 @@
 import org.apache.commons.io.IOUtils;
 import org.apache.james.mime4j.parser.Field;
 import org.apache.james.mime4j.parser.MimeEntityConfig;
+import org.apache.james.mime4j.util.ContentUtil;
 import org.apache.james.mime4j.util.CharsetUtil;
 import org.apache.log4j.BasicConfigurator;
 
@@ -143,7 +144,8 @@
         
         sb.append("<header>\r\n");
         for (Field field : e.getHeader().getFields()) {
-            sb.append("<field>\r\n" + escape(field.getRaw()) 
+            sb.append("<field>\r\n"
+                    + escape(ContentUtil.decode(field.getRaw()))
                     + "</field>\r\n");
         }
         sb.append("</header>\r\n");

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageTest.java?rev=748583&r1=748582&r2=748583&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageTest.java (original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageTest.java Fri
Feb 27 16:45:02 2009
@@ -167,7 +167,7 @@
 
         String id = "<msg17@localhost>";
         Header header = new Header();
-        header.setField(AbstractField.parse("Message-ID", id));
+        header.setField(AbstractField.parse("Message-ID: " + id));
         m.setHeader(header);
         assertEquals(id, m.getMessageId());
     }
@@ -188,11 +188,11 @@
 
         String subject = "testing 1 2";
         Header header = new Header();
-        header.setField(AbstractField.parse("Subject", subject));
+        header.setField(AbstractField.parse("Subject: " + subject));
         m.setHeader(header);
         assertEquals(subject, m.getSubject());
 
-        header.setField(AbstractField.parse("Subject", "=?windows-1252?Q?99_=80?="));
+        header.setField(AbstractField.parse("Subject: =?windows-1252?Q?99_=80?="));
         assertEquals("99 \u20ac", m.getSubject());
     }
 
@@ -213,7 +213,7 @@
         assertNull(m.getDate());
 
         Header header = new Header();
-        header.setField(AbstractField.parse("Date", "Thu, 1 Jan 1970 05:30:00 +0530"));
+        header.setField(AbstractField.parse("Date: Thu, 1 Jan 1970 05:30:00 +0530"));
         m.setHeader(header);
 
         assertEquals(new Date(0), m.getDate());
@@ -236,7 +236,7 @@
         assertNull(m.getSender());
 
         Header header = new Header();
-        header.setField(AbstractField.parse("Sender", "john.doe@example.net"));
+        header.setField(AbstractField.parse("Sender: john.doe@example.net"));
         m.setHeader(header);
 
         assertEquals("john.doe@example.net", m.getSender().getAddress());
@@ -258,7 +258,7 @@
         assertNull(m.getFrom());
 
         Header header = new Header();
-        header.setField(AbstractField.parse("From", "john.doe@example.net"));
+        header.setField(AbstractField.parse("From: john.doe@example.net"));
         m.setHeader(header);
 
         assertEquals("john.doe@example.net", m.getFrom().get(0).getAddress());
@@ -291,7 +291,7 @@
         assertNull(m.getTo());
 
         Header header = new Header();
-        header.setField(AbstractField.parse("To", "john.doe@example.net"));
+        header.setField(AbstractField.parse("To: john.doe@example.net"));
         m.setHeader(header);
 
         assertEquals("john.doe@example.net", ((Mailbox) m.getTo().get(0))
@@ -329,7 +329,7 @@
         assertNull(m.getCc());
 
         Header header = new Header();
-        header.setField(AbstractField.parse("Cc", "john.doe@example.net"));
+        header.setField(AbstractField.parse("Cc: john.doe@example.net"));
         m.setHeader(header);
 
         assertEquals("john.doe@example.net", ((Mailbox) m.getCc().get(0))
@@ -367,7 +367,7 @@
         assertNull(m.getBcc());
 
         Header header = new Header();
-        header.setField(AbstractField.parse("Bcc", "john.doe@example.net"));
+        header.setField(AbstractField.parse("Bcc: john.doe@example.net"));
         m.setHeader(header);
 
         assertEquals("john.doe@example.net", ((Mailbox) m.getBcc().get(0))
@@ -405,7 +405,7 @@
         assertNull(m.getReplyTo());
 
         Header header = new Header();
-        header.setField(AbstractField.parse("Reply-To", "john.doe@example.net"));
+        header.setField(AbstractField.parse("Reply-To: john.doe@example.net"));
         m.setHeader(header);
 
         assertEquals("john.doe@example.net", ((Mailbox) m.getReplyTo().get(0))

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageWriteToTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageWriteToTest.java?rev=748583&r1=748582&r2=748583&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageWriteToTest.java
(original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageWriteToTest.java
Fri Feb 27 16:45:02 2009
@@ -38,27 +38,11 @@
         super.tearDown();
     }
     
-    public void testSimpleMailStrictIgnore() throws Exception {
+    public void testSimpleMail() throws Exception {
         Message message = createMessage(ExampleMail.RFC822_SIMPLE_BYTES);
         assertFalse("Not multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MessageWriter.STRICT_IGNORE.writeEntity(message, out);
-        assertEquals(out.toByteArray(), ExampleMail.RFC822_SIMPLE_BYTES);
-    }
-    
-    public void testSimpleMailStrictError() throws Exception {
-        Message message = createMessage(ExampleMail.RFC822_SIMPLE_BYTES);
-        assertFalse("Not multipart", message.isMultipart());
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MessageWriter.STRICT_ERROR.writeEntity(message, out);
-        assertEquals(out.toByteArray(), ExampleMail.RFC822_SIMPLE_BYTES);
-    }
-    
-    public void testSimpleMailLenient() throws Exception {
-        Message message = createMessage(ExampleMail.RFC822_SIMPLE_BYTES);
-        assertFalse("Not multipart", message.isMultipart());
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MessageWriter.LENIENT.writeEntity(message, out);
+        message.writeTo(out);
         assertEquals(out.toByteArray(), ExampleMail.RFC822_SIMPLE_BYTES);
     }
     
@@ -71,27 +55,11 @@
         }
     }
     
-    public void testBinaryAttachmentLenient() throws Exception {
-        Message message = createMessage(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES);
-        assertTrue("Is multipart", message.isMultipart());
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MessageWriter.LENIENT.writeEntity(message, out);
-        assertEquals(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES, out.toByteArray());
-    }
-    
-    public void testBinaryAttachmentStrictError() throws Exception {
-        Message message = createMessage(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES);
-        assertTrue("Is multipart", message.isMultipart());
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MessageWriter.STRICT_ERROR.writeEntity(message, out);
-        assertEquals(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES, out.toByteArray());
-    }
-    
-    public void testBinaryAttachmentStrictIgnore() throws Exception {
+    public void testBinaryAttachment() throws Exception {
         Message message = createMessage(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES);
         assertTrue("Is multipart", message.isMultipart());
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MessageWriter.STRICT_IGNORE.writeEntity(message, out);
+        message.writeTo(out);
         assertEquals(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES, out.toByteArray());
     }
     

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java?rev=748583&r1=748582&r2=748583&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java
(original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java
Fri Feb 27 16:45:02 2009
@@ -59,7 +59,7 @@
         multipart.addBodyPart(p3);
         
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        MessageWriter.LENIENT.writeMultipart(multipart, out);
+        MessageWriter.DEFAULT.writeMultipart(multipart, out);
         out.close();
         
         String expected = "\r\n" + 

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserTest.java?rev=748583&r1=748582&r2=748583&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserTest.java
(original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserTest.java
Fri Feb 27 16:45:02 2009
@@ -22,6 +22,8 @@
 import org.apache.james.mime4j.descriptor.BodyDescriptor;
 import org.apache.james.mime4j.parser.AbstractContentHandler;
 import org.apache.james.mime4j.parser.MimeStreamParser;
+import org.apache.james.mime4j.util.ByteSequence;
+import org.apache.james.mime4j.util.ContentUtil;
 import org.apache.log4j.BasicConfigurator;
 
 import java.io.ByteArrayInputStream;
@@ -140,7 +142,7 @@
         parser.setContentHandler(new AbstractContentHandler() {
             @Override
             public void field(Field field) {
-                assertEquals(expected.removeFirst(), field.getRaw());
+                assertEquals(expected.removeFirst(), decode(field.getRaw()));
             }
         });
         
@@ -164,7 +166,7 @@
         parser.setContentHandler(new AbstractContentHandler() {
             @Override
             public void field(Field field) {
-                assertEquals(expected.removeFirst(), field.getRaw());
+                assertEquals(expected.removeFirst(), decode(field.getRaw()));
             }
         });
         
@@ -188,7 +190,7 @@
         parser.setContentHandler(new AbstractContentHandler() {
             @Override
             public void field(Field field) {
-                assertEquals(expected.removeFirst(), field.getRaw());
+                assertEquals(expected.removeFirst(), decode(field.getRaw()));
             }
         });
         
@@ -249,7 +251,7 @@
         parser.setContentHandler(new AbstractContentHandler() {
             @Override
             public void field(Field field) {
-                assertEquals(expected.removeFirst(), field.getRaw());
+                assertEquals(expected.removeFirst(), decode(field.getRaw()));
             }
         });
         
@@ -372,7 +374,7 @@
         parser.setContentHandler(new AbstractContentHandler() {
             @Override
             public void field(Field field) {
-                assertEquals(expected.removeFirst(), field.getRaw());
+                assertEquals(expected.removeFirst(), decode(field.getRaw()));
             }
             @Override
             public void body(BodyDescriptor bd, InputStream is) throws IOException {
@@ -400,7 +402,7 @@
         parser.setContentHandler(new AbstractContentHandler() {
             @Override
             public void field(Field field) {
-                assertEquals(expected.removeFirst(), field.getRaw());
+                assertEquals(expected.removeFirst(), decode(field.getRaw()));
             }
         });
         
@@ -419,7 +421,7 @@
         parser.setContentHandler(new AbstractContentHandler() {
             @Override
             public void field(Field field) {
-                assertEquals(expected.removeFirst(), field.getRaw());
+                assertEquals(expected.removeFirst(), decode(field.getRaw()));
             }
         });
         
@@ -466,4 +468,8 @@
         assertEquals(expected, result);
     }
     
+    protected String decode(ByteSequence byteSequence) {
+        return ContentUtil.decode(byteSequence);
+    }
+    
 }

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/parser/TestHandler.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/parser/TestHandler.java?rev=748583&r1=748582&r2=748583&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/parser/TestHandler.java (original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/parser/TestHandler.java Fri Feb
27 16:45:02 2009
@@ -21,6 +21,7 @@
 
 import org.apache.james.mime4j.descriptor.BodyDescriptor;
 import org.apache.james.mime4j.parser.ContentHandler;
+import org.apache.james.mime4j.util.ContentUtil;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -91,7 +92,9 @@
         sb.append("<header>\r\n");
     }
     public void field(Field field) {
-        sb.append("<field>\r\n" + escape(field.getRaw()) + "</field>\r\n");
+        sb.append("<field>\r\n"
+                + escape(ContentUtil.decode(field.getRaw()))
+                + "</field>\r\n");
     }
     public void endHeader() {
         sb.append("</header>\r\n");



Mime
View raw message