Работа с файлами IBM Notes (NSF)
IBM Notes (теперь HCL Notes) хранит почту, записи календаря и данные приложений в базах NSF — формате Notes Storage Facility. Aspose.Email для 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();