1: <?php
2: /**
3: * Copyright 2010-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2010-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Common code relating to image viewing preferences.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2010-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Images
24: {
25: /**
26: * Always show inline images?
27: *
28: * @var boolean
29: */
30: public $alwaysShow = false;
31:
32: /**
33: * Results cache.
34: *
35: * @var array
36: */
37: protected $_cache = array();
38:
39: /**
40: * Show inline images in messages?
41: *
42: * @param IMP_Contents $contents The contents object containing the
43: * message.
44: *
45: * @return boolean True if inline image should be shown.
46: */
47: public function showInlineImage(IMP_Contents $contents)
48: {
49: $cid = strval($contents);
50:
51: if (!isset($this->_cache[$cid])) {
52: $this->_cache[$cid] = $this->_showInlineImage($contents);
53: }
54:
55: return $this->_cache[$cid];
56: }
57:
58: /**
59: * @see showInlineImage
60: */
61: protected function _showInlineImage(IMP_Contents $contents)
62: {
63: global $injector, $prefs;
64:
65: if ($this->alwaysShow || !$prefs->getValue('image_replacement')) {
66: return true;
67: }
68:
69: if (!$contents ||
70: !($from = $contents->getHeader()->getOb('from'))) {
71: return false;
72: }
73:
74: $res = $injector->getInstance('IMP_Contacts')->searchEmail($from[0]->bare_address, array(
75: 'email_exact' => true
76: ));
77:
78: if (count($res)) {
79: /* Don't allow personal addresses by default - this is the only
80: * e-mail address a Spam sender for sure knows you will recognize
81: * so it is too much of a loophole. */
82: $res->setIteratorFilter(0, $injector->getInstance('IMP_Identity')->getAllFromAddresses());
83:
84: foreach ($from as $val) {
85: if ($res->contains($val)) {
86: return true;
87: }
88: }
89: }
90:
91: /* Check safe address list. */
92: $safeAddrs = $injector->getInstance('IMP_Prefs_Special_ImageReplacement')->safeAddrList();
93: foreach ($from as $val) {
94: if ($safeAddrs->contains($val)) {
95: return true;
96: }
97: }
98:
99: return false;
100: }
101:
102: }
103: