I know this issue has been reported in the past (repeatedly), however this is both a bug report and a patch to resolve it in a manner which I think will eliminate it for the foreseeable future.
Issue:
Using Simplenews to send newsletter, I was getting accented A characters when a table in the html was configured with a non-breaking space. The html email looked correct in Outlook and on Gmail, but showed accented characters on the iPhone. Investigating the file I found that the charset within the email was ISO-8859-1. I inserted a specific accented character and examined the result. The accent character was corrupted into a different accent character. Looking at a UTF-8 table of character values, and ISO-8859-1 character values allowed me to determine that the accent character was appearing because the raw data was UTF-8 encoded, and not ISO-8859-1 as indicated by the content-type charset attribute. (The accent A character is a partial encoding of the non-breaking space UTF-8 character.)
As Drupal outputs UTF-8 encoded characters by default I determined the best course of action was to get smtp to default to UTF-8 unless it was being overridden locally. I do this by checking if 'charset' is configured and pre-setting it to UTF-8 if it is not. This is handled in smtp.mail.inc. Whatever value charset is configured to is carried over to the final email.
If there is a reasonable alternative to embedding 'UTF-8' in the patch I would be inclined to utilize it, but I'm not yet aware of a place in Drupal to query the currently in-use character encoding.
(patch to follow once issue # is assigned)
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | fix-character-encoding-conflict-1330714-5.patch | 1.11 KB | fabianx |
| #1 | smtp-1330714-charset_utf8.patch | 788 bytes | topham |
Comments
Comment #1
topham commentedPatch to modify smtp.mail.inc to use a default of UTF-8 unless charset is configured.
Comment #2
topham commentedChanged Status to Needs Review, after reviewing Status descriptions.
Comment #3
fabianx commentedReviewed and tested, works like a charm, please commit!
The patch does work, because drupal uses UTF-8 everwhere else. PHPMailer has iso-8859-1 as default. This _will_ automatically lead to conflicts.
This patch solves this by always setting "UTF-8", when nothing else is specified.
Comment #4
franzplease, use soft tabs (i.e. spaces)
Comment #5
fabianx commentedHere is re-rolled patch.
Comment #6
fabianx commentedAs only markup has changed -> back to RTBC
Comment #7
franzCommitted, thanks for the fix.