Xpages 如何避免MIME导出中的额外换行?
我正在导出具有以下代码的MIME电子邮件:Xpages 如何避免MIME导出中的额外换行?,xpages,lotus-notes,mime,Xpages,Lotus Notes,Mime,我正在导出具有以下代码的MIME电子邮件: public String fromRawMime(final Session s, final Document doc) throws NotesException { final Stream notesStream = s.createStream(); final MIMEEntity rootMime = doc.getMIMEEntity(); // check if it is
public String fromRawMime(final Session s, final Document doc) throws NotesException {
final Stream notesStream = s.createStream();
final MIMEEntity rootMime = doc.getMIMEEntity();
// check if it is multi-part or single
if (rootMime.getContentType().equals("multipart")) {
this.printMIME(rootMime, notesStream);
} else {
// We can just write the content into the
// Notes stream to get the bytes
rootMime.getEntityAsText(notesStream);
}
// Write it out
notesStream.setPosition(0);
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.append(notesStream.read());
notesStream.close();
notesStream.recycle();
rootMime.recycle();
return out.toString();
}
// Write out a mime entry to a Stream object, includes sub entries
private void printMIME(final MIMEEntity mimeRoot, final Stream out) throws NotesException {
if (mimeRoot == null) {
return;
}
// Encode binary as base64
if (mimeRoot.getEncoding() == MIMEEntity.ENC_IDENTITY_BINARY) {
mimeRoot.decodeContent();
mimeRoot.encodeContent(MIMEEntity.ENC_BASE64);
}
out.writeText(mimeRoot.getBoundaryStart(), Stream.EOL_NONE);
mimeRoot.getEntityAsText(out);
out.writeText(mimeRoot.getBoundaryEnd(), Stream.EOL_NONE);
if (mimeRoot.getContentType().equalsIgnoreCase("multipart")) {
// Print preamble if it isn't empty
final String preamble = mimeRoot.getPreamble();
if (!preamble.isEmpty()) {
out.writeText(preamble, Stream.EOL_NONE);
}
// Print content of each child entity - recursive calls
// Include recycle of mime elements
MIMEEntity mimeChild = mimeRoot.getFirstChildEntity();
while (mimeChild != null) {
this.printMIME(mimeChild, out);
final MIMEEntity mimeNext = mimeChild.getNextSibling();
// Recycle to ensure we don't bleed memory
mimeChild.recyle();
mimeChild = mimeNext;
}
}
}
结果每行包含一个空行。包括使用
getEntityAsText
添加的内容。要去掉多余的行,我缺少什么?电子邮件RFC需要使用CRLF来终止文本行
您使用的是EOL_NONE,因此writeText方法没有向文本添加任何内容,但显然CR和LF都被视为输出中的换行符。您可能想尝试将out.writeText与EOL_平台一起使用。魔鬼就在细节中
printMIME
函数工作正常。更改EOL没有产生影响。不过,我后来添加了EOL_平台,以便最终将标题与内容分开
违规代码如下:
notesStream.setPosition(0);
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.append(notesStream.read());
notesStream.close();
事实证明,它似乎将MIME中的任何内容解释为两行提要。因此,代码需要更改为:
notesStream.setPosition(0);
String out = notesStream.readText();
notesStream.close();
因此,我需要的不是OutputStream
而是String
,而不是read()
我需要readText()
。现在在我的“城堡计划”中愉快地工作着out.append(notesStream.read());不接受EOL*参数,这是我的主要问题。我的意思是:getEntityAsText(out)不接受EOL*参数-这就是问题所在