使用Java API从Lotus Notes NSF文件中提取电子邮件消息
我想使用Java API(Notes.jar),我正在运行安装了Lotus Notes 8.5的Windows机器。
我对Lotus Notes一无所知,我只需要做一个简单的任务:从NSF文件中提取电子邮件。 我希望能够遍历所有电子邮件消息,获取元数据(From,To,Cc等)或原始MIME(如果可用)。
我已经搜索了很多,但我没有找到任何直接的东西,而不需要一些重要的Lotus Notes领域专业知识。
一些示例代码让我开始将非常感谢。 谢谢!
更新:我发现了一个在Python中执行此操作的开源项目:
http://code.google.com/p/nlconverter/
但是,仍然在寻找一种在Java中执行此操作的方法。
您可以编写一个简单的Java应用程序来获取您感兴趣的邮件数据库的句柄,然后获取该数据库中标准视图的句柄,然后迭代视图中的文档。 这是一些(粗略的)示例代码:
import lotus.domino.*; public class sample extends NotesThread { public static void main(String argv[]) { sample mySample = new sample(); mySample.start(); } public void runNotes() { try { Session s = NotesFactory.createSession(); Database db = s.getDatabase ("Server", "pathToMailDB.nsf"); View vw = db.getView ("By Person"); // this view exists in r8 mail template; may need to change for earlier versions Document doc = vw.getFirstDocument(); while (doc != null) { System.out.println (doc.getItemValueString("Subject")); doc = vw.getNextDocument(doc); } } catch (Exception e) { e.printStackTrace(); } } }
getItemValueString
方法获取给定的“字段”值。 邮件文档上的其他重要字段包括:From,SendTo,CopyTo,BlindCopyTo,Subject,Body和DeliveredDate。 请注意,Body是Notes“富文本”项, getItemValueString
将返回纯文本部分。 DeliveredDate是一个NotesDate项,您需要使用getItemValueDateTimeArray
方法。
对于未来的搜索者在Linux或Windows中,您可以设法以纯文本格式读取NSF文件
使用strings命令的示例用法:
strings file.nsf
当然,您可以使用优先语言以二进制模式打开文件并解析输出
注意:不需要IBM Lotus Notes或Domino。