Available as of Camel 2.17
This data format that can convert a Camel message with attachments into a Camel message having a MIME-Multipart message as message body (and no attachments).
The use case for this is to enable the user to send attachments over endpoints that do not directly support attachments, either as special protocol implementation (e.g. send a MIME-multipart over an HTTP endpoint) or as a kind of tunneling solution (e.g. because camel-jms does not support attachments but by marshalling the message with attachments into a MIME-Multipart, sending that to a JMS queue, receiving the message from the JMS queue and unmarshalling it again (into a message body with attachments).
The marshal option of the mime-multipart data format will convert a message with attachments into a MIME-Multipart message. If the parameter "multipartWithoutAttachment" is set to true it will also marshal messages without attachments into a multipart message with a single part, if the parameter is set to false it will leave the message alone.
MIME headers of the mulitpart as "MIME-Version" and "Content-Type" are set as camel headers to the message. If the parameter "headersInline" is set to true it will also create a MIME multipart message in any case.
Furthermore the MIME headers of the multipart are written as part of the message body, not as camel headers.
The unmarshal option of the mime-multipart data format will convert a MIME-Multipart message into a camel message with attachments and leaves other messages alone. MIME-Headers of the MIME-Multipart message have to be set as Camel headers. The unmarshalling will only take place if the "Content-Type" header is set to a "multipart" type. If the option "headersInline" is set to true, the body is always parsed as a MIME message.As a consequence if the message body is a stream and stream caching is not enabled, a message body that is actually not a MIME message with MIME headers in the message body will be replaced by an empty message. Up to Camel version 2.17.1 this will happen all message bodies that do not contain a MIME multipart message regardless of body type and stream cache setting.
|multipartWithoutAttachment||false||If set to true the marshal operation will create a multipart (with a single part) if the message does not contain any attachments. If this is set to false it will leave messages without attachments alone.|
If set to true the marshal operation will add the MIME headers of the Multipart as part of the message body and not as a camel header. In case of a unmarshal operations the MIME headers are assumed to be contained in the message body and the operation will always parse the message as MIME message.
Note: Any message is a valid MIME message, so the unmarshal operation with this parameter set to true will never result in an error. However if the parsing result does not contain any MIME part, starting with Camel 2.17.2 the unmarshaller tries to restore the original message. If this is not possible because the message body is a stream and stream caching is not enabled or with older Camel versions, the resulting message body is empty.
Note: If the headersInline parameter is set to "true", the message will also always be rendered into a MIME multipart regardless whether it has an attachment or not.
A regex that defines which Camel headers are also included as MIME headers into the MIME multipart. This will only work if headersInline is set to true.
|binaryContent||false||If set to true non-text content will be transferred in binary mode, if set to false (default) binary content will be transferred in base64 encoding. This is shorter but might not work for all transfer methods.|
|multipartSubType||mixed||The subtype of the generated MIME multipart. Other options are related, alternative, digest, or parallel. The data type does not enforce any semantics for these subtypes (so e.g. the user has to make sure that the first body part of a multipart/digest message is proper message/rfc822 data). The default mixed is usually a good choice.|
Message Headers (marshal)
|Message-Id||String||The marshal operation will set this parameter to the generated MIME message id if the "headersInline" parameter is set to false.|
|MIME-Version||String||The marshal operation will set this parameter to the applied MIME version (1.0) if the "headersInline" parameter is set to false.|
|Content-Type||String||The content of this header will be used as a content type for the message body part. If no content type is set, "application/octet-stream" is assumed. After the marshal operation the content type is set to "multipart/related" or empty if the "headersInline" parameter is set to true.|
|Content-Encoding||String||If the incoming content type is "text/*" the content encoding will be set to the encoding parameter of the Content-Type MIME header of the body part. Furthermore the given charset is applied for text to binary conversions.|
Message Headers (unmarshal)
|Content-Type||String||If this header is not set to "multipart/*" the unmarshal operation will not do anything. In other cases the multipart will be parsed into a camel message with attachments and the header is set to the Content-Type header of the body part, except if this is application/octet-stream. In the latter case the header is removed.|
|Content-Encoding||String||If the content-type of the body part contains an encoding parameter this header will be set to the value of this encoding parameter (converted from MIME endoding descriptor to Java encoding descriptor)|
|MIME-Version||String||The unmarshal operation will read this header and use it for parsing the MIME multipart. The header is removed afterwards|
With a message where no Content-Type header is set, will create a Message with the following message Camel headers:
The message body will be:
A message with the header Content-Type set to "text/plain" sent to the route
will create a message without any specific MIME headers set as Camel headers (the Content-Type header is removed from the Camel message) and the following message body that includes also all headers of the original message starting with "x-" and the header with name "included":
To use MIME-Multipart in your Camel routes you need to add a dependency on camel-mail which implements this data format.
If you use Maven you can just add the following to your pom.xml: