There're problems with attachment names in parts without charset specification. Example message can be found here http://trac.roundcube.net/ticket/1484969
I think we have two solutions:
according to it, but what when there's no charset data? 2. Detect charset using ie. mb_detect_encoding().
Here's a patch for 2.
diff -ruN rc-beta3/program/include/rcube_imap.php rc-beta2/program/include/rcube_imap.php --- rc-beta3/program/include/rcube_imap.php 2008-06-06 10:20:39.672800689 +0200 +++ rc-beta2/program/include/rcube_imap.php 2008-06-06 09:39:49.031952834 +0200 @@ -1159,10 +1159,13 @@ if (is_array($part[8]) && empty($struct->parts)) $struct->parts[] = $this->_structure_part($part[8], ++$count, $struct->mime_id); }
$struct->filename = rcube_imap::decode_mime_string($filename_mime, $this->default_charset);
$struct->filename = rcube_imap::decode_mime_string($filename_mime,
$struct->charset ? $struct->charset : rc_detect_encoding($filename_mime, $this->default_charset));
@@ -1170,7 +1173,8 @@ $struct->filename = rcube_charset_convert(urldecode($filename_urlencoded), $filename_charset); } else if (!empty($struct->headers['content-description']))
$struct->filename = rcube_imap::decode_mime_string($struct->headers['content-description'], $this->default_charset);
$struct->filename = rcube_imap::decode_mime_string($struct->headers['content-description'],
$struct->charset ? $struct->charset : rc_detect_encoding($struct->headers['content-description'],$this->default_charset));
return $struct; }
diff -ruN rc-beta3/program/include/rcube_shared.inc rc-beta2/program/include/rcube_shared.inc --- rc-beta3/program/include/rcube_shared.inc 2008-06-06 10:20:39.416799300 +0200 +++ rc-beta2/program/include/rcube_shared.inc 2008-06-06 10:07:39.177963387 +0200 @@ -581,4 +581,33 @@ return $mime_type; }
-?> \ Brak znaku nowej linii na ko�cu pliku
+/**
+function rc_detect_encoding($string, $failover='') +{
return $failover;
+}
+?>
Can #2 be used to set directionality of message display?
A.L.E.C wrote:
There're problems with attachment names in parts without charset specification. Example message can be found here http://trac.roundcube.net/ticket/1484969
I think we have two solutions:
- Check charset of first (all) part(s) of message and convert filename
according to it, but what when there's no charset data? 2. Detect charset using ie. mb_detect_encoding().
Here's a patch for 2.
diff -ruN rc-beta3/program/include/rcube_imap.php rc-beta2/program/include/rcube_imap.php --- rc-beta3/program/include/rcube_imap.php 2008-06-06 10:20:39.672800689 +0200 +++ rc-beta2/program/include/rcube_imap.php 2008-06-06 09:39:49.031952834 +0200 @@ -1159,10 +1159,13 @@ if (is_array($part[8]) && empty($struct->parts)) $struct->parts[] = $this->_structure_part($part[8], ++$count, $struct->mime_id); }
- // normalize filename property if ($filename_mime = $struct->d_parameters['filename'] ? $struct->d_parameters['filename'] : $struct->ctype_parameters['name'])
$struct->filename = rcube_imap::decode_mime_string($filename_mime, $this->default_charset);
- {
$struct->filename = rcube_imap::decode_mime_string($filename_mime,
$struct->charset ? $struct->charset : rc_detect_encoding($filename_mime, $this->default_charset));
- } else if ($filename_encoded = $struct->d_parameters['filename*'] ? $struct->d_parameters['filename*'] : $struct->ctype_parameters['name*']) { // decode filename according to RFC 2231, Section 4
@@ -1170,7 +1173,8 @@ $struct->filename = rcube_charset_convert(urldecode($filename_urlencoded), $filename_charset); } else if (!empty($struct->headers['content-description']))
$struct->filename = rcube_imap::decode_mime_string($struct->headers['content-description'], $this->default_charset);
$struct->filename = rcube_imap::decode_mime_string($struct->headers['content-description'],
$struct->charset ? $struct->charset : rc_detect_encoding($struct->headers['content-description'],$this->default_charset));
return $struct; }
diff -ruN rc-beta3/program/include/rcube_shared.inc rc-beta2/program/include/rcube_shared.inc --- rc-beta3/program/include/rcube_shared.inc 2008-06-06 10:20:39.416799300 +0200 +++ rc-beta2/program/include/rcube_shared.inc 2008-06-06 10:07:39.177963387 +0200 @@ -581,4 +581,33 @@ return $mime_type; }
-?> \ Brak znaku nowej linii na ko�cu pliku
+/**
- A method to guess encoding of a string.
- @param string $string String.
- @param string $failover Default result for failover.
- @return string
- */
+function rc_detect_encoding($string, $failover='') +{
- if (!function_exists('mb_detect_encoding')) {
return $failover;
- }
- // FIXME: the order is important, because sometimes
- // iso string is detected as euc-jp and etc.
- $enc = array(
- 'UTF-8', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4',
- 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9',
- 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16',
- 'WINDOWS-1252', 'WINDOWS-1251', 'EUC-JP', 'EUC-TW', 'KOI8-R'
- );
- $result = mb_detect_encoding($string, join(',', $enc));
- return $result ? $result : $failover;
+}
+?>
Moish wrote:
Can #2 be used to set directionality of message display?
You mean text directionality (RTL/LTR)? I think not, with mb_detect_encoding() we can determine only charset, not the language. It could be done by searching in (converted to unicode) text for letters specific for RTL languages using regular expressions.
On Fri, Jun 6, 2008 at 1:41 PM, A.L.E.C alec@alec.pl wrote:
Moish wrote:
Can #2 be used to set directionality of message display?
You mean text directionality (RTL/LTR)? I think not, with mb_detect_encoding() we can determine only charset, not the language. It could be done by searching in (converted to unicode) text for letters specific for RTL languages using regular expressions.
Alec,
nice to see that you are working on it. There are a bunch other of tickets with attachment issues, which is related to the "encoding" or better to "special characters" used in the filename. Specifically, there is one about Chinese encoding.
I am looking and marking the other as duplicate of #1484969, but if you looked around the issue system too, that would help.
Thanks again for the hard work!
Till _______________________________________________ List info: http://lists.roundcube.net/dev/