私は自分のソリューションのコードを公開するために答えます:
// source is the encrypted MimeMessage
// MimeMessageWrapper is a wrapper which can copy a messgae but keep the message ID unchanged
boolean keepMessageId = true;
MimeMessageWrapper newMime = new MimeMessageWrapper(source, keepMessageId);
MimeMultipart mmp = new MimeMultipart("mixed");
List<MimePart> parts = MimeMultipartUtils.findPartsByMimeType(mime, "*");
for (MimePart part : parts) {
// Do some part processing
// Decrypt Adn verify individual parts
// End of processing
ContentType type = new ContentType(part.getContentType());
String encoding = part.getEncoding();
String name = type.getParameter("name");
part.setContent(new String(decPart.toByteArray()), type.toString());
// Add the part to the brand new MimeMultipart
mmp.addBodyPart((BodyPart) part);
}
// Set the original copy Message with the new modified content (decrypted parts)
mime.setContent(mmp);
mime.saveChanges();
実際、元のメッセージを変更する別の方法はないようですが、コピーを作成するだけで十分でした。重要な点は、復号化されたパーツを含み、コンテンツとしてMimeMessage(Wrapper)に渡される新しいMimeMultipartオブジェクトを作成することでした。これにより、新しいコンテンツタイプの値が「自動的に」生成されます。
参考までに、MimeMessageWrapperを使用しました。これは、メッセージIDをコピーに対して変更しない(または変更しない)ことができる単なるラッパークラスです。考えられる実装の1つは、ApacheJamesプロジェクトです。
もう1つの重要な点は、最終的にそのソリューションでは、基礎となる部分が変更されましたが、境界も調整されました(EncryptedXXXXとはもう言われていません)。これは、私たちの場合はさらにクリーンです。