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 | Example—Extracting All Parts from a Multipart MIME Message
 
Example—Extracting All Parts from a Multipart MIME Message
The following flow service shows how you might process each part in a multipart MIME message sequentially. This example receives a multipart MIME message containing a unknown number of body parts. After discovering the number of body parts, the example uses a REPEAT block to extract the payload from each part.
Flow service that extracts the content from multiple parts
Note:
This example is only for those messages that are within the threshold value specified by the watt.server.mime.largeDataThreshold configuration parameter.
Step
Description
1
This step acquires a MIME message. This example uses a helper service that generates a three-part MIME message and puts it in the pipeline as an InputStream call envStream. In a production solution, it is more likely that a MIME message would be passed into the pipeline by a content handler or a back-end system.
2
This step takes the MIME message and creates a MIME object (mimeData) containing the message’s headers and content. If you view the pipeline, you will note that the InputStream produced by step 1 is linked to this step’s input variable.
3
This step inspects the mimeData object and returns the number of body parts (in this case 3) in a String called numParts.
4
This step sets the following variables that are used by the REPEAT block:
Variable
Value
Purpose
RepeatCounter
numParts-1
Sets the counter that specifies the number of times the REPEAT block needs to re-execute. Since a REPEAT block always executes once, this counter is set to one number less than the total number of body parts in the message.
PartIndex
0
Initializes the pointer that is used to step through the body parts in this message.
5
This REPEAT block does the following for each body part in mimeData:
1. Extracts the content
2. Converts the retrieved content to a String
3. Appends that String to a String list
The last step in the block increments PartIndex. If you view the pipeline, you will see that this variable is linked to the index parameter for the getBodyPartContent service.
6
This step drops unnecessary variables, leaving only the populated String list in the pipeline.