gen-smtp / gen_smtp

The extensible Erlang SMTP client and server library.
Other
683 stars 266 forks source link

RFC2231 header parameter-value encoding #311

Closed Maria-12648430 closed 1 year ago

Maria-12648430 commented 2 years ago

As pointed out in #310, parameters are supposed to be encoded according to RFC2231, not RFC2047.

The value is first analyzed to decide which representation can/must be used, based on the presence of CTLs, spaces, tspecials, and UTF-8 multibyte characters. Then it is encoded in the selected representation. If the parameter lines become too long (>76 bytes), they are split up according to the continuation scheme described in RFC2231.

In hindsight, getting this right was surprisingly difficult, and therefore a careful review seems to be called for.

seriyps commented 2 years ago

Was surprized it did not trigger proper test failure, but it seems we don't generate long or non-ascii header parameter values.

https://github.com/gen-smtp/gen_smtp/blob/c6f25a758d60da9788bf5ddf73e985dacb28f74b/test/prop_mimemail.erl#L396

Might be nice to update when parser part is also implemented.

I'll have a deeper look bit later today, thank you!

Maria-12648430 commented 2 years ago

Last commit takes care of an edge case: invalid UTF-8 sequences were not encoded but left as-is. Also added specs.

mworrell commented 2 years ago

@seriyps Ok to merge this?

seriyps commented 1 year ago

Great work! Sorry for the delay, it was due to UA-RU war.

Maria-12648430 commented 1 year ago

@seriyps thanks 😄 TBH, I totally forgot about this one 😅

mworrell commented 1 year ago

@seriyps I am ok with this being merged.