{"record":{"id":"dbc5961bd254c3ec","repo":"jstedfast/MailKit","slug":"the-set-of-unique-identifiers-is-too-large-to-fetch-with-a","errorCode":null,"errorMessage":"The set of unique identifiers is too large to fetch with a partial range.","messagePattern":"The set of unique identifiers is too large to fetch with a partial range\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolderFetch.cs","lineNumber":1147,"sourceCode":"\t\t\t\tcommand.Append (')');\n\t\t\t}\n\n\t\t\tcommand.Append (\"\\r\\n\");\n\n\t\t\treturn command.ToString ();\n\t\t}\n\n\t\tIEnumerable<ImapCommand> CreateFetchCommands (IList<UniqueId> uids, IFetchRequest request, string command, CancellationToken cancellationToken)\n\t\t{\n\t\t\tvar commands = Engine.CreateCommands (cancellationToken, this, command, uids);\n\n\t\t\tif (request.PartialRange.HasValue) {\n\t\t\t\t// Note: The PARTIAL fetch modifier applies to each FETCH command individually, so splitting the\n\t\t\t\t// set of UIDs into multiple FETCH commands would change the semantics of the request.\n\t\t\t\tvar list = new List<ImapCommand> (commands);\n\n\t\t\t\tif (list.Count > 1)\n\t\t\t\t\tthrow new NotSupportedException (\"The set of unique identifiers is too large to fetch with a partial range.\");\n\n\t\t\t\treturn list;\n\t\t\t}\n\n\t\t\treturn commands;\n\t\t}\n\n\t\tstatic int EstimateInitialCapacity (IList<UniqueId> uids)\n\t\t{\n\t\t\tif (uids is UniqueIdRange || uids is UniqueIdSet) {\n\t\t\t\t// UniqueIdRange is likely to refer to UIDs that have not yet been assigned or have been expunged,\n\t\t\t\t// so cap our maximum initial capacity to 1024 (a reasonable limit?).\n\t\t\t\treturn Math.Min (uids.Count, 1024);\n\t\t\t}\n\n\t\t\t// If the user supplied an exact set of UIDs, then we'll assume they all exist\n\t\t\t// and therefore we can use the capacity of `uids` as our initial capacity.\n\t\t\treturn uids.Count;","sourceCodeStart":1129,"sourceCodeEnd":1165,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolderFetch.cs#L1129-L1165","documentation":"CreateFetchCommands throws this NotSupportedException when a PARTIAL fetch would require more than one FETCH command. The PARTIAL modifier applies per-command, so MailKit would have to split large UID sets into multiple commands, and splitting would restart the partial offset for each command, changing the request semantics. Rather than return wrong data, it throws.","triggerScenarios":"Calling Fetch/FetchAsync by UID with request.PartialRange set and a UID set so large (typically > ~1000 UIDs, Engine's per-command batch size) that MailKit splits it into multiple UID FETCH commands.","commonSituations":"Resuming download of a large mailbox with PartialRange while passing thousands of UIDs at once; resync jobs that pass UniqueIdRange covering every message combined with partial fetch.","solutions":["Batch the UID list so each call stays within the single-command limit (fetch in chunks of ~1000 or fewer UIDs)","Fetch by sequence-number range or use a single UID range (e.g. new UniqueIdRange(...)) that maps to one command","Drop PartialRange if you don't need partial semantics, allowing the normal multi-command splitting"],"exampleFix":"// before\nvar summaries = folder.Fetch(allUids, requestWithPartialRange); // allUids.Count = 5000\n// after\nforeach (var chunk in Chunk(allUids, 1000))\n    folder.Fetch(chunk, requestWithPartialRange); // each within a single FETCH command","handlingStrategy":"validation","validationCode":"const int MaxUidsPerPartialFetch = 1000;\nif (request.PartialRange.HasValue && uids.Count > MaxUidsPerPartialFetch)\n    throw new InvalidOperationException(\"Chunk the UID set before a partial fetch.\");","typeGuard":null,"tryCatchPattern":"try {\n    summaries = folder.Fetch(uids, request);\n} catch (NotSupportedException ex) when (ex.Message.Contains(\"partial range\")) {\n    foreach (var chunk in Chunk(uids, 1000))\n        foreach (var s in folder.Fetch(chunk, request))\n            yield return s;\n}","preventionTips":["Never combine large UID sets with PartialRange; chunk to ~1000 UIDs per call","Remember PARTIAL applies per FETCH command, so splitting changes offsets","Use a single UID range instead of large exact UID sets when resuming with partial fetch"],"tags":["imap","mailkit","not-supported","partial","uid-limit","fetch"],"backgroundTag":"payload-too-large","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}