{"record":{"id":"24e01d8ab87fdc4b","repo":"jstedfast/MailKit","slug":"invalid-annotation-entry-path","errorCode":null,"errorMessage":"Invalid annotation entry path.","messagePattern":"Invalid annotation entry path\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/AnnotationEntry.cs","lineNumber":138,"sourceCode":"\t\t\tif (path[0] != '/' && path[0] != '*' && path[0] != '%')\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths must begin with '/'.\", nameof (path));\n\n\t\t\tif (path.Length > 1 && path[1] >= '0' && path[1] <= '9')\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths must not include a part-specifier.\", nameof (path));\n\n\t\t\tif (path == \"*\" || path == \"%\")\n\t\t\t\treturn;\n\n\t\t\tchar pc = path[0];\n\n\t\t\tfor (int i = 1; i < path.Length; i++) {\n\t\t\t\tchar c = path[i];\n\n\t\t\t\tif (c > 127)\n\t\t\t\t\tthrow new ArgumentException ($\"Invalid character in annotation entry path: '{c}'.\", nameof (path));\n\n\t\t\t\tif (c >= '0' && c <= '9' && pc == '/')\n\t\t\t\t\tthrow new ArgumentException (\"Invalid annotation entry path.\", nameof (path));\n\n\t\t\t\tif ((pc == '/' || pc == '.') && (c == '/' || c == '.'))\n\t\t\t\t\tthrow new ArgumentException (\"Invalid annotation entry path.\", nameof (path));\n\n\t\t\t\tpc = c;\n\t\t\t}\n\n\t\t\tint endIndex = path.Length - 1;\n\n\t\t\tif (path[endIndex] == '/')\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths must not end with '/'.\", nameof (path));\n\n\t\t\tif (path[endIndex] == '.')\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths must not end with '.'.\", nameof (path));\n\t\t}\n\n\t\tstatic void ValidatePartSpecifier (string partSpecifier)\n\t\t{","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AnnotationEntry.cs#L120-L156","documentation":"AnnotationEntry.ValidatePath throws the generic \"Invalid annotation entry path\" when a digit follows a '/' — meaning the path embeds a part specifier segment like \"/1/\". Per RFC 5257, digits immediately after a separator start a MIME part specifier, which is not allowed in AnnotationEntry paths.","triggerScenarios":"Calling `new AnnotationEntry(\"/1/comment\", ...)` or \"/2/text\", where the second path character (or any character following '/') is a digit.","commonSituations":"Encoding MIME part numbers into entry paths by hand; converting raw IMAP annotation strings without stripping part specifiers; following documentation for part-level annotations incorrectly.","solutions":["Remove the numeric part-specifier segment so the path segment after each '/' starts with a non-digit (e.g. \"/1/comment\" -> \"/comment\").","Use the library's supported API for part-specific annotations if needed.","Validate path segments before construction: reject segments beginning with a digit."],"exampleFix":"// before\nvar entry = new AnnotationEntry(\"/1/comment\", AnnotationScope.Shared);\n// after\nvar entry = new AnnotationEntry(\"/comment\", AnnotationScope.Shared);","handlingStrategy":"validation","validationCode":"bool HasDigitAfterSlash(string p) {\n    for (int i = 1; i < p.Length; i++)\n        if (char.IsDigit(p[i]) && p[i-1] == '/') return true;\n    return false;\n}\nif (HasDigitAfterSlash(path))\n    throw new FormatException(\"Path must not start a segment with a digit (part specifier)\");","typeGuard":"bool IsValidEntryPath(string p) => p != null && p.Length > 0 && p[0] != '/' || p == \"*\" || p == \"%\";","tryCatchPattern":"try\n{\n    var entry = new AnnotationEntry(path, AnnotationScope.Shared);\n}\ncatch (ArgumentException ex) when (ex.Message == \"Invalid annotation entry path.\")\n{\n    // strip/repair the part-specifier segment before retrying\n}","preventionTips":["Reject path segments beginning with digits during input validation.","Keep MIME part handling in dedicated APIs, not entry paths.","Test path builders against samples like \"/1/comment\" to catch regressions."],"tags":["mailkit","imap","annotations","path-format","mime"],"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-16T04:17:20.429Z"}