{"record":{"id":"82a03bb38f71820e","repo":"jstedfast/MailKit","slug":"the-name-of-the-subfolder-is-invalid","errorCode":null,"errorMessage":"The name of the subfolder is invalid.","messagePattern":"The name of the subfolder is invalid\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolder.cs","lineNumber":1853,"sourceCode":"\t\t\t\tawait Engine.LookupParentFoldersAsync (list, cancellationToken).ConfigureAwait (false);\n\n\t\t\tif (status) {\n\t\t\t\tfor (int i = 0; i < children.Count; i++) {\n\t\t\t\t\tif (children[i].Exists)\n\t\t\t\t\t\tawait ((ImapFolder) children[i]).StatusAsync (items, false, cancellationToken).ConfigureAwait (false);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn children;\n\t\t}\n\n\t\tbool TryQueueGetSubfolderCommand (string name, CancellationToken cancellationToken, [NotNullWhen (true)] out ImapCommand? ic, [NotNullWhen (true)] out List<ImapFolder>? list, [NotNullWhen (true)] out string? fullName, [NotNullWhen (true)] out string? encodedName, out ImapFolder? folder)\n\t\t{\n\t\t\tif (name == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (name));\n\n\t\t\tif (!ImapEngine.IsValidMailboxName (name, DirectorySeparator))\n\t\t\t\tthrow new ArgumentException (\"The name of the subfolder is invalid.\", nameof (name));\n\n\t\t\tCheckState (false, false);\n\n\t\t\t// Any folder with a nil directory separator cannot have children.\n\t\t\tif (DirectorySeparator == '\\0') {\n\t\t\t\tencodedName = null;\n\t\t\t\tfullName = null;\n\t\t\t\tfolder = null;\n\t\t\t\tlist = null;\n\t\t\t\tic = null;\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tfullName = FullName.Length > 0 ? FullName + DirectorySeparator + name : name;\n\t\t\tencodedName = Engine.EncodeMailboxName (fullName);\n\n\t\t\tif (Engine.TryGetCachedFolder (encodedName, out folder)) {\n\t\t\t\tlist = null;","sourceCodeStart":1835,"sourceCodeEnd":1871,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolder.cs#L1835-L1871","documentation":"After the null check, GetSubfolder validates the name with ImapEngine.IsValidMailboxName against the folder's DirectorySeparator; illegal names (containing the hierarchy separator, leading delimiter, etc.) throw ArgumentException with paramName 'name'.","triggerScenarios":"Calling folder.GetSubfolder(name) where name contains the folder's DirectorySeparator (e.g. '/' on most servers) or otherwise fails IsValidMailboxName — e.g. passing a full path like 'Parent/Child' to a folder's GetSubfolder instead of the bare child name.","commonSituations":"Passing fully-qualified folder paths instead of the leaf name; user input with slashes; using a separator from a different server (e.g. '.' on Courier) after migrating hosts.","solutions":["Pass only the immediate child's name, not a path; resolve nested paths iteratively via GetSubfolder chains or client.GetFolder(fullName)","Sanitize/reject names containing DirectorySeparator before calling","Use ImapClient.GetFolder for full-path lookup instead of parent.GetSubfolder"],"exampleFix":"// before\nvar sub = inbox.GetSubfolder(\"Work/2024\"); // throws\n// after\nvar work = inbox.GetSubfolder(\"Work\");\nvar sub = work.GetSubfolder(\"2024\");","handlingStrategy":"validation","validationCode":"if (name != null && name.Contains(folder.DirectorySeparator))\n    throw new ArgumentException($\"Use GetSubfolder per path segment; '{folder.DirectorySeparator}' is not allowed.\");\nvar sub = folder.GetSubfolder(name);","typeGuard":null,"tryCatchPattern":"try {\n    sub = folder.GetSubfolder(name);\n} catch (ArgumentException ex) when (ex.ParamName == \"name\") {\n    // split the path and walk segments, or use client.GetFolder(fullPath)\n}","preventionTips":["Pass leaf names to GetSubfolder, full paths to ImapClient.GetFolder","Split paths on DirectorySeparator and resolve hierarchically","Never assume '/' — read the server's DirectorySeparator"],"tags":["imap","mailkit","argument-validation","folder-naming"],"backgroundTag":"invalid-argument-format","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"}