james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r659953 - in /james/mime4j/trunk/src: main/java/org/apache/james/mime4j/ main/java/org/apache/james/mime4j/message/ test/java/org/apache/james/mime4j/ test/java/org/apache/james/mime4j/message/
Date Sun, 25 May 2008 10:22:48 GMT
Author: rdonkin
Date: Sun May 25 03:22:48 2008
New Revision: 659953

URL: http://svn.apache.org/viewvc?rev=659953&view=rev
Log:
Confirmed and fixed MIME4J-40 Message.MessageBuilder#startMultupart does not set multipart
subType https://issues.apache.org/jira/browse/MIME4J-40.

Modified:
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/ContentDescriptor.java
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/DefaultBodyDescriptor.java
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Multipart.java
    james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java
    james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamBodyDescriptorTest.java
    james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java
    james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MultipartFormTest.java

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/ContentDescriptor.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/ContentDescriptor.java?rev=659953&r1=659952&r2=659953&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/ContentDescriptor.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/ContentDescriptor.java Sun May
25 03:22:48 2008
@@ -30,13 +30,32 @@
 public interface ContentDescriptor {
     /**
      * Returns the body descriptors MIME type.
+     * @see #getMediaType()
+     * @see #getSubType()
      * @return The MIME type, which has been parsed from the
      *   content-type definition. Must not be null, but
      *   "text/plain", if no content-type was specified.
      */
     String getMimeType();
+    
+    /**
+     * Gets the defaulted MIME media type for this content.
+     * For example <code>TEXT</code>, <code>IMAGE</code>, <code>MULTIPART</code>
+     * @see #getMimeType()
+     * @return the MIME media type when content-type specified,
+     * otherwise the correct default (<code>TEXT</code>)
+     */
+    String getMediaType();
 
     /**
+     * Gets the defaulted MIME sub type for this content.
+     * @see #getMimeType()
+     * @return the MIME media type when content-type is specified,
+     * otherwise the correct default (<code>PLAIN</code>)
+     */
+    String getSubType();
+    
+    /**
      * The body descriptors character set.
      * @return Character set, which has been parsed from the
      *   content-type definition. Must not be null, but "US-ASCII",

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/DefaultBodyDescriptor.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/DefaultBodyDescriptor.java?rev=659953&r1=659952&r2=659953&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/DefaultBodyDescriptor.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/DefaultBodyDescriptor.java Sun
May 25 03:22:48 2008
@@ -33,9 +33,25 @@
  * @version $Id: BodyDescriptor.java,v 1.4 2005/02/11 10:08:37 ntherning Exp $
  */
 public class DefaultBodyDescriptor implements BodyDescriptor {
+    private static final String SUB_TYPE_EMAIL = "rfc822";
+
+    private static final String MEDIA_TYPE_TEXT = "text";
+
+    private static final String MEDIA_TYPE_MESSAGE = "message";
+
+    private static final String EMAIL_MESSAGE_MIME_TYPE = MEDIA_TYPE_MESSAGE + "/" + SUB_TYPE_EMAIL;
+
+    private static final String DEFAULT_SUB_TYPE = "plain";
+
+    private static final String DEFAULT_MEDIA_TYPE = MEDIA_TYPE_TEXT;
+
+    private static final String DEFAULT_MIME_TYPE = DEFAULT_MEDIA_TYPE + "/" + DEFAULT_SUB_TYPE;
+
     private static Log log = LogFactory.getLog(DefaultBodyDescriptor.class);
     
-    private String mimeType = "text/plain";
+    private String mediaType = DEFAULT_MEDIA_TYPE;
+    private String subType = DEFAULT_SUB_TYPE;
+    private String mimeType = DEFAULT_MIME_TYPE;
     private String boundary = null;
     private String charset = "us-ascii";
     private String transferEncoding = "7bit";
@@ -59,9 +75,13 @@
      */
     public DefaultBodyDescriptor(BodyDescriptor parent) {
         if (parent != null && MimeUtil.isSameMimeType("multipart/digest", parent.getMimeType()))
{
-            mimeType = "message/rfc822";
+            mimeType = EMAIL_MESSAGE_MIME_TYPE;
+            subType = SUB_TYPE_EMAIL;
+            mediaType = MEDIA_TYPE_MESSAGE;
         } else {
-            mimeType = "text/plain";
+            mimeType = DEFAULT_MIME_TYPE;
+            subType = DEFAULT_SUB_TYPE;
+            mediaType = DEFAULT_MEDIA_TYPE;
         }
     }
     
@@ -110,13 +130,15 @@
             Map params = MimeUtil.getHeaderParams(sb.toString());
             
             String main = (String) params.get("");
+            String type = null;
+            String subtype = null;
             if (main != null) {
                 main = main.toLowerCase().trim();
                 int index = main.indexOf('/');
                 boolean valid = false;
                 if (index != -1) {
-                    String type = main.substring(0, index).trim();
-                    String subtype = main.substring(index + 1).trim();
+                    type = main.substring(0, index).trim();
+                    subtype = main.substring(index + 1).trim();
                     if (type.length() > 0 && subtype.length() > 0) {
                         main = type + "/" + subtype;
                         valid = true;
@@ -125,6 +147,8 @@
                 
                 if (!valid) {
                     main = null;
+                    type = null;
+                    subtype = null;
                 }
             }
             String b = (String) params.get("boundary");
@@ -134,6 +158,8 @@
                             || !main.startsWith("multipart/"))) {
                 
                 mimeType = main;
+                this.subType = subtype;
+                this.mediaType = type;
             }
             
             if (MimeUtil.isMultipart(mimeType)) {
@@ -210,4 +236,12 @@
     public long getContentLength() {
         return contentLength;
     }
+
+    public String getMediaType() {
+        return mediaType;
+    }
+
+    public String getSubType() {
+        return subType;
+    }
 }

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java?rev=659953&r1=659952&r2=659953&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Message.java Sun May
25 03:22:48 2008
@@ -168,11 +168,12 @@
         /**
          * @see org.apache.james.mime4j.ContentHandler#startMultipart(org.apache.james.mime4j.BodyDescriptor)
          */
-        public void startMultipart(BodyDescriptor bd) {
+        public void startMultipart(final BodyDescriptor bd) {
             expect(Entity.class);
             
-            Entity e = (Entity) stack.peek();
-            Multipart multiPart = new Multipart();
+            final Entity e = (Entity) stack.peek();
+            final String subType = bd.getSubType();
+            final Multipart multiPart = new Multipart(subType);
             e.setBody(multiPart);
             stack.push(multiPart);
         }

Modified: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Multipart.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Multipart.java?rev=659953&r1=659952&r2=659953&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Multipart.java (original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/message/Multipart.java Sun May
25 03:22:48 2008
@@ -50,12 +50,13 @@
     private String epilogue = "";
     private List bodyParts = new LinkedList();
     private Entity parent = null;
-    private String subType = "alternative";
+    private String subType;
 
     /**
      * Creates a new empty <code>Multipart</code> instance.
      */
-    public Multipart() {
+    public Multipart(String subType) {
+        this.subType = subType;
     }
 
     /**

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java?rev=659953&r1=659952&r2=659953&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java (original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java Sun May 25 03:22:48
2008
@@ -207,7 +207,7 @@
     public static final String MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_END = 
             "\r\n--1729--\r\n";
     
-    public static final String MIME_MIXED_ALTERNATIVE = 
+    public static final String MIME_MULTIPART_ALTERNATIVE = 
         "From: Timothy Tayler <timothy@example.org>\r\n" +
         "To: Samual Smith <samual@example.org>\r\n" +
         "Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
@@ -238,7 +238,7 @@
         EncodeUtils.toBase64(ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BASE64)),
         ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_END),
     };
-    public static final byte[] MIME_MIXED_ALTERNATIVE_BYTES = ascii(MIME_MIXED_ALTERNATIVE);
+    public static final byte[] MIME_MULTIPART_ALTERNATIVE_BYTES = ascii(MIME_MULTIPART_ALTERNATIVE);
     public static final byte[] MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BYTES = join(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BYTE_ARRAYS);
     public static final byte[] ONE_PART_MIME_QUOTED_PRINTABLE_ASCII_BYTES = ascii(ONE_PART_MIME_QUOTED_PRINTABLE_ASCII);
     public static final byte[] ONE_PART_MIME_BASE64_LATIN1_BYTES = join(ascii(ONE_PART_MIME_BASE64_LATIN1_HEADERS),
ONE_PART_MIME_BASE64_LATIN1_ENCODED);

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamBodyDescriptorTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamBodyDescriptorTest.java?rev=659953&r1=659952&r2=659953&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamBodyDescriptorTest.java
(original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MimeTokenStreamBodyDescriptorTest.java
Sun May 25 03:22:48 2008
@@ -29,7 +29,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         parser = new MimeTokenStream();
-        parser.parse(new ByteArrayInputStream(ExampleMail.MIME_MIXED_ALTERNATIVE_BYTES));
+        parser.parse(new ByteArrayInputStream(ExampleMail.MIME_MULTIPART_ALTERNATIVE_BYTES));
     }
 
     protected void tearDown() throws Exception {

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java?rev=659953&r1=659952&r2=659953&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java
(original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/message/MessageCompleteMailTest.java
Sun May 25 03:22:48 2008
@@ -34,11 +34,18 @@
         super.tearDown();
     }
     
+    public void testMultipartAlternative() throws Exception {
+        Message message = createMessage(ExampleMail.MIME_MULTIPART_ALTERNATIVE_BYTES);
+        assertTrue("Should be a multipart/alternative mail", message.isMultipart());
+        Multipart part = (Multipart)message.getBody();
+        assertEquals("alternative", part.getSubType());
+    }    
+    
     public void testMultipartMixed() throws Exception {
-        Message message = createMessage(ExampleMail.MIME_MIXED_ALTERNATIVE_BYTES);
+        Message message = createMessage(ExampleMail.MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BYTES);
         assertTrue("Should be a multipart/mixed mail", message.isMultipart());
-//        Multipart part = (Multipart)message.getBody();
-//        assertEquals("mixed", part.getSubType());
+        Multipart part = (Multipart)message.getBody();
+        assertEquals("mixed", part.getSubType());
     }
     
     private Message createMessage(byte[] octets) throws Exception {

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=659953&r1=659952&r2=659953&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
Sun May 25 03:22:48 2008
@@ -45,7 +45,7 @@
                 Field.parse("Content-Type: multipart/form-data; boundary=foo"));
         message.setHeader(header);
         
-        Multipart multipart = new Multipart();
+        Multipart multipart = new Multipart("alternative");
         multipart.setParent(message);
         BodyPart p1 = new BodyPart();
         Header h1 = new Header();



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message