ทำงานกับไฟล์ 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();