Làm việc với các tệp IBM Notes (NSF)
IBM Notes (hiện là HCL Notes) lưu trữ thư, mục lịch và dữ liệu ứng dụng trong các cơ sở dữ liệu NSF - định dạng Notes Storage Facility. Aspose.Email cho C++ có thể nhận dạng cơ sở dữ liệu này và lấy các tin nhắn ra thông qua NotesStorageFacility lớp của Aspose::Email::Storage::Nsf không gian tên. Không cần khách hàng Notes hay máy chủ Domino.
Các mẫu dưới đây sử dụng các tiêu đề và không gian tên sau:
#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;
Phát hiện Định dạng NSF
Trước khi mở một tệp có nguồn gốc không rõ, hãy hỏi FileFormatUtil::DetectFileFormat cái nó là. Giá trị trả về FileFormatInfo báo cáo FileFormatType::Nsf cho một cơ sở dữ liệu 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).");
}
Đọc các Tin Nhắn
Mở cơ sở dữ liệu bằng một NotesStorageFacility bộ khởi tạo - một đường dẫn tệp hoặc một stream, tùy chọn với NsfLoadOptions - và lặp qua EnumerateMessages. Mỗi mục được cung cấp dưới dạng một MailMessage, vì vậy chủ đề, địa chỉ, nội dung và tệp đính kèm có sẵn chính xác như một tệp 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();
Xuất các Tin Nhắn từ Stream
Bộ khởi tạo stream hữu ích khi cơ sở dữ liệu không ở trên đĩa cục bộ. Ví dụ này đọc các tin nhắn và lưu mỗi tin dưới dạng tệp EML; bất kỳ thiết lập nào khác SaveOptions - MSG, MHTML, HTML - sẽ hoạt động theo cùng cách.
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();