MsgReader

Overview

MsgReader gives direct access to the raw Compound File Binary (CFB) structure of an Outlook MSG file. It is the underlying engine used by MapiMessage and MsgDocument, and is exposed for advanced scenarios where you need to inspect property streams, directory entries, or storage layout without the overhead of full deserialization. Always use it as a context manager or call close() explicitly to free file handles.

from aspose.email_foss import msg

with msg.MsgReader.from_file("message.msg") as reader:
    cfb = reader.cfb_reader
    print(f"sector_size={cfb.sector_size}")
    print(f"recipients={len(list(reader.iter_recipient_storages()))}")
    print(f"attachments={len(list(reader.iter_attachment_storages()))}")
    for entry in reader.iter_top_level_fixed_length_properties():
        print(f"  tag=0x{entry.property_tag:08X}")

Class Methods

SignatureDescription
from_file(path, strict=False) -> MsgReaderOpen a .msg file and return a reader. Set strict=True to raise on non-fatal issues.
parse_top_level_property_stream(data) -> Tuple[PropertyStreamHeaderTopLevel, List[PropertyEntryFixedLength]]Parse a raw top-level property stream from bytes.
parse_subobject_property_stream_data(data) -> Tuple[PropertyStreamHeaderSubobject, List[PropertyEntryFixedLength]]Parse a raw sub-object (recipient/attachment) property stream from bytes.

Properties

NameTypeAccessDescription
cfb_readerCFBReaderread-onlyThe underlying CFB file reader.
storage_layoutStorageLayoutread-onlyParsed storage directory layout.
strictboolread-onlyWhether strict parsing mode is enabled.
validation_issuesTuple[str, ...]read-onlyNon-fatal issues found during open.

Methods

SignatureDescription
close() -> NoneClose the underlying file handle.
iter_top_level_fixed_length_properties() -> Iterator[PropertyEntryFixedLength]Iterate fixed-length property entries from the top-level property stream.
iter_recipient_storages() -> Iterator[DirectoryEntry]Iterate CFB directory entries for each recipient storage.
iter_attachment_storages() -> Iterator[DirectoryEntry]Iterate CFB directory entries for each attachment storage.
parse_message_property_stream(storage_stream_id=0) -> Tuple[PropertyStreamHeaderTopLevel, List[PropertyEntryFixedLength]]Parse the message-level property stream.
parse_subobject_property_stream(storage_stream_id) -> Tuple[PropertyStreamHeaderSubobject, List[PropertyEntryFixedLength]]Parse a sub-object property stream by storage stream ID.

See Also