source: trunk/prototype/modules/filters/interceptors/FilterMapping.php @ 6028

Revision 6028, 20.8 KB checked in by airton, 12 years ago (diff)

Ticket #2655 - Inconsistencia em filtros com a opcao armazenar na pasta

RevLine 
[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)
[5862]52* @author     Airton Bordin Junior <airton@prognus.com.br>
53* @author     Gustavo Pereira dos Santos <gustavo@prognus.com.br>
[5539]54* @version    1.0
55* @since      Classe disponibilizada na versão 2.4
56*/
[5341]57class FilterMapping
58{
[5539]59        var $service;
60       
[6021]61        /**
62        * Método que cria o ID da regra que está sendo criada.
63        *
64        * @license    http://www.gnu.org/copyleft/gpl.html GPL
65        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
66        * @sponsor    Caixa EconÃŽmica Federal
67        * @author     Airton Bordin Junior <airton@prognus.com.br>
68        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>   
69        * @author         Natan Fonseca <natan@prognus.com.br> 
70        * @param      <$uri>
71        * @param      <$result>
72        * @param      <$criteria>
73        * @param      <$original>
74        * @access     <public>
75        */
76        public function makeId(&$uri , &$result , &$criteria , $original) {
77                $result['id'] = $uri['id'];
78        }
[5539]79       
[6021]80       
[5539]81        /**
82        * Método que formata o Script de acordo com a sintaxe do Sieve.
83        *
84        * @license    http://www.gnu.org/copyleft/gpl.html GPL
85        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
86        * @sponsor    Caixa EconÃŽmica Federal
[5862]87        * @author     Airton Bordin Junior <airton@prognus.com.br>
88        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>   
[5539]89        * @param      <Array> <$rules> <Array com as regras do usuário>
90        * @return     <Regra de acordo com a sintaxe do Sieve>
91        * @access     <public>
92        */
93        public function formatSieveScript( $rules )
[5341]94    {
[5630]95       
[5539]96                $require_fileinto = $require_flag = $require_reject = $require_vacation = $require_body = $require_imapflag = $vacation = $startswith = $endswith = false;
[5341]97
[5629]98                $script_rules = $script_header = $script_criteria = $vacation_action = "";
99
[5539]100                $i = 0;
[6009]101               
[5539]102                foreach( $rules as $name => $data )
[6009]103                {       
104                        if( $data['enabled'] == 'false' )
105                                continue;
106                               
[5747]107                        if(array_key_exists("block", $data)) {
108                                /* Usado na opção Bloquear usuário do ExpressoMail */
109                                if($data['block']) {
110                                        ($i >0) ? $script_match = 'elsif anyof' : $script_match = 'if anyof';
111                                        $script_match = $script_match . "(address :is \"from\" [\"" .$data['name'] . "\"]) {\r\n"; 
112                                        $script_match .= "fileinto \"INBOX/Spam\"; \r\n}\r\n";
113                                        $script_rules .= $script_match;
114                                        $script_match = "";
115                                        $script_criteria = "";
116                                        $require_fileinto = true;
117                                        $i++;
118                                        continue;
119                                }
[5630]120                        }
[5747]121                        //if( $data['enabled'] == 'false' )
122                                //continue;
[6009]123                               
[5629]124                        $vacation = false;
[5539]125                        $criteria = $data['criteria'];
126                        $action   = $data['actions'];
127                       
128                        ($i >0) ? $script_match = 'els' : $script_match = '';
129                        $data['isExact'] == 'false' ?  $script_match .= 'if anyof (' : $script_match .= 'if allof (';
[5341]130
[5728]131                        if( is_array($criteria) )
[5996]132                        foreach ($criteria as $j => $value)
[5539]133                        {                                       
[5862]134
[5539]135                                switch($criteria[$j]['field']) {
136                                        case 'To':   
137                                        case 'to':   
138                                        case 'CC':
139                                        case 'Cc':
140                                                $criteria[$j]['field'] = "[\"To\", \"TO\", \"Cc\", \"CC\"]";
141                                                $script_criteria .= "address :";
142                                                break;
143                                        case 'from':
144                                                $criteria[$j]['field'] = "\"" . $criteria[$j]['field'] . "\"";
145                                                $script_criteria .= "address :";
146                                                break;
147                                        case 'size':   
148                                                $criteria[$j]['field'] = '';
149                                                $script_criteria .= "size :";
150                                                break;
151                                        case 'subject':
152                                                $criteria[$j]['field'] = "\"" . $criteria[$j]['field'] . "\"";
153                                                $criteria[$j]['value'] = "" . imap_8bit($criteria[$j]['value']) . "\", \"" . base64_encode($criteria[$j]['value']) . "";
154                                                $script_criteria .= "header :";
155                                                break;
156                                        case 'body':
157                                                $criteria[$j]['field'] = '';
158                                                $script_criteria .= "body :";
159                                                $require_body = true;
160                                                break;
161                                        case 'vacation':
[5601]162                                                continue;
[5539]163                                        default:
164                                                $script_criteria .= "header :";
165                                                break;
166                                }
167                               
168                                switch ($criteria[$j]['operator']) {
169                                        case '>':
170                                                $criteria[$j]['operator'] = "over";
[6001]171                                                $criteria[$j]['value'] = $criteria[$j]['value'] . "K";
[5539]172                                                break;
173                                        case '<':
174                                                $criteria[$j]['operator'] = "under";
[6001]175                                                $criteria[$j]['value'] = $criteria[$j]['value'] . "K";
[5539]176                                                break;
177                                        case '=':
178                                                $criteria[$j]['operator'] = "is";
179                                                $criteria[$j]['value'] = "[\"" . $criteria[$j]['value'] . "\"]";
180                                                break;
181                                        case '*':
182                                                $criteria[$j]['operator'] = "contains";
183                                                $criteria[$j]['value'] = "[\"" . $criteria[$j]['value'] . "\"]";
184                                                break;                                         
185                                        case '^':
186                                                $criteria[$j]['operator'] = "matches";
187                                                $criteria[$j]['value'] = "[\"" . $criteria[$j]['value'] . "*\"]";
188                                                $startswith = true;
189                                                break;
190                                        case '$':
191                                                $criteria[$j]['operator'] = "matches";
192                                                $criteria[$j]['value'] = "[\"*" . $criteria[$j]['value'] . "\"]";
193                                                $endswith = true;
194                                                break;
195                                        /*
196                                           TO-DO:
[5862]197                                           Inconsistência na regra do "não contém".
[5539]198                                        */
199                                        case '!*':
200                                                $criteria[$j]['operator'] = "contains";
201                                                $criteria[$j]['value'] = "[\"" . $criteria[$j]['value'] . "\"]";
202                                                break;
203                                }
204                               
205                                if ($criteria[$j]['field'] == "" || $criteria[$j]['field'] == "\"subject\"" || $startswith || $endswith)
206                                {
207                                        $script_criteria .= $criteria[$j]['operator'] . " " . $criteria[$j]['field'] . " " . $criteria[$j]['value'] . ", ";
208                                        $startswith = $endswith = false;
209                                }
210                                else
211                                        $script_criteria .= $criteria[$j]['operator'] . " " . $criteria[$j]['field'] . " " . $criteria[$j]['value'] . ", ";
212                        }
213                        $script_criteria = substr($script_criteria,0,-2);
[5629]214                        /* if ($vacation == false) */
215                        $script_criteria .= ")";
216
[5539]217                        $script_action = " {\r\n ";
[5728]218                       
[5747]219                        if( is_array($action) )
[5996]220                        foreach ($action as $k => $value)
[5539]221                        {
222                                switch ($action[$k]['type']) {
223                                        case 'redirect':
224                                                break;
225                                        case 'reject':
226                                                $require_reject = true;
227                                                break;
228                                        case 'fileinto':
229                                                $require_fileinto = true;
[6028]230                                                $action[$k]['parameter'] = imap_utf7_encode($action[$k]['parameter']);
[5539]231                                                break;
232                                        case 'vacation':
233                                                $require_vacation = true;
234                                                $action[$k]['parameter'] = "\"" . $action[$k]['parameter'] . "\"";
[5952]235                                                $vacation_action = " :subject \"Fora do Escrit&oacuterio\" " . $action[$k]['parameter'] . ";";
[5539]236                                                $vacation = true;
[5601]237                                                continue;
[5539]238                                        case 'setflag':
239                                                $require_flag = true;
240                                                $action[$k]['parameter'] = "\\\\" . $action[$k]['parameter'];
241                                                break;
242                                        case 'discard':
243                                                break;
244                                }
[5629]245                                if ($vacation == false) $script_action .= $action[$k]['type'] . " \"" . $action[$k]['parameter'] . "\";\r\n ";
[5539]246                        }
[5629]247                        $script_action .= "}";
248                       
249                        if($vacation != true)
250                                $script_rules .= $script_match . $script_criteria . $script_action . "\r\n";
[5539]251
[5629]252                        if($data['id'] != "vacation")
253                                $i++;
[5539]254                        $script_match = "";
[5862]255                        $script_criteria = ""; 
256                        $data['applyMessages'] = "";                                                   
[5341]257                }
[5539]258
259                if($require_reject || $require_fileinto || $require_vacation || $require_body || $require_flag)
[5341]260                {
[5539]261                        $script_header .= "require [";
262                        $require_reject ? $script_header .= "\"reject\", " : "";
263                        $require_fileinto ? $script_header .= "\"fileinto\", " : "";
264                        $require_vacation? $script_header .= "\"vacation\", " : ""; 
265                        $require_flag ? $script_header .= "\"imapflags\", " : ""; 
266                        $require_body ? $script_header .= "\"body\", " : "";  /* tem que instalar as extensões no Cyrus */
267                        $script_header = substr($script_header,0,-2);
268                        $script_header .= "];\r\n";
[5341]269                }
270
[5629]271                if( $vacation_action )
[5601]272                {
273                  $script_rules .= "vacation" . $vacation_action . "\r\n";
274                }
275
[5539]276                $json_data = json_encode($rules);
277               
278                $script_begin = "#Filtro gerado por Expresso Livre versão 2.4\r\n\r\n";
[5341]279
[5539]280                $content = $script_begin . $script_header . $script_rules . "\r\n\r\n#PseudoScript#" . "\r\n#" . $json_data;
[5747]281
[5539]282                return( $content );
[5341]283        }
[5539]284       
[5672]285        /**
286        * Método que lê e faz o parser dos filtros antigos
287        *
288        * @license    http://www.gnu.org/copyleft/gpl.html GPL
289        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
290        * @sponsor    Caixa EconÃŽmica Federal
[5862]291        * @author     Airton Bordin Junior <airton@prognus.com.br>
292        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>   
[5672]293        * @param      <$scriptName> <Regras do usuário>
294        * @return     <Regra do usuário parseada>
295        * @access     <public>
296        */
297        public function readOldScript($scriptName)
298        {
299        // Recebe o conteúdo do array;
300        $lines = array();
301        $lines = preg_split("/\n/", $scriptName);
[5341]302
[5672]303        // Pega o tamanho da regra na primeira do script;
304        $size_rule = array_shift($lines);
305
306        // Recebe o tamanho do script, pela primeira linha;
[5862]307        //$this->size = trim($size_rule);
[5672]308
309        // Verifica a composição do script; */
[5862]310        $line = array_shift($lines);
[5672]311
312        // Variaveis para a regra e o campo ferias;
[5862]313        $regexps = array('##PSEUDO', '#rule', '#vacation', '#mode');
[5672]314        $retorno['rule'] = array();
315
316        $line = array_shift($lines);
[5862]317        while (isset($line)) {
[5672]318            foreach ($regexps as $regp) {
[5862]319                if (preg_match("/$regp/i", $line)) {
[5672]320                    // Recebe todas as regras criadas no servidor;
[5862]321                    if (preg_match("/#rule&&/i", $line)) {
322                        $retorno['rule'][] = ltrim($line) . "\n";                         
[5672]323                    }
324                }
325            }
326            // Pega a proxima linha do sript;
327            $line = array_shift($lines);
328        }
329        return $retorno;
330    }
331       
332       
333       
334       
[5539]335        /**
336        * Método que faz o parsing do Script Sieve, transformando em Array.
337        *
338        * @license    http://www.gnu.org/copyleft/gpl.html GPL
339        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
340        * @sponsor    Caixa EconÃŽmica Federal
[5862]341        * @author     Airton Bordin Junior <airton@prognus.com.br>
342        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>   
[5539]343        * @param      <String> <$script> <Script Sieve com as regras do usuário>
344        * @return     <Regras do usuário em Array>
345        * @access     <public>
346        */
347        public function parseSieveScript( $script )
[5341]348        {
[5952]349                 $old_rule = strripos($script, "##PSEUDO script start");
[5672]350               
351                if($old_rule) {
[5862]352                        $parsed_rule = $this->readOldScript($script);
353                        $old_rules = array();
354                        $j = 0;
355                        foreach ($parsed_rule['rule'] as $i => $value) {
356                               
357                                $array_rule = explode("&&", $parsed_rule['rule'][$i]);
[5672]358
[5862]359                                /* TO-DO: Ver as actions possíveis além de reject e fileinto */
360                                switch($array_rule[6]) {
361                                        case 'reject':
362                                                $action_type      = 'reject';
363                                                $action_parameter = $array_rule[7];
364                                                break;
365                                        case 'folder':
366                                                $action_type      = 'fileinto';
367                                                $action_parameter = $array_rule[7];
368                                                break;
369                                }
[5672]370
[5862]371                                if($array_rule[3] != "") {
372                                        $criteria_value = $array_rule[3];
373                                        $criteria_operator = '=';
374                                        $criteria_field = 'from';
375                                }
376                                else
377                                {
378                                        $criteria_value = $array_rule[5];
379                                        $criteria_operator = '=';
380                                        $criteria_field = 'subject';
381                                }
382
383                                $old_retorno = array();
384                                $old_retorno['isExact']                                 = true;
385                                $old_retorno['name']                                    = 'regra_migrada_' . $array_rule[1];
386                                $old_retorno['criteria']                                = array();
387                                $old_retorno['criteria'][0]                     = array();
388                                $old_retorno['criteria'][0]['value']    = $criteria_value;
389                                $old_retorno['criteria'][0]['operator'] = $criteria_operator;
390                                $old_retorno['criteria'][0]['field']    = $criteria_field;
391                                $old_retorno['actions']                 = array();
392                                $old_retorno['actions'][0]              = array();
393                                $old_retorno['actions'][0]['parameter'] = $action_parameter;
394                                $old_retorno['actions'][0]['type']      = $action_type;
395                                $old_retorno['enabled']                 = ($array_rule[2] == 'ENABLED') ? true: false;
396                                $old_retorno['id']                      = 'regra_migrada_' . $array_rule[1];
397                                $old_retorno['applyMessages']           = '';
398
399                                $old_rules[$j] = $old_retorno;
400                                $j++;
401                        }                       
402                        return $old_rules;
[5952]403                }
[5862]404                /* Não tem regra antiga */
[5539]405                $pos = strripos($script, "#PseudoScript#");
406                $pseudo_script = substr( $script, $pos+17 );
[5341]407
[5539]408                $return = json_decode( $pseudo_script, true );
[5862]409       
[5539]410                return $return;
411        }
[5341]412
[5539]413        var $rules = false;
[5341]414
[5539]415        /**
416        * Construtor da classe.
417        *
418        * @license    http://www.gnu.org/copyleft/gpl.html GPL
419        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
420        * @sponsor    Caixa EconÃŽmica Federal
[5862]421        * @author     Airton Bordin Junior <airton@prognus.com.br>
422        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>   
[5539]423        * @access     <public>
424        */
425        public function __construct()
426        {
427                $this->service = Controller::service("Sieve");
428        }
[5341]429
[5539]430       
431        /**
432        * Método que recupera as regras do usuário.
433        *
434        * @license    http://www.gnu.org/copyleft/gpl.html GPL
435        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
436        * @sponsor    Caixa EconÃŽmica Federal
[5862]437        * @author     Airton Bordin Junior <airton@prognus.com.br>
438        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>   
[5539]439        * @return     <Regras do usuário>
440        * @access     <public>
441        */
442        public function getRules()
443        {
444                $this->rules = Controller::find( array( 'concept' => 'filter' ) );
[5341]445
[5539]446                if( !$this->rules ) {
447                        $this->rules = array();
448                }
[5862]449               
[5539]450                return( $this->rules );
451        }
[5341]452
[5539]453       
454        /**
455        * Método que aplica o filtro para as mensagens do usuário.
456        *
457        * @license    http://www.gnu.org/copyleft/gpl.html GPL
458        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
459        * @sponsor    Caixa EconÃŽmica Federal
[5862]460        * @author     Airton Bordin Junior <airton@prognus.com.br>
461        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>   
[5539]462        * @param      <$uri>
463        * @param      <$result>
464        * @param      <$criteria>
465        * @param      <$original>
466        * @access     <public>
467        */
468        public function applySieveFilter( &$uri , &$result , &$criteria , $original  )
469        {
[5692]470               
[5862]471                //if()                 
472                //{                                             
473                        $rule_apply = array();
474                       
475                        $filter = Controller::read($uri);
476                        $filter_ = $this->parseSieveScript($filter['content']);
477                       
478                        foreach ($filter_ as $f_) {
479                                if($f_['id'] == $uri['id']) {
480                                        $rule_apply     = $f_;
481                                }
[5692]482                        }
[5862]483                                       
484                        $actions = array();
485                        $actions['type']      = $rule_apply['actions'][0]['type'];
486                        $actions['parameter'] = $rule_apply['actions'][0]['parameter'];
487                        /* Hardcoded */
488                        $actions['keep']      = false;
489
490                        $messages_to_apply = array();                   
491
492                        $messages = $rule_apply['applyMessages'];
493                        /*       
494                        $proc = array();
495                        $proc['keep'] = false;
496                                 
497                        */
498                        $imap = Controller::service( 'Imap' );
499                        $imap->apliSieveFilter($messages , $actions);
500                        return $result;
501                //}
[5539]502        }
[5341]503
[5539]504       
505        /**
506        * Método que lê o script do usuário.
507        *
508        * @license    http://www.gnu.org/copyleft/gpl.html GPL
509        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
510        * @sponsor    Caixa EconÃŽmica Federal
[5862]511        * @author     Airton Bordin Junior <airton@prognus.com.br>
512        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>   
[5539]513        * @param      <$uri>
514        * @param      <$result>
515        * @param      <$criteria>
516        * @param      <$original>
517        * @return     <Script do usuário>
518        * @access     <public>
519        */
520        public function readUserScript( &$uri , &$params , &$criteria , $original )
521        { 
522                $uri['id'] = $this->service->config['user'];
523        }
524 
525 
526        /**
527        * Método que seta o script do usuário.
528        *
529        * @license    http://www.gnu.org/copyleft/gpl.html GPL
530        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
531        * @sponsor    Caixa EconÃŽmica Federal
[5862]532        * @author     Airton Bordin Junior <airton@prognus.com.br>
533        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>   
[5539]534        * @param      <$uri>
535        * @param      <$result>
536        * @param      <$criteria>
537        * @param      <$original>
538        * @return     <Script do usuário>
539        * @access     <public>
540        */
541        public function setRule( &$uri , &$params , &$criteria , $original  )
[5601]542        {
[5630]543                if( !$this->rules )
[5539]544                $this->rules = $this->getRules();
[5341]545
[5601]546            $uri['id'] = $params['id'] = isset($params['id']) ? $params['id'] : urlencode($params['name']);
[5341]547
[5601]548            $i = 0;
[5341]549
[5629]550            for( ; isset($this->rules[$i]) && $this->rules[$i]['id'] !== $params['id']; $i++ );
[5601]551
[5629]552            $this->rules[$i] = array_merge( ( isset($this->rules[$i]) ? $this->rules[$i] : array() ), $params );
[5601]553
554            $params = array( 'name' => $this->service->config['user'],
555                             'content' => $this->formatSieveScript( $this->rules ),
556                             'active' => true );
[5539]557        }
[5341]558
[5539]559       
560        /**
561        * Método que deleta o script 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
[5862]566        * @author     Airton Bordin Junior <airton@prognus.com.br>
567        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>   
[5539]568        * @param      <$uri>
569        * @param      <$result>
570        * @param      <$criteria>
571        * @param      <$original>
572        * @access     <public>
573        */
574        public function deleteRule( &$uri, &$params, &$criteria, $original )
575        {
[5601]576                if( !$this->rules ) {   
577                        $this->rules = $this->getRules();
578                }         
[5539]579                $params['id'] = $uri['id'];
[5341]580
[5539]581                $update = false;
[5601]582               
583                $rules = array();
[5341]584
[5539]585                foreach( $this->rules as $i => $rule )
[5601]586                        if( $rule['id'] !== $uri['id'] )
587                                $rules[] = $this->rules[$i];
[5341]588
[5601]589                $this->rules = $rules;
590               
[5539]591                $uri['id'] = '';
[5341]592
[5539]593                $params = array( 'name' => $this->service->config['user'],
594                           'content' => $this->formatSieveScript( $this->rules ),
595                           'active' => true );
[5341]596
[5539]597                $URI = Controller::URI( $uri['concept'], $this->service->config['user'] );
598                $this->service->update( $URI, $params );
[5601]599       
[5539]600                return( false );
601        }
[5341]602
[5539]603       
604        /**
605        * Método que pega o script do usuário.
606        *
607        * @license    http://www.gnu.org/copyleft/gpl.html GPL
608        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
609        * @sponsor    Caixa EconÃŽmica Federal
[5862]610        * @author     Airton Bordin Junior <airton@prognus.com.br>
611        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>   
[5539]612        * @param      <$uri>
613        * @param      <$result>
614        * @param      <$criteria>
615        * @param      <$original>
616        * @return     <Script do usuário>
617        * @access     <public>
618        */
619        public function getSieveRule( &$uri , &$params , &$criteria , $original )
620        {         
621                $script = $this->parseSieveScript( $params['content'] );
[5341]622
[5539]623                foreach( $script as $i => $rule )
[5747]624                        if(is_array ($rule['name']) && is_array($original['id']))
[5539]625                        if( $rule['name'] === $original['id'] )
626                                return( $params = $rule );
627        }
[5341]628
[5539]629       
630        /**
631        * Método que lista as regras do usuário.
632        *
633        * @license    http://www.gnu.org/copyleft/gpl.html GPL
634        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
635        * @sponsor    Caixa EconÃŽmica Federal
[5862]636        * @author     Airton Bordin Junior <airton@prognus.com.br>
637        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>   
[5539]638        * @param      <$uri>
639        * @param      <$result>
640        * @param      <$criteria>
641        * @param      <$original>
642        * @return     <Regras do usuário>
643        * @access     <public>
644        */
645        public function listSieveRules( &$uri , &$params , &$criteria , $original  )
[5629]646        {
[5539]647                $return = $params = $this->parseSieveScript( $params[0]['content'] );
648                return( $return );
649        }
650}
Note: See TracBrowser for help on using the repository browser.