Skip to content

Commit

Permalink
Added IMailFolder.CanOpen property
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Jan 21, 2025
1 parent 2d7bf76 commit 9df535c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions MailKit/IMailFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ public interface IMailFolder : IEnumerable<MimeMessage>
/// <value><see langword="true" /> if the folder is currently open; otherwise, <see langword="false" />.</value>
bool IsOpen { get; }

/// <summary>
/// Get whether or not the folder can be opened.
/// </summary>
/// <remarks>
/// Gets whether or not the folder can be opened.
/// </remarks>
/// <value><see langword="true" /> if the folder can be opened; otherwise, <see langword="false" />.</value>
bool CanOpen { get; }

/// <summary>
/// Get whether or not the folder exists.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions MailKit/MailFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ public abstract bool IsOpen {
get;
}

/// <summary>
/// Get whether or not the folder can be opened.
/// </summary>
/// <remarks>
/// Gets whether or not the folder can be opened.
/// </remarks>
/// <value><see langword="true" /> if the folder can be opened; otherwise, <see langword="false" />.</value>
public bool CanOpen {
get { return (Attributes & (FolderAttributes.NoSelect | FolderAttributes.NonExistent)) == 0; }
}

/// <summary>
/// Get a value indicating whether the folder exists.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions UnitTests/Net/Imap/ImapFolderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,7 @@ public void TestCreateRenameDelete ()
sublevel1.Closed += (o, e) => { sub1Closed++; };
sublevel2.Closed += (o, e) => { sub2Closed++; };

Assert.That (sublevel1.CanOpen, Is.True, "SubLevel1 can be opened");
sublevel1.Open (FolderAccess.ReadWrite);
sublevel1.Rename (toplevel2, "SubLevel1");

Expand All @@ -1722,6 +1723,7 @@ public void TestCreateRenameDelete ()
Assert.That (top1Deleted, Is.EqualTo (1), "TopLevel1 should have received a Deleted event");
Assert.That (toplevel1.Exists, Is.False, "TopLevel1.Exists");

Assert.That (sublevel2.CanOpen, Is.True, "SubLevel2 can be opened");
sublevel2.Open (FolderAccess.ReadWrite);
toplevel2.Rename (personal, "TopLevel");

Expand Down Expand Up @@ -1786,6 +1788,7 @@ public async Task TestCreateRenameDeleteAsync ()
sublevel1.Closed += (o, e) => { sub1Closed++; };
sublevel2.Closed += (o, e) => { sub2Closed++; };

Assert.That (sublevel1.CanOpen, Is.True, "SubLevel1 can be opened");
await sublevel1.OpenAsync (FolderAccess.ReadWrite);
await sublevel1.RenameAsync (toplevel2, "SubLevel1");

Expand All @@ -1797,6 +1800,7 @@ public async Task TestCreateRenameDeleteAsync ()
Assert.That (top1Deleted, Is.EqualTo (1), "TopLevel1 should have received a Deleted event");
Assert.That (toplevel1.Exists, Is.False, "TopLevel1.Exists");

Assert.That (sublevel2.CanOpen, Is.True, "SubLevel2 can be opened");
await sublevel2.OpenAsync (FolderAccess.ReadWrite);
await toplevel2.RenameAsync (personal, "TopLevel");

Expand Down

0 comments on commit 9df535c

Please sign in to comment.