Ignore:
Timestamp:
04/02/12 17:58:17 (12 years ago)
Author:
airton
Message:

Ticket #1794 - Codificar DFD0060 - Aplicacao das regras nas mensagens da caixa de entrada

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/modules/filters/interceptors/FilterMapping.php

    r5747 r5862  
    5050* @license    http://www.gnu.org/copyleft/gpl.html GPL 
    5151* @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 
     52* @author     Airton Bordin Junior <airton@prognus.com.br> 
     53* @author     Gustavo Pereira dos Santos <gustavo@prognus.com.br> 
    5454* @version    1.0 
    5555* @since      Classe disponibilizada na versão 2.4 
     
    6767        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    6868        * @sponsor    Caixa EconÃŽmica Federal 
    69         * @author     Airton Bordin Junior 
    70         * @author         Gustavo Pereira dos Santos     
     69        * @author     Airton Bordin Junior <airton@prognus.com.br> 
     70        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>    
    7171        * @param      <Array> <$rules> <Array com as regras do usuário> 
    7272        * @return     <Regra de acordo com a sintaxe do Sieve> 
     
    109109                        $data['isExact'] == 'false' ?  $script_match .= 'if anyof (' : $script_match .= 'if allof ('; 
    110110 
    111  
    112111                        if( is_array($criteria) ) 
    113112                        foreach ($criteria as $j => $value); 
    114113                        {                                        
    115                                   
     114 
    116115                                switch($criteria[$j]['field']) { 
    117116                                        case 'To':     
     
    174173                                        /*  
    175174                                           TO-DO: 
    176                                            Arrrumar regra do "não contém". 
     175                                           Inconsistência na regra do "não contém". 
    177176                                        */ 
    178177                                        case '!*': 
     
    232231                                $i++; 
    233232                        $script_match = ""; 
    234                         $script_criteria = ""; 
    235                          
     233                        $script_criteria = "";   
     234                        $data['applyMessages'] = "";                                                     
    236235                } 
    237236 
     
    258257 
    259258                $content = $script_begin . $script_header . $script_rules . "\r\n\r\n#PseudoScript#" . "\r\n#" . $json_data; 
    260                 //$content = "";  
    261259 
    262260                return( $content ); 
     
    269267        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    270268        * @sponsor    Caixa EconÃŽmica Federal 
    271         * @author     Airton Bordin Junior 
    272         * @author         Gustavo Pereira dos Santos     
     269        * @author     Airton Bordin Junior <airton@prognus.com.br> 
     270        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>    
    273271        * @param      <$scriptName> <Regras do usuário> 
    274272        * @return     <Regra do usuário parseada> 
     
    285283 
    286284        // Recebe o tamanho do script, pela primeira linha; 
    287         $this->size = trim($size_rule); 
     285        //$this->size = trim($size_rule); 
    288286 
    289287        // Verifica a composição do script; */ 
    290          $line = array_shift($lines); 
     288        $line = array_shift($lines); 
    291289 
    292290        // Variaveis para a regra e o campo ferias; 
    293         $regexps = array('^ *##PSEUDO', '^ *#rule', '^ *#vacation', '^ *#mode'); 
     291        $regexps = array('##PSEUDO', '#rule', '#vacation', '#mode'); 
    294292        $retorno['rule'] = array(); 
    295293 
    296294        $line = array_shift($lines); 
    297         while (isset($line)) { 
     295        while (isset($line)) {  
    298296            foreach ($regexps as $regp) { 
    299                 if (preg_match("/$regp/i", $line)) { 
     297                if (preg_match("/$regp/i", $line)) {  
    300298                    // Recebe todas as regras criadas no servidor; 
    301                     if (preg_match("/^ *#rule&&/i", $line)) { 
    302                         $retorno['rule'][] = $line . "\n"; 
     299                    if (preg_match("/#rule&&/i", $line)) { 
     300                        $retorno['rule'][] = ltrim($line) . "\n";                           
    303301                    } 
    304302                } 
     
    319317        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    320318        * @sponsor    Caixa EconÃŽmica Federal 
    321         * @author     Airton Bordin Junior 
    322         * @author         Gustavo Pereira dos Santos     
     319        * @author     Airton Bordin Junior <airton@prognus.com.br> 
     320        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>    
    323321        * @param      <String> <$script> <Script Sieve com as regras do usuário> 
    324322        * @return     <Regras do usuário em Array> 
     
    327325        public function parseSieveScript( $script ) 
    328326        { 
    329                 /* 
     327                /* Faz a verificação por filtros criados com a funcionalidade antiga */ 
    330328                $old_rule = strripos($script, "##PSEUDO script start"); 
    331329                 
    332330                if($old_rule) { 
    333                          
    334                         $parsed_rule = $this->readOldScript($old_script); 
    335                         $array_rule = explode("&&", $parsed_rule['rule'][0]); 
    336  
    337                         $old_retorno = array(); 
    338                         $old_retorno['isExact'] = false; 
    339                         $old_retorno['name'] = $array_rule[1]; 
    340                         $old_retorno['criteria'] = array(); 
    341                         $old_retorno['criteria'][0] = array(); 
    342                         $old_retorno['criteria'][0]['value'] = $array_rule[5]; 
    343                         $old_retorno['criteria'][0]['operator'] = '='; 
    344                         $old_retorno['criteria'][0]['field'] = 'subject'; 
    345                         $old_retorno['actions'] = array(); 
    346                         $old_retorno['actions'][0] = array(); 
    347                         $old_retorno['actions'][0]['parameter'] = $array_rule[7]; 
    348                         $old_retorno['actions'][0]['type'] = $array_rule[6]; 
    349                         $old_retorno['enabled'] = true; 
    350                         $old_retorno['id'] = $array_rule[1]; 
    351                         $old_retorno['applyMessages'] = ''; 
    352  
    353                         return $old_retorno; 
     331                        $parsed_rule = $this->readOldScript($script); 
     332                        $old_rules = array();  
     333                        $j = 0; 
     334                        foreach ($parsed_rule['rule'] as $i => $value) { 
     335                                 
     336                                $array_rule = explode("&&", $parsed_rule['rule'][$i]); 
     337 
     338                                /* TO-DO: Ver as actions possíveis além de reject e fileinto */ 
     339                                switch($array_rule[6]) { 
     340                                        case 'reject': 
     341                                                $action_type      = 'reject'; 
     342                                                $action_parameter = $array_rule[7]; 
     343                                                break; 
     344                                        case 'folder': 
     345                                                $action_type      = 'fileinto'; 
     346                                                $action_parameter = $array_rule[7]; 
     347                                                break; 
     348                                } 
     349 
     350                                if($array_rule[3] != "") { 
     351                                        $criteria_value = $array_rule[3]; 
     352                                        $criteria_operator = '='; 
     353                                        $criteria_field = 'from'; 
     354                                }  
     355                                else 
     356                                { 
     357                                        $criteria_value = $array_rule[5]; 
     358                                        $criteria_operator = '='; 
     359                                        $criteria_field = 'subject'; 
     360                                } 
     361 
     362                                $old_retorno = array(); 
     363                                $old_retorno['isExact']                                 = true; 
     364                                $old_retorno['name']                                    = 'regra_migrada_' . $array_rule[1]; 
     365                                $old_retorno['criteria']                                = array(); 
     366                                $old_retorno['criteria'][0]                     = array(); 
     367                                $old_retorno['criteria'][0]['value']    = $criteria_value; 
     368                                $old_retorno['criteria'][0]['operator'] = $criteria_operator; 
     369                                $old_retorno['criteria'][0]['field']    = $criteria_field; 
     370                                $old_retorno['actions']                 = array(); 
     371                                $old_retorno['actions'][0]              = array(); 
     372                                $old_retorno['actions'][0]['parameter'] = $action_parameter; 
     373                                $old_retorno['actions'][0]['type']      = $action_type; 
     374                                $old_retorno['enabled']                 = ($array_rule[2] == 'ENABLED') ? true: false; 
     375                                $old_retorno['id']                      = 'regra_migrada_' . $array_rule[1]; 
     376                                $old_retorno['applyMessages']           = ''; 
     377 
     378                                $old_rules[$j] = $old_retorno; 
     379                                $j++; 
     380                        }                        
     381                        return $old_rules; 
    354382                } 
    355                 */ 
     383                /* Não tem regra antiga */ 
    356384                $pos = strripos($script, "#PseudoScript#"); 
    357385                $pseudo_script = substr( $script, $pos+17 ); 
    358386 
    359387                $return = json_decode( $pseudo_script, true ); 
    360  
     388         
    361389                return $return; 
    362390        } 
     
    370398        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    371399        * @sponsor    Caixa EconÃŽmica Federal 
    372         * @author     Airton Bordin Junior 
    373         * @author         Gustavo Pereira dos Santos     
     400        * @author     Airton Bordin Junior <airton@prognus.com.br> 
     401        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>    
    374402        * @access     <public> 
    375403        */ 
     
    386414        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    387415        * @sponsor    Caixa EconÃŽmica Federal 
    388         * @author     Airton Bordin Junior 
    389         * @author         Gustavo Pereira dos Santos     
     416        * @author     Airton Bordin Junior <airton@prognus.com.br> 
     417        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>    
    390418        * @return     <Regras do usuário> 
    391419        * @access     <public> 
     
    398426                        $this->rules = array(); 
    399427                } 
     428                 
    400429                return( $this->rules ); 
    401430        } 
     
    408437        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    409438        * @sponsor    Caixa EconÃŽmica Federal 
    410         * @author     Airton Bordin Junior 
    411         * @author         Gustavo Pereira dos Santos     
     439        * @author     Airton Bordin Junior <airton@prognus.com.br> 
     440        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>    
    412441        * @param      <$uri>  
    413442        * @param      <$result>  
     
    418447        public function applySieveFilter( &$uri , &$result , &$criteria , $original  ) 
    419448        { 
    420                 /* 
    421                 $result['id'] = $uri['id']; 
    422                 $rule_apply = array();  
    423449                 
    424                 $filter = Controller::read($uri); 
    425                 $filter_ = $this->parseSieveScript($filter['content']); 
    426                  
    427                 foreach ($filter_ as $f_) { 
    428                         if($f_['id'] == $uri['id']) {  
    429                                 $rule_apply     = $f_; 
     450                //if()                   
     451                //{                                              
     452                        $result['id'] = $uri['id']; 
     453                        $rule_apply = array();  
     454                         
     455                        $filter = Controller::read($uri); 
     456                        $filter_ = $this->parseSieveScript($filter['content']); 
     457                         
     458                        foreach ($filter_ as $f_) { 
     459                                if($f_['id'] == $uri['id']) {  
     460                                        $rule_apply     = $f_; 
     461                                } 
    430462                        } 
    431                 } 
    432                  
    433                 $actions = array(); 
    434                 $actions['type']      = $rule_apply['actions'][0]['type']; 
    435                 $actions['parameter'] = $rule_apply['actions'][0]['parameter']; 
    436                  
    437                 $messages = $rule_apply['applyMessages']; 
    438                    
    439                            
    440                 $proc = array(); 
    441                 $proc['keep'] = false; 
    442                 */       
    443                  
    444                 //$imap = Controller::service( 'Imap' ); 
    445                 //$imap->apliSieveFilter($original['properties']['applyMessages'] , $proc );  
    446                 //$imap->apliSieveFilter($messages , $actions );  
    447                 //return $result; 
     463                                         
     464                        $actions = array(); 
     465                        $actions['type']      = $rule_apply['actions'][0]['type']; 
     466                        $actions['parameter'] = $rule_apply['actions'][0]['parameter']; 
     467                        /* Hardcoded */ 
     468                        $actions['keep']      = false; 
     469 
     470                        $messages_to_apply = array();                    
     471 
     472                        $messages = $rule_apply['applyMessages']; 
     473                        /*         
     474                        $proc = array(); 
     475                        $proc['keep'] = false; 
     476                                  
     477                        */ 
     478                        $imap = Controller::service( 'Imap' ); 
     479                        $imap->apliSieveFilter($messages , $actions);  
     480                        return $result; 
     481                //} 
    448482        } 
    449483 
     
    455489        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    456490        * @sponsor    Caixa EconÃŽmica Federal 
    457         * @author     Airton Bordin Junior 
    458         * @author         Gustavo Pereira dos Santos     
     491        * @author     Airton Bordin Junior <airton@prognus.com.br> 
     492        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>    
    459493        * @param      <$uri>  
    460494        * @param      <$result>  
     
    476510        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    477511        * @sponsor    Caixa EconÃŽmica Federal 
    478         * @author     Airton Bordin Junior 
    479         * @author         Gustavo Pereira dos Santos     
     512        * @author     Airton Bordin Junior <airton@prognus.com.br> 
     513        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>    
    480514        * @param      <$uri>  
    481515        * @param      <$result>  
     
    510544        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    511545        * @sponsor    Caixa EconÃŽmica Federal 
    512         * @author     Airton Bordin Junior 
    513         * @author         Gustavo Pereira dos Santos     
     546        * @author     Airton Bordin Junior <airton@prognus.com.br> 
     547        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>    
    514548        * @param      <$uri>  
    515549        * @param      <$result>  
     
    554588        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    555589        * @sponsor    Caixa EconÃŽmica Federal 
    556         * @author     Airton Bordin Junior 
    557         * @author         Gustavo Pereira dos Santos     
     590        * @author     Airton Bordin Junior <airton@prognus.com.br> 
     591        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>    
    558592        * @param      <$uri>  
    559593        * @param      <$result>  
     
    580614        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) 
    581615        * @sponsor    Caixa EconÃŽmica Federal 
    582         * @author     Airton Bordin Junior 
    583         * @author         Gustavo Pereira dos Santos     
     616        * @author     Airton Bordin Junior <airton@prognus.com.br> 
     617        * @author         Gustavo Pereira dos Santos <gustavo@prognus.com.br>    
    584618        * @param      <$uri>  
    585619        * @param      <$result>  
Note: See TracChangeset for help on using the changeset viewer.