From fdaed514a9f940f7ae5dc42101f9ac81a197263d Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 9 Feb 2010 13:29:43 -0700 Subject: [PATCH] Bug #8858: Auto-determine charset for text attachments --- imp/docs/CHANGES | 1 + imp/lib/Compose.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index a5b7c0544..e84db882f 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -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). diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index e29b1881e..5749d60e2 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -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'); -- 2.11.0