mikel / mail

A Really Ruby Mail Library
MIT License
3.6k stars 931 forks source link

Fix exception when multibyte UTF-8 chars are in multipart boundary. #1601

Open pdg137 opened 5 months ago

pdg137 commented 5 months ago

The gem splits multipart emails on a boundary string using a Regex, but this fails on certain invalid emails when the boundary is interpreted as UTF-8 and the body is considered ASCII-8BIT, causing an exception:

Encoding::CompatibilityError: incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string)

I changed it to detect that case and simply force the encoding of boundary to ASCII-8BIT so it can work without exception. Not sure if it should do something smarter, but this seems to at least work for the tiny fraction of emails that have this problem.