{"record":{"id":"633f16b4022bcad3","repo":"jstedfast/MailKit","slug":"invalid-part-specifier","errorCode":null,"errorMessage":"Invalid part-specifier.","messagePattern":"Invalid part-specifier\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/AnnotationEntry.cs","lineNumber":166,"sourceCode":"\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{\n\t\t\tif (partSpecifier == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (partSpecifier));\n\n\t\t\tchar pc = '\\0';\n\n\t\t\tfor (int i = 0; i < partSpecifier.Length; i++) {\n\t\t\t\tchar c = partSpecifier[i];\n\n\t\t\t\tif (!((c >= '0' && c <= '9') || c == '.') || (c == '.' && (pc == '.' || pc == '\\0')))\n\t\t\t\t\tthrow new ArgumentException (\"Invalid part-specifier.\", nameof (partSpecifier));\n\n\t\t\t\tpc = c;\n\t\t\t}\n\n\t\t\tif (pc == '.')\n\t\t\t\tthrow new ArgumentException (\"Invalid part-specifier.\", nameof (partSpecifier));\n\t\t}\n\n\t\tAnnotationEntry (string? partSpecifier, string entry, string path, AnnotationScope scope)\n\t\t{\n\t\t\tPartSpecifier = partSpecifier;\n\t\t\tEntry = entry;\n\t\t\tPath = path;\n\t\t\tScope = scope;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"MailKit.AnnotationEntry\"/> struct.","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AnnotationEntry.cs#L148-L184","documentation":"AnnotationEntry.ValidatePartSpecifier rejects part specifiers that are not valid MIME part numbers. Each character must be a digit or '.', a '.' may not start the specifier or follow another '.', making strings like \".1\", \"1..2\", or \"text/html\" invalid. Thrown as ArgumentException naming partSpecifier.","triggerScenarios":"Passing a part specifier containing non-digit characters (e.g. \"text\", \"1.A\"), starting with '.', or containing consecutive dots ('.') to an AnnotationEntry constructor/factory.","commonSituations":"Confusing MIME section specifiers with body-part names like \"text\" or \"HEADER\" (valid elsewhere in IMAP but not here); building part paths with string joins that produce double dots.","solutions":["Use only digit-and-dot MIME part numbers, e.g. \"1\", \"1.2\", \"1.3.1\"","Remove leading dots and collapse consecutive dots in the specifier","If annotating a non-numeric section, check whether a different overload or entry form is appropriate"],"exampleFix":"// before\nvar entry = AnnotationEntry.Create (\"1..2\", \"comment\", AnnotationScope.Shared);\n// after\nvar entry = AnnotationEntry.Create (\"1.2\", \"comment\", AnnotationScope.Shared);","handlingStrategy":"validation","validationCode":"static bool IsValidPartSpecifier (string? s) =>\n    !string.IsNullOrEmpty (s)\n    && s.All (c => (c >= '0' && c <= '9') || c == '.')\n    && !s.StartsWith (\".\") && !s.EndsWith (\".\") && !s.Contains (\"..\");","typeGuard":"bool IsNumericPartSpecifier (string? s) =>\n    s != null && System.Text.RegularExpressions.Regex.IsMatch (s, @\"^\\d+(\\.\\d+)*$\");","tryCatchPattern":"try {\n    var entry = AnnotationEntry.Create (partSpecifier, path, scope);\n} catch (ArgumentException ex) when (ex.ParamName == \"partSpecifier\") {\n    logger.LogError (ex, \"Invalid part specifier: {Spec}\", partSpecifier);\n}","preventionTips":["Only pass digit-and-dot MIME part numbers to this API","Use a regex like ^\\d+(\\.\\d+)*$ to validate specifiers","Do not reuse IMAP section names (\"HEADER\", \"TEXT\") as part specifiers here"],"tags":["imap","annotation","mime","argument-validation"],"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"}