{"record":{"id":"21eaa9926b165fbe","repo":"jstedfast/MailKit","slug":"the-specified-folder-does-not-exist","errorCode":null,"errorMessage":"The specified folder does not exist","messagePattern":"The specified folder does not exist","errorType":"exception","errorClass":"FolderNotFoundException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolder.cs","lineNumber":1945,"sourceCode":"\t\t/// <exception cref=\"System.OperationCanceledException\">\n\t\t/// The operation was canceled via the cancellation token.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.IO.IOException\">\n\t\t/// An I/O error occurred.\n\t\t/// </exception>\n\t\t/// <exception cref=\"FolderNotFoundException\">\n\t\t/// The requested folder could not be found.\n\t\t/// </exception>\n\t\t/// <exception cref=\"ImapProtocolException\">\n\t\t/// The server's response contained unexpected tokens.\n\t\t/// </exception>\n\t\t/// <exception cref=\"ImapCommandException\">\n\t\t/// The server replied with a NO or BAD response.\n\t\t/// </exception>\n\t\tpublic override IMailFolder GetSubfolder (string name, CancellationToken cancellationToken = default)\n\t\t{\n\t\t\tif (!TryQueueGetSubfolderCommand (name, cancellationToken, out var ic, out var list, out var fullName, out var encodedName, out var folder))\n\t\t\t\treturn folder ?? throw new FolderNotFoundException (name);\n\n\t\t\tEngine.Run (ic);\n\n\t\t\tfolder = ProcessGetSubfolderResponse (ic, list, encodedName);\n\n\t\t\tif (list.Count > 1 || folder == null) {\n\t\t\t\t// Note: if any folders returned in the LIST command are unparented, have the ImapEngine look up their\n\t\t\t\t// parent folders now so that they are not left in an inconsistent state.\n\t\t\t\tEngine.LookupParentFolders (list, cancellationToken);\n\t\t\t}\n\n\t\t\tif (folder == null)\n\t\t\t\tthrow new FolderNotFoundException (fullName);\n\n\t\t\treturn folder;\n\t\t}\n\n\t\t/// <summary>","sourceCodeStart":1927,"sourceCodeEnd":1963,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolder.cs#L1927-L1963","documentation":"When the subfolder is found locally cached/known but the queuing path indicates it cannot exist, GetSubfolder throws FolderNotFoundException carrying the requested name. This is MailKit's typed signal that the requested child mailbox does not exist.","triggerScenarios":"Calling GetSubfolder(name) where TryQueueGetSubfolderCommand returns false and folder is null — the requested child folder does not exist under this parent (or the parent has no children because DirectorySeparator is '\\0').","commonSituations":"Expecting a folder ('Sent', 'Drafts') the server never created; renamed or deleted folders; connecting to a fresh mailbox without standard folders; case-sensitivity mismatches.","solutions":["Wrap in try/catch (FolderNotFoundException) and create the folder if missing","List existing subfolders with GetSubfolders() to verify the exact name/casing first","Ensure the server actually has the folder (LIST command) before assuming standard special folders exist"],"exampleFix":"// before\nvar archive = inbox.GetSubfolder(\"Archive\"); // throws if missing\n// after\nIMailFolder archive;\ntry {\n    archive = inbox.GetSubfolder(\"Archive\");\n} catch (FolderNotFoundException) {\n    archive = inbox.Create(\"Archive\", true);\n}","handlingStrategy":"try-catch","validationCode":"var existing = folder.GetSubfolders().FirstOrDefault(f => f.Name == name);\nif (existing != null) return existing;","typeGuard":null,"tryCatchPattern":"try {\n    sub = folder.GetSubfolder(name);\n} catch (FolderNotFoundException ex) {\n    sub = folder.Create(name, true); // ensure-folder pattern\n}","preventionTips":["Adopt an ensure-folder helper instead of assuming standard folders exist","Verify folder names via GetSubfolders before lookup","Handle fresh mailboxes where Sent/Drafts/Trash were never created"],"tags":["imap","mailkit","folder-not-found","resource-lookup"],"backgroundTag":"record-not-found","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"}