Bug #8858: Auto-determine charset for text attachments
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 9 Feb 2010 20:29:43 +0000 (13:29 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 9 Feb 2010 20:30:24 +0000 (13:30 -0700)
imp/docs/CHANGES
imp/lib/Compose.php

index a5b7c05..e84db88 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] Auto-determine charset for text attachments (Bug #8858).
 [mms] Remove IE 6 (and below) and Safari 2 (and below) support for DIMP.
 [mms] Add chance to switch between forward options on compose page when using
       auto-forward (DIMP).
index e29b188..5749d60 100644 (file)
@@ -1759,7 +1759,16 @@ class IMP_Compose
 
         $part = new Horde_Mime_Part();
         $part->setType($type);
-        $part->setCharset(Horde_Nls::getCharset());
+        if ($part->getPrimaryType() == 'text') {
+            if ($analyzetype = Horde_Mime_Magic::analyzeFile($tempfile, empty($conf['mime']['magic_db']) ? null : $conf['mime']['magic_db'], array('nostrip' => true))) {
+                $analyzetype = Horde_Mime::decodeParam('Content-Type', $analyzetype);
+                $part->setCharset(isset($analyzetype['params']['charset']) ? $analyzetype['params']['charset'] : Horde_Nls::getCharset());
+            } else {
+                $part->setCharset(Horde_Nls::getCharset());
+            }
+        } else {
+            $part->setHeaderCharset(Horde_Nls::getCharset());
+        }
         $part->setName($filename);
         $part->setBytes($_FILES[$name]['size']);
         $part->setDisposition('attachment');