Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix email headers when using long email subjects and \r\n as crlf. #1709

Merged
merged 3 commits into from

5 participants

@bbarao

Issue

When using long email subjects and \r\n as crlf, the header is badly formatted, and either the email appears with headers on the body, or doesn't arrive at all.

The problem is that on the preg_replace, the multiline mode only matches the \n leaving the \r to be matched on the regex.

Examples

I'm showing the part of the header where the subject is set.

Current Code (notice the ^M on the first two lines)

Subject: =?utf-8?Q?Big_email_subject_with_some_non_ascii_chars:_=c3=a0_=c3=a1_=c3^M?=
 =?utf-8?Q?=a9_=c3=a8_=c3=b6_=c3=af_@_=e2=82=ac_=c2=a9_=c2=ae_>_=c2=bb_an^M?=
 =?utf-8?Q?d_so_on,_and_so_on...?=^M

Patched Code

Subject: =?utf-8?Q?Big_email_subject_with_some_non_ascii_chars:_=c3=a0_=c3=a1_=c3?=^M
 =?utf-8?Q?=a9_=c3=a8_=c3=b6_=c3=af_@_=e2=82=ac_=c2=a9_=c2=ae_>_=c2=bb_an?=^M
 =?utf-8?Q?d_so_on,_and_so_on...?=^M
system/libraries/Email.php
@@ -1228,7 +1228,7 @@ protected function _prep_q_encoding($str, $from = FALSE)
// wrap each line with the shebang, charset, and transfer encoding
// the preceding space on successive lines is required for header "folding"
- return trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $output.$temp));
+ return trim(preg_replace('/^(.*?)(\n|\r)*$/m', ' =?'.$this->charset.'?Q?$1?=$2', $output.$temp));
@narfbg Owner
narfbg added a note

Why (.*?) ?

@bbarao
bbarao added a note

To make (.*) non-greedy, and prevent it to capture \r

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@narfbg
Owner

Could you add a changelog entry describing what's fixed? And if possible, can somebody confirm if this fixes #1409?

@bbarao

I will do it later today or tomorow.

@alexbilbie

Did you add the changelog @bbarao so we can pull this?

@Chronial

Sry for this pointless comment, but please get this in the code – this bug is very annoying.

@ckdarby

@Chronial Please don't comment; Please fix & make the pull request

@narfbg
Owner

Still waiting on this one to be updated ... @bbarao ?

@bbarao

Sorry about the delay. Is the changelog entry in the right place?

@narfbg narfbg merged commit 60e719b into from
@narfbg narfbg referenced this pull request from a commit
@narfbg narfbg [ci skip] Polish changes from pull #1709 5098859
@narfbg
Owner

Corrected what's needed, thanks @bbarao.

@narfbg
Owner

@bbarao Can you tell if this is the same issue as #1409, #1498?

@Chronial

This did definitely not fix #1498

@nonchip nonchip referenced this pull request from a commit in nonchip/CodeIgniter
@narfbg narfbg [ci skip] Polish changes from pull #1709 ed1fc2f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 15, 2012
  1. @bbarao
Commits on Oct 8, 2012
  1. @bbarao
  2. @bbarao

    Fix email headers when using long email subjects and \r\n as crlf. (P…

    bbarao authored
    …art2)
    
     - Better expression for the preg_replace.
     - Added a entry to the changelog.
This page is out of date. Refresh to see the latest.
View
4 system/libraries/Email.php
@@ -1237,7 +1237,7 @@ protected function _prep_q_encoding($str, $from = FALSE)
// wrap each line with the shebang, charset, and transfer encoding
// the preceding space on successive lines is required for header "folding"
- return trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $output.$temp));
+ return trim(preg_replace('/^(.*?)(\r*)$/m', ' =?'.$this->charset.'?Q?$1?=$2', $output.$temp));
}
// --------------------------------------------------------------------
@@ -1861,4 +1861,4 @@ protected function _mime_types($ext = '')
}
/* End of file Email.php */
-/* Location: ./system/libraries/Email.php */
View
1  user_guide_src/source/changelog.rst
@@ -243,6 +243,7 @@ Release Date: Not Released
Bug fixes for 3.0
------------------
+- Fixed a bug (#1709) where the email headers were broken when using long email subjects and \r\n as crlf.
- Fixed a bug where ``unlink()`` raised an error if cache file did not exist when you try to delete it.
- Fixed a bug (#181) where a mis-spelling was in the form validation language file.
- Fixed a bug (#159, #163) that mishandled Query Builder nested transactions because _trans_depth was not getting incremented.
Something went wrong with that request. Please try again.