/usr/share/horde/ingo/lib/Storage.php is in php-horde-ingo 3.2.13-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | <?php
/**
* Copyright 2002-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/apache.
*
* @author Jan Schneider <jan@horde.org>
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/apache ASL
* @package Ingo
*/
/**
* Ingo_Storage defines an API to store the various filter rules.
*
* @author Jan Schneider <jan@horde.org>
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/apache ASL
* @package Ingo
*/
class Ingo_Storage
{
/**
* Ingo_Storage:: 'combine' constants
*/
const COMBINE_ALL = 1;
const COMBINE_ANY = 2;
/**
* Ingo_Storage:: 'action' constants
*/
const ACTION_FILTERS = 0;
const ACTION_KEEP = 1;
const ACTION_MOVE = 2;
const ACTION_DISCARD = 3;
const ACTION_REDIRECT = 4;
const ACTION_REDIRECTKEEP = 5;
const ACTION_REJECT = 6;
const ACTION_BLACKLIST = 7;
const ACTION_VACATION = 8;
const ACTION_WHITELIST = 9;
const ACTION_FORWARD = 10;
const ACTION_MOVEKEEP = 11;
const ACTION_FLAGONLY = 12;
const ACTION_NOTIFY = 13;
const ACTION_SPAM = 14;
/**
* Ingo_Storage:: 'flags' constants
*/
const FLAG_ANSWERED = 1;
const FLAG_DELETED = 2;
const FLAG_FLAGGED = 4;
const FLAG_SEEN = 8;
/**
* Ingo_Storage:: 'type' constants.
*/
const TYPE_HEADER = 1;
const TYPE_SIZE = 2;
const TYPE_BODY = 3;
/**
* Cached rules.
*
* @var array
*/
protected $_cache = array();
/**
* Configuration parameters.
*
* @var array
*/
protected $_params = array();
/**
* Constructor.
*
* @params array $params Configuration parameters.
*/
public function __construct(array $params = array())
{
$this->_params = $params;
}
/**
* Retrieves the specified data.
*
* @param integer $field The field name of the desired data
* (ACTION_* constants).
* @param boolean $readonly Whether to disable any write operations.
*
* @return Ingo_Storage_Rule|Ingo_Storage_Filters The specified object.
* @throws Ingo_Exception
*/
public function retrieve($field, $readonly = false)
{
if (!isset($this->_cache[$field])) {
$this->_cache[$field] = $this->_retrieve($field, $readonly);
}
return $this->_cache[$field];
}
/**
* Retrieves the specified data from the storage backend.
*
* @param integer $field The field name of the desired data.
* See lib/Storage.php for the available fields.
* @param boolean $readonly Whether to disable any write operations.
*
* @return Ingo_Storage_Rule|Ingo_Storage_Filters The specified data.
*/
protected function _retrieve($field, $readonly = false)
{
return false;
}
/**
* Stores the specified data.
*
* @param Ingo_Storage_Rule|Ingo_Storage_Filters $ob The object to store.
*
* @throws Ingo_Exception
*/
public function store($ob)
{
global $session;
switch ($type = $ob->obType()) {
case self::ACTION_BLACKLIST:
$name = 'Blacklist';
break;
case self::ACTION_VACATION:
$name = 'Vacation';
break;
case self::ACTION_WHITELIST:
$name = 'Whitelist';
break;
case self::ACTION_FORWARD:
$name = 'Forward';
break;
case self::ACTION_SPAM:
$name = 'Spam Filter';
break;
default:
$name = null;
break;
}
if (!is_null($name) &&
($filters = $this->retrieve(self::ACTION_FILTERS)) &&
($filters->findRuleId($type) === null)) {
$filters->addRule(array('action' => $type, 'name' => $name));
$this->store($filters);
}
$this->_store($ob);
$this->_cache[$type] = $ob;
$session->set('ingo', 'change', time());
}
/**
* Stores the specified data in the storage backend.
*
* @param Ingo_Storage_Rule|Ingo_Storage_Filters $ob The object to store.
*/
protected function _store($ob)
{
}
/**
* Returns information on a given action constant.
*
* @param integer $action The ACTION_* value.
*
* @return object Object with the following values:
* - flags: (boolean) Does this action allow flags to be set?
* - label: (string) The label for this action.
* - type: (string) Either 'folder', 'text', or empty.
*/
public function getActionInfo($action)
{
$ob = new stdClass;
$ob->flags = false;
$ob->type = 'text';
switch ($action) {
case self::ACTION_KEEP:
$ob->label = _("Deliver into my Inbox");
$ob->type = false;
$ob->flags = true;
break;
case self::ACTION_MOVE:
$ob->label = _("Deliver to folder...");
$ob->type = 'folder';
$ob->flags = true;
break;
case self::ACTION_DISCARD:
$ob->label = _("Delete message completely");
$ob->type = false;
break;
case self::ACTION_REDIRECT:
$ob->label = _("Redirect to...");
break;
case self::ACTION_REDIRECTKEEP:
$ob->label = _("Deliver into my Inbox and redirect to...");
$ob->flags = true;
break;
case self::ACTION_MOVEKEEP:
$ob->label = _("Deliver into my Inbox and copy to...");
$ob->type = 'folder';
$ob->flags = true;
break;
case self::ACTION_REJECT:
$ob->label = _("Reject with reason...");
break;
case self::ACTION_FLAGONLY:
$ob->label = _("Only flag the message");
$ob->type = false;
$ob->flags = true;
break;
case self::ACTION_NOTIFY:
$ob->label = _("Notify email address...");
break;
}
return $ob;
}
/**
* Returns information on a given test string.
*
* @param string $action The test string.
*
* @return object Object with the following values:
* - label: (string) The label for this action.
* - type: (string) Either 'int', 'none', or 'text'.
*/
public function getTestInfo($test)
{
/* Mapping of gettext strings -> labels. */
$labels = array(
'contains' => _("Contains"),
'not contain' => _("Doesn't contain"),
'is' => _("Is"),
'not is' => _("Isn't"),
'begins with' => _("Begins with"),
'not begins with' => _("Doesn't begin with"),
'ends with' => _("Ends with"),
'not ends with' => _("Doesn't end with"),
'exists' => _("Exists"),
'not exist' => _("Doesn't exist"),
'regex' => _("Regular expression"),
'not regex' => _("Doesn't match regular expression"),
'matches' => _("Matches (with placeholders)"),
'not matches' => _("Doesn't match (with placeholders)"),
'less than' => _("Less than"),
'less than or equal to' => _("Less than or equal to"),
'greater than' => _("Greater than"),
'greater than or equal to' => _("Greater than or equal to"),
'equal' => _("Equal to"),
'not equal' => _("Not equal to")
);
/* The type of tests available. */
$types = array(
'int' => array(
'less than', 'less than or equal to', 'greater than',
'greater than or equal to', 'equal', 'not equal'
),
'none' => array(
'exists', 'not exist'
),
'text' => array(
'contains', 'not contain', 'is', 'not is', 'begins with',
'not begins with', 'ends with', 'not ends with', 'regex',
'not regex', 'matches', 'not matches'
)
);
/* Create the information object. */
$ob = new stdClass;
$ob->label = $labels[$test];
foreach ($types as $key => $val) {
if (in_array($test, $val)) {
$ob->type = $key;
break;
}
}
return $ob;
}
/**
* Removes the user data from the storage backend.
* Stub for child class to override if it can implement.
*
* @param string $user The user name to delete filters for.
*
* @throws Ingo_Exception
*/
public function removeUserData($user)
{
throw new Ingo_Exception(_("Removing user data is not supported with the current filter storage backend."));
}
/**
* Output description for a rule.
*
* @param array $rule Rule.
*
* @return string Text description.
*/
public function ruleDescription($rule)
{
$condition_size = count($rule['conditions']) - 1;
$descrip = '';
foreach ($rule['conditions'] as $key => $val) {
$info = $this->getTestInfo($val['match']);
$descrip .= sprintf("%s %s \"%s\"", _($val['field']), $info->label, $val['value']);
if (!empty($val['case'])) {
$descrip .= ' [' . _("Case Sensitive") . ']';
}
if ($key < $condition_size) {
$descrip .= ($rule['combine'] == self::COMBINE_ALL)
? _(" and")
: _(" or");
$descrip .= "\n ";
}
}
$descrip .= "\n" . $this->getActionInfo($rule['action'])->label;
if ($rule['action-value']) {
$descrip .= ': ' . $rule['action-value'];
}
if ($rule['stop']) {
$descrip .= "\n[stop]";
}
return $descrip;
}
/**
* Clears the internal rule cache.
*
* @since Ingo 3.2.12
*/
public function clearCache()
{
$this->_cache = array();
}
}
|