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

Add getRawHeader() method to allow retrieving headers without charset conversion #67

Merged
merged 2 commits into from
Nov 12, 2015

Conversation

pako-pl
Copy link

@pako-pl pako-pl commented Nov 12, 2015

When the subject of an e-mail cannot be decoded by iconv(), the getHeader('subject') call generates iconv() warnings. It makes it impossible to retrieve the header contents (even without decoding). I added a getRawHeader() to make it possible to access raw headers.

Sample invalid subject (consists of two parts, but decodeHeader() currently doesn't handle that):

=?GB2312?B?1rvSqsTjxNzP66Os1rvSqsTjz+vX9qOsv827p7K7ysfOyszio6zLq8+yyO28?= =?GB2312?B?/rDvxPq94r72o6GjoQ==?=

… conversion (which sometimes generates errors)
public function getHeader($name)
{
$rawHeader = $this->getRawHeader($name);
if($rawHeader === false) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 space after IF keyword; 0 found

@kklem0
Copy link

kklem0 commented Nov 12, 2015

Reviewed-by: me if you fix that PSR formatting problem.

eXorus added a commit that referenced this pull request Nov 12, 2015
Add getRawHeader() method to allow retrieving headers without charset conversion
@eXorus eXorus merged commit 96e852e into php-mime-mail-parser:master Nov 12, 2015
@eXorus
Copy link
Member

eXorus commented Nov 12, 2015

Thnaks for this solution but I would like to résolve the decoded header.

What is the expected result of ?
=?GB2312?B?1rvSqsTjxNzP66Os1rvSqsTjz+vX9qOsv827p7K7ysfOyszio6zLq8+yyO28?=
=?GB2312?B?/rDvxPq94r72o6GjoQ==?=

@pako-pl
Copy link
Author

pako-pl commented Nov 13, 2015

This subject comes from a spam message and is probably malformed. It looks like two separate message subjects, each encoded separately.

The getRawHeader() method is supposed to provide a workaround for situations, when we receive messages with invalid headers. I'm not sure if trying to decode the headers in such cases is worth the effort.

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

Successfully merging this pull request may close these issues.

4 participants