MessagePart Class

A MIME part containing a MimeMessage as its content.

Definition

Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public class MessagePart : MimeEntity, 
	IMessagePart, IMimeEntity, IDisposable
Inheritance
Object    MimeEntity    MessagePart
Derived
Implements
IMessagePart, IMimeEntity, IDisposable

Remarks

Represents MIME entities such as those with a Content-Type of message/rfc822 or message/news.

Example

C#
                    public static IList<MimeMessage> GetAttachedMessages (MimeMessage message)
{
    var messages = new List<MimeMessage> ();

    // Attached (or forwarded) messages are represented by MessagePart objects. The
    // BodyParts property does not traverse into attached messages, so recurse into each
    // MessagePart's Message to find messages attached to the attached messages as well.
    foreach (var part in message.BodyParts.OfType<MessagePart> ()) {
        if (part.Message != null) {
            messages.Add (part.Message);
            messages.AddRange (GetAttachedMessages (part.Message));
        }
    }

    return messages;
}
                  
C#
                    public static MimeMessage Forward (MimeMessage original, MailboxAddress from, IEnumerable<InternetAddress> to)
{
    var message = new MimeMessage ();
    message.From.Add (from);
    message.To.AddRange (to);

    // set the forwarded subject
    if (!original.Subject?.StartsWith ("FW:", StringComparison.OrdinalIgnoreCase))
        message.Subject = "FW: " + (original.Subject ?? string.Empty);
    else
        message.Subject = original.Subject;

    // create the main textual body of the message
    var text = new TextPart ("plain") { Text = "Here's the forwarded message:" };

    // create the message/rfc822 attachment for the original message
    var rfc822 = new MessagePart { Message = original };

    // create a multipart/mixed container for the text body and the forwarded message
    var multipart = new Multipart ("mixed");
    multipart.Add (text);
    multipart.Add (rfc822);

    // set the multipart as the body of the message
    message.Body = multipart;

    return message;
}
                  

Constructors

MessagePart Initialize a new instance of the MessagePart class.
MessagePart(MimeEntityConstructorArgs) Initialize a new instance of the MessagePart class.
MessagePart(String) Initialize a new instance of the MessagePart class.
MessagePart(String, Object) Initialize a new instance of the MessagePart class.
MessagePart(String, String) Initialize a new instance of the MessagePart class.

Properties

ContentBase Get or set the base content URI.
(Inherited from MimeEntity)
ContentDisposition Get or set the content disposition.
(Inherited from MimeEntity)
ContentId Get or set the Content-Id.
(Inherited from MimeEntity)
ContentLocation Get or set the content location.
(Inherited from MimeEntity)
ContentType Get the type of the content.
(Inherited from MimeEntity)
Headers Get the list of headers.
(Inherited from MimeEntity)
IsAttachment Get a value indicating whether this MimePart is an attachment.
(Inherited from MimeEntity)
Message Gets or sets the message content.

Methods

Accept Dispatches to the specific visit method for this MIME entity.
(Overrides MimeEntityAccept(MimeVisitor))
Dispose Releases all resources used by the MimeEntity object.
(Inherited from MimeEntity)
Dispose(Boolean) Releases the unmanaged resources used by the MimeEntity and optionally releases the managed resources.
(Inherited from MimeEntity)
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)
OnHeadersChanged Called when the headers change in some way.
(Inherited from MimeEntity)
Prepare Prepare the MIME entity for transport using the specified encoding constraints.
(Overrides MimeEntityPrepare(EncodingConstraint, Int32))
RemoveHeader Remove a header by name.
(Inherited from MimeEntity)
SetHeader(String, Byte) Set the value of a header using the raw value.
(Inherited from MimeEntity)
SetHeader(String, String) Set the value of a header.
(Inherited from MimeEntity)
ToString Return a String that represents the MimeEntity for debugging purposes.
(Inherited from MimeEntity)
TryInit Tries to use the given object to initialize the appropriate property.
(Inherited from MimeEntity)
WriteTo(Stream, CancellationToken) Write the MimeEntity to the specified output stream.
(Inherited from MimeEntity)
WriteTo(String, CancellationToken) Write the MimeEntity to the specified file.
(Inherited from MimeEntity)
WriteTo(FormatOptions, Stream, CancellationToken) Write the MimeEntity to the specified output stream.
(Inherited from MimeEntity)
WriteTo(FormatOptions, String, CancellationToken) Write the MimeEntity to the specified file.
(Inherited from MimeEntity)
WriteTo(Stream, Boolean, CancellationToken) Write the MimeEntity to the specified output stream.
(Inherited from MimeEntity)
WriteTo(String, Boolean, CancellationToken) Write the MimeEntity to the specified file.
(Inherited from MimeEntity)
WriteTo(FormatOptions, Stream, Boolean, CancellationToken) Write the MimeEntity to the specified output stream.
(Inherited from MimeEntity)
WriteTo(FormatOptions, String, Boolean, CancellationToken) Write the MimeEntity to the specified file.
(Inherited from MimeEntity)
WriteToAsync(Stream, CancellationToken) Asynchronously write the MimeEntity to the specified output stream.
(Inherited from MimeEntity)
WriteToAsync(String, CancellationToken) Asynchronously write the MimeEntity to the specified file.
(Inherited from MimeEntity)
WriteToAsync(FormatOptions, Stream, CancellationToken) Asynchronously write the MimeEntity to the specified output stream.
(Inherited from MimeEntity)
WriteToAsync(FormatOptions, String, CancellationToken) Asynchronously write the MimeEntity to the specified file.
(Inherited from MimeEntity)
WriteToAsync(Stream, Boolean, CancellationToken) Asynchronously write the MimeEntity to the specified output stream.
(Inherited from MimeEntity)
WriteToAsync(String, Boolean, CancellationToken) Asynchronously write the MimeEntity to the specified file.
(Inherited from MimeEntity)
WriteToAsync(FormatOptions, Stream, Boolean, CancellationToken) Asynchronously write the MimeEntity to the specified output stream.
(Inherited from MimeEntity)
WriteToAsync(FormatOptions, String, Boolean, CancellationToken) Asynchronously write the MimeEntity to the specified file.
(Inherited from MimeEntity)

See Also

Reference