עבודה עם קבצי 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 מה זה. ה‑returned 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();