From d33f65fe0026f72b67db4dd34112121cb72464c3 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 18 Jun 2015 19:50:07 -0400 Subject: [PATCH] Changed BodyParts and Attachments to be IEnumerable Fixes issue #148 --- MimeKit/MimeMessage.cs | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/MimeKit/MimeMessage.cs b/MimeKit/MimeMessage.cs index a2dd679833..da0b22309b 100644 --- a/MimeKit/MimeMessage.cs +++ b/MimeKit/MimeMessage.cs @@ -865,7 +865,7 @@ public string GetTextBody (TextFormat format) return null; } - static IEnumerable EnumerateMimeParts (MimeEntity entity) + static IEnumerable EnumerateMimeParts (MimeEntity entity) { if (entity == null) yield break; @@ -881,30 +881,18 @@ static IEnumerable EnumerateMimeParts (MimeEntity entity) yield break; } - var msgpart = entity as MessagePart; - - if (msgpart != null) { - var message = msgpart.Message; - - if (message != null) { - foreach (var part in EnumerateMimeParts (message.Body)) - yield return part; - } - - yield break; - } - - yield return (MimePart) entity; + yield return entity; } /// /// Gets the body parts of the message. /// /// - /// Traverses over the MIME tree, enumerating all of the objects. + /// Traverses over the MIME tree, enumerating all of the objects, + /// but does not traverse into the bodies of attached messages. /// /// The body parts. - public IEnumerable BodyParts { + public IEnumerable BodyParts { get { return EnumerateMimeParts (Body); } } @@ -912,12 +900,12 @@ public IEnumerable BodyParts { /// Gets the attachments. /// /// - /// Traverses over the MIME tree, enumerating all of the objects that + /// Traverses over the MIME tree, enumerating all of the objects that /// have a Content-Disposition header set to "attachment". /// /// The attachments. - public IEnumerable Attachments { - get { return EnumerateMimeParts (Body).Where (part => part.IsAttachment); } + public IEnumerable Attachments { + get { return EnumerateMimeParts (Body).Where (x => x.IsAttachment); } } ///