Check for UTF-8 browsers when viewing text inline
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 11 Nov 2008 20:03:33 +0000 (13:03 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 11 Nov 2008 20:03:33 +0000 (13:03 -0700)
imp/lib/Contents.php

index 7cbdde8..ca06d8c 100644 (file)
@@ -313,6 +313,26 @@ class IMP_Contents
 
         $ret = $viewer->render($mode);
         $ret['name'] = $mime_part->getName(true);
+
+        /* If this is a text/* part, AND the browser does not support UTF-8,
+         * give the user a link to open the part in a new window with the
+         * correct character set. */
+        if (($mode != 'full') && ($mime_part->getPrimaryType() == 'text')) {
+            $default_charset = String::upper(NLS::getCharset());
+            if ($default_charset !== 'UTF-8') {
+                $charset_upper = String::upper($mime_part->getCharset());
+                if (($charset_upper != 'US-ASCII') &&
+                    ($charset_upper != $default_charset)) {
+                    $ret['status'][] = array(
+                        'text' => array(
+                            sprintf(_("This message was written in a character set (%s) other than your own."), htmlspecialchars($charset_upper)),
+                            sprintf(_("If it is not displayed correctly, %s to open it in a new window."), $this->linkViewJS($mime_part, 'view_attach', _("click here")))
+                        )
+                    );
+                }
+            }
+        }
+
         return $ret;
     }