Skip to content

Commit

Permalink
MimeMessage and MimeEntity now implement IDisposable
Browse files Browse the repository at this point in the history
Fixes issue #732
  • Loading branch information
jstedfast committed Dec 10, 2021
1 parent 9f9efe9 commit be3e8cc
Show file tree
Hide file tree
Showing 22 changed files with 1,168 additions and 21 deletions.
25 changes: 22 additions & 3 deletions MimeKit/AttachmentCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ public bool IsReadOnly {
}

/// <summary>
/// Gets or sets the <see cref="MimeEntity"/> at the specified index.
/// Get or set the <see cref="MimeEntity"/> at the specified index.
/// </summary>
/// <remarks>
/// Gets or sets the <see cref="MimeEntity"/> at the specified index.
/// <para>Gets or sets the <see cref="MimeEntity"/> at the specified index.</para>
/// <note type="note">It is the responsibility of the caller to dispose the original entity at the specified <paramref name="index"/>.</note>
/// </remarks>
/// <value>The attachment at the specified index.</value>
/// <param name="index">The index.</param>
Expand Down Expand Up @@ -796,6 +797,23 @@ public void Add (MimeEntity attachment)
/// </remarks>
public void Clear ()
{
Clear (false);
}

/// <summary>
/// Clears the attachment collection.
/// </summary>
/// <remarks>
/// Removes all attachments from the collection, optionally disposing them in the process.
/// </remarks>
/// <param name="dispose"><c>true</c> if all of the attachments should be disposed; otherwise, <c>false</c>.</param>
public void Clear (bool dispose)
{
if (dispose) {
for (int i = 0; i < attachments.Count; i++)
attachments[i].Dispose ();
}

attachments.Clear ();
}

Expand Down Expand Up @@ -912,7 +930,8 @@ public bool Remove (MimeEntity attachment)
/// Removes the attachment at the specified index.
/// </summary>
/// <remarks>
/// Removes the attachment at the specified index.
/// <para>Removes the attachment at the specified index.</para>
/// <note type="note">It is the responsibility of the caller to dispose the entity at the specified <paramref name="index"/>.</note>
/// </remarks>
/// <param name="index">The index.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
Expand Down
10 changes: 10 additions & 0 deletions MimeKit/Cryptography/ApplicationPgpEncrypted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public ApplicationPgpEncrypted () : base ("application", "pgp-encrypted")
Content = new MimeContent (content);
}

void CheckDisposed ()
{
CheckDisposed (nameof (ApplicationPgpEncrypted));
}

/// <summary>
/// Dispatches to the specific visit method for this MIME entity.
/// </summary>
Expand All @@ -86,11 +91,16 @@ public ApplicationPgpEncrypted () : base ("application", "pgp-encrypted")
/// <exception cref="System.ArgumentNullException">
/// <paramref name="visitor"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="ApplicationPgpEncrypted"/> has been disposed.
/// </exception>
public override void Accept (MimeVisitor visitor)
{
if (visitor == null)
throw new ArgumentNullException (nameof (visitor));

CheckDisposed ();

visitor.VisitApplicationPgpEncrypted (this);
}
}
Expand Down
10 changes: 10 additions & 0 deletions MimeKit/Cryptography/ApplicationPgpSignature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public ApplicationPgpSignature (Stream stream) : base ("application", "pgp-signa
FileName = "signature.asc";
}

void CheckDisposed ()
{
CheckDisposed (nameof (ApplicationPgpSignature));
}

/// <summary>
/// Dispatches to the specific visit method for this MIME entity.
/// </summary>
Expand All @@ -95,11 +100,16 @@ public ApplicationPgpSignature (Stream stream) : base ("application", "pgp-signa
/// <exception cref="System.ArgumentNullException">
/// <paramref name="visitor"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="ApplicationPgpSignature"/> has been disposed.
/// </exception>
public override void Accept (MimeVisitor visitor)
{
if (visitor == null)
throw new ArgumentNullException (nameof (visitor));

CheckDisposed ();

visitor.VisitApplicationPgpSignature (this);
}
}
Expand Down
Loading

0 comments on commit be3e8cc

Please sign in to comment.