{"record":{"id":"58b7ebc081035c99","repo":"jstedfast/MailKit","slug":"no-indexes-were-specified","errorCode":null,"errorMessage":"No indexes were specified.","messagePattern":"No indexes were specified\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapUtils.cs","lineNumber":274,"sourceCode":"\t\t/// <para>-or-</para>\n\t\t/// <para><paramref name=\"indexes\"/> is <see langword=\"null\" />.</para>\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ArgumentOutOfRangeException\">\n\t\t/// One or more of the indexes has a negative value.\n\t\t/// </exception>\n\t\tpublic static void FormatIndexSet (ImapEngine engine, StringBuilder builder, IList<int> indexes)\n\t\t{\n\t\t\tif (engine == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (engine));\n\n\t\t\tif (builder == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (builder));\n\n\t\t\tif (indexes == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (indexes));\n\n\t\t\tif (indexes.Count == 0)\n\t\t\t\tthrow new ArgumentException (\"No indexes were specified.\", nameof (indexes));\n\n\t\t\tint index = 0;\n\n\t\t\twhile (index < indexes.Count) {\n\t\t\t\tif (indexes[index] < 0)\n\t\t\t\t\tthrow new ArgumentException (\"One or more of the indexes is negative.\", nameof (indexes));\n\n\t\t\t\tint begin = indexes[index];\n\t\t\t\tint end = indexes[index];\n\t\t\t\tint i = index + 1;\n\n\t\t\t\tif (i < indexes.Count) {\n\t\t\t\t\tif (indexes[i] == end + 1) {\n\t\t\t\t\t\tend = indexes[i++];\n\n\t\t\t\t\t\twhile (i < indexes.Count && indexes[i] == end + 1) {\n\t\t\t\t\t\t\tend++;\n\t\t\t\t\t\t\ti++;","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapUtils.cs#L256-L292","documentation":"ImapUtils.FormatIndexSet builds IMAP message-sequence sets and throws an ArgumentNullException if indexes is null and an ArgumentException if the list is empty. An IMAP sequence set cannot be formed from zero indexes, so the library refuses early rather than emitting an invalid command.","triggerScenarios":"Calling methods like folder.GetMessages(IList<int>, ...), AddFlags/RemoveFlags with an index list, or StoreAsync with UniqueIds where the passed IList<int>/uint list is empty (e.g. no messages matched a previous query).","commonSituations":"Passing the result of a filtered search straight into GetMessages without checking Count; using message count of an empty folder; downstream code produced an empty ID list.","solutions":["Check indexes != null && indexes.Count > 0 before calling the API and skip the call when empty.","Guard by folder Count: only fetch ranges when folder.Count > 0.","When indexes come from a search, handle the empty result as a no-op instead of a fetch."],"exampleFix":"// before\nvar messages = await folder.GetMessagesAsync(searchResults, summary);\n\n// after\nif (searchResults == null || searchResults.Count == 0)\n    return new List<IMessageSummary>();\nvar messages = await folder.GetMessagesAsync(searchResults, summary);","handlingStrategy":"validation","validationCode":"if (indexes == null || indexes.Count == 0)\n    return; // nothing to fetch — treat as no-op","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always check collection Count before index/UID-based MailKit calls","Treat empty search results as an early return, not a fetch","Never pass through nullable lists without a null check"],"tags":["imap","argument-validation","empty-collection","mailkit"],"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-16T04:17:20.429Z"}