使用 Java API 从 Lotus Notes NSF 文件中提取电子邮件消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1610055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 17:16:38  来源:igfitidea点击:

Extracting email messages from a Lotus Notes NSF file using Java API

javalotus-notes

提问by bajafresh4life

I'd like to use the Java API (Notes.jar), and I'm running a Windows box with Lotus Notes 8.5 installed.

我想使用 Java API (Notes.jar),并且我正在运行安装了 Lotus Notes 8.5 的 Windows 机器。

I know nothing about Lotus Notes, and I only need to do this one narrow task: extracting email messages from an NSF file. I want to be able to iterate through all the email messages, grab the metadata (From, To, Cc, etc) or the raw MIME if available.

我对 Lotus Notes 一无所知,我只需要完成一项狭窄的任务:从 NSF 文件中提取电子邮件消息。我希望能够遍历所有电子邮件,获取元数据(发件人、收件人、抄送等)或原始 MIME(如果可用)。

I've googled around quite a bit, but I haven't found anything straightforward without requiring some significant Lotus Notes domain expertise.

我已经在谷歌上搜索了很多,但我没有找到任何不需要一些重要的 Lotus Notes 领域专业知识的简单方法。

Some sample code to get me started would be greatly appreciated. Thanks!

一些让我开始的示例代码将不胜感激。谢谢!

UPDATE: I found an open source project that does this in Python:

更新:我发现了一个用 Python 执行此操作的开源项目:

http://code.google.com/p/nlconverter/

http://code.google.com/p/nlconverter/

However, still looking for a way to do this in Java.

但是,仍在寻找一种在 Java 中执行此操作的方法。

回答by Ed Schembor

You can write a simple Java app which gets a handle to the mail database you are interested in, then gets a handle to a standard view in that database, and then iterates over the documents in the view. Here is some (rough) sample code:

您可以编写一个简单的 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();
      }
    }
}

The getItemValueStringmethod gets a given "field" value. Other important fields on a mail document are: From, SendTo, CopyTo, BlindCopyTo, Subject, Body and DeliveredDate. Note that Body is a Notes "rich text" item, and getItemValueStringwill return the text-only portion. DeliveredDate is a NotesDate item, and you would need to use the getItemValueDateTimeArraymethod for that.

getItemValueString方法获取给定的“字段”值。邮件文档上的其他重要字段是:From、SendTo、CopyTo、BlindCopyTo、Subject、Body 和 DeliveredDate。请注意,正文是 Notes 的“富文本”项目,getItemValueString将返回纯文本部分。DeliveredDate 是一个 NotesDate 项目,您需要为此使用该getItemValueDateTimeArray方法。

回答by Marware

For future searchers In Linux or Windows you can manage to read the NSF file as plain text

对于未来的搜索者在 Linux 或 Windows 中,您可以设法以纯文本形式阅读 NSF 文件

Example usage using strings command:

使用字符串命令的示例用法:

strings file.nsf

Of course you can open the file in binary mode in your preffered language and parse the output

当然,您可以使用首选语言以二进制模式打开文件并解析输出

Note: Doesn't need IBM Lotus Notes or Domino.

注意:不需要 IBM Lotus Notes 或 Domino。