{"record":{"id":"f749393bd80cc5ac","repo":"jstedfast/MailKit","slug":"must-supply-at-least-one-folder","errorCode":null,"errorMessage":"Must supply at least one folder.","messagePattern":"Must supply at least one folder\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapEventGroup.cs","lineNumber":309,"sourceCode":"\t\t\t/// </remarks>\n\t\t\t/// <param name=\"name\">The name of the mailbox filter.</param>\n\t\t\t/// <param name=\"folders\">The list of folders to watch for events.</param>\n\t\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t\t/// <paramref name=\"folders\"/> is <see langword=\"null\" />.\n\t\t\t/// </exception>\n\t\t\t/// <exception cref=\"System.ArgumentException\">\n\t\t\t/// <para>The list of <paramref name=\"folders\"/> is empty.</para>\n\t\t\t/// <para>-or-</para>\n\t\t\t/// <para>The list of <paramref name=\"folders\"/> contains folders that are not of\n\t\t\t/// type <see cref=\"ImapFolder\"/>.</para>\n\t\t\t/// </exception>\n\t\t\tinternal Mailboxes (string name, IList<IMailFolder> folders) : base (name)\n\t\t\t{\n\t\t\t\tif (folders == null)\n\t\t\t\t\tthrow new ArgumentNullException (nameof (folders));\n\n\t\t\t\tif (folders.Count == 0)\n\t\t\t\t\tthrow new ArgumentException (\"Must supply at least one folder.\", nameof (folders));\n\n\t\t\t\tthis.folders = new ImapFolder[folders.Count];\n\t\t\t\tfor (int i = 0; i < folders.Count; i++) {\n\t\t\t\t\tif (folders[i] is not ImapFolder folder)\n\t\t\t\t\t\tthrow new ArgumentException (\"All folders must be ImapFolders.\", nameof (folders));\n\n\t\t\t\t\tthis.folders[i] = folder;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/// <summary>\n\t\t\t/// Format the IMAP NOTIFY command for this particular IMAP mailbox filter.\n\t\t\t/// </summary>\n\t\t\t/// <remarks>\n\t\t\t/// Formats the IMAP NOTIFY command for this particular IMAP mailbox filter.\n\t\t\t/// </remarks>\n\t\t\t/// <param name=\"engine\">The IMAP engine.</param>\n\t\t\t/// <param name=\"command\">The IMAP command builder.</param>","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapEventGroup.cs#L291-L327","documentation":"ImapEventGroup.Mailboxes.CreateEventGroup-style constructor requires a non-empty list of folders; passing an empty IList<IMailFolder> throws ArgumentException(\"Must supply at least one folder.\"). A mailboxes event group with zero folders would produce a meaningless NOTIFY filter.","triggerScenarios":"Calling ImapEventGroup.Mailboxes (the static factory/constructor for a folders-based group) with an empty List<IMailFolder>, e.g. when a folder-search produced no results before constructing the group.","commonSituations":"Computing the folder list dynamically (e.g. from a UI selection or GetFolders result) and passing it unfiltered; empty search results silently flowing into the NOTIFY setup.","solutions":["Check folders.Count > 0 before calling Mailboxes and skip or short-circuit the NOTIFY setup if empty","Fall back to ImapEventGroup.Personal or Selected when no specific folders are available","Fix the upstream query that produced the empty folder list if it should have returned folders"],"exampleFix":"// before\nvar group = ImapEventGroup.Mailboxes(\"notify\", matchedFolders);\n\n// after\nif (matchedFolders.Count == 0) {\n    var group = ImapEventGroup.Personal();\n} else {\n    var group = ImapEventGroup.Mailboxes(\"notify\", matchedFolders);\n}","handlingStrategy":"validation","validationCode":"if (folders == null || folders.Count == 0)\n    throw new ArgumentException(\"Must supply at least one folder before building a Mailboxes event group.\");","typeGuard":"bool HasFolders(IList<IMailFolder> folders) => folders is { Count: > 0 };","tryCatchPattern":"try {\n    var group = ImapEventGroup.Mailboxes(name, folders);\n} catch (ArgumentException ex) when (ex.ParamName == \"folders\") {\n    // fall back to Personal/Selected group or skip NOTIFY\n}","preventionTips":["Guard folder lists before constructing groups","Log when a folder query returns empty so the NOTIFY setup can be skipped","Validate derived configuration before applying it to the client"],"tags":["imap","notify","argument-validation","empty-list"],"backgroundTag":"empty-required-field","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}