// Insert a new text/plain body part after every body part of the
// template.
final int count = multipart.getCount();
for (int i = 0; i < count; i++) {
String text = "Text inserted after part " + (i + 1);
BodyPart bodyPart = createTextPart(text);
multipart.addBodyPart(bodyPart, 2 * i + 1);
}
// For no particular reason remove the second binary body part (now
// at index four).
BodyPart removed = multipart.removeBodyPart(4);
// The removed body part no longer has a parent entity it belongs to so
// it should be disposed of.
removed.dispose();
// Set some headers on the transformed message
message.createMessageId(HOSTNAME);
message.setSubject("Transformed message");
message.setDate(new Date());