Mime Content Class
Encapsulates a content stream used by MimePart.
Definition
Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public class MimeContent : IMimeContent,
IDisposable- Inheritance
- Object MimeContent
- Implements
- IMimeContent, IDisposable
Remarks
A MimeContent represents the content of a MimePart.
The content has both a stream and an encoding (typically Unspecified).
Example
C#
foreach (var attachment in message.Attachments) {
if (attachment is MessagePart) {
var fileName = attachment.ContentDisposition?.FileName ?? attachment.ContentType.Name;
var rfc822 = (MessagePart) attachment;
if (string.IsNullOrEmpty (fileName))
fileName = "attached-message.eml";
// make sure that the filename value does not contain a full path or invalid path characters
fileName = Path.GetFileName (fileName);
using (var stream = File.Create (fileName))
rfc822.Message.WriteTo (stream);
} else {
var part = (MimePart) attachment;
var fileName = part.FileName;
if (string.IsNullOrEmpty (fileName))
fileName = "untitled.dat";
// make sure that the filename value does not contain a full path or invalid path characters
fileName = Path.GetFileName (fileName);
using (var stream = File.Create (fileName))
part.Content.DecodeTo (stream);
}
}
Constructors
| MimeContent | Initialize a new instance of the MimeContent class. |
Properties
| Encoding | Get or set the content encoding. |
| NewLineFormat | Get the new-line format, if known. |
| Stream | Get the content stream. |
Methods
| DecodeTo | Decode the content stream into another stream. |
| DecodeToAsync | Asynchronously decode the content stream into another stream. |
| Dispose | Release all resources used by the MimeContent object. |
| Dispose(Boolean) | Release the unmanaged resources used by the MimeContent and optionally releases the managed resources. |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
| Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) |
| GetHashCode | Serves as the default hash function. (Inherited from Object) |
| GetType | Gets the Type of the current instance. (Inherited from Object) |
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) |
| Open | Open the decoded content stream. |
| ToString | Returns a string that represents the current object. (Inherited from Object) |
| WriteTo | Copy the content stream to the specified output stream. |
| WriteToAsync | Asynchronously copy the content stream to the specified output stream. |