Current implementation of drupal_wrap_mail uses PHP wordwrap function, which wraps lines only bytewise. This produces incorrectly wrapped narrow results if text contains lots of 2-byte encoded (or longer) utf-8 characters. For example, all Cyrillic letters are encoded with 2 bytes in utf-8 and Russian text will is wrapped at about 38 characters instead of 77.
Steps to reproduce:
1. Install anything that sends emails from drupal.
2. Insert long text in Russian to be sent (you may copy-paste some from here).
3. Send the email.
4. Observe a result with very short-wrapped lines.
The attached patch tries to fix the problem with a custom implementation of wordwrap function which uses mbstring functions to wrap the lines properly regardless of utf-8 byte encoding.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 364670_incorrect_wrapping_of_utf-8_lines_in_drupal_wrap_mail-11.patch | 3.11 KB | hijera |
| 0001-mb_wrap-instead-of-wordwrap.patch | 1.89 KB | abbot |
Comments
Comment #1
brianV commentedI don't think mb_wrap is a good title for this function. Perhaps something like drupal_wordwrap should be used so it's clear this is part of the Drupal API.
Also, This definately needs more comments on the code, including a header comment.
Finally, place it above the comment for _drupal_mail_wrap_line() instead between the comment and the other function.
Comment #2
catofcheshir commentedsubscribe.
Comment #3
maximn commentedComment #5
OnkelTem commentedRe-rolled patch from #3 for 7.34
Comment #7
OnkelTem commentedSorry, there was wrong path.
Comment #9
OnkelTem commentedThe patch stopped applying after 7.39 so I manually edited it a bit. Unfortunately it is failing some tests, but I have no time to fix this.
Comment #11
maximpodorov commentedThe patch is re-rolled.
Comment #13
hijera commentedRe-worked patch for Drupal 7.64