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

imap processing error when "from" field is utf8 encoded #850

Closed
ericLemanissier opened this Issue May 5, 2014 · 5 comments

Comments

Projects
None yet
5 participants
@ericLemanissier
Contributor

ericLemanissier commented May 5, 2014

When an email is received with the "from" header encoded (for example "From: =?utf-8?q?D=C3=A9tection_de_spam_=3Cnoreply=401and1=2Efr=3E?="), the email is badly parsed, generating the following notification "Excessive errors processing emails for imap.1und1.de/support@xxx.com. Please manually check the inbox".

This is caused by the call of imap_headerinfo in class.mailfetch.php, returning a variable without any "from" nor "fromaddress" field.
In this case, the "from" can be read by calling imap_rfc822_parse_headers(imap_fetchheader(...)) which gives a result with the following fields:
...
["fromaddress"]=>
string(69) "=?utf-8?q?D=C3=A9tection_de_spam_=3Cnoreply=401and1=2Efr=3E?=@unknown"
["from"]=>
array(1) {
[0]=>
object(stdClass)#29 (2) {
["mailbox"]=>
string(61) "=?utf-8?q?D=C3=A9tection_de_spam_=3Cnoreply=401and1=2Efr=3E?="
["host"]=>
string(7) "UNKNOWN"
}
}
...

The from->mailbox and from->host would still have to be adapted after that

@protich

This comment has been minimized.

Show comment
Hide comment
@protich

protich May 5, 2014

Member

Unfortunately, even with imap_rfc822_parse_headers, the from address will still be invalid email as required by osTicket.

Member

protich commented May 5, 2014

Unfortunately, even with imap_rfc822_parse_headers, the from address will still be invalid email as required by osTicket.

@ericLemanissier

This comment has been minimized.

Show comment
Hide comment
@ericLemanissier

ericLemanissier May 5, 2014

Contributor

couldn't that be handled by doing something like:
$headerinfo= imap_rfc822_parse_headers(imap_fetchheader($this->mbox, $mid))
$sender=$headerinfo->from[0];
$email = imap_mime_header_decode($headerinfo->from);
preg_match(/^([^<]*)<([a-z0-9.-]+)@([a-z0-9.-]{2,}.[a-z]{2,4})>$/', $email[0]->text, $matches)
$sender->personal= matches[1];
$sender->mailbox = matches[2];
$sender->host= matches[3];

sorry about the formatting of the regex, it gets messed because of the markup, the pattern before and after the @ is [a-z0-9._-]

Contributor

ericLemanissier commented May 5, 2014

couldn't that be handled by doing something like:
$headerinfo= imap_rfc822_parse_headers(imap_fetchheader($this->mbox, $mid))
$sender=$headerinfo->from[0];
$email = imap_mime_header_decode($headerinfo->from);
preg_match(/^([^<]*)<([a-z0-9.-]+)@([a-z0-9.-]{2,}.[a-z]{2,4})>$/', $email[0]->text, $matches)
$sender->personal= matches[1];
$sender->mailbox = matches[2];
$sender->host= matches[3];

sorry about the formatting of the regex, it gets messed because of the markup, the pattern before and after the @ is [a-z0-9._-]

@greezybacon

This comment has been minimized.

Show comment
Hide comment
@greezybacon

greezybacon May 5, 2014

Member

Would you consider posting the entire, unparsed (raw) email and headers, so I could take a closer look at the parser?

Member

greezybacon commented May 5, 2014

Would you consider posting the entire, unparsed (raw) email and headers, so I could take a closer look at the parser?

@ericLemanissier

This comment has been minimized.

Show comment
Hide comment
@ericLemanissier

ericLemanissier May 5, 2014

Contributor

of course, the output of var_dump(imap_fetchheader($this->mbox, $mid)); is the following:

string(655) "Return-Path: <>
Delivery-Date: Fri, 11 Apr 2014 03:27:57 +0100
Received: from spamreport by localhost id 0MRpI7-1WRWOS48ML-00Skij for
support@XXX.com (mailbox m51559649-71621086);
Fri, 11 Apr 2014 03:27:57 +0100
From: =?utf-8?q?D=C3=A9tection_de_spam_=3Cnoreply=401and1=2Efr=3E?=
Subject: Rapport quotidien du dossier Spam du compte email
support@XXX.com
Date: Fri, 11 Apr 2014 03:27:57 +0100
To: support@XXX.com
Message-Id: 0MRpI7-1WRWOS48ML-00Skij@spamreport.1and1.fr
Envelope-To: support@XXX.com
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

"

Contributor

ericLemanissier commented May 5, 2014

of course, the output of var_dump(imap_fetchheader($this->mbox, $mid)); is the following:

string(655) "Return-Path: <>
Delivery-Date: Fri, 11 Apr 2014 03:27:57 +0100
Received: from spamreport by localhost id 0MRpI7-1WRWOS48ML-00Skij for
support@XXX.com (mailbox m51559649-71621086);
Fri, 11 Apr 2014 03:27:57 +0100
From: =?utf-8?q?D=C3=A9tection_de_spam_=3Cnoreply=401and1=2Efr=3E?=
Subject: Rapport quotidien du dossier Spam du compte email
support@XXX.com
Date: Fri, 11 Apr 2014 03:27:57 +0100
To: support@XXX.com
Message-Id: 0MRpI7-1WRWOS48ML-00Skij@spamreport.1and1.fr
Envelope-To: support@XXX.com
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

"

@sdolemelipone

This comment has been minimized.

Show comment
Hide comment
@sdolemelipone

sdolemelipone Mar 22, 2017

Can this issue be re-opened? This has been causing problems processing emails, in the meantime we have to maintain our own patch to osticket using imap_rfc822_parse_headers(imap_fetchheader($this->mbox, $mid))
instead of imap_headerinfo($this->mbox, $mid).

sdolemelipone commented Mar 22, 2017

Can this issue be re-opened? This has been causing problems processing emails, in the meantime we have to maintain our own patch to osticket using imap_rfc822_parse_headers(imap_fetchheader($this->mbox, $mid))
instead of imap_headerinfo($this->mbox, $mid).

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