Praca z plikami IBM Notes (NSF)

IBM Notes (obecnie HCL Notes) przechowuje pocztę, wpisy kalendarza i dane aplikacji w bazach NSF – w formacie Notes Storage Facility. Aspose.Email dla C++ potrafi rozpoznać taką bazę i wyciągnąć z niej wiadomości pocztowe poprzez NotesStorageFacility klasa Aspose::Email::Storage::Nsf przestrzeń nazw. Nie wymaga klienta Notes ani serwera Domino.

Przykłady poniżej używają następujących nagłówków i przestrzeni nazw:

#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;

Wykryj format NSF

Przed otwarciem pliku nieznanego pochodzenia, poproś FileFormatUtil::DetectFileFormat co to jest. Zwrócony FileFormatInfo raporty FileFormatType::Nsf dla bazy danych 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).");
}

Odczytaj wiadomości

Otwórz bazę danych za pomocą NotesStorageFacility konstruktor - ścieżka do pliku lub strumień, opcjonalnie z NsfLoadOptions - i iteruj po EnumerateMessages. Każdy element jest dostarczany jako MailMessage, tak więc temat, adresy, treść i załączniki są dostępne dokładnie tak, jak w pliku 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();

Eksportuj wiadomości ze strumienia

Konstruktor strumienia jest przydatny, gdy baza danych nie znajduje się na lokalnym dysku. Przykład odczytuje wiadomości i zapisuje każdą jako plik EML; każdy inny SaveOptions - MSG, MHTML, HTML - działałoby w ten sam sposób.

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();