diff options
author | Aleksander Machniak <alec@alec.pl> | 2013-02-19 16:56:02 +0100 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2013-02-19 16:56:49 +0100 |
commit | fd777a86270494e45b38c4bfd8a45625ea46425b (patch) | |
tree | 7c17b74fe417eaf4007a158b00e11e6d8171732d | |
parent | 0ffb1a7af33bddd30d52080c99e5cf4fd5757416 (diff) |
Add workaround for invalid message charset detection by IMAP servers (#1488968)
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | program/lib/Roundcube/rcube_imap.php | 30 | ||||
-rw-r--r-- | program/steps/mail/func.inc | 2 |
3 files changed, 26 insertions, 9 deletions
@@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail -=========================== +========================a=== +- Add workaround for invalid message charset detection by IMAP servers (#1488968) - Fix NUL characters in content-type of ms-tnef attachment (#1488964) - Fix regression in handling LDAP contact identifiers (#1488959) - Updated translations from Transifex diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 74c1f5324..18c6b12af 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -1634,9 +1634,15 @@ class rcube_imap extends rcube_storage // Example of structure for malformed MIME message: // ("text" "plain" NIL NIL NIL "7bit" 2154 70 NIL NIL NIL) if ($headers->ctype && !is_array($structure[0]) && $headers->ctype != 'text/plain' - && strtolower($structure[0].'/'.$structure[1]) == 'text/plain') { + && strtolower($structure[0].'/'.$structure[1]) == 'text/plain' + ) { + // A special known case "Content-type: text" (#1488968) + if ($headers->ctype == 'text') { + $structure[1] = 'plain'; + $headers->ctype = 'text/plain'; + } // we can handle single-part messages, by simple fix in structure (#1486898) - if (preg_match('/^(text|application)\/(.*)/', $headers->ctype, $m)) { + else if (preg_match('/^(text|application)\/(.*)/', $headers->ctype, $m)) { $structure[0] = $m[1]; $structure[1] = $m[2]; } @@ -1660,11 +1666,21 @@ class rcube_imap extends rcube_storage $struct = $this->structure_part($structure, 0, '', $headers); } - // don't trust given content-type - if (empty($struct->parts) && !empty($headers->ctype)) { - $struct->mime_id = '1'; - $struct->mimetype = strtolower($headers->ctype); - list($struct->ctype_primary, $struct->ctype_secondary) = explode('/', $struct->mimetype); + // some workarounds on simple messages... + if (empty($struct->parts)) { + // ...don't trust given content-type + if (!empty($headers->ctype)) { + $struct->mime_id = '1'; + $struct->mimetype = strtolower($headers->ctype); + list($struct->ctype_primary, $struct->ctype_secondary) = explode('/', $struct->mimetype); + } + + // ...and charset (there's a case described in #1488968 where invalid content-type + // results in invalid charset in BODYSTRUCTURE) + if (!empty($headers->charset) && $headers->charset != $struct->ctype_parameters['charset']) { + $struct->charset = $headers->charset; + $struct->ctype_parameters['charset'] = $headers->charset; + } } $headers->structure = $struct; diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index f82e60a36..5058dccc6 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -1850,7 +1850,7 @@ function rcmail_attachment_name($attachment, $display = false) $filename = rcube_label('htmlmessage'); } else { - $ext = rcube_mime::get_mime_extensions($attachment->mimetype); + $ext = (array) rcube_mime::get_mime_extensions($attachment->mimetype); $ext = array_shift($ext); $filename = rcube_label('messagepart') . ' ' . $attachment->mime_id; if ($ext) { |