Software AG Products 10.7 | Integrating On-Premises and Cloud Applications | Managing MIME messages | Extracting Data from MIME and S/MIME Messages | Extracting the Payload from a MIME Message | How to Extract the Payload from a MIME Message
 
How to Extract the Payload from a MIME Message
The following procedure describes the general steps you take to extract data from a MIME message.
1. Place the MIME message in the pipeline as an InputStream or a MimeMessage. For the Integration Server services to work with a MIME message, the message must be passed into the pipeline as an InputStream or a MimeMessage. If your solution acquires the MIME message in another form (such as a String or a byte[]) you must convert it to an InputStream before running the MIME services against it.
Note:
The way in which you acquire a MIME message and put it in the pipeline will depend on your particular solution. You might retrieve it from a back-end system, you might read it from a file, or you might receive it from a custom content handler. Regardless of how you acquire the message, it must be in the form of an InputStream or a MimeMessage to be able to use it with the MIME services.
2. Convert the MIME message to a MIME object using the pub.mime:createMimeData service. Pass the InputStream or MimeMessage containing the MIME message to createMimeData. This service returns a MIME object called mimeData that contains the message’s constituent elements (header fields and content). It also returns a set of values indicating whether the enclosed message is encrypted or digitally signed. (For information about extracting information from an encrypted and/or signed MIME message, see Extracting the Payload from a Signed MIME Message and Extracting the Payload from a MIME Message.
Important:
The MIME object that the createMimeData service returns is an IData object whose contents you can examine during testing and debugging. However, the internal structure of this object is subject to change in future versions of Integration Server. To extract content from a MIME object, you must always use the MIME services that Integration Server provides for this purpose. Do not explicitly map data from the elements in the MIME object with the pipeline editor.
3. Extract the payload from the MIME object using the pub.mime:getBodyPartContent service. This service takes as input the MIME object that you created in the previous step 2. If the message contains multiple parts, you can use the index or contentID parameter to specify which part you want to retrieve, where:
*index is a String that specifies the index number (that is, position number) of the part whose content you want to retrieve. (Index 0 is the first part, Index 1 is the second part, and so forth.)
*contentID is a String that specifies the value of the content-ID header whose content you want to retrieve. For example, if you wanted to retrieve the content of from the part with the “content-ID: AJ9994388-0500,” you would set contentID to “AJ9994388-0500.”
If you do not specify index or contentID, getBodyPartContent returns the content from the first body part in the message.
The content of the requested body part is returned as an InputStream named content.