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

拈花ヽ惹草 提交于 2019-12-03 17:28:39
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:

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 getItemValueString method 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 getItemValueString will return the text-only portion. DeliveredDate is a NotesDate item, and you would need to use the getItemValueDateTimeArray method for that.

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

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!