Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email subject line starts with “?utf-8?Q?” #1409

Closed
mga242 opened this issue May 30, 2012 · 20 comments
Closed

Email subject line starts with “?utf-8?Q?” #1409

mga242 opened this issue May 30, 2012 · 20 comments
Milestone

Comments

@mga242
Copy link

mga242 commented May 30, 2012

Sending email using CI the subject line starts with “?utf-8?Q?”. The subject line is not over 75 characters
The following post suggestions don't solve the problem:

http://codeigniter.com/forums/viewthread/154493/

http://stackoverflow.com/questions/8350865/malformed-email-subject-header-when-subject-75-chars-using-codeigniter-email-l

I copied the email class into my application/libraries and then made the edits suggested here:

http://codeigniter.com/forums/viewthread/119946/

Works correctly now…

@ckdarby
Copy link
Contributor

ckdarby commented Jun 6, 2012

@ciuser Which version of CI were you using?

@mga242
Copy link
Author

mga242 commented Jun 6, 2012

Version 2.1.0

@mickeywu
Copy link
Contributor

mickeywu commented Jun 6, 2012

I actually encountered this as well and I believe this happens on Windows servers only. I was also able to resolve the issue using the thread posted by the OP.

@narfbg Any suggestions as to whether or not the code should be modified and committed into core?

@narfbg
Copy link
Contributor

narfbg commented Jun 6, 2012

Windows?
How does it behave if you do $this->email->set_crlf("\r\n"); after you load the library, no modifications?

@mga242
Copy link
Author

mga242 commented Jun 6, 2012

I had it set in the email config but didn't help.

$config['crlf'] = "\r\n";

@narfbg
Copy link
Contributor

narfbg commented Jun 6, 2012

A quote from RFC 2047, on the "Q" encoding:

(1) Any 8-bit value may be represented by a "=" followed by two
hexadecimal digits. For example, if the character set in use
were ISO-8859-1, the "=" character would thus be encoded as
"=3D", and a SPACE by "=20". (Upper case should be used for
hexadecimal digits "A" through "F".)

I guess Outlook could complain about that. What does happen if you change this:

$char = '='.dechex($ascii);

to this:

$char = '='.strtoupper(dechex($ascii));

?

@narfbg
Copy link
Contributor

narfbg commented Jun 11, 2012

I'd still like feedback on those questions, but here's a proposed solution: #1253, #1281

@narfbg
Copy link
Contributor

narfbg commented Aug 15, 2012

#1709 could also fix this.

@narfbg
Copy link
Contributor

narfbg commented Oct 8, 2012

@ciuser @mickeywu Could you guys check and see if this bug is fixed with the current code from develop branch?

@narfbg
Copy link
Contributor

narfbg commented Oct 9, 2012

@takyana You too, since you've submitted #1498.

@takyanagida
Copy link

@narfbg Thank you for letting me know.
Email.php in develop branch still seems to have the same issue (splitting multibyte character). I tried the same test code as #1498 and got the following result.

array(1) { ["Subject"]=> string(134) "=?UTF-8?Q?=e3=81=93=e3=82=8c=e3=81=af=e6=97=a5=e6=9c=ac=e8=aa=9e=e3=81?= =?UTF-8?Q?=ae=e3=83=86=e3=82=b9=e3=83=88=e3=81=a7=e3=81=99?=" }

Note that you have to change $_headers of CI_Email into public to use the same test code.

@narfbg
Copy link
Contributor

narfbg commented Oct 11, 2012

OK, does this do it? https://gist.github.com/3870694

It be really helpful if you try commenting out appropriate sections and test each of the solutions (mb_encode_mimeheader(), iconv_mime_encode() and "manually" with the use of iconv_substr()).

Those are all features that are not turned on by default on PHP, so there's no guarantee that it would absolutely always be failproof, but I've tried to fallback to the next in line when needed and 99 out of 100 will have at least mbstring enabled. Each of them looks to be working fine on my end, but I'm only looking at what gets generated and can't do a real test.

@takyanagida
Copy link

I tried each of 3 solutions by changing comment out and all seem to produce correct results.
For each solution, I tried 3 strings like followings (see leading ascii characters) and all worked.

    $this->email->subject('これは日本語のテストです');
    $this->email->subject('aこれは日本語のテストです');
    $this->email->subject('abこれは日本語のテストです');

But please note that I checked the generated headers, too. (Currently I cannot touch the application code, which really sent Email)

@narfbg
Copy link
Contributor

narfbg commented Oct 12, 2012

Thanks @takyana, please let me know if you get the chance to test it for real.
In the mantime, maybe @bbarao could try this?

@narfbg
Copy link
Contributor

narfbg commented Oct 12, 2012

@evinw You can read the contribution guide here: http://codeigniter.com/news/contribution_guide

@mga242
Copy link
Author

mga242 commented Dec 4, 2012

Hi guys,

Just tested this with 2.1.3 and still having the same problem:

Subject: =?utf-8?Q?Test_Message?=

From: Evin Weissenberg [mailto:notifications@github.com]
Sent: Friday, October 12, 2012 3:47 PM
To: EllisLab/CodeIgniter
Cc: Matt Casella
Subject: Re: [CodeIgniter] Email subject line starts with “?utf-8?Q?” (#1409)

Hey guys,

I want to contribute to this excellent framework, let me know who is the
lead or what work is needed and how to contribute thanks

On 10/12/12 10:49 AM, Andrey Andreev wrote:

Thanks @takyana https://github.com/takyana, please let me know if
you get the chance to test it for real.
In the mantime, maybe @bbarao https://github.com/bbarao could try this?


Reply to this email directly or view it on GitHub
#1409 (comment).

Creative Problem Solving Electro Chemical Organism


Reply to this email directly or view it on GitHub #1409 (comment) .

https://github.com/notifications/beacon/2LOc660UtaDiMmW5i6Hi4m3uthh0fe6wbcE90z4o387l-oXMRysUPNJb9BSokwLY.gif

Protected by PowerView Email Defense

@narfbg
Copy link
Contributor

narfbg commented Dec 4, 2012

@ciuser The fix is applied on the develop branch here on GitHub, it hasn't been released officially yet.

nonchip pushed a commit to nonchip/CodeIgniter that referenced this issue Jun 29, 2013
@jitendraF5buddy
Copy link

This code are working properly you need to change "system/libraries/Email.php"

public function subject($subject)
{
/$subject = $this->_prep_q_encoding($subject);
$this->_set_header('Subject', $subject);
return $this;
/
$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
$this->_set_header('Subject', $subject);
return $this;
}

@jitendraF5buddy
Copy link

Also so you have to add in config variable when you load email library

$config = array(
'protocol' => 'smtp',
'charset' => 'utf-8',
'newline' => "\r\n",
'crlf' => "\n",
'mailtype' => "html"
);

Again I got this issue “?utf-8?Q?” in subject

@somsgod
Copy link

somsgod commented Nov 30, 2018

Was facing the same issue , the solution suggested here https://forum.codeigniter.com/archive/index.php?thread-54634.html solved the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants