jstedfast/MailKit · error · ImapProtocolException

STATUS

Error message

STATUS

What it means

Thrown when parsing an untagged STATUS response: the mailbox name token was not an atom, quoted string, or NIL as allowed by RFC 3501, so the STATUS response is syntactically invalid. MailKit rejects the malformed token instead of misinterpreting the response.

Solutions

  1. Capture the protocol log to see the exact STATUS response line that failed
  2. Check whether the mailbox name contains characters that require quoting; verify the server quotes them per RFC 3501
  3. Test with a reference server (Dovecot) to confirm which side is non-compliant
  4. Upgrade MailKit in case parser handling of mailbox-name encodings (UTF-8/UTF-7) has improved
  5. If you control the server, fix it to emit atom, quoted string, or NIL for the mailbox name

Example fix

// before
// server: * STATUS INBOX (MESSAGES 5)   <- name with spaces unquoted
// after
// server: * STATUS "My Inbox" (MESSAGES 5)
Defensive patterns

Strategy: try-catch

Try / catch

try {
    var status = folder.Status (StatusItems.Count);
} catch (ImapProtocolException ex) {
    logger.LogError (ex, "Malformed STATUS response from server");
    // degrade: fall back to Examine/GetFolder information
}

Prevention

When it happens

Trigger: Server sends `* STATUS <bad-token> (...)` where the mailbox name is something other than a valid atom, quoted string, or NIL — encountered while processing unsolicited or requested STATUS responses during ImapClient operations (e.g. GetFolder status queries, IDLE with NOTIFY).

Common situations: Broken or experimental server implementations emitting raw or unquoted strings with special characters in mailbox names; servers not quoting names containing spaces or non-ASCII (UTF-7/UTF-8) characters; proxies corrupting the response.

Related errors


AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15). Data as JSON: /api/errors/ad00c99b7b833008. Report an issue: GitHub.

Appendix: source

Thrown at MailKit/Net/Imap/ImapEngine.cs:2688

		void UpdateStatus (CancellationToken cancellationToken)
		{
			var token = ReadToken (ImapStream.AtomSpecials, cancellationToken);
			string name;

			switch (token.Type) {
			case ImapTokenType.Literal:
				name = ReadLiteral (cancellationToken);
				break;
			case ImapTokenType.QString:
			case ImapTokenType.Atom:
				name = (string) token.Value;
				break;
			case ImapTokenType.Nil:
				// Note: according to rfc3501, section 4.5, NIL is acceptable as a mailbox name.
				name = (string) token.Value;
				break;
			default:
				throw UnexpectedToken (GenericUntaggedResponseSyntaxErrorFormat, "STATUS", token);
			}

			// Note: if the folder is null, then it probably means the user is using NOTIFY
			// and hasn't yet requested the folder. That's ok.
			TryGetCachedFolder (name, out var folder);

			token = ReadToken (cancellationToken);

			AssertToken (token, ImapTokenType.OpenParen, GenericUntaggedResponseSyntaxErrorFormat, "STATUS", token);

			do {
				token = ReadToken (cancellationToken);

				if (token.Type == ImapTokenType.CloseParen)
					break;

				AssertToken (token, ImapTokenType.Atom, GenericUntaggedResponseSyntaxErrorFormat, "STATUS", token);

View on GitHub (pinned to 9d3859a785)