功能
功能概述
Aspose.Email FOSS for C++ 提供了一个分层 API,用于处理 Outlook MSG 文件和
复合文件二进制(CFB)容器。该库在两个子系统中拥有 26 个公共类:CFB 和 MSG/MAPI。
CFB 容器访问
CFB 子系统读取和写入 Microsoft Compound File Binary 格式——Outlook .msg 文件所基于的容器格式。
| 类 | 用途 |
|---|---|
cfb_reader | 打开并遍历现有的 CFB 文件 |
cfb_writer | 将 CFB 文档序列化为字节或文件 |
cfb_document | CFB 文件的内存表示 |
cfb_node | 目录树中的单个存储或流节点 |
cfb_storage | 具名存储条目 |
cfb_stream | 包含二进制数据的具名流 |
关键操作:
- 从文件、流或字节打开:
cfb_reader::from_file(),cfb_reader::from_stream(),cfb_reader::from_bytes(),cfb_reader::from_buffer() - 枚举内容:
storage_ids(),stream_ids(),child_ids(),directory_entry_count() - 按路径导航:
find_child_by_name(),resolve_path() - 检查节点:
cfb_node::is_storage(),cfb_node::is_stream(),creation_time(),modified_time() - 写入容器:
cfb_writer::to_bytes(),cfb_writer::write_file(),cfb_writer::write_stream()
MSG 文件读取和写入
MSG 子系统在 CFB 之上处理 Outlook 消息格式。
| 类 | 用途 |
|---|---|
msg_reader | 打开并解析 MSG 文件 |
msg_writer | 序列化 MSG 文档 |
msg_document | MSG 文件的内存表示 |
关键操作:
- 打开 MSG 文件:
msg_reader::from_file(),msg_reader::from_stream() - 检查元数据:
msg_document::major_version(),msg_document::minor_version(),msg_document::strict() - 写入 MSG 文件:
msg_writer::to_bytes(),msg_writer::write_file(),msg_writer::write_stream() - 转换为 CFB:
msg_document::to_cfb_document()用于低级 CFB 访问
高级 MAPI 消息 API
mapi_message 类提供了一个用于创建、读取和转换电子邮件消息的高级接口。
创建消息:
mapi_message::create()— 构建一个带有主题和正文的新消息set_subject(),set_body(),set_html_body()— 设置消息内容set_sender_name(),set_sender_email_address(),set_sender_address_type()— 设置发件人set_internet_message_id()— 设置 Message-ID 头set_message_class()— 设置 MAPI 消息类unicode_strings()/set_unicode_strings()— 控制 Unicode 字符串编码
加载消息:
mapi_message::from_file()— 从文件路径加载mapi_message::from_stream()— 从输入流加载mapi_message::from_msg_document()— 从msg_document加载
保存消息:
save()— 序列化为字节、流或文件to_msg_document()— 转换为msg_document以进行低级访问
附件:
mapi_attachment::from_bytes(),mapi_attachment::from_stream()— 加载附件数据mapi_attachment::is_embedded_message()— 检查附件是否为嵌入的 MSGmapi_attachment::load_data()— 延迟加载附件内容
MAPI 属性:
mapi_property::property_id(),property_type(),property_tag()— 属性标识mapi_property::set_value(),flags(),set_flags()— 属性操作mapi_property_collection::remove()— 从集合中移除属性
EML 和 MIME 转换
在 Outlook MSG 格式和标准 EML(RFC 5322 / MIME)之间转换:
mapi_message::load_from_eml()— 解析一个.eml文件为mapi_messagemapi_message::save_to_eml()— 将mapi_message序列化为 EML 格式
主题、正文、发件人、收件人和附件在往返传输中得以保留。
枚举和常量
| 枚举 | 用途 |
|---|---|
common_message_property_id | 标准 MAPI 属性标识符(主题、正文、发件人、附件) |
property_type_code | MAPI 属性类型代码(整数、字符串、二进制、时间、GUID) |
msg_storage_role | MSG 文件中的存储角色(消息、收件人、附件) |
directory_object_type | CFB 目录项类型(存储、流、根) |
directory_color_flag | CFB 目录项的红黑树颜色标志 |
sector_marker | CFB 文件分配表中的特殊扇区值 |