[5341] | 1 | <?php |
---|
[5539] | 2 | /** |
---|
| 3 | * |
---|
| 4 | * Copyright (C) 2011 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 5 | * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it under |
---|
| 7 | * the terms of the GNU Affero General Public License version 3 as published by |
---|
| 8 | * the Free Software Foundation with the addition of the following permission |
---|
| 9 | * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED |
---|
| 10 | * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE |
---|
| 11 | * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
| 16 | * details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU Affero General Public License |
---|
| 19 | * along with this program; if not, see www.gnu.org/licenses or write to |
---|
| 20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
---|
| 21 | * MA 02110-1301 USA. |
---|
| 22 | * |
---|
| 23 | * This code is based on the OpenXchange Connector and on the Prognus pSync |
---|
| 24 | * Connector both developed by the community and licensed under the GPL |
---|
| 25 | * version 2 or above as published by the Free Software Foundation. |
---|
| 26 | * |
---|
| 27 | * You can contact Prognus Software Livre headquarters at Av. Tancredo Neves, |
---|
| 28 | * 6731, PTI, Bl. 05, Esp. 02, Sl. 10, Foz do Iguaçu - PR - Brasil or at |
---|
| 29 | * e-mail address prognus@prognus.com.br. |
---|
| 30 | * |
---|
| 31 | * Descrição rápida do arquivo |
---|
| 32 | * |
---|
| 33 | * Arquivo responsável pela manipulação dos filtros |
---|
| 34 | * |
---|
| 35 | * @package filters |
---|
| 36 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 37 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 38 | * @version 1.0 |
---|
| 39 | * @sponsor Caixa EconÃŽmica Federal |
---|
| 40 | * @since Arquivo disponibilizado na versão 2.4 |
---|
| 41 | */ |
---|
[5341] | 42 | |
---|
[5539] | 43 | |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * Classe responsável pela manipulação dos filtros. |
---|
| 47 | * |
---|
| 48 | * |
---|
| 49 | * @package prototype |
---|
| 50 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 51 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 52 | * @author Airton Bordin Junior |
---|
| 53 | * @author Gustavo Pereira dos Santos |
---|
| 54 | * @version 1.0 |
---|
| 55 | * @since Classe disponibilizada na versão 2.4 |
---|
| 56 | */ |
---|
[5341] | 57 | class FilterMapping |
---|
| 58 | { |
---|
[5539] | 59 | |
---|
| 60 | var $service; |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * Método que formata o Script de acordo com a sintaxe do Sieve. |
---|
| 65 | * |
---|
| 66 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 67 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 68 | * @sponsor Caixa EconÃŽmica Federal |
---|
| 69 | * @author Airton Bordin Junior |
---|
| 70 | * @author Gustavo Pereira dos Santos |
---|
| 71 | * @param <Array> <$rules> <Array com as regras do usuário> |
---|
| 72 | * @return <Regra de acordo com a sintaxe do Sieve> |
---|
| 73 | * @access <public> |
---|
| 74 | */ |
---|
| 75 | public function formatSieveScript( $rules ) |
---|
[5341] | 76 | { |
---|
[5630] | 77 | |
---|
[5539] | 78 | $require_fileinto = $require_flag = $require_reject = $require_vacation = $require_body = $require_imapflag = $vacation = $startswith = $endswith = false; |
---|
[5341] | 79 | |
---|
[5629] | 80 | $script_rules = $script_header = $script_criteria = $vacation_action = ""; |
---|
| 81 | |
---|
[5539] | 82 | $i = 0; |
---|
[5629] | 83 | |
---|
[5539] | 84 | foreach( $rules as $name => $data ) |
---|
| 85 | { |
---|
[5630] | 86 | /* Usado na opção Bloquear usuário do ExpressoMail */ |
---|
| 87 | if($data['block']) { |
---|
| 88 | ($i >0) ? $script_match = 'elsif anyof' : $script_match = 'if anyof'; |
---|
| 89 | $script_match = $script_match . "(address :is \"from\" [\"" .$data['name'] . "\"]) {\r\n"; |
---|
| 90 | $script_match .= "fileinto \"INBOX/Spam\"; \r\n}\r\n"; |
---|
| 91 | $script_rules .= $script_match; |
---|
| 92 | $script_match = ""; |
---|
| 93 | $script_criteria = ""; |
---|
| 94 | $require_fileinto = true; |
---|
| 95 | $i++; |
---|
| 96 | continue; |
---|
| 97 | } |
---|
| 98 | |
---|
[5629] | 99 | if( $data['enabled'] == 'false' ) |
---|
[5601] | 100 | continue; |
---|
[5341] | 101 | |
---|
[5629] | 102 | $vacation = false; |
---|
[5539] | 103 | $criteria = $data['criteria']; |
---|
| 104 | $action = $data['actions']; |
---|
| 105 | |
---|
| 106 | ($i >0) ? $script_match = 'els' : $script_match = ''; |
---|
| 107 | $data['isExact'] == 'false' ? $script_match .= 'if anyof (' : $script_match .= 'if allof ('; |
---|
[5341] | 108 | |
---|
[5539] | 109 | for ($j=0; $j<count($criteria); $j++) |
---|
| 110 | { |
---|
| 111 | switch($criteria[$j]['field']) { |
---|
| 112 | case 'To': |
---|
| 113 | case 'to': |
---|
| 114 | case 'CC': |
---|
| 115 | case 'Cc': |
---|
| 116 | $criteria[$j]['field'] = "[\"To\", \"TO\", \"Cc\", \"CC\"]"; |
---|
| 117 | $script_criteria .= "address :"; |
---|
| 118 | break; |
---|
| 119 | case 'from': |
---|
| 120 | $criteria[$j]['field'] = "\"" . $criteria[$j]['field'] . "\""; |
---|
| 121 | $script_criteria .= "address :"; |
---|
| 122 | break; |
---|
| 123 | case 'size': |
---|
| 124 | $criteria[$j]['field'] = ''; |
---|
| 125 | $script_criteria .= "size :"; |
---|
| 126 | break; |
---|
| 127 | case 'subject': |
---|
| 128 | $criteria[$j]['field'] = "\"" . $criteria[$j]['field'] . "\""; |
---|
| 129 | $criteria[$j]['value'] = "" . imap_8bit($criteria[$j]['value']) . "\", \"" . base64_encode($criteria[$j]['value']) . ""; |
---|
| 130 | $script_criteria .= "header :"; |
---|
| 131 | break; |
---|
| 132 | case 'body': |
---|
| 133 | $criteria[$j]['field'] = ''; |
---|
| 134 | $script_criteria .= "body :"; |
---|
| 135 | $require_body = true; |
---|
| 136 | break; |
---|
| 137 | case 'vacation': |
---|
[5601] | 138 | continue; |
---|
[5539] | 139 | default: |
---|
| 140 | $script_criteria .= "header :"; |
---|
| 141 | break; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | switch ($criteria[$j]['operator']) { |
---|
| 145 | case '>': |
---|
| 146 | $criteria[$j]['operator'] = "over"; |
---|
| 147 | break; |
---|
| 148 | case '<': |
---|
| 149 | $criteria[$j]['operator'] = "under"; |
---|
| 150 | break; |
---|
| 151 | case '=': |
---|
| 152 | $criteria[$j]['operator'] = "is"; |
---|
| 153 | $criteria[$j]['value'] = "[\"" . $criteria[$j]['value'] . "\"]"; |
---|
| 154 | break; |
---|
| 155 | case '*': |
---|
| 156 | $criteria[$j]['operator'] = "contains"; |
---|
| 157 | $criteria[$j]['value'] = "[\"" . $criteria[$j]['value'] . "\"]"; |
---|
| 158 | break; |
---|
| 159 | case '^': |
---|
| 160 | $criteria[$j]['operator'] = "matches"; |
---|
| 161 | $criteria[$j]['value'] = "[\"" . $criteria[$j]['value'] . "*\"]"; |
---|
| 162 | $startswith = true; |
---|
| 163 | break; |
---|
| 164 | case '$': |
---|
| 165 | $criteria[$j]['operator'] = "matches"; |
---|
| 166 | $criteria[$j]['value'] = "[\"*" . $criteria[$j]['value'] . "\"]"; |
---|
| 167 | $endswith = true; |
---|
| 168 | break; |
---|
| 169 | /* |
---|
| 170 | TO-DO: |
---|
| 171 | Arrrumar regra do "não contém". |
---|
| 172 | */ |
---|
| 173 | case '!*': |
---|
| 174 | $criteria[$j]['operator'] = "contains"; |
---|
| 175 | $criteria[$j]['value'] = "[\"" . $criteria[$j]['value'] . "\"]"; |
---|
| 176 | break; |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | if ($criteria[$j]['field'] == "" || $criteria[$j]['field'] == "\"subject\"" || $startswith || $endswith) |
---|
| 180 | { |
---|
| 181 | $script_criteria .= $criteria[$j]['operator'] . " " . $criteria[$j]['field'] . " " . $criteria[$j]['value'] . ", "; |
---|
| 182 | $startswith = $endswith = false; |
---|
| 183 | } |
---|
| 184 | else |
---|
| 185 | $script_criteria .= $criteria[$j]['operator'] . " " . $criteria[$j]['field'] . " " . $criteria[$j]['value'] . ", "; |
---|
| 186 | } |
---|
| 187 | $script_criteria = substr($script_criteria,0,-2); |
---|
[5629] | 188 | /* if ($vacation == false) */ |
---|
| 189 | $script_criteria .= ")"; |
---|
| 190 | |
---|
[5539] | 191 | $script_action = " {\r\n "; |
---|
| 192 | for ($k=0; $k<count($action); $k++) |
---|
| 193 | { |
---|
| 194 | switch ($action[$k]['type']) { |
---|
| 195 | case 'redirect': |
---|
| 196 | break; |
---|
| 197 | case 'reject': |
---|
| 198 | $require_reject = true; |
---|
| 199 | break; |
---|
| 200 | case 'fileinto': |
---|
| 201 | $require_fileinto = true; |
---|
| 202 | break; |
---|
| 203 | case 'vacation': |
---|
| 204 | $require_vacation = true; |
---|
| 205 | $action[$k]['parameter'] = "\"" . $action[$k]['parameter'] . "\""; |
---|
[5601] | 206 | $vacation_action = " :subject \"Fora do Escritório\" " . $action[$k]['parameter'] . ";"; |
---|
[5539] | 207 | $vacation = true; |
---|
[5601] | 208 | continue; |
---|
[5539] | 209 | case 'setflag': |
---|
| 210 | $require_flag = true; |
---|
| 211 | $action[$k]['parameter'] = "\\\\" . $action[$k]['parameter']; |
---|
| 212 | break; |
---|
| 213 | case 'discard': |
---|
| 214 | break; |
---|
| 215 | } |
---|
[5629] | 216 | if ($vacation == false) $script_action .= $action[$k]['type'] . " \"" . $action[$k]['parameter'] . "\";\r\n "; |
---|
[5539] | 217 | } |
---|
[5341] | 218 | |
---|
[5629] | 219 | $script_action .= "}"; |
---|
| 220 | |
---|
| 221 | if($vacation != true) |
---|
| 222 | $script_rules .= $script_match . $script_criteria . $script_action . "\r\n"; |
---|
[5539] | 223 | |
---|
[5629] | 224 | if($data['id'] != "vacation") |
---|
| 225 | $i++; |
---|
[5539] | 226 | $script_match = ""; |
---|
| 227 | $script_criteria = ""; |
---|
[5629] | 228 | |
---|
[5341] | 229 | } |
---|
[5539] | 230 | |
---|
| 231 | if($require_reject || $require_fileinto || $require_vacation || $require_body || $require_flag) |
---|
[5341] | 232 | { |
---|
[5539] | 233 | $script_header .= "require ["; |
---|
| 234 | $require_reject ? $script_header .= "\"reject\", " : ""; |
---|
| 235 | $require_fileinto ? $script_header .= "\"fileinto\", " : ""; |
---|
| 236 | $require_vacation? $script_header .= "\"vacation\", " : ""; |
---|
| 237 | $require_flag ? $script_header .= "\"imapflags\", " : ""; |
---|
| 238 | $require_body ? $script_header .= "\"body\", " : ""; /* tem que instalar as extensões no Cyrus */ |
---|
| 239 | $script_header = substr($script_header,0,-2); |
---|
| 240 | $script_header .= "];\r\n"; |
---|
[5341] | 241 | } |
---|
| 242 | |
---|
[5629] | 243 | if( $vacation_action ) |
---|
[5601] | 244 | { |
---|
| 245 | $script_rules .= "vacation" . $vacation_action . "\r\n"; |
---|
| 246 | } |
---|
| 247 | |
---|
[5539] | 248 | $json_data = json_encode($rules); |
---|
| 249 | |
---|
| 250 | $script_begin = "#Filtro gerado por Expresso Livre versão 2.4\r\n\r\n"; |
---|
[5341] | 251 | |
---|
[5539] | 252 | $content = $script_begin . $script_header . $script_rules . "\r\n\r\n#PseudoScript#" . "\r\n#" . $json_data; |
---|
[5629] | 253 | //$content = ""; |
---|
[5539] | 254 | return( $content ); |
---|
[5341] | 255 | } |
---|
[5539] | 256 | |
---|
[5672] | 257 | /** |
---|
| 258 | * Método que lê e faz o parser dos filtros antigos |
---|
| 259 | * |
---|
| 260 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 261 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 262 | * @sponsor Caixa EconÃŽmica Federal |
---|
| 263 | * @author Airton Bordin Junior |
---|
| 264 | * @author Gustavo Pereira dos Santos |
---|
| 265 | * @param <$scriptName> <Regras do usuário> |
---|
| 266 | * @return <Regra do usuário parseada> |
---|
| 267 | * @access <public> |
---|
| 268 | */ |
---|
| 269 | public function readOldScript($scriptName) |
---|
| 270 | { |
---|
| 271 | // Recebe o conteúdo do array; |
---|
| 272 | $lines = array(); |
---|
| 273 | $lines = preg_split("/\n/", $scriptName); |
---|
[5341] | 274 | |
---|
[5672] | 275 | // Pega o tamanho da regra na primeira do script; |
---|
| 276 | $size_rule = array_shift($lines); |
---|
| 277 | |
---|
| 278 | // Recebe o tamanho do script, pela primeira linha; |
---|
| 279 | $this->size = trim($size_rule); |
---|
| 280 | |
---|
| 281 | // Verifica a composição do script; */ |
---|
| 282 | $line = array_shift($lines); |
---|
| 283 | |
---|
| 284 | // Variaveis para a regra e o campo ferias; |
---|
| 285 | $regexps = array('^ *##PSEUDO', '^ *#rule', '^ *#vacation', '^ *#mode'); |
---|
| 286 | $retorno['rule'] = array(); |
---|
| 287 | |
---|
| 288 | $line = array_shift($lines); |
---|
| 289 | while (isset($line)) { |
---|
| 290 | foreach ($regexps as $regp) { |
---|
| 291 | if (preg_match("/$regp/i", $line)) { |
---|
| 292 | // Recebe todas as regras criadas no servidor; |
---|
| 293 | if (preg_match("/^ *#rule&&/i", $line)) { |
---|
| 294 | $retorno['rule'][] = $line . "\n"; |
---|
| 295 | } |
---|
| 296 | } |
---|
| 297 | } |
---|
| 298 | // Pega a proxima linha do sript; |
---|
| 299 | $line = array_shift($lines); |
---|
| 300 | } |
---|
| 301 | return $retorno; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | |
---|
| 305 | |
---|
| 306 | |
---|
[5539] | 307 | /** |
---|
| 308 | * Método que faz o parsing do Script Sieve, transformando em Array. |
---|
| 309 | * |
---|
| 310 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 311 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 312 | * @sponsor Caixa EconÃŽmica Federal |
---|
| 313 | * @author Airton Bordin Junior |
---|
| 314 | * @author Gustavo Pereira dos Santos |
---|
| 315 | * @param <String> <$script> <Script Sieve com as regras do usuário> |
---|
| 316 | * @return <Regras do usuário em Array> |
---|
| 317 | * @access <public> |
---|
| 318 | */ |
---|
| 319 | public function parseSieveScript( $script ) |
---|
[5341] | 320 | { |
---|
[5672] | 321 | $old_rule = strripos($script, "##PSEUDO script start"); |
---|
| 322 | |
---|
| 323 | if($old_rule) { |
---|
| 324 | |
---|
| 325 | $parsed_rule = $this->readOldScript($old_script); |
---|
| 326 | $array_rule = explode("&&", $parsed_rule['rule'][0]); |
---|
| 327 | |
---|
| 328 | $old_retorno = array(); |
---|
| 329 | $old_retorno['isExact'] = false; |
---|
| 330 | $old_retorno['name'] = $array_rule[1]; |
---|
| 331 | $old_retorno['criteria'] = array(); |
---|
| 332 | $old_retorno['criteria'][0] = array(); |
---|
| 333 | $old_retorno['criteria'][0]['value'] = $array_rule[5]; |
---|
| 334 | $old_retorno['criteria'][0]['operator'] = '='; |
---|
| 335 | $old_retorno['criteria'][0]['field'] = 'subject'; |
---|
| 336 | $old_retorno['actions'] = array(); |
---|
| 337 | $old_retorno['actions'][0] = array(); |
---|
| 338 | $old_retorno['actions'][0]['parameter'] = $array_rule[7]; |
---|
| 339 | $old_retorno['actions'][0]['type'] = $array_rule[6]; |
---|
| 340 | $old_retorno['enabled'] = true; |
---|
| 341 | $old_retorno['id'] = $array_rule[1]; |
---|
| 342 | $old_retorno['applyMessages'] = ''; |
---|
| 343 | |
---|
| 344 | return $old_retorno; |
---|
| 345 | } |
---|
| 346 | |
---|
[5539] | 347 | $pos = strripos($script, "#PseudoScript#"); |
---|
| 348 | $pseudo_script = substr( $script, $pos+17 ); |
---|
[5341] | 349 | |
---|
[5539] | 350 | $return = json_decode( $pseudo_script, true ); |
---|
[5341] | 351 | |
---|
[5539] | 352 | return $return; |
---|
| 353 | } |
---|
[5341] | 354 | |
---|
[5539] | 355 | var $rules = false; |
---|
[5341] | 356 | |
---|
[5539] | 357 | /** |
---|
| 358 | * Construtor da classe. |
---|
| 359 | * |
---|
| 360 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 361 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 362 | * @sponsor Caixa EconÃŽmica Federal |
---|
| 363 | * @author Airton Bordin Junior |
---|
| 364 | * @author Gustavo Pereira dos Santos |
---|
| 365 | * @access <public> |
---|
| 366 | */ |
---|
| 367 | public function __construct() |
---|
| 368 | { |
---|
| 369 | $this->service = Controller::service("Sieve"); |
---|
| 370 | } |
---|
[5341] | 371 | |
---|
[5539] | 372 | |
---|
| 373 | /** |
---|
| 374 | * Método que recupera as regras do usuário. |
---|
| 375 | * |
---|
| 376 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 377 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 378 | * @sponsor Caixa EconÃŽmica Federal |
---|
| 379 | * @author Airton Bordin Junior |
---|
| 380 | * @author Gustavo Pereira dos Santos |
---|
| 381 | * @return <Regras do usuário> |
---|
| 382 | * @access <public> |
---|
| 383 | */ |
---|
| 384 | public function getRules() |
---|
| 385 | { |
---|
| 386 | $this->rules = Controller::find( array( 'concept' => 'filter' ) ); |
---|
[5341] | 387 | |
---|
[5539] | 388 | if( !$this->rules ) { |
---|
| 389 | $this->rules = array(); |
---|
| 390 | } |
---|
| 391 | return( $this->rules ); |
---|
| 392 | } |
---|
[5341] | 393 | |
---|
[5539] | 394 | |
---|
| 395 | /** |
---|
| 396 | * Método que aplica o filtro para as mensagens do usuário. |
---|
| 397 | * |
---|
| 398 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 399 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 400 | * @sponsor Caixa EconÃŽmica Federal |
---|
| 401 | * @author Airton Bordin Junior |
---|
| 402 | * @author Gustavo Pereira dos Santos |
---|
| 403 | * @param <$uri> |
---|
| 404 | * @param <$result> |
---|
| 405 | * @param <$criteria> |
---|
| 406 | * @param <$original> |
---|
| 407 | * @access <public> |
---|
| 408 | */ |
---|
| 409 | public function applySieveFilter( &$uri , &$result , &$criteria , $original ) |
---|
| 410 | { |
---|
[5601] | 411 | $result['id'] = $uri['id']; |
---|
| 412 | |
---|
[5539] | 413 | if( $original['properties']['applyMessages'] ) |
---|
| 414 | { |
---|
[5601] | 415 | $filter = Controller::read($uri); |
---|
[5341] | 416 | |
---|
[5601] | 417 | $proc = array(); |
---|
| 418 | $proc['keep'] = false; |
---|
| 419 | |
---|
| 420 | foreach ($filter['actions'] as $v){ |
---|
| 421 | if($v['type'] == 'keep') |
---|
| 422 | $proc['keep'] = true; |
---|
| 423 | else{ |
---|
| 424 | $proc['type'] = $v['type']; |
---|
| 425 | $proc['parameter'] = $v['parameter']; |
---|
| 426 | } |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | $imap = Controller::service( 'Imap' ); |
---|
| 430 | $imap->apliSieveFilter($original['properties']['applyMessages'] , $proc ); |
---|
| 431 | return $result; |
---|
[5539] | 432 | } |
---|
| 433 | } |
---|
[5341] | 434 | |
---|
[5539] | 435 | |
---|
| 436 | /** |
---|
| 437 | * Método que lê o script do usuário. |
---|
| 438 | * |
---|
| 439 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 440 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 441 | * @sponsor Caixa EconÃŽmica Federal |
---|
| 442 | * @author Airton Bordin Junior |
---|
| 443 | * @author Gustavo Pereira dos Santos |
---|
| 444 | * @param <$uri> |
---|
| 445 | * @param <$result> |
---|
| 446 | * @param <$criteria> |
---|
| 447 | * @param <$original> |
---|
| 448 | * @return <Script do usuário> |
---|
| 449 | * @access <public> |
---|
| 450 | */ |
---|
| 451 | public function readUserScript( &$uri , &$params , &$criteria , $original ) |
---|
| 452 | { |
---|
| 453 | $uri['id'] = $this->service->config['user']; |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | |
---|
| 457 | /** |
---|
| 458 | * Método que seta o script do usuário. |
---|
| 459 | * |
---|
| 460 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 461 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 462 | * @sponsor Caixa EconÃŽmica Federal |
---|
| 463 | * @author Airton Bordin Junior |
---|
| 464 | * @author Gustavo Pereira dos Santos |
---|
| 465 | * @param <$uri> |
---|
| 466 | * @param <$result> |
---|
| 467 | * @param <$criteria> |
---|
| 468 | * @param <$original> |
---|
| 469 | * @return <Script do usuário> |
---|
| 470 | * @access <public> |
---|
| 471 | */ |
---|
| 472 | public function setRule( &$uri , &$params , &$criteria , $original ) |
---|
[5601] | 473 | { |
---|
[5630] | 474 | if( !$this->rules ) |
---|
[5539] | 475 | $this->rules = $this->getRules(); |
---|
[5341] | 476 | |
---|
[5601] | 477 | $uri['id'] = $params['id'] = isset($params['id']) ? $params['id'] : urlencode($params['name']); |
---|
[5341] | 478 | |
---|
[5601] | 479 | $i = 0; |
---|
[5341] | 480 | |
---|
[5629] | 481 | for( ; isset($this->rules[$i]) && $this->rules[$i]['id'] !== $params['id']; $i++ ); |
---|
[5601] | 482 | |
---|
[5629] | 483 | $this->rules[$i] = array_merge( ( isset($this->rules[$i]) ? $this->rules[$i] : array() ), $params ); |
---|
[5601] | 484 | |
---|
| 485 | $params = array( 'name' => $this->service->config['user'], |
---|
| 486 | 'content' => $this->formatSieveScript( $this->rules ), |
---|
| 487 | 'active' => true ); |
---|
[5539] | 488 | } |
---|
[5341] | 489 | |
---|
[5539] | 490 | |
---|
| 491 | /** |
---|
| 492 | * Método que deleta o script do usuário. |
---|
| 493 | * |
---|
| 494 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 495 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 496 | * @sponsor Caixa EconÃŽmica Federal |
---|
| 497 | * @author Airton Bordin Junior |
---|
| 498 | * @author Gustavo Pereira dos Santos |
---|
| 499 | * @param <$uri> |
---|
| 500 | * @param <$result> |
---|
| 501 | * @param <$criteria> |
---|
| 502 | * @param <$original> |
---|
| 503 | * @access <public> |
---|
| 504 | */ |
---|
| 505 | public function deleteRule( &$uri, &$params, &$criteria, $original ) |
---|
| 506 | { |
---|
[5601] | 507 | if( !$this->rules ) { |
---|
| 508 | $this->rules = $this->getRules(); |
---|
| 509 | } |
---|
[5539] | 510 | $params['id'] = $uri['id']; |
---|
[5341] | 511 | |
---|
[5539] | 512 | $update = false; |
---|
[5601] | 513 | |
---|
| 514 | $rules = array(); |
---|
[5341] | 515 | |
---|
[5539] | 516 | foreach( $this->rules as $i => $rule ) |
---|
[5601] | 517 | if( $rule['id'] !== $uri['id'] ) |
---|
| 518 | $rules[] = $this->rules[$i]; |
---|
[5341] | 519 | |
---|
[5601] | 520 | $this->rules = $rules; |
---|
| 521 | |
---|
[5539] | 522 | $uri['id'] = ''; |
---|
[5341] | 523 | |
---|
[5539] | 524 | $params = array( 'name' => $this->service->config['user'], |
---|
| 525 | 'content' => $this->formatSieveScript( $this->rules ), |
---|
| 526 | 'active' => true ); |
---|
[5341] | 527 | |
---|
[5539] | 528 | $URI = Controller::URI( $uri['concept'], $this->service->config['user'] ); |
---|
| 529 | $this->service->update( $URI, $params ); |
---|
[5601] | 530 | |
---|
[5539] | 531 | return( false ); |
---|
| 532 | } |
---|
[5341] | 533 | |
---|
[5539] | 534 | |
---|
| 535 | /** |
---|
| 536 | * Método que pega o script do usuário. |
---|
| 537 | * |
---|
| 538 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 539 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 540 | * @sponsor Caixa EconÃŽmica Federal |
---|
| 541 | * @author Airton Bordin Junior |
---|
| 542 | * @author Gustavo Pereira dos Santos |
---|
| 543 | * @param <$uri> |
---|
| 544 | * @param <$result> |
---|
| 545 | * @param <$criteria> |
---|
| 546 | * @param <$original> |
---|
| 547 | * @return <Script do usuário> |
---|
| 548 | * @access <public> |
---|
| 549 | */ |
---|
| 550 | public function getSieveRule( &$uri , &$params , &$criteria , $original ) |
---|
| 551 | { |
---|
| 552 | $script = $this->parseSieveScript( $params['content'] ); |
---|
[5341] | 553 | |
---|
[5539] | 554 | foreach( $script as $i => $rule ) |
---|
| 555 | if( $rule['name'] === $original['id'] ) |
---|
| 556 | return( $params = $rule ); |
---|
| 557 | } |
---|
[5341] | 558 | |
---|
[5539] | 559 | |
---|
| 560 | /** |
---|
| 561 | * Método que lista as regras do usuário. |
---|
| 562 | * |
---|
| 563 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 564 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 565 | * @sponsor Caixa EconÃŽmica Federal |
---|
| 566 | * @author Airton Bordin Junior |
---|
| 567 | * @author Gustavo Pereira dos Santos |
---|
| 568 | * @param <$uri> |
---|
| 569 | * @param <$result> |
---|
| 570 | * @param <$criteria> |
---|
| 571 | * @param <$original> |
---|
| 572 | * @return <Regras do usuário> |
---|
| 573 | * @access <public> |
---|
| 574 | */ |
---|
| 575 | public function listSieveRules( &$uri , &$params , &$criteria , $original ) |
---|
[5629] | 576 | { |
---|
[5539] | 577 | $return = $params = $this->parseSieveScript( $params[0]['content'] ); |
---|
| 578 | return( $return ); |
---|
| 579 | } |
---|
| 580 | } |
---|