{"record":{"id":"f1a041677ba44530","repo":"jstedfast/MailKit","slug":"invalid-part-specifier-in-annotation-entry","errorCode":null,"errorMessage":"Invalid part-specifier in annotation entry.","messagePattern":"Invalid part-specifier in annotation entry\\.","errorType":"validation","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"MailKit/AnnotationEntry.cs","lineNumber":458,"sourceCode":"\t\t\tstring path;\n\n\t\t\tfor (int i = 1; i < entry.Length; i++) {\n\t\t\t\tchar c = entry[i];\n\n\t\t\t\tif (c >= '0' && c <= '9' && pc == '/') {\n\t\t\t\t\tif (component > 0)\n\t\t\t\t\t\tthrow new FormatException (\"Invalid annotation entry.\");\n\n\t\t\t\t\tstartIndex = i;\n\t\t\t\t\tendIndex = i + 1;\n\t\t\t\t\tpc = c;\n\n\t\t\t\t\twhile (endIndex < entry.Length) {\n\t\t\t\t\t\tc = entry[endIndex];\n\n\t\t\t\t\t\tif (c == '/') {\n\t\t\t\t\t\t\tif (pc == '.')\n\t\t\t\t\t\t\t\tthrow new FormatException (\"Invalid part-specifier in annotation entry.\");\n\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!(c >= '0' && c <= '9') && c != '.')\n\t\t\t\t\t\t\tthrow new FormatException ($\"Invalid character in part-specifier: '{c}'.\");\n\n\t\t\t\t\t\tif (c == '.' && pc == '.')\n\t\t\t\t\t\t\tthrow new FormatException (\"Invalid part-specifier in annotation entry.\");\n\n\t\t\t\t\t\tendIndex++;\n\t\t\t\t\t\tpc = c;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (endIndex >= entry.Length)\n\t\t\t\t\t\tthrow new FormatException (\"Incomplete part-specifier in annotation entry.\");\n\n\t\t\t\t\tpartSpecifier = entry.Substring (startIndex, endIndex - startIndex);","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AnnotationEntry.cs#L440-L476","documentation":"MailKit's AnnotationEntry.Parse validates IMAP ANNOTATE entry part-specifiers (the '3.1' section digits between slashes). A part-specifier may not start with a separator after a slash, i.e. a '.' immediately following '/' is malformed, so Parse throws FormatException. This guards against entry strings like '/3.1/text' that violate RFC 5257 syntax.","triggerScenarios":"Calling AnnotationEntry.Parse or AnnotationEntry.Create with an entry whose part-specifier begins with '.' right after a '/' (e.g. \"/.1/text\" or \"2/.text\").","commonSituations":"Hand-constructed annotation entry strings, string concatenation that produces empty part segments (e.g. joining a section prefix with a separator), copying entry names from server logs with typos.","solutions":["Fix the entry string so the part-specifier contains only digits and single '.' separators, with no leading or trailing '.' after '/'","Use AnnotationEntry.Create with a numeric part specifier string like \"1.2\" instead of embedding separators","Validate the part-specifier with a regex like ^\\d+(\\.\\d+)*$ before calling Parse"],"exampleFix":"// before\nvar entry = AnnotationEntry.Parse (\"/.1/text.priv\");\n// after\nvar entry = AnnotationEntry.Parse (\"/1.1/text.priv\");","handlingStrategy":"validation","validationCode":"static bool IsValidPartSpecifier (string entry) =>\n    entry != null && System.Text.RegularExpressions.Regex.IsMatch (entry, @\"^/\\d+(\\.\\d)*/[^\"]+\";) ;","typeGuard":"bool IsValidEntry (string entry) =>\n    !string.IsNullOrEmpty (entry) && entry.StartsWith (\"/\") && System.Text.RegularExpressions.Regex.IsMatch (entry, @\"^(/[0-9]+(\\.[0-9]+)*)+/\",\" );","tryCatchPattern":"try { var entry = AnnotationEntry.Parse (input); }\ncatch (FormatException ex) { log.Warn ($\"Bad annotation entry '{input}': {ex.Message}\"); }","preventionTips":["Validate entry strings with ^/\\d+(\\.\\d+)* before parsing","Build entries with AnnotationEntry.Create instead of raw string concatenation","Check for empty segments after splitting on '/' and '.'"],"tags":["imap","annotations","format-exception","parser"],"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-15T23:17:13.987Z"}