From adfc55a7a1f56afe835f444f37d6a563f0081000 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Sat, 30 Dec 2023 13:02:39 -0500 Subject: [PATCH] Modified Add/RemoveFlags and Add/RemoveLabels to accept empty flags/labels The ImapFolder.Store() methods already allowed this. --- MailKit/IMailFolderStoreExtensions.cs | 304 ++++++--------------- UnitTests/Net/Imap/ImapClientTests.cs | 56 ++++ UnitTests/Net/Imap/ImapFolderFlagsTests.cs | 64 ----- 3 files changed, 133 insertions(+), 291 deletions(-) diff --git a/MailKit/IMailFolderStoreExtensions.cs b/MailKit/IMailFolderStoreExtensions.cs index 185e28bd8f..312e224637 100644 --- a/MailKit/IMailFolderStoreExtensions.cs +++ b/MailKit/IMailFolderStoreExtensions.cs @@ -36,9 +36,6 @@ public static partial class IMailFolderExtensions static StoreFlagsRequest GetStoreFlagsRequest (StoreAction action, bool silent, MessageFlags flags, HashSet keywords = null, ulong? modseq = null) { - if (action != StoreAction.Set && flags == MessageFlags.None && (keywords == null || keywords.Count == 0)) - throw new ArgumentException ("No flags were specified.", nameof (flags)); - if (keywords != null) { return new StoreFlagsRequest (action, flags, keywords) { UnchangedSince = modseq, @@ -64,9 +61,7 @@ static StoreFlagsRequest GetStoreFlagsRequest (StoreAction action, bool silent, /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -110,9 +105,7 @@ public static void AddFlags (this IMailFolder folder, UniqueId uid, MessageFlags /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -159,9 +152,7 @@ public static Task AddFlagsAsync (this IMailFolder folder, UniqueId uid, Message /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -209,9 +200,7 @@ public static void AddFlags (this IMailFolder folder, UniqueId uid, MessageFlags /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -260,9 +249,7 @@ public static Task AddFlagsAsync (this IMailFolder folder, UniqueId uid, Message /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -312,9 +299,7 @@ public static void AddFlags (this IMailFolder folder, IList uids, Mess /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -364,9 +349,7 @@ public static Task AddFlagsAsync (this IMailFolder folder, IList uids, /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -417,9 +400,7 @@ public static void AddFlags (this IMailFolder folder, IList uids, Mess /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -465,9 +446,7 @@ public static Task AddFlagsAsync (this IMailFolder folder, IList uids, /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -514,9 +493,7 @@ public static void RemoveFlags (this IMailFolder folder, UniqueId uid, MessageFl /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -563,9 +540,7 @@ public static Task RemoveFlagsAsync (this IMailFolder folder, UniqueId uid, Mess /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -613,9 +588,7 @@ public static void RemoveFlags (this IMailFolder folder, UniqueId uid, MessageFl /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -664,9 +637,7 @@ public static Task RemoveFlagsAsync (this IMailFolder folder, UniqueId uid, Mess /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -716,9 +687,7 @@ public static void RemoveFlags (this IMailFolder folder, IList uids, M /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -768,9 +737,7 @@ public static Task RemoveFlagsAsync (this IMailFolder folder, IList ui /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -821,9 +788,7 @@ public static void RemoveFlags (this IMailFolder folder, IList uids, M /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -1244,9 +1209,7 @@ public static Task SetFlagsAsync (this IMailFolder folder, IList uids, /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -1297,9 +1260,7 @@ public static IList AddFlags (this IMailFolder folder, IList /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -1351,9 +1312,7 @@ public static Task> AddFlagsAsync (this IMailFolder folder, ILis /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -1405,9 +1364,7 @@ public static IList AddFlags (this IMailFolder folder, IList /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -1458,9 +1415,7 @@ public static Task> AddFlagsAsync (this IMailFolder folder, ILis /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -1511,9 +1466,7 @@ public static IList RemoveFlags (this IMailFolder folder, IList is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -1565,9 +1518,7 @@ public static Task> RemoveFlagsAsync (this IMailFolder folder, I /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -1619,9 +1570,7 @@ public static IList RemoveFlags (this IMailFolder folder, IList is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -1873,9 +1822,7 @@ public static Task> SetFlagsAsync (this IMailFolder folder, ILis /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -1919,9 +1866,7 @@ public static void AddFlags (this IMailFolder folder, int index, MessageFlags fl /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -1965,9 +1910,7 @@ public static Task AddFlagsAsync (this IMailFolder folder, int index, MessageFla /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -2012,9 +1955,7 @@ public static void AddFlags (this IMailFolder folder, int index, MessageFlags fl /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -2060,9 +2001,7 @@ public static Task AddFlagsAsync (this IMailFolder folder, int index, MessageFla /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -2109,9 +2048,7 @@ public static void AddFlags (this IMailFolder folder, IList indexes, Messag /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -2158,9 +2095,7 @@ public static Task AddFlagsAsync (this IMailFolder folder, IList indexes, M /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -2208,9 +2143,7 @@ public static void AddFlags (this IMailFolder folder, IList indexes, Messag /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -2253,9 +2186,7 @@ public static Task AddFlagsAsync (this IMailFolder folder, IList indexes, M /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -2299,9 +2230,7 @@ public static void RemoveFlags (this IMailFolder folder, int index, MessageFlags /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -2345,9 +2274,7 @@ public static Task RemoveFlagsAsync (this IMailFolder folder, int index, Message /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -2392,9 +2319,7 @@ public static void RemoveFlags (this IMailFolder folder, int index, MessageFlags /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. - /// -or- - /// No flags were specified. + /// is invalid. /// /// /// The has been disposed. @@ -2440,9 +2365,7 @@ public static Task RemoveFlagsAsync (this IMailFolder folder, int index, Message /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -2489,9 +2412,7 @@ public static void RemoveFlags (this IMailFolder folder, IList indexes, Mes /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -2538,9 +2459,7 @@ public static Task RemoveFlagsAsync (this IMailFolder folder, IList indexes /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -2588,9 +2507,7 @@ public static void RemoveFlags (this IMailFolder folder, IList indexes, Mes /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -2633,7 +2550,7 @@ public static Task RemoveFlagsAsync (this IMailFolder folder, IList indexes /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. + /// is invalid. /// /// /// The has been disposed. @@ -2677,7 +2594,7 @@ public static void SetFlags (this IMailFolder folder, int index, MessageFlags fl /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. + /// is invalid. /// /// /// The has been disposed. @@ -2721,7 +2638,7 @@ public static Task SetFlagsAsync (this IMailFolder folder, int index, MessageFla /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. + /// is invalid. /// /// /// The has been disposed. @@ -2766,7 +2683,7 @@ public static void SetFlags (this IMailFolder folder, int index, MessageFlags fl /// If set to true, no events will be emitted. /// The cancellation token. /// - /// is invalid. + /// is invalid. /// /// /// The has been disposed. @@ -3002,9 +2919,7 @@ public static Task SetFlagsAsync (this IMailFolder folder, IList indexes, M /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -3055,9 +2970,7 @@ public static IList AddFlags (this IMailFolder folder, IList indexes, /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -3109,9 +3022,7 @@ public static Task> AddFlagsAsync (this IMailFolder folder, IList is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -3163,9 +3074,7 @@ public static IList AddFlags (this IMailFolder folder, IList indexes, /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -3216,9 +3125,7 @@ public static Task> AddFlagsAsync (this IMailFolder folder, IList is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -3269,9 +3176,7 @@ public static IList RemoveFlags (this IMailFolder folder, IList indexe /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -3323,9 +3228,7 @@ public static Task> RemoveFlagsAsync (this IMailFolder folder, IList< /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -3377,9 +3280,7 @@ public static IList RemoveFlags (this IMailFolder folder, IList indexe /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No flags were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -3628,9 +3529,6 @@ static StoreLabelsRequest GetStoreLabelsRequest (StoreAction action, bool silent if (labels == null) throw new ArgumentNullException (nameof (labels)); - if (action != StoreAction.Set && labels.Count == 0) - throw new ArgumentException ("No labels were specified.", nameof (labels)); - return new StoreLabelsRequest (action, labels) { UnchangedSince = modseq, Silent = silent @@ -3652,9 +3550,7 @@ static StoreLabelsRequest GetStoreLabelsRequest (StoreAction action, bool silent /// is null. /// /// - /// is invalid. - /// -or- - /// No labels were specified. + /// is invalid. /// /// /// The has been disposed. @@ -3701,9 +3597,7 @@ public static void AddLabels (this IMailFolder folder, UniqueId uid, IList is null. /// /// - /// is invalid. - /// -or- - /// No labels were specified. + /// is invalid. /// /// /// The has been disposed. @@ -3751,9 +3645,7 @@ public static Task AddLabelsAsync (this IMailFolder folder, UniqueId uid, IList< /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -3802,9 +3694,7 @@ public static void AddLabels (this IMailFolder folder, IList uids, ILi /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -3850,9 +3740,7 @@ public static Task AddLabelsAsync (this IMailFolder folder, IList uids /// is null. /// /// - /// is invalid. - /// -or- - /// No labels were specified. + /// is invalid. /// /// /// The has been disposed. @@ -3899,9 +3787,7 @@ public static void RemoveLabels (this IMailFolder folder, UniqueId uid, IList is null. /// /// - /// is invalid. - /// -or- - /// No labels were specified. + /// is invalid. /// /// /// The has been disposed. @@ -3949,9 +3835,7 @@ public static Task RemoveLabelsAsync (this IMailFolder folder, UniqueId uid, ILi /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -4000,9 +3884,7 @@ public static void RemoveLabels (this IMailFolder folder, IList uids, /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -4243,8 +4125,6 @@ public static Task SetLabelsAsync (this IMailFolder folder, IList uids /// /// /// One or more of the is invalid. - /// -or- - /// No labels were specified. /// /// /// The has been disposed. @@ -4297,9 +4177,7 @@ public static IList AddLabels (this IMailFolder folder, IList is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -4352,9 +4230,7 @@ public static Task> AddLabelsAsync (this IMailFolder folder, ILi /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -4407,9 +4283,7 @@ public static IList RemoveLabels (this IMailFolder folder, IList is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -4564,9 +4438,7 @@ public static Task> SetLabelsAsync (this IMailFolder folder, ILi /// is null. /// /// - /// is invalid. - /// -or- - /// No labels were specified. + /// is invalid. /// /// /// The has been disposed. @@ -4613,9 +4485,7 @@ public static void AddLabels (this IMailFolder folder, int index, IList /// is null. /// /// - /// is invalid. - /// -or- - /// No labels were specified. + /// is invalid. /// /// /// The has been disposed. @@ -4663,9 +4533,7 @@ public static Task AddLabelsAsync (this IMailFolder folder, int index, IList is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -4714,9 +4582,7 @@ public static void AddLabels (this IMailFolder folder, IList indexes, IList /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -4762,9 +4628,7 @@ public static Task AddLabelsAsync (this IMailFolder folder, IList indexes, /// is null. /// /// - /// is invalid. - /// -or- - /// No labels were specified. + /// is invalid. /// /// /// The has been disposed. @@ -4811,9 +4675,7 @@ public static void RemoveLabels (this IMailFolder folder, int index, IList is null. /// /// - /// is invalid. - /// -or- - /// No labels were specified. + /// is invalid. /// /// /// The has been disposed. @@ -4861,9 +4723,7 @@ public static Task RemoveLabelsAsync (this IMailFolder folder, int index, IList< /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -4912,9 +4772,7 @@ public static void RemoveLabels (this IMailFolder folder, IList indexes, IL /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -4960,7 +4818,7 @@ public static Task RemoveLabelsAsync (this IMailFolder folder, IList indexe /// is null. /// /// - /// is invalid. + /// is invalid. /// /// /// The has been disposed. @@ -5007,7 +4865,7 @@ public static void SetLabels (this IMailFolder folder, int index, IList /// is null. /// /// - /// is invalid. + /// is invalid. /// /// /// The has been disposed. @@ -5154,9 +5012,7 @@ public static Task SetLabelsAsync (this IMailFolder folder, IList indexes, /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -5209,9 +5065,7 @@ public static IList AddLabels (this IMailFolder folder, IList indexes, /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -5264,9 +5118,7 @@ public static Task> AddLabelsAsync (this IMailFolder folder, IList is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. @@ -5319,9 +5171,7 @@ public static IList RemoveLabels (this IMailFolder folder, IList index /// is null. /// /// - /// One or more of the is invalid. - /// -or- - /// No labels were specified. + /// One or more of the is invalid. /// /// /// The has been disposed. diff --git a/UnitTests/Net/Imap/ImapClientTests.cs b/UnitTests/Net/Imap/ImapClientTests.cs index d1f300fe62..4b878b1aae 100644 --- a/UnitTests/Net/Imap/ImapClientTests.cs +++ b/UnitTests/Net/Imap/ImapClientTests.cs @@ -5649,10 +5649,38 @@ public void TestGMail () created.RemoveLabels (indexes, 5, labels, true); created.AddLabels (indexes, 5, labels, false); + // Verify that Adding and/or removing an empty set of labels is a no-op + labels = Array.Empty (); + + created.RemoveLabels (matches, labels, true); + created.AddLabels (matches, labels, false); + + created.RemoveLabels (matches, 5, labels, true); + created.AddLabels (matches, 5, labels, false); + + created.RemoveLabels (indexes, labels, true); + created.AddLabels (indexes, labels, false); + + created.RemoveLabels (indexes, 5, labels, true); + created.AddLabels (indexes, 5, labels, false); + created.SetFlags (matches, MessageFlags.Seen | MessageFlags.Answered, false); created.RemoveFlags (matches, MessageFlags.Answered, true); created.AddFlags (matches, MessageFlags.Deleted, true); + // Verify that Adding and/or removing an empty set of flags is a no-op + created.RemoveFlags (matches, MessageFlags.None, true); + created.AddFlags (matches, MessageFlags.None, true); + + created.RemoveFlags (matches, 5, MessageFlags.None, true); + created.AddFlags (matches, 5, MessageFlags.None, true); + + created.RemoveFlags (indexes, MessageFlags.None, true); + created.AddFlags (indexes, MessageFlags.None, true); + + created.RemoveFlags (indexes, 5, MessageFlags.None, true); + created.AddFlags (indexes, 5, MessageFlags.None, true); + created.Check (); created.Close (); @@ -5820,10 +5848,38 @@ public async Task TestGMailAsync () await created.RemoveLabelsAsync (indexes, 5, labels, true); await created.AddLabelsAsync (indexes, 5, labels, false); + // Verify that Adding and/or removing an empty set of labels is a no-op + labels = Array.Empty (); + + await created.RemoveLabelsAsync (matches, labels, true); + await created.AddLabelsAsync (matches, labels, false); + + await created.RemoveLabelsAsync (matches, 5, labels, true); + await created.AddLabelsAsync (matches, 5, labels, false); + + await created.RemoveLabelsAsync (indexes, labels, true); + await created.AddLabelsAsync (indexes, labels, false); + + await created.RemoveLabelsAsync (indexes, 5, labels, true); + await created.AddLabelsAsync (indexes, 5, labels, false); + await created.SetFlagsAsync (matches, MessageFlags.Seen | MessageFlags.Answered, false); await created.RemoveFlagsAsync (matches, MessageFlags.Answered, true); await created.AddFlagsAsync (matches, MessageFlags.Deleted, true); + // Verify that Adding and/or removing an empty set of flags is a no-op + await created.RemoveFlagsAsync (matches, MessageFlags.None, true); + await created.AddFlagsAsync (matches, MessageFlags.None, true); + + await created.RemoveFlagsAsync (matches, 5, MessageFlags.None, true); + await created.AddFlagsAsync (matches, 5, MessageFlags.None, true); + + await created.RemoveFlagsAsync (indexes, MessageFlags.None, true); + await created.AddFlagsAsync (indexes, MessageFlags.None, true); + + await created.RemoveFlagsAsync (indexes, 5, MessageFlags.None, true); + await created.AddFlagsAsync (indexes, 5, MessageFlags.None, true); + await created.CheckAsync (); await created.CloseAsync (); diff --git a/UnitTests/Net/Imap/ImapFolderFlagsTests.cs b/UnitTests/Net/Imap/ImapFolderFlagsTests.cs index f7ec7fbc12..58eca16a25 100644 --- a/UnitTests/Net/Imap/ImapFolderFlagsTests.cs +++ b/UnitTests/Net/Imap/ImapFolderFlagsTests.cs @@ -73,102 +73,54 @@ public void TestArgumentExceptions () // AddFlags Assert.Throws (() => inbox.AddFlags (-1, MessageFlags.Seen, true)); Assert.ThrowsAsync (() => inbox.AddFlagsAsync (-1, MessageFlags.Seen, true)); - Assert.Throws (() => inbox.AddFlags (0, MessageFlags.None, true)); - Assert.ThrowsAsync (() => inbox.AddFlagsAsync (0, MessageFlags.None, true)); Assert.Throws (() => inbox.AddFlags (UniqueId.Invalid, MessageFlags.Seen, true)); Assert.ThrowsAsync (() => inbox.AddFlagsAsync (UniqueId.Invalid, MessageFlags.Seen, true)); - Assert.Throws (() => inbox.AddFlags (UniqueId.MinValue, MessageFlags.None, true)); - Assert.ThrowsAsync (() => inbox.AddFlagsAsync (UniqueId.MinValue, MessageFlags.None, true)); Assert.Throws (() => inbox.AddFlags (-1, MessageFlags.Seen, keywords, true)); Assert.ThrowsAsync (() => inbox.AddFlagsAsync (-1, MessageFlags.Seen, keywords, true)); - Assert.Throws (() => inbox.AddFlags (0, MessageFlags.None, null, true)); - Assert.ThrowsAsync (() => inbox.AddFlagsAsync (0, MessageFlags.None, null, true)); Assert.Throws (() => inbox.AddFlags (UniqueId.Invalid, MessageFlags.Seen, keywords, true)); Assert.ThrowsAsync (() => inbox.AddFlagsAsync (UniqueId.Invalid, MessageFlags.Seen, keywords, true)); - Assert.Throws (() => inbox.AddFlags (UniqueId.MinValue, MessageFlags.None, null, true)); - Assert.ThrowsAsync (() => inbox.AddFlagsAsync (UniqueId.MinValue, MessageFlags.None, null, true)); Assert.Throws (() => inbox.AddFlags ((IList) null, MessageFlags.Seen, true)); Assert.ThrowsAsync (() => inbox.AddFlagsAsync ((IList) null, MessageFlags.Seen, true)); - Assert.Throws (() => inbox.AddFlags (new int[1], MessageFlags.None, true)); - Assert.ThrowsAsync (() => inbox.AddFlagsAsync (new int[1], MessageFlags.None, true)); Assert.Throws (() => inbox.AddFlags ((IList) null, MessageFlags.Seen, true)); Assert.ThrowsAsync (() => inbox.AddFlagsAsync ((IList) null, MessageFlags.Seen, true)); - Assert.Throws (() => inbox.AddFlags (UniqueIdRange.All, MessageFlags.None, true)); - Assert.ThrowsAsync (() => inbox.AddFlagsAsync (UniqueIdRange.All, MessageFlags.None, true)); Assert.Throws (() => inbox.AddFlags ((IList) null, MessageFlags.Seen, keywords, true)); Assert.ThrowsAsync (() => inbox.AddFlagsAsync ((IList) null, MessageFlags.Seen, keywords, true)); - Assert.Throws (() => inbox.AddFlags (new int[1], MessageFlags.None, null, true)); - Assert.ThrowsAsync (() => inbox.AddFlagsAsync (new int[1], MessageFlags.None, null, true)); Assert.Throws (() => inbox.AddFlags ((IList) null, MessageFlags.Seen, keywords, true)); Assert.ThrowsAsync (() => inbox.AddFlagsAsync ((IList) null, MessageFlags.Seen, keywords, true)); - Assert.Throws (() => inbox.AddFlags (UniqueIdRange.All, MessageFlags.None, null, true)); - Assert.ThrowsAsync (() => inbox.AddFlagsAsync (UniqueIdRange.All, MessageFlags.None, null, true)); Assert.Throws (() => inbox.AddFlags ((IList) null, 1, MessageFlags.Seen, true)); Assert.ThrowsAsync (() => inbox.AddFlagsAsync ((IList) null, 1, MessageFlags.Seen, true)); - Assert.Throws (() => inbox.AddFlags (new int[1], 1, MessageFlags.None, true)); - Assert.ThrowsAsync (() => inbox.AddFlagsAsync (new int[1], 1, MessageFlags.None, true)); Assert.Throws (() => inbox.AddFlags ((IList) null, 1, MessageFlags.Seen, true)); Assert.ThrowsAsync (() => inbox.AddFlagsAsync ((IList) null, 1, MessageFlags.Seen, true)); - Assert.Throws (() => inbox.AddFlags (UniqueIdRange.All, 1, MessageFlags.None, true)); - Assert.ThrowsAsync (() => inbox.AddFlagsAsync (UniqueIdRange.All, 1, MessageFlags.None, true)); Assert.Throws (() => inbox.AddFlags ((IList) null, 1, MessageFlags.Seen, keywords, true)); Assert.ThrowsAsync (() => inbox.AddFlagsAsync ((IList) null, 1, MessageFlags.Seen, keywords, true)); - Assert.Throws (() => inbox.AddFlags (new int[1], 1, MessageFlags.None, null, true)); - Assert.ThrowsAsync (() => inbox.AddFlagsAsync (new int[1], 1, MessageFlags.None, null, true)); Assert.Throws (() => inbox.AddFlags ((IList) null, 1, MessageFlags.Seen, keywords, true)); Assert.ThrowsAsync (() => inbox.AddFlagsAsync ((IList) null, 1, MessageFlags.Seen, keywords, true)); - Assert.Throws (() => inbox.AddFlags (UniqueIdRange.All, 1, MessageFlags.None, null, true)); - Assert.ThrowsAsync (() => inbox.AddFlagsAsync (UniqueIdRange.All, 1, MessageFlags.None, null, true)); // RemoveFlags Assert.Throws (() => inbox.RemoveFlags (-1, MessageFlags.Seen, true)); Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (-1, MessageFlags.Seen, true)); - Assert.Throws (() => inbox.RemoveFlags (0, MessageFlags.None, true)); - Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (0, MessageFlags.None, true)); Assert.Throws (() => inbox.RemoveFlags (UniqueId.Invalid, MessageFlags.Seen, true)); Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (UniqueId.Invalid, MessageFlags.Seen, true)); - Assert.Throws (() => inbox.RemoveFlags (UniqueId.MinValue, MessageFlags.None, true)); - Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (UniqueId.MinValue, MessageFlags.None, true)); Assert.Throws (() => inbox.RemoveFlags (-1, MessageFlags.Seen, keywords, true)); Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (-1, MessageFlags.Seen, keywords, true)); - Assert.Throws (() => inbox.RemoveFlags (0, MessageFlags.None, null, true)); - Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (0, MessageFlags.None, null, true)); Assert.Throws (() => inbox.RemoveFlags (UniqueId.Invalid, MessageFlags.Seen, keywords, true)); Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (UniqueId.Invalid, MessageFlags.Seen, keywords, true)); - Assert.Throws (() => inbox.RemoveFlags (UniqueId.MinValue, MessageFlags.None, null, true)); - Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (UniqueId.MinValue, MessageFlags.None, null, true)); Assert.Throws (() => inbox.RemoveFlags ((IList) null, MessageFlags.Seen, true)); Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync ((IList) null, MessageFlags.Seen, true)); - Assert.Throws (() => inbox.RemoveFlags (new int[1], MessageFlags.None, true)); - Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (new int[1], MessageFlags.None, true)); Assert.Throws (() => inbox.RemoveFlags ((IList) null, MessageFlags.Seen, true)); Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync ((IList) null, MessageFlags.Seen, true)); - Assert.Throws (() => inbox.RemoveFlags (UniqueIdRange.All, MessageFlags.None, true)); - Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (UniqueIdRange.All, MessageFlags.None, true)); Assert.Throws (() => inbox.RemoveFlags ((IList) null, MessageFlags.Seen, keywords, true)); Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync ((IList) null, MessageFlags.Seen, keywords, true)); - Assert.Throws (() => inbox.RemoveFlags (new int[1], MessageFlags.None, null, true)); - Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (new int[1], MessageFlags.None, null, true)); Assert.Throws (() => inbox.RemoveFlags ((IList) null, MessageFlags.Seen, keywords, true)); Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync ((IList) null, MessageFlags.Seen, keywords, true)); - Assert.Throws (() => inbox.RemoveFlags (UniqueIdRange.All, MessageFlags.None, null, true)); - Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (UniqueIdRange.All, MessageFlags.None, null, true)); Assert.Throws (() => inbox.RemoveFlags ((IList) null, 1, MessageFlags.Seen, true)); Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync ((IList) null, 1, MessageFlags.Seen, true)); - Assert.Throws (() => inbox.RemoveFlags (new int[1], 1, MessageFlags.None, true)); - Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (new int[1], 1, MessageFlags.None, true)); Assert.Throws (() => inbox.RemoveFlags ((IList) null, 1, MessageFlags.Seen, true)); Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync ((IList) null, 1, MessageFlags.Seen, true)); - Assert.Throws (() => inbox.RemoveFlags (UniqueIdRange.All, 1, MessageFlags.None, true)); - Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (UniqueIdRange.All, 1, MessageFlags.None, true)); Assert.Throws (() => inbox.RemoveFlags ((IList) null, 1, MessageFlags.Seen, keywords, true)); Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync ((IList) null, 1, MessageFlags.Seen, keywords, true)); - Assert.Throws (() => inbox.RemoveFlags (new int[1], 1, MessageFlags.None, null, true)); - Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (new int[1], 1, MessageFlags.None, null, true)); Assert.Throws (() => inbox.RemoveFlags ((IList) null, 1, MessageFlags.Seen, keywords, true)); Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync ((IList) null, 1, MessageFlags.Seen, keywords, true)); - Assert.Throws (() => inbox.RemoveFlags (UniqueIdRange.All, 1, MessageFlags.None, null, true)); - Assert.ThrowsAsync (() => inbox.RemoveFlagsAsync (UniqueIdRange.All, 1, MessageFlags.None, null, true)); // SetFlags Assert.Throws (() => inbox.SetFlags (-1, MessageFlags.Seen, true)); @@ -233,10 +185,6 @@ public void TestArgumentExceptions () Assert.ThrowsAsync (() => inbox.AddLabelsAsync (new int [] { 0 }, null, true)); Assert.Throws (() => inbox.AddLabels (UniqueIdRange.All, null, true)); Assert.ThrowsAsync (() => inbox.AddLabelsAsync (UniqueIdRange.All, null, true)); - Assert.Throws (() => inbox.AddLabels (new int [] { 0 }, emptyLabels, true)); - Assert.ThrowsAsync (() => inbox.AddLabelsAsync (new int [] { 0 }, emptyLabels, true)); - Assert.Throws (() => inbox.AddLabels (UniqueIdRange.All, emptyLabels, true)); - Assert.ThrowsAsync (() => inbox.AddLabelsAsync (UniqueIdRange.All, emptyLabels, true)); Assert.Throws (() => inbox.AddLabels ((IList) null, 1, labels, true)); Assert.ThrowsAsync (() => inbox.AddLabelsAsync ((IList) null, 1, labels, true)); @@ -246,10 +194,6 @@ public void TestArgumentExceptions () Assert.ThrowsAsync (() => inbox.AddLabelsAsync (new int [] { 0 }, 1, null, true)); Assert.Throws (() => inbox.AddLabels (UniqueIdRange.All, 1, null, true)); Assert.ThrowsAsync (() => inbox.AddLabelsAsync (UniqueIdRange.All, 1, null, true)); - Assert.Throws (() => inbox.AddLabels (new int [] { 0 }, 1, emptyLabels, true)); - Assert.ThrowsAsync (() => inbox.AddLabelsAsync (new int [] { 0 }, 1, emptyLabels, true)); - Assert.Throws (() => inbox.AddLabels (UniqueIdRange.All, 1, emptyLabels, true)); - Assert.ThrowsAsync (() => inbox.AddLabelsAsync (UniqueIdRange.All, 1, emptyLabels, true)); // RemoveLabels Assert.Throws (() => inbox.RemoveLabels (-1, labels, true)); @@ -266,10 +210,6 @@ public void TestArgumentExceptions () Assert.ThrowsAsync (() => inbox.RemoveLabelsAsync (new int [] { 0 }, null, true)); Assert.Throws (() => inbox.RemoveLabels (UniqueIdRange.All, null, true)); Assert.ThrowsAsync (() => inbox.RemoveLabelsAsync (UniqueIdRange.All, null, true)); - Assert.Throws (() => inbox.RemoveLabels (new int [] { 0 }, emptyLabels, true)); - Assert.ThrowsAsync (() => inbox.RemoveLabelsAsync (new int [] { 0 }, emptyLabels, true)); - Assert.Throws (() => inbox.RemoveLabels (UniqueIdRange.All, emptyLabels, true)); - Assert.ThrowsAsync (() => inbox.RemoveLabelsAsync (UniqueIdRange.All, emptyLabels, true)); Assert.Throws (() => inbox.RemoveLabels ((IList) null, 1, labels, true)); Assert.ThrowsAsync (() => inbox.RemoveLabelsAsync ((IList) null, 1, labels, true)); @@ -279,10 +219,6 @@ public void TestArgumentExceptions () Assert.ThrowsAsync (() => inbox.RemoveLabelsAsync (new int [] { 0 }, 1, null, true)); Assert.Throws (() => inbox.RemoveLabels (UniqueIdRange.All, 1, null, true)); Assert.ThrowsAsync (() => inbox.RemoveLabelsAsync (UniqueIdRange.All, 1, null, true)); - Assert.Throws (() => inbox.RemoveLabels (new int [] { 0 }, 1, emptyLabels, true)); - Assert.ThrowsAsync (() => inbox.RemoveLabelsAsync (new int [] { 0 }, 1, emptyLabels, true)); - Assert.Throws (() => inbox.RemoveLabels (UniqueIdRange.All, 1, emptyLabels, true)); - Assert.ThrowsAsync (() => inbox.RemoveLabelsAsync (UniqueIdRange.All, 1, emptyLabels, true)); // SetLabels Assert.Throws (() => inbox.SetLabels (-1, labels, true));