-
-
Notifications
You must be signed in to change notification settings - Fork 253
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_fetchstructure sometimes returns encoding 6 and it is not present in Part::$encodingsMap #64
Comments
Values 7-10 are also returned by |
I've started seeing this issue within the past week from emails @didx.net, I'm not seeing them from anywhere else. Presuming the 'encoding' is derived from the Content-Transfer-Encoding header then their emails are seeing them to "quoted -printable" (without quotes). I haven't yet had sufficient time to replay this issue in my development environment and find a solution but when I do I will update this issue. |
Also, I'm using PHP 5.5.20-2 (CentOS 6) package from the REMI repository. PHP information shows: IMAP c-Client Version => 2007e |
On closer inspection it looks like the remote mail client may be incorrectly building the header. I've noticed in all of the failed emails there is a space between quoted and -printable. May be able to apply a patch to Message/Part.php in the parseStructure method to look for broken encoding types and correct them. Depending on the reuse from the call to loadStructure in Message.php it may be better to apply the adjustments there. |
I've had some time tonight to investigate further. I must say that i'm conflicted on what the right thing to do here is. Part of me thinks in the real-world you need to work round quirks with broken email messages to ensure that it doesn't impact your ability to work with 'all email messages' and the other part of me thinks that you should reject them if they are invalid. I'm more than happy to do a PR if the developers feel its something of value. Either way, here is a diff of my changes to fix my scenario: Index: src/Ddeboer/Imap/Message.php
===================================================================
--- src/Ddeboer/Imap/Message.php (revision 2802)
+++ src/Ddeboer/Imap/Message.php (working copy)
@@ -306,6 +306,23 @@
protected function loadStructure()
{
$structure = \imap_fetchstructure($this->stream, $this->messageNumber, \FT_UID);
+
+ // look for an unknown character type encoding
+ // to provide manual overrides if applicable
+ if ($structure->encoding > 5) {
+ $headers = \imap_fetchheader($this->stream, $this->messageNumber, \FT_UID);
+
+ // match the character type encoding header to apply
+ // any additional manual fixups or overrides
+ if (preg_match('/^Content-Transfer-Encoding: (.*)$/im', $headers, $matches)) {
+ $matches[1] = trim(preg_replace('/\s+/', '', $matches[1]));
+
+ // pattern match other content type encoding that needs
+ // to be manually remapped to another encoding type
+ if ($matches[1] == 'quoted-printable') $structure->encoding = 4;
+ }
+ }
+
$this->parseStructure($structure);
}
}
\ No newline at end of file |
@perk11 I would be interested to see messages that were returning values 7-10 from imap_fetchstructure if you have any examples. |
@mrtimp I'm not sure how to get full message text from debugger, here is structure of one of these messages: http://imgur.com/SAX4O97 |
So I logged headers for ALL messages from the problem account in |
Without examples and testable data, we can't do better than throw exception in case of unknown encoding, implemented in #197. @mrtimp we can implement manual look up for
As soon as we'll have all this info, we'll adapt the code. Until that time, we'll stick with throwing an exception. Thank you all for the feedbacks. |
I couldn't find any information what this encoding means. PHP doc says encoding "may vary with used library".
I'm using
IMAP c-Client Version => 2007f
coming with PHP 5.5 for Windows distribution and I get this encoding sometimes. This throws error since there is no such item in Part::$encodingsMap array.The text was updated successfully, but these errors were encountered: