Skip to content

Commit

Permalink
Changed BodyParts and Attachments to be IEnumerable<MimeEntity>
Browse files Browse the repository at this point in the history
Fixes issue #148
  • Loading branch information
jstedfast committed Jun 18, 2015
1 parent f4eea92 commit d33f65f
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions MimeKit/MimeMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ public string GetTextBody (TextFormat format)
return null;
}

static IEnumerable<MimePart> EnumerateMimeParts (MimeEntity entity)
static IEnumerable<MimeEntity> EnumerateMimeParts (MimeEntity entity)
{
if (entity == null)
yield break;
Expand All @@ -881,43 +881,31 @@ static IEnumerable<MimePart> 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;
}

/// <summary>
/// Gets the body parts of the message.
/// </summary>
/// <remarks>
/// Traverses over the MIME tree, enumerating all of the <see cref="MimePart"/> objects.
/// Traverses over the MIME tree, enumerating all of the <see cref="MimeEntity"/> objects,
/// but does not traverse into the bodies of attached messages.
/// </remarks>
/// <value>The body parts.</value>
public IEnumerable<MimePart> BodyParts {
public IEnumerable<MimeEntity> BodyParts {
get { return EnumerateMimeParts (Body); }
}

/// <summary>
/// Gets the attachments.
/// </summary>
/// <remarks>
/// Traverses over the MIME tree, enumerating all of the <see cref="MimePart"/> objects that
/// Traverses over the MIME tree, enumerating all of the <see cref="MimeEntity"/> objects that
/// have a Content-Disposition header set to <c>"attachment"</c>.
/// </remarks>
/// <value>The attachments.</value>
public IEnumerable<MimePart> Attachments {
get { return EnumerateMimeParts (Body).Where (part => part.IsAttachment); }
public IEnumerable<MimeEntity> Attachments {
get { return EnumerateMimeParts (Body).Where (x => x.IsAttachment); }
}

/// <summary>
Expand Down

0 comments on commit d33f65f

Please sign in to comment.