22

I'm looking for the maximum character length allowed for an internet Message-ID field for validation purposes within an application. I've reviewed sources such as RFC-2822 and Wikipedia "Message-ID" as well as this SO question, among other various places. The closest answer I can find is "998 characters" because that is the maximum length that the specification allows for each line in an internet message (from RFC-2822), and the Message-ID field cannot be multiple lines.

Is 998 characters the definitive answer? Is there no such limit?

3 Answers 3

17

If there's one thing I've learned about email, it must be that it's a massively distributed system for fuzzing email software. That is, no matter what the RFCs say, you will find emails violating them, some email software coping and some failing. I think most will limp along with the robustness principle in mind.

With that out of the way, I think the maximum RFC compliant Message-ID length is 995 characters.

The maximum line length per the RFC you cite is 998 characters. That would include the "Message-ID:" field name, but you can do line folding between the field name and the field body. The line containing the actual Message-ID would then contain a space (the folding whitespace), "<", Message-ID, and ">". Semantically, the angle brackets are not part of the Message-ID. Therefore you end up with a maximum of 998 - 3 = 995 characters.

4

Actually there's no limit

RFC2822 defines these productions:

message-id      =       "Message-ID:" msg-id CRLF

msg-id          =       [CFWS] "<" id-left "@" id-right ">" [CFWS]

id-left         =       dot-atom-text / no-fold-quote / obs-id-left

obs-id-left     =       local-part

local-part      =       dot-atom / quoted-string / obs-local-part

quoted-string   =       [CFWS]
                        DQUOTE *([FWS] qcontent) [FWS] DQUOTE
                        [CFWS]

CFWS            =       *([FWS] comment) (([FWS] comment) / FWS)

FWS             =       ([*WSP CRLF] 1*WSP) /   ; Folding white space

So id-left can be local-part which can be quoted-string (and thus have multiple FWS) so you can fold it as many times as needed to fit any arbitrary length of payload and still comply with the restrictions given by the RFC.

1
  • 1
    Of course, if one chooses to accept arbitrary messages conforming to RFC-822, it doesn't even impose a maximum line length.
    – Jani
    Mar 14, 2017 at 20:56
1

It's quite wilde guess, but i would say 2000 chars is more than enough and here is why:

The only related length requirement I found is message line can't be longer than 998 chars. My wild assumption would be this: Message id should be able to be within one line of message and this limit is 998 chars. From message ids i saw during my time it's not that long. So from all the uncertainty i would say 1000 chars is very "safe" minimum range and like 2000 should cover any scenario if there is any kind of "structural overhead" of some data shape.

https://www.rfc-editor.org/rfc/rfc2822

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.