mikel/mail — Issue #363: win1251 charset mail contains invalid UTF-8 characters after decoding
Author: rfc2822
Created: 2012-02-29 01:25:45+00:00
State: open

mail-2.4.1 (under FreeBSD): Plain text mail with Win1251 charset returns invalid UTF-8 characters.

Sample mail:

```
From: test@test.at
Subject: XXX
Content-Type: text/plain; charset="windows-1252"
Content-Transfer-Encoding: quoted-printable

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=
XXXX
XXXXXXXXXXX Write a script=85 or suggest solid action recording. XXXXXXXXXX=
XXX
```

mail = Mail.read(); mail.body.decoded returns:
```
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXX Write a script� or suggest solid action recording. XXXXXXXXXXXXX
```

Where the character after "script" is invalid UTF-8. Workaround to ignore the bad UTF-8 character:

```ruby
body = Iconv.iconv('UTF-8//IGNORE', 'UTF-8', body)
```

(but then, the character is lost instead of the correct one)