Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Sep 14, 2023
1 parent 832d765 commit 469c27c
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions MailKit/Net/Imap/ImapFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ void CheckAllowIndexes ()
throw new InvalidOperationException ("Indexes and '*' cannot be used while MessageNew/MessageExpunge is registered with NOTIFY for SELECTED.");
}

void CheckValidDestination (IMailFolder destination)
{
if (destination == null)
throw new ArgumentNullException (nameof (destination));

if (destination is not ImapFolder target || (target.Engine != Engine))
throw new ArgumentException ("The destination folder does not belong to this ImapClient.", nameof (destination));
}

internal void Reset ()
{
// basic state
Expand Down Expand Up @@ -1503,7 +1512,7 @@ async Task<IList<IMailFolder>> GetSubfoldersAsync (StatusItems items, bool subsc
// in order to reduce the list of folders returned by our LIST command.
var pattern = new StringBuilder (EncodedName.Length + 2);
pattern.Append (EncodedName);
for (int i = 0; i < EncodedName.Length; i++) {
for (int i = 0; i < pattern.Length; i++) {
if (pattern[i] == '*')
pattern[i] = '%';
}
Expand Down Expand Up @@ -4931,11 +4940,7 @@ async Task<UniqueIdMap> CopyToAsync (IList<UniqueId> uids, IMailFolder destinati
if (uids == null)
throw new ArgumentNullException (nameof (uids));

if (destination == null)
throw new ArgumentNullException (nameof (destination));

if (destination is not ImapFolder target || (target.Engine != Engine))
throw new ArgumentException ("The destination folder does not belong to this ImapClient.", nameof (destination));
CheckValidDestination (destination);

CheckState (true, false);

Expand Down Expand Up @@ -5106,11 +5111,7 @@ async Task<UniqueIdMap> MoveToAsync (IList<UniqueId> uids, IMailFolder destinati
if (uids == null)
throw new ArgumentNullException (nameof (uids));

if (destination == null)
throw new ArgumentNullException (nameof (destination));

if (destination is not ImapFolder || ((ImapFolder) destination).Engine != Engine)
throw new ArgumentException ("The destination folder does not belong to this ImapClient.", nameof (destination));
CheckValidDestination (destination);

CheckState (true, true);

Expand Down Expand Up @@ -5278,11 +5279,7 @@ async Task CopyToAsync (IList<int> indexes, IMailFolder destination, bool doAsyn
if (indexes == null)
throw new ArgumentNullException (nameof (indexes));

if (destination == null)
throw new ArgumentNullException (nameof (destination));

if (destination is not ImapFolder || ((ImapFolder) destination).Engine != Engine)
throw new ArgumentException ("The destination folder does not belong to this ImapClient.", nameof (destination));
CheckValidDestination (destination);

CheckState (true, false);
CheckAllowIndexes ();
Expand Down Expand Up @@ -5424,11 +5421,7 @@ async Task MoveToAsync (IList<int> indexes, IMailFolder destination, bool doAsyn
if (indexes == null)
throw new ArgumentNullException (nameof (indexes));

if (destination == null)
throw new ArgumentNullException (nameof (destination));

if (destination is not ImapFolder || ((ImapFolder) destination).Engine != Engine)
throw new ArgumentException ("The destination folder does not belong to this ImapClient.", nameof (destination));
CheckValidDestination (destination);

CheckState (true, true);
CheckAllowIndexes ();
Expand Down

0 comments on commit 469c27c

Please sign in to comment.