gpt4 book ai didi

java - 带边界的 MimeMultipart 消息转储

转载 作者:行者123 更新时间:2023-12-02 04:50:25 25 4
gpt4 key购买 nike

我正在尝试使用如下代码记录 MimeMultipart 消息

MimeMultipart mimeMultipart = null;
try {
mimeMultipart = (MimeMultipart) msg.getContent();
} catch (IOException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
ByteArrayOutputStream outStream = new ByteArrayOutputStream();

for (int i = 0; i < mimeMultipart.getCount(); i++) {
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
String contentType = bodyPart.getContentType();
bodyPart.writeTo(outStream);
}

outStream.flush();
String content = new String(outStream.toByteArray());
LOGGER.info("Raw message: \r\n" + content);

但这看起来只是 MimeMultipart 消息的内容,而不是原始消息(缺少边界和 header )。

我也尝试过

msg.writeTo(outStream);
String content = outStream.toString();

但由于某种原因,它只是转储主消息 header ,但没有带有多部分 header 的正文部分,看起来像

Date: Fri, 31 May 2019 14:19:36 -0400 (EDT)
From: postmaster@dev.box.local
To: user@dev.box.local
Message-ID: <1293434275.167.1559326776862.JavaMail@devbox>
In-Reply-To: <984954674.27.1559326769277.JavaMail@devbox>
Subject: Re:
MIME-Version: 1.0
Content-Type: multipart/report;
boundary="----=_Part_166_602016356.1559326776861";
report-type=delivery-status

我做错了什么?

最佳答案

只需使用msg.writeTo(outStream);

关于java - 带边界的 MimeMultipart 消息转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56447240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com