OutlookMailAttachment Class
Definition
- Assembly
- Bodu.Formats.Outlook.Pst.dll
- Package
- Bodu.Formats.Outlook.Pst 1.3.0
- Source
- OutlookMailAttachment.cs
Represents one attachment of an OutlookMailMessage: a typed view over the attachment object's decoded properties, with access to the by-value payload or the nested attached message.
public sealed class OutlookMailAttachment
- Inheritance
-
OutlookMailAttachment
- Inherited Members
- Extension Methods
Remarks
The conveniences return null when the underlying property is absent; every attachment property remains reachable through Properties. Content access is method-specific: OpenContentStream() serves a by-value payload and OpenMessage() serves an embedded message - each throws NotSupportedException for the other method kinds. Container corruption met while the attachment decodes, or while its content stream is read, throws OutlookPstFormatException, with the container's PstFileException as the inner exception.
Properties
ContentId
Gets the content identifier used to reference the attachment from an HTML body.
public string? ContentId { get; }
Property Value
FileName
Gets the attachment file name, preferring the long form.
public string? FileName { get; }
Property Value
Method
Gets how the attachment's content is stored.
public OutlookAttachmentMethod Method { get; }
Property Value
- OutlookAttachmentMethod
The
PidTagAttachMethodvalue when present and defined. When the property is absent - or, under the tolerant validation levels, carries an undefined value - an attachment that carries a by-value payload reports ByValue (real-world writers frequently omit the method); otherwise None.
Exceptions
- OutlookPstFormatException
The declared method is not a defined value and the session validates strictly.
MimeTag
Gets the attachment MIME type.
public string? MimeTag { get; }
Property Value
Properties
Gets every decoded property of the attachment.
public MapiPropertyCollection Properties { get; }
Property Value
- MapiPropertyCollection
The tag-addressed property collection, decoded once on first access.
Remarks
A by-value payload (PidTagAttachDataBinary) larger than
MaxInlineAttachmentBytes is not decoded: the property is present
with a null value and the content is served by OpenContentStream() directly from
the store.
An exception thrown by ValueOmittedCallback while the properties are decoded propagates from this access unchanged.
Exceptions
- ObjectDisposedException
The owning session has been disposed.
- OutlookPstFormatException
The container is malformed, or, under strict validation, a property value cannot be decoded.
Size
Gets the attachment size.
public long? Size { get; }
Property Value
- long?
The
PidTagAttachSizevalue the writer recorded; when absent, the length of the by-value payload; null when neither is available.
Remarks
The payload length is read from the store's index structures, so a deferred payload is never materialized to measure it.
Exceptions
- OutlookPstFormatException
The container is malformed.
Methods
OpenContentStream()
Opens the by-value content payload as a read-only stream.
public Stream OpenContentStream()
Returns
- Stream
The content stream; dispose it when reading is complete.
Remarks
A payload decoded inline (at or below MaxInlineAttachmentBytes) is served from the decoded bytes without copying; a larger payload is streamed from the store block by block and is never held in memory in full. The stream is bound to the owning session, and a read that meets a corrupt block throws OutlookPstFormatException, with the container's PstFileException as the inner exception.
Exceptions
- ObjectDisposedException
The owning session has been disposed.
- NotSupportedException
The attachment's Method is not ByValue - a referenced, web-referenced, embedded, or OLE attachment, or one that declares no content, carries no byte payload in the store.
- OutlookPstFormatException
The by-value content payload is missing, or the container is malformed.
OpenMessage()
Opens the nested attached message.
public OutlookMailMessage OpenMessage()
Returns
- OutlookMailMessage
The nested message view. It is bound to the owning session and becomes unusable when the session is disposed.
Remarks
The nested message is the message-typed subnode of the attachment object (MS-PST §2.4.6.3); its code-page strings inherit the attachment's encoding.
Exceptions
- ObjectDisposedException
The owning session has been disposed.
- NotSupportedException
The attachment's Method is not EmbeddedMessage.
- OutlookPstFormatException
The attachment carries no nested message subnode, the nested message would sit deeper than MaxEmbeddedMessageDepth, or the container is malformed.
ToString()
Returns a textual form of the attachment for diagnostics.
public override string ToString()
Returns
- string
The method and file name.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |