소개
Aspose.Email FOSS for C++는 Outlook MSG 파일, RFC 5322 EML 메시지, 그리고 MSG 형식이 기반으로 하는 Compound File Binary (CFB) 컨테이너를 읽고, 만들고, 변환하기 위한 새로운 오픈 소스 라이브러리입니다. C++17로 작성되었으며 외부 런타임 의존성이 없고, CMake를 통해 Linux, macOS, Windows에서 빌드됩니다 — COM 의존성이 없으며 플랫폼별 코드 경로도 없습니다.
Outlook MSG 파일은 기업 통합 작업—아카이브 파이프라인, 마이그레이션 도구, 컴플라이언스 내보내기—에서 지속적으로 등장하지만, Outlook 없이 이를 읽는 것은 일반적으로 Windows에서의 COM 자동화 또는 상용 라이브러리를 의미했습니다. Aspose.Email FOSS for C++는 휴대 가능한 대안을 제공합니다: 일상적인 메시지 읽기와 생성을 위한 고수준 mapi_message 클래스와, 필요할 때 기본 컨테이너 형식에 직접 접근할 수 있는 저수준 msg_reader, msg_document, cfb_reader 클래스.
이 라이브러리는 MIT 라이선스 하에 C++17 소스로 배포되며, 프로젝트에 CMake 서브디렉터리로 추가되어 AsposeEmailFoss 타깃을 노출합니다 — 패키지 매니저 등록이나 미리 빌드된 바이너리가 필요하지 않습니다.
핵심 기능
Outlook MSG 파일 읽기
.msg 파일을 msg_reader::from_file() 또는 msg_reader::from_stream()로 엽니다. 메시지의 스토리지와 스트림에 직접 접근하려면, msg_document::from_reader()와 함께 msg_document에 리더를 래핑합니다.
#include "aspose/email/foss/msg/msg_reader.hpp"
#include "aspose/email/foss/msg/msg_document.hpp"
#include <filesystem>
namespace aef = aspose::email::foss;
auto reader = aef::msg::msg_reader::from_file(
std::filesystem::path("message.msg"), /*strict=*/false);
auto document = aef::msg::msg_document::from_reader(reader);
프로그래밍 방식으로 메시지 생성
mapi_message::create()는 제목과 본문으로 새로운 메모리 내 메시지를 생성합니다. 발신자를 설정하고, 수신자를 추가하며, 바이너리 또는 텍스트 페이로드를 첨부한 뒤 save()로 저장합니다.
#include "aspose/email/foss/msg/mapi_message.hpp"
#include <filesystem>
namespace aef = aspose::email::foss;
auto message = aef::msg::mapi_message::create(
"Quarterly status update", "Hello team,\n\nRollout summary attached.");
message.set_sender_name("Build Agent");
message.set_sender_email_address("build.agent@example.com");
message.add_recipient("alice@example.com", "Alice Example");
message.add_recipient("carol@example.com", "Carol Example",
aef::msg::mapi_message::recipient_type_cc);
message.add_attachment("report.txt", std::vector<std::uint8_t>{'o', 'k'}, "text/plain");
message.save(std::filesystem::path("output.msg"));
MSG와 EML 간 변환
mapi_message::save_to_eml()는 현재 메시지를 RFC 5322 EML 파일로 기록하고, mapi_message::load_from_eml()는 이를 다시 읽어들입니다. 양쪽 방향 모두 제목, 발신자, 수신자 및 첨부 파일을 보존하므로 Outlook 없이도 메시지를 MSG와 EML 사이에서 이동시킬 수 있습니다.
auto message = aef::msg::mapi_message::from_file(
std::filesystem::path("message.msg"), /*strict=*/false);
message.save_to_eml(std::filesystem::path("message.eml"));
auto restored = aef::msg::mapi_message::load_from_eml(std::filesystem::path("message.eml"));
restored.save(std::filesystem::path("restored.msg"));
메시지 속성 및 첨부 파일 검사
로드된 mapi_message는 표준 헤더 필드를 직접 노출합니다 — subject(), sender_name(), sender_email_address(), message_class(), 및 internet_message_id() — 그리고 recipients()와 attachments()을 mapi_recipient와 mapi_attachment의 벡터 형태로 제공합니다. 전용 접근자가 없는 MAPI 필드의 경우, get_property_value()은 common_message_property_id와 property_type_code를 통해 모든 속성을 읽어들입니다.
#include "aspose/email/foss/msg/mapi_message.hpp"
#include "aspose/email/foss/msg/common_message_property_id.hpp"
#include "aspose/email/foss/msg/property_type_code.hpp"
#include <iostream>
namespace aef = aspose::email::foss;
template <typename E>
constexpr auto to_underlying(E value) noexcept {
return static_cast<std::underlying_type_t<E>>(value);
}
auto message = aef::msg::mapi_message::from_file(
std::filesystem::path("message.msg"), /*strict=*/false);
std::cout << "Subject: " << message.subject() << '\n';
std::cout << "From: " << message.sender_name()
<< " <" << message.sender_email_address() << ">\n";
std::cout << "Recipients: " << message.recipients().size() << '\n';
for (const auto& attachment : message.attachments()) {
std::cout << "- " << attachment.filename
<< " (" << attachment.mime_type << ", "
<< attachment.data.size() << " bytes)\n";
}
const auto display_cc = message.get_property_value(
to_underlying(aef::msg::common_message_property_id::display_cc),
to_underlying(aef::msg::property_type_code::ptyp_string));
저수준 CFB 컨테이너 접근
MSG 파일은 복합 파일 바이너리(CFB) 컨테이너 내부에 저장됩니다 — 레거시 Office 바이너리 형식에서도 사용되는 구조화 저장 형식입니다. cfb_reader는 원시 컨테이너를 열고 디렉터리 트리를 직접 노출합니다: storage_ids()와 stream_ids()는 모든 항목을 나열하고, directory_entry_count()은 총 개수를 보고하며, header()는 컨테이너의 섹터 레이아웃을 반환합니다. 이는 mapi_message API이(가) 표시하지 않는 MAPI 데이터를 필요로 할 때 유용합니다.
#include "aspose/email/foss/cfb/cfb_reader.hpp"
#include <iostream>
namespace aef = aspose::email::foss;
auto cfb = aef::cfb::cfb_reader::from_file(std::filesystem::path("message.msg"));
std::cout << "Directory entries: " << cfb.directory_entry_count() << '\n';
std::cout << "Storages: " << cfb.storage_ids().size() << '\n';
std::cout << "Streams: " << cfb.stream_ids().size() << '\n';
빠른 시작
프로젝트에 라이브러리를 추가합니다:
git clone https://github.com/aspose-email-foss/Aspose.Email-FOSS-for-Cpp.git# CMakeLists.txt
add_subdirectory(Aspose.Email-FOSS-for-Cpp)
target_link_libraries(your_target PRIVATE AsposeEmailFoss::AsposeEmailFoss)그런 다음 메시지를 생성하고, MSG로 저장한 뒤 EML로 라운드트립합니다:
#include "aspose/email/foss/msg/mapi_message.hpp"
#include <filesystem>
#include <vector>
#include <cstdint>
namespace aef = aspose::email::foss;
int main() {
auto message = aef::msg::mapi_message::create("Hello from C++", "Body text here");
message.set_sender_name("Alice");
message.set_sender_email_address("alice@example.com");
message.add_recipient("bob@example.com", "Bob");
message.add_attachment("note.txt", std::vector<std::uint8_t>{'a', 'b', 'c'}, "text/plain");
message.save(std::filesystem::path("hello.msg"));
auto loaded = aef::msg::mapi_message::from_file(
std::filesystem::path("hello.msg"), /*strict=*/false);
loaded.save_to_eml(std::filesystem::path("hello.eml"));
return 0;
}
지원되는 형식
| 형식 | 확장자 | 읽기 | 쓰기 |
|---|---|---|---|
| Outlook 메시지 (MSG) | .msg | ✓ | ✓ |
| EML (RFC 5322 / MIME) | .eml | ✓ | ✓ |
| Compound File Binary (CFB) | .cfb | ✓ | ✓ |
오픈 소스 및 라이선스
Aspose.Email FOSS for C++는 MIT 라이선스로 제공됩니다. 전체 소스는 aspose-email-foss/Aspose.Email-FOSS-for-Cpp에서 확인할 수 있으며, 상업적 사용도 로열티 없이 허용됩니다. 이 라이브러리는 C++17 컴파일러와 CMake 3.26 이상을 제외하고는 런타임 의존성이 없습니다.