Refactor inline message image blocking to operate on all messages, not just HTML...
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 15 Nov 2010 23:18:24 +0000 (16:18 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 15 Nov 2010 23:41:24 +0000 (16:41 -0700)
imp/config/mime_drivers.php.dist
imp/config/prefs.php.dist
imp/docs/CHANGES
imp/docs/UPGRADING
imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php
imp/lib/Mime/Viewer/Html.php
imp/lib/Mime/Viewer/Images.php
imp/lib/Prefs/Ui.php
imp/lib/Ui/Imageview.php [new file with mode: 0644]
imp/locale/en/help.xml

index b00f899..41dc979 100644 (file)
@@ -59,12 +59,7 @@ $mime_drivers = array(
         'limit_inline_size' => 1048576,
 
         /* Check for phishing exploits? */
-        'phishing_check' => true,
-
-        /* A list of from e-mail addresses that are considered "safe" for
-         * purposes of image blocking (if image blocking is enabled in the
-         * preferences). */
-        'safe_addrs' => array()
+        'phishing_check' => true
     ),
 
     /* Default smil driver. */
@@ -86,7 +81,12 @@ $mime_drivers = array(
         'allthumbs' => true,
 
         /* Display images inline that are less than this size (in bytes). */
-        'inlinesize' => 262144
+        'inlinesize' => 262144,
+
+        /* A list of from e-mail addresses that are considered "safe" for
+         * purposes of image blocking (if image blocking is enabled in the
+         * preferences). */
+        'safe_addrs' => array()
     ),
 
     /* Enriched text display. */
index d9bb74c..081c371 100644 (file)
@@ -729,7 +729,7 @@ $prefGroups['viewing'] = array(
     'desc' => _("Configure how messages are displayed."),
     'members' => array(
         'filtering', 'strip_attachments', 'alternative_display',
-        'html_image_replacement', 'html_image_addrbook', 'highlight_text',
+        'image_replacement', 'image_addrbook', 'highlight_text',
         'highlight_simple_markup', 'show_quoteblocks', 'dim_signature',
         'emoticons', 'parts_display', 'mail_hdr', 'default_msg_charset',
         'disposition_send_mdn'
@@ -762,21 +762,21 @@ $_prefs['alternative_display'] = array(
     'desc' => _("For messages with alternative representations of the text part, which part should we display?")
 );
 
-// Replace image tags in inline viewed HTML messages with blank images?
-$_prefs['html_image_replacement'] = array(
+// Replace image tags in inline messages with blank images?
+$_prefs['image_replacement'] = array(
     'value' => 1,
     'type' => 'checkbox',
-    'desc' => _("Block images in inline viewed HTML messages unless they are specifically requested?"),
-    'help' => 'prefs-html_image_replacement'
+    'desc' => _("Block images in messages unless they are specifically requested?"),
+    'help' => 'prefs-image_replacement'
 );
 
-// By default, automatically show images in inline viewed HTML messages if the
-// sender is in the user's addressbook?
-$_prefs['html_image_addrbook'] = array(
+// By default, automatically show images in inline messages if the sender is
+// in the user's addressbook?
+$_prefs['image_addrbook'] = array(
     'value' => 1,
     'type' => 'checkbox',
-    'desc' => _("Automatically show images in inline viewed HTML messages when the sender is in my address book?"),
-    'help' => 'prefs-html_image_addrbook'
+    'desc' => _("Automatically show images in messages when the sender is in my address book?"),
+    'help' => 'prefs-image_addrbook'
 );
 
 // should we try to mark different conversations with different colors?
index 19cacde..cb782c6 100644 (file)
@@ -2,6 +2,8 @@
 v5.0-git
 --------
 
+[mms] Refactor inline message image blocking to operate on all messages, not
+      just HTML messages.
 [mms] Add attachment message filter.
 [mms] Add post_spam hook called after reporting spam/ham (Request #6455).
 [mms] Implement stationery support in DIMP.
index c29823a..12556dc 100644 (file)
@@ -79,6 +79,8 @@ your ``config/prefs.php`` file and your preferences backend::
    fetchmail_menu
    filter_on_sidebar
    forward_bodytext
+   image_addrbook
+   image_replacement
    nav_expanded_sidebar
    use_vinbox
    use_vtrash
index f16c7d3..6114d6a 100644 (file)
@@ -29,6 +29,7 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT
         $this->_upgradeAbookPrefs();
         $this->_upgradeForwardPrefs();
         $this->_upgradeLoginTasksPrefs();
+        $this->_upgradeMsgDisplayPrefs();
         $this->_upgradeSortPrefs();
         $this->_upgradeVirtualFolders();
     }
@@ -109,6 +110,24 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT
     {
         global $prefs;
 
+        $replace = $prefs->getValue('html_image_replacement');
+        if (!is_null($replace) && !$replace) {
+            $prefs->setValue('image_replacement', 0);
+        }
+
+        $addrbook = $prefs->getValue('html_image_addrbook');
+        if (!is_null($addrbook) && !$addrbook) {
+            $prefs->setValue('image_addrbook', 0);
+        }
+    }
+
+    /**
+     * Upgrade to the new message display preferences.
+     */
+    protected function _upgradeMsgDisplayPrefs()
+    {
+        global $prefs;
+
         if (!$prefs->isDefault('initial_page') &&
             ($prefs->getValue('initial_page') == 'folders.php')) {
             $prefs->setValue('initial_page', IMP_Prefs_Ui::PREF_FOLDER_PAGE);
index 43175aa..9cfa8e1 100644 (file)
@@ -140,10 +140,17 @@ class IMP_Mime_Viewer_Html extends Horde_Mime_Viewer_Html
             (!$inline && Horde_Util::getFormData('convert_text'))) {
             $this->_imptmp = null;
         } else {
+            if ($inline) {
+                $imgview = new IMP_Ui_Imageview();
+                $blockimg = !$imgview->showInlineImage($this->getConfigParam('imp_contents'));
+            } else {
+                $blockimg = false;
+            }
+
             $this->_imptmp = array(
                 'blockimg' => null,
                 'cid' => null,
-                'img' => ($inline && $GLOBALS['prefs']->getValue('html_image_replacement') && !$this->_inAddressBook()),
+                'img' => $blockimg,
                 'imgblock' => false,
                 'inline' => $inline,
                 'target' => strval(new Horde_Support_Randomid())
index 09958d8..9433a98 100644 (file)
@@ -81,20 +81,27 @@ class IMP_Mime_Viewer_Images extends Horde_Mime_Viewer_Images
         /* Only display the image inline if the browser can display it and the
          * size of the image is below the config value. */
         if ($GLOBALS['browser']->isViewable($this->_getType())) {
-            if (isset($this->_conf['inlinesize']) &&
+            if (!isset($this->_conf['inlinesize']) ||
                 ($this->_mimepart->getBytes() < $this->_conf['inlinesize'])) {
-                /* Viewing inline, and the browser can handle the image type
-                 * directly. So output an <img> tag to load the image. */
-                return array(
-                    $this->_mimepart->getMimeId() => array(
-                        'data' => $this->_outputImgTag('data', $this->_mimepart->getName(true)),
-                        'status' => array(),
-                        'type' => 'text/html; charset=' . $this->getConfigParam('charset')
-                    )
-                );
+                $imgview = new IMP_Ui_Imageview();
+                $showimg = $imgview->showInlineImage($this->getConfigParam('imp_contents'));
             } else {
+                $showimg = false;
+            }
+
+            if (!$showimg) {
                 return $this->_renderInfo();
             }
+
+            /* Viewing inline, and the browser can handle the image type
+             * directly. So output an <img> tag to load the image. */
+            return array(
+                $this->_mimepart->getMimeId() => array(
+                    'data' => $this->_outputImgTag('data', $this->_mimepart->getName(true)),
+                    'status' => array(),
+                    'type' => 'text/html; charset=' . $this->getConfigParam('charset')
+                )
+            );
         }
 
         /* The browser cannot view this image. Inform the user of this and
index b98d90d..55d50c8 100644 (file)
@@ -301,8 +301,6 @@ class IMP_Prefs_Ui
 
             if (!$v->canRender('inline')) {
                 $ui->suppress[] = 'alternative_display';
-                $ui->suppress[] = 'html_image_replacement';
-                $ui->suppress[] = 'html_image_addrbook';
             }
 
             /* Sort encodings. */
diff --git a/imp/lib/Ui/Imageview.php b/imp/lib/Ui/Imageview.php
new file mode 100644 (file)
index 0000000..3eb2045
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/**
+ * This class is designed to provide a place to store common code shared among
+ * various MIME Viewers relating to image viewing preferences.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/gpl.html GPL
+ * @package  IMP
+ */
+class IMP_Ui_Imageview
+{
+    /**
+     * Show inline images in messages?
+     *
+     * @param IMP_Contents $contents  The contents object containing the
+     *                                message.
+     *
+     * @return boolean  True if inline image should be shown.
+     */
+    public function showInlineImage($contents)
+    {
+        global $injector, $prefs, $registry;
+
+        if (!$prefs->getValue('image_replacement')) {
+            return true;
+        }
+
+        if (!$contents) {
+            return false;
+        }
+
+        $from = Horde_Mime_Address::bareAddress($contents->getHeaderOb()->getValue('from'));
+        if ($prefs->getValue('image_addrbook') &&
+            $registry->hasMethod('contacts/getField')) {
+            $params = IMP::getAddressbookSearchParams();
+            try {
+                if ($registry->call('contacts/getField', array($from, '__key', $params['sources'], false, true))) {
+                    return true;
+                }
+            } catch (Horde_Exception $e) {}
+        }
+
+        /* Check admin defined e-mail list. */
+        list(, $config) = $injector->getInstance('Horde_Core_Factory_MimeViewer')->getViewerConfig('image/*', 'imp');
+        return (!empty($config['safe_addrs']) && in_array($from, $config['safe_addrs']));
+    }
+
+}
index ce8c19c..3b3ebfb 100644 (file)
     </para>
 </entry>
 
-<entry id="prefs-html_image_replacement">
-    <title>Preferences: HTML Image Replacement</title>
+<entry id="prefs-image_replacement">
+    <title>Preferences: Image Replacement</title>
     <para>
-    For HTML messages displayed inline, should all image tags be blocked until you specifically decide to view those images? Note that, if viewing an HTML attachment, the images will always be displayed.
+    For messages displayed inline, should all image tags be blocked until you specifically decide to view those images? Note that, if viewing as an attachment, the images will always be displayed.
     </para>
 </entry>
 
-<entry id="prefs-html_image_addrbook">
-    <title>Preferences: HTML Image Replacement/Addressbook Show</title>
+<entry id="prefs-image_addrbook">
+    <title>Preferences: Image Replacement/Addressbook Show</title>
     <para>
-    If blocking images for inline HTML messages, should we automatically display them instead if the sender appears in your addressbook?
+    If blocking images for inline messages, should they be displayed automatically if the sender appears in your addressbook?
     </para>
 </entry>