From 91ffa129ee86b75d506351e1d6ac66e921676273 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 15 Nov 2010 16:18:24 -0700 Subject: [PATCH] Refactor inline message image blocking to operate on all messages, not just HTML messages. --- imp/config/mime_drivers.php.dist | 14 +++--- imp/config/prefs.php.dist | 20 ++++----- imp/docs/CHANGES | 2 + imp/docs/UPGRADING | 2 + imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php | 19 ++++++++ imp/lib/Mime/Viewer/Html.php | 9 +++- imp/lib/Mime/Viewer/Images.php | 27 +++++++----- imp/lib/Prefs/Ui.php | 2 - imp/lib/Ui/Imageview.php | 54 +++++++++++++++++++++++ imp/locale/en/help.xml | 12 ++--- 10 files changed, 125 insertions(+), 36 deletions(-) create mode 100644 imp/lib/Ui/Imageview.php diff --git a/imp/config/mime_drivers.php.dist b/imp/config/mime_drivers.php.dist index b00f899be..41dc979d5 100644 --- a/imp/config/mime_drivers.php.dist +++ b/imp/config/mime_drivers.php.dist @@ -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. */ diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index d9bb74ccf..081c371f9 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -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? diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 19cacde3f..cb782c638 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -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. diff --git a/imp/docs/UPGRADING b/imp/docs/UPGRADING index c29823ab6..12556dce4 100644 --- a/imp/docs/UPGRADING +++ b/imp/docs/UPGRADING @@ -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 diff --git a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php index f16c7d375..6114d6a15 100644 --- a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php +++ b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php @@ -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); diff --git a/imp/lib/Mime/Viewer/Html.php b/imp/lib/Mime/Viewer/Html.php index 43175aac7..9cfa8e14c 100644 --- a/imp/lib/Mime/Viewer/Html.php +++ b/imp/lib/Mime/Viewer/Html.php @@ -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()) diff --git a/imp/lib/Mime/Viewer/Images.php b/imp/lib/Mime/Viewer/Images.php index 09958d8d6..9433a9886 100644 --- a/imp/lib/Mime/Viewer/Images.php +++ b/imp/lib/Mime/Viewer/Images.php @@ -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 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 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 diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php index b98d90d53..55d50c885 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -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 index 000000000..3eb20459f --- /dev/null +++ b/imp/lib/Ui/Imageview.php @@ -0,0 +1,54 @@ + + * @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'])); + } + +} diff --git a/imp/locale/en/help.xml b/imp/locale/en/help.xml index ce8c19c59..3b3ebfb11 100644 --- a/imp/locale/en/help.xml +++ b/imp/locale/en/help.xml @@ -812,17 +812,17 @@ - - Preferences: HTML Image Replacement + + Preferences: Image Replacement - 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. - - Preferences: HTML Image Replacement/Addressbook Show + + Preferences: Image Replacement/Addressbook Show - 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? -- 2.11.0