Click or drag to resize
MimeKit

MimeIteratorParent Property

Get the parent of the current entity.

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll) Version: 4.3.0
Syntax
C#
public MimeEntity Parent { get; }

Property Value

MimeEntity
The parent entity.
Exceptions
ExceptionCondition
InvalidOperationException Either MoveNext has not been called or MoveNext has moved beyond the end of the message.
Remarks

After an iterator is created or after the Reset method is called, the MoveNext method must be called to advance the iterator to the first entity of the message before reading the value of the Parent property; otherwise, Parent throws a InvalidOperationException. Parent also throws a InvalidOperationException if the last call to MoveNext returned false, which indicates the end of the message.

If the current entity is the top-level entity of the message, then the parent will be null; otherwise the parent will be either be a MessagePart or a Multipart.

Example
C#
var attachments = new List<MimePart> ();
var multiparts = new List<Multipart> ();

using (var iter = new MimeIterator (message)) {
    // collect our list of attachments and their parent multiparts
    while (iter.MoveNext ()) {
        var multipart = iter.Parent as Multipart;
        var part = iter.Current as MimePart;

        if (multipart != null && part != null && part.IsAttachment) {
            // keep track of each attachment's parent multipart
            multiparts.Add (multipart);
            attachments.Add (part);
        }
    }
}

// now remove each attachment from its parent multipart...
for (int i = 0; i < attachments.Count; i++)
    multiparts[i].Remove (attachments[i]);
See Also