使用 IBM Notes(NSF)文件

IBM Notes(现为 HCL Notes)将邮件、日历条目和应用程序数据保存在 NSF 数据库中——即 Notes 存储设施格式。Aspose.Email for C++ 能识别此类数据库,并通过 NotesStorageFacility 类的 Aspose::Email::Storage::Nsf 命名空间。无需 Notes 客户端或 Domino 服务器。

以下示例使用以下头文件和命名空间:

#include <MailMessage.h>
#include <SaveOptions.h>
#include <EmlSaveOptions.h>
#include <Storage/Nsf/NotesStorageFacility.h>
#include <Tools/FileFormat/FileFormatUtil.h>
#include <Tools/FileFormat/FileFormatInfo.h>
#include <Tools/FileFormat/FileFormatType.h>
#include <system/io/file.h>
#include <system/io/directory.h>
#include <system/convert.h>

using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Tools;
using namespace Aspose::Email::Storage::Nsf;

检测 NSF 格式

在打开来源未知的文件之前,先询问 FileFormatUtil::DetectFileFormat 它是什么。返回的 FileFormatInfo 报告 FileFormatType::Nsf 用于 Notes 数据库。

SharedPtr<FileFormatInfo> info = FileFormatUtil::DetectFileFormat(u"SampleNSF.nsf");

if (info->get_FileFormatType() == FileFormatType::Nsf)
{
    Console::WriteLine(u"The file is an IBM Notes storage (NSF).");
}

读取消息

使用 NotesStorageFacility 构造函数 - 文件路径或流,可选地带有 NsfLoadOptions - 并遍历 EnumerateMessages。每个项目都作为一个 MailMessage,因此主题、地址、正文和附件与 EML 文件完全一致。

SharedPtr<NotesStorageFacility> nsf = MakeObject<NotesStorageFacility>(u"SampleNSF.nsf");

// messages come out one by one as regular MailMessage objects
for (SharedPtr<MailMessage> eml : nsf->EnumerateMessages())
{
    Console::WriteLine(eml->get_Subject());
}

nsf->Dispose();

从流导出消息

当数据库不在本地磁盘时,流构造函数很有用。示例读取消息并将每条存储为 EML 文件;任何其他 SaveOptions - MSG、MHTML、HTML - 将以相同方式工作。

SharedPtr<IO::FileStream> stream = IO::File::OpenRead(u"SampleNSF.nsf");
SharedPtr<NotesStorageFacility> nsf = MakeObject<NotesStorageFacility>(stream);

IO::Directory::CreateDirectory_(u"NsfExport");
int32_t index = 0;

for (SharedPtr<MailMessage> eml : nsf->EnumerateMessages())
{
    // any MailMessage output format is available: EML, MSG, MHTML...
    eml->Save(String::Format(u"NsfExport\\message_{0}.eml", index++), SaveOptions::get_DefaultEml());
}

Console::WriteLine(u"Exported messages: " + Convert::ToString(index));

nsf->Dispose();
stream->Close();