Fixed libraries/Email.php: UTF8 subject line encoding for Apple Mail (and iOS Mail) / WordWrap for plaintext email #1281

Closed
wants to merge 5 commits into
from

Projects

None yet

3 participants

@williamli

This patches the Email.php library so that UTF8 subject lines (currently encoded with Q encoding) will show up correctly in Apple Mail / iOS Mail (using B encoding instead).

It also patches the _get_alt_message function so that emails sent from CI will honor the $config['wordwrap'] and $config['wrapchars'] settings.

PS: The word_wrap function used in the master source code does not work well with multibyte characters. It wraps multibyte characters in the middle and breaks multibyte characters making them look like random symbol. This led me to try and disable wordwrap in config only to find out wordwrap wasn't honored in the existing source.

williamli added some commits Apr 23, 2012
@williamli williamli makes the _get_alt_message function honor the $config['wordwrap'] and…
… $config['wrapchars'] settings so that even the plaintext of a multipart email will follow the wordwrap parameters in the email config file.
3866e7a
@williamli williamli use B encoding for UTF-8 subject lines instead of the current Q encod…
…ing as Apple Mail (and iOS Mail) have problems loading many of the UTF-8 subject lines when they are encoded with Q encoding (_prep_q_encoding)
972216f
@narfbg narfbg and 1 other commented on an outdated diff Apr 24, 2012
system/libraries/Email.php
@@ -367,11 +367,11 @@ public function bcc($bcc, $limit = '')
* @return object
*/
public function subject($subject)
- {
- $subject = $this->_prep_q_encoding($subject);
- $this->_set_header('Subject', $subject);
+ {
+ $subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
+ parent::_set_header('Subject', $subject);
narfbg
narfbg Apr 24, 2012 Contributor

CI_Email doesn't have a parent class - this would probably trigger a fatal error.
Also, use tabs for indentation instead of spaces. See the coding style guidelines for more info.

williamli
williamli Apr 24, 2012

oops sorry, I copied the code over from MY_Email class last night where I was doing all the testing.

@narfbg narfbg and 1 other commented on an outdated diff Apr 24, 2012
system/libraries/Email.php
@@ -760,7 +760,14 @@ protected function _get_alt_message()
{
if ($this->alt_message != '')
{
- return $this->word_wrap($this->alt_message, '76');
+ if ($this->wordwrap === TRUE)
narfbg
narfbg Apr 24, 2012 Contributor

Could very well be:

return ($this->wordwrap) ? $this->word_wrap($this->alt_message) : $this->alt_messasge;

... and the same in _get_alt_message().

williamli
williamli Apr 24, 2012

Yep. I have shortened the code as suggested now. Please note that the last part of the code should read $this->alt_message instead of $this->alt_messasge (typo)

I have fixed the error and shortened the code as suggested by @narfbg

@narfbg narfbg added a commit that referenced this pull request Oct 19, 2012
@narfbg narfbg Fix another mailing issue (based on #1281) 8df1ae2
Contributor
narfbg commented Oct 19, 2012

Both issues resolved and hopefully I won't forget to look at the multibyte characters issue.

@narfbg narfbg closed this Oct 19, 2012
Contributor
GDmac commented Oct 21, 2012

if the encoding is known, could use multibyte functions like mb_strcut() or mb_split()

@nonchip nonchip pushed a commit to nonchip/CodeIgniter that referenced this pull request Jun 29, 2013
@narfbg narfbg Fix another mailing issue (based on #1281) 3f6e5c6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment