Skip to content

Improve Handling of Badly Encoded Messages

Compare
Choose a tag to compare
@joeyates joeyates released this 31 Aug 16:09
· 325 commits to main since this release

We now force the body encoding to UTF-8

With badly encoded message, an error was being thrown:

    Encoding::CompatibilityError: incompatible character encodings: UTF-8
    and ASCII-8BIT

The problem occurred when:

  1. The server returned a badly encoded email message,
  2. there were non-ASCII characters in the 'From' line
  3. there were non-ASCII characters in other parts of the message.

In this case, the 'mail' gem force encoded the 'From' line as UTF-8,
but the body was still be "ASCII-8BIT". Without non-ASCII characters,
the 'From' line got coerced to the same encoding as the body,
but when both parts had non-ASCII characters, the error was thrown.

Now, we force the body to UTF-8 before uniting it tieh the 'From' line.