我正在尝试使用.NET Domino互操作解析Lotus Notes中的MIME电子邮件。当电子邮件不是MIME格式时,我通过简单的NotesDocument.GetFirstItem("Body").Text;
子句成功获取了Body内容。但是对于MIME,当我尝试解析正文内容时,我会得到null或空字符串。
var session = new NotesSession();
session.Initialize("RadioLotus028");
session.ConvertMime = false;
var db = session.GetDatabase("PRGLNApps01/CZ/RFERL", "mail-in\\SEEurope\\MIA.nsf", false);
if (db == null) throw new ArgumentNullException("cannot load database");
var legnth = db.AllDocuments.Count;
for (int i = 1; i < legnth; i++)
{
NotesDocument doc = db.AllDocuments.GetNthDocument(i);
NotesMIMEEntity bodyMIME = doc.GetMIMEEntity();
NotesStream stream = session.CreateStream();
//bodyMIME.GetContentAsBytes(stream);
//bodyMIME.GetEntityAsText(stream);
bodyMIME.GetContentAsText(stream);
string bodyString = stream.ReadText();
var bodyString2 = stream.Read();
string bodyString3 = bodyMIME.ContentAsText;
var from = doc.GetFirstItem("From").Text;
var subject = doc.GetFirstItem("Subject").Text;
}
有没有人有这个问题的经验?或者如何将正文内容作为HTML或RichfullText或任何其他方式获取?
答案 0 :(得分:3)
您很可能需要找到子MIME实体。以下Java逻辑应该可以帮助您朝着正确的方向发展:
MIMEEntity mime = sourceDoc.getMIMEEntity(bodyField);
if (mime != null) {
// If multipart MIME entity
if (mime.getContentType().equals("multipart")) {
// Find text/html content of each child entity
MIMEEntity child1 = mime.getFirstChildEntity();
while (child1 != null) {
if (child1.getContentType().contains("text")) {
html = child1.getContentAsText();
}
MIMEEntity child2 = child1.getFirstChildEntity();
if (child2 == null) {
child2 = child1.getNextSibling();
if (child2 == null) {
child2 = child1.getParentEntity();
if (child2 != null) {
child2 = child2.getNextSibling();
}
}
}
child1 = child2;
}
} else {
// Not multipart
html = mime.getContentAsText();
}
}