You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2016/04/28 22:46:10 UTC

svn commit: r1741514 - /webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java

Author: veithen
Date: Thu Apr 28 20:46:10 2016
New Revision: 1741514

URL: http://svn.apache.org/viewvc?rev=1741514&view=rev
Log:
Correctly identify the root part of a MIME message.

Modified:
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java?rev=1741514&r1=1741513&r2=1741514&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java Thu Apr 28 20:46:10 2016
@@ -62,7 +62,7 @@ class MIMEMessage {
 
     /** <code>ContentType</code> of the MIME message */
     private final ContentType contentType;
-    
+    private final String rootPartContentID;
     private final MimeTokenStream parser;
     
     /**
@@ -100,6 +100,9 @@ class MIMEMessage {
                     , e);
         }
 
+        String start = contentType.getParameter("start");
+        rootPartContentID = start == null ? null : Util.normalizeContentID(start);
+
         MimeConfig config = new MimeConfig();
         config.setStrictParsing(true);
         parser = new MimeTokenStream(config);
@@ -159,19 +162,14 @@ class MIMEMessage {
     }
 
     String getRootPartContentID() {
-        String rootContentID = contentType.getParameter("start");
-        if (log.isDebugEnabled()) {
-            log.debug("getRootPartContentID rootContentID=" + rootContentID);
-        }
-
         // to handle the Start parameter not mentioned situation
-        if (rootContentID == null) {
+        if (rootPartContentID == null) {
             if (attachmentsMap.isEmpty()) {
                 getNextPartDataHandler();
             }
             return firstPartId;
         } else {
-            return Util.normalizeContentID(rootContentID);
+            return rootPartContentID;
         }
     }
     
@@ -237,7 +235,8 @@ class MIMEMessage {
         if (parser.getState() == EntityState.T_END_MULTIPART) {
             return null;
         } else {
-            boolean isRootPart = attachmentsMap.isEmpty();
+            String partContentID = null;
+            boolean isRootPart;
 
             try {
                 checkParserState(parser.next(), EntityState.T_START_HEADER);
@@ -252,10 +251,24 @@ class MIMEMessage {
                         log.debug("addHeader: (" + name + ") value=(" + value +")");
                     }
                     headers.add(new Header(name, value));
+                    if (partContentID == null && name.equalsIgnoreCase("Content-ID")) {
+                        partContentID = Util.normalizeContentID(value);
+                    }
                 }
                 
                 checkParserState(parser.next(), EntityState.T_BODY);
                 
+                if (rootPartContentID == null) {
+                    isRootPart = attachmentsMap.isEmpty();
+                } else {
+                    isRootPart = rootPartContentID.equals(partContentID);
+                }
+                
+                if (!isRootPart && partContentID == null) {
+                    throw new OMException(
+                            "Part content ID cannot be blank for non root MIME parts");
+                }
+                
                 currentPart = new PartImpl(isRootPart ? rootPartBlobFactory : attachmentBlobFactory, headers, parser);
             } catch (IOException ex) {
                 throw new OMException(ex);
@@ -263,7 +276,6 @@ class MIMEMessage {
                 throw new OMException(ex);
             }
 
-            String partContentID = currentPart.getContentID();
             if (partContentID == null & attachmentsMap.isEmpty()) {
                 String id = "firstPart_" + UIDGenerator.generateContentId();
                 firstPartId = id;
@@ -271,11 +283,6 @@ class MIMEMessage {
                 attachmentsMap.put(id, dataHandler);
                 return dataHandler;
             }
-            if (partContentID == null) {
-                throw new OMException(
-                        "Part content ID cannot be blank for non root MIME parts");
-            }
-            partContentID = Util.normalizeContentID(partContentID);
             if (attachmentsMap.isEmpty()) {
                 firstPartId = partContentID;
             }