OutlookMailAttachment Class
Definition
- Assembly
- Bodu.Formats.Outlook.Pst.dll
- Package
- Bodu.Formats.Outlook.Pst 0.7.1
- 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.
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.
Exceptions
- ObjectDisposedException
The owning session has been disposed.
- PstFileException
The container is malformed.
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.
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.
Exceptions
- NotSupportedException
The attachment's Method is EmbeddedMessage or Ole - the payload is an object, not a byte stream.
- OutlookPstFormatException
The by-value content payload is missing.
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
- NotSupportedException
The attachment's Method is not EmbeddedMessage.
- OutlookPstFormatException
The attachment carries no nested message subnode, or the nested message would sit deeper than MaxEmbeddedMessageDepth.
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 |