From 044b7607c15cf2d2c05f6db3378218c787d0a649 Mon Sep 17 00:00:00 2001
From: Albert Solana <albert.solana@upcnet.es>
Date: Tue, 7 Jun 2016 15:55:40 +0200
Subject: [PATCH] // New IMP Preference: image_replacement_domain

---
 imp/lib/Images.php                         | 10 ++++++++++
 imp/lib/Prefs/Special/ImageReplacement.php | 24 ++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/imp/lib/Images.php b/imp/lib/Images.php
index 1be4d50..1160a71 100644
--- a/imp/lib/Images.php
+++ b/imp/lib/Images.php
@@ -89,6 +89,16 @@ class IMP_Images
             }
         }
 
+        /* Check safe domain list. */
+        $safeDomain = $injector->getInstance('IMP_Prefs_Special_ImageReplacement')->safeDomainList();
+        foreach ($from as $valFrom) {
+           foreach ($safeDomain as $valDomain) {
+              if (strpos($valFrom,'@'.$valDomain) !== false) {
+                return true;
+              }
+           }
+        }
+
         /* Check safe address list. */
         $safeAddrs = $injector->getInstance('IMP_Prefs_Special_ImageReplacement')->safeAddrList();
         foreach ($from as $val) {
diff --git a/imp/lib/Prefs/Special/ImageReplacement.php b/imp/lib/Prefs/Special/ImageReplacement.php
index ccac3a6..e537df0 100644
--- a/imp/lib/Prefs/Special/ImageReplacement.php
+++ b/imp/lib/Prefs/Special/ImageReplacement.php
@@ -30,6 +30,13 @@ class IMP_Prefs_Special_ImageReplacement implements Horde_Core_Prefs_Ui_Special
     protected $_addrlist;
 
     /**
+     * Safe domain list.
+     *
+     * @var List
+     */    
+    protected $_addrdomain;
+
+    /**
      */
     public function init(Horde_Core_Prefs_Ui $ui)
     {
@@ -82,6 +89,23 @@ class IMP_Prefs_Special_ImageReplacement implements Horde_Core_Prefs_Ui_Special
     }
 
     /**
+     * @return Domain_List
+     */
+    public function safeDomainList()
+    {
+        if (!isset($this->_addrdomain)) {
+            $alist = json_decode($GLOBALS['prefs']->getValue('image_replacement_domain'));
+            if (empty($alist)) {
+                $alist = array();
+            }
+
+            $this->_addrdomain = new ArrayIterator($alist);
+        }
+
+        return new ArrayIterator($this->_addrdomain);
+    }
+
+    /**
      * @param mixed $address  Address to add to the safe address list.
      *
      * @return boolean  True if successfully added.
-- 
1.9.1