{"record":{"id":"0539905c2800d0dd","repo":"jstedfast/MailKit","slug":"the-format-i-format-specifier-is-not-supported","errorCode":null,"errorMessage":"The %{format[i]} format specifier is not supported.","messagePattern":"The %(.+?) format specifier is not supported\\.","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapCommand.cs","lineNumber":232,"sourceCode":"\n\t\t\t\t\t\tbuilder.Append (LiteralTokenSuffix, 0, LiteralTokenSuffix.Length);\n\n\t\t\t\t\t\ttotalSize += length;\n\n\t\t\t\t\t\tparts.Add (new ImapCommandPart (builder.ToArray (), literal, wait));\n\t\t\t\t\t\tbuilder.Clear ();\n\n\t\t\t\t\t\tif (prefix == UTF8LiteralTokenPrefix)\n\t\t\t\t\t\t\tbuilder.Append ((byte) ')');\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'S': // a string which may need to be quoted or made into a literal\n\t\t\t\t\t\tAppendString (options, true, builder, (string) args[argc++]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'Q': // similar to %S but string must be quoted at a minimum\n\t\t\t\t\t\tAppendString (options, false, builder, (string) args[argc++]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new FormatException ($\"The %{format[i]} format specifier is not supported.\");\n\t\t\t\t\t}\n\t\t\t\t} else if (format[i] < 128) {\n\t\t\t\t\tbuilder.Append ((byte) format[i]);\n\t\t\t\t} else {\n\t\t\t\t\tint nchars = char.IsSurrogate (format[i]) ? 2 : 1;\n\t\t\t\t\tint nbytes = Encoding.UTF8.GetBytes (format, i, nchars, utf8, 0);\n\t\t\t\t\tbuilder.Append (utf8, 0, nbytes);\n\t\t\t\t\ti += nchars - 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tparts.Add (new ImapCommandPart (builder.ToArray (), null));\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"MailKit.Net.Imap.ImapCommand\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapCommand.cs#L214-L250","documentation":"ImapCommand uses a printf-style format string (e.g. \"LOGIN %S %S\") to build IMAP commands; %S, %Q, etc. are the only supported specifiers. A FormatException is thrown when an unknown specifier appears, meaning MailKit itself passed a malformed internal format string or a subclass/user-built command used an invalid one.","triggerScenarios":"Passing a format string containing an unrecognized specifier (anything other than the supported set like %S, %Q) to command construction that formats arguments; a literal '%' in a command template not doubled/escaped properly.","commonSituations":"Custom IMAP extensions built on top of MailKit internals; MailKit version differences where a specifier was added later; typos in derived command builders.","solutions":["Use only documented specifiers (%S, %Q and companions) in the command format string.","Escape literal percent signs if the format mechanism supports it, or restructure so the '%' is part of an argument passed via %S.","Check the MailKit source (ImapCommand.FormatCommand) for the exact supported specifier set in your version and upgrade if a needed specifier was added later."],"exampleFix":"// before\nvar ic = new ImapCommand(engine, token, null, \"MYCMD %X\", arg);\n\n// after\nvar ic = new ImapCommand(engine, token, null, \"MYCMD %S\", arg.ToString());","handlingStrategy":"try-catch","validationCode":"// pre-validate custom format strings before use\nbool IsValidSpecifier(char c) => \"SLQ\".Contains(c) || char.IsLetter(c) == false; // restrict to known set","typeGuard":null,"tryCatchPattern":"try { ic = new ImapCommand(engine, token, null, format, args); } catch (FormatException ex) { throw new InvalidOperationException($\"Bad command format '{format}': {ex.Message}\", ex); }","preventionTips":["Use only specifiers documented in ImapCommand.FormatCommand for your MailKit version.","Add a unit test that formats every command template your app builds.","Avoid hand-building format strings from user input."],"tags":["imap","format-string","internal-error"],"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"}