3
0 Comments

[mailwipJuly 07] did you know that email has 1000 characters line length limit

Today I finally have time to dive deep into a mysterious bug in my email forwarding app where email from reddit and meetup will randomly have DKIM signature mismatch.

Not every email but just a few emails which make really hard to see what is the problem. Clearly the email is changed someway but I cannot see anything.

Today I finally identified the root cause. All the emails that fail the DKIM signature has 7 bit content transfer encoding and line that has more than 1000 characters

In email protocol, the mail reader parse your email accordingly to the encoding. Example you can say the email is base64 and entire of email is based64-encoded, the reader will decode it. Or you say the email has multi parts, each part has different encoding.

An interesting thing is email cannot have line longer than 1000 character, in fact 998 because the \n\r is already 2 characters.

And hanami failed to format that properly and apparently write line that longer than 1000 character instead of breaking them to a new line.

Note that this is 1000 character in the raw source, the mail reader happily render line with more than 1000 character just fine.

That's my Build In Public story for today. Trying to fix my email parser to handle those long email.

on July 8, 2021