Camel
  1. Camel
  2. CAMEL-4083

MailBinding may drop characters from content type when using determineContentType option

    Details

      Description

      The method "determineContentType" in the MailBinding class may drop characters from the end of the Content-Type header (specifically ending quotes).

      Example:

      Take the following SMINE enveloped data content type:

         Content-Type: application/pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"
      

      When an incoming Exchange is processed by the mail Component with the above content type header, the resulting content type after the determineContentType is application/pkcs7-mime; smime-type=enveloped-data; name="smime.p7m (note the ending quote). This results in a parsing error later on the processing chain. The following simple unit test demonstrates the issue as it fails on the assertEquals call.

      -----------------------------------------------------------------------------------------------------

      package org.apache.camel.component.mail;
      
      import org.apache.camel.CamelContext;
      import org.apache.camel.impl.DefaultExchange;
      import org.junit.Test;
      import static org.junit.Assert.assertEquals;
      
      public class ContentTypeTest
      {
          @Test
          public void testDetermineContentType_endingWithQuotes_assertContentMatches()
          {
          	final String contentType = "application/pkcs7-mime; smime-type=enveloped-data; name=\"smime.p7m\""; 
          	
          	final MailConfiguration configuration = new MailConfiguration();
          	final MailBinding binding = new MailBinding();
          	
          	final DefaultExchange exchange = new DefaultExchange((CamelContext)null);
          	exchange.getIn().setHeader("Content-Type", contentType);
          	
          	
          	String determinedType = binding.determineContentType(configuration, exchange);
          	
          	assertEquals(contentType, determinedType);
          }
      }
      

        Activity

        Greg Meyer created issue -
        Claus Ibsen made changes -
        Field Original Value New Value
        Summary MailBinding creating invalid content type MailBinding may drop characters from content type when using determineContentType option
        Fix Version/s 2.8.0 [ 12316226 ]
        Fix Version/s 2.9.0 [ 12316374 ]
        Fix Version/s 2.7.2 [ 12316478 ]
        Description The method "determineContentType" in the MailBinding class may drop characters from the end of the Content-Type header (specifically ending quotes).

        Example:

        Take the following SMINE enveloped data content type:

           Content-Type: application/pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"

        When an incoming Exchange is processed by the mail Component with the above content type header, the resulting content type after the determineContentType is application/pkcs7-mime; smime-type=enveloped-data; name="smime.p7m (note the ending quote). This results in a parsing error later on the processing chain. The following simple unit test demonstrates the issue as it fails on the assertEquals call.

        -----------------------------------------------------------------------------------------------------
        package org.apache.camel.component.mail;

        import org.apache.camel.CamelContext;
        import org.apache.camel.impl.DefaultExchange;
        import org.junit.Test;
        import static org.junit.Assert.assertEquals;

        public class ContentTypeTest
        {
            @Test
            public void testDetermineContentType_endingWithQuotes_assertContentMatches()
            {
             final String contentType = "application/pkcs7-mime; smime-type=enveloped-data; name=\"smime.p7m\"";
            
             final MailConfiguration configuration = new MailConfiguration();
             final MailBinding binding = new MailBinding();
            
             final DefaultExchange exchange = new DefaultExchange((CamelContext)null);
             exchange.getIn().setHeader("Content-Type", contentType);
            
            
             String determinedType = binding.determineContentType(configuration, exchange);
            
             assertEquals(contentType, determinedType);
            }
        }
        The method "determineContentType" in the MailBinding class may drop characters from the end of the Content-Type header (specifically ending quotes).

        Example:

        Take the following SMINE enveloped data content type:
        {code}
           Content-Type: application/pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"
        {code}

        When an incoming Exchange is processed by the mail Component with the above content type header, the resulting content type after the determineContentType is application/pkcs7-mime; smime-type=enveloped-data; name="smime.p7m (note the ending quote). This results in a parsing error later on the processing chain. The following simple unit test demonstrates the issue as it fails on the assertEquals call.

        -----------------------------------------------------------------------------------------------------
        {code}
        package org.apache.camel.component.mail;

        import org.apache.camel.CamelContext;
        import org.apache.camel.impl.DefaultExchange;
        import org.junit.Test;
        import static org.junit.Assert.assertEquals;

        public class ContentTypeTest
        {
            @Test
            public void testDetermineContentType_endingWithQuotes_assertContentMatches()
            {
             final String contentType = "application/pkcs7-mime; smime-type=enveloped-data; name=\"smime.p7m\"";
            
             final MailConfiguration configuration = new MailConfiguration();
             final MailBinding binding = new MailBinding();
            
             final DefaultExchange exchange = new DefaultExchange((CamelContext)null);
             exchange.getIn().setHeader("Content-Type", contentType);
            
            
             String determinedType = binding.determineContentType(configuration, exchange);
            
             assertEquals(contentType, determinedType);
            }
        }
        {code}
        Claus Ibsen made changes -
        Assignee Claus Ibsen [ davsclaus ]
        Hide
        Claus Ibsen added a comment -

        Yeah the logic seems a bit misleading. It mistakenly looks for charset, without checking that the key is charset=xxx in the Content-Type.

        Show
        Claus Ibsen added a comment - Yeah the logic seems a bit misleading. It mistakenly looks for charset, without checking that the key is charset=xxx in the Content-Type.
        Claus Ibsen made changes -
        Fix Version/s 2.9.0 [ 12316374 ]
        Claus Ibsen made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Daniel Kulp made changes -
        Fix Version/s 2.7.3 [ 12316520 ]
        Daniel Kulp made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        1d 20h 48m 1 Claus Ibsen 12/Jun/11 11:01
        Resolved Resolved Closed Closed
        135d 34m 1 Daniel Kulp 25/Oct/11 11:35

          People

          • Assignee:
            Claus Ibsen
            Reporter:
            Greg Meyer
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development