Ignore:
Timestamp:
05/14/12 12:29:34 (12 years ago)
Author:
cristiano
Message:

Ticket #2314 - Reutilização da conexão IMAP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/services/ImapServiceAdapter.php

    r6132 r6171  
    6666        {  
    6767         
    68                 $context = $justthese['context']; 
    69                 $URI = $URI['concept']; 
    70  
    71                 switch( $URI ) 
     68                $context = isset($justthese['context']) ? $justthese['context'] : '' ; 
     69 
     70                switch( $URI['concept'] ) 
    7271                { 
    7372                        case 'folder': 
     
    9089                        { 
    9190                                //begin: for grid        
    92                                 $page  = $criteria['page']; //{1}    get the requested page 
    93                                 $limit = $criteria['rows']; //{10}   get how many rows we want to have into the grid 
    94                                 $sidx  = $criteria['sidx']; //{id}   get index row - i.e. user click to sort 
    95                                 $sord  = $criteria['sord']; //{desc} get the direction 
     91                                $page  = isset($criteria['page']) ? $criteria['page'] : 1 ; //{1}    get the requested page 
     92                                $limit = isset($criteria['rows']) ? $criteria['rows'] : 10 ; //{10}   get how many rows we want to have into the grid 
     93                                $sidx  = isset($criteria['sidx']) ? $criteria['sidx'] : 0; //{id}   get index row - i.e. user click to sort 
     94                                $sord  = isset($criteria['sord']) ? $criteria['sord'] : ''; //{desc} get the direction 
    9695 
    9796                                $filter = $criteria['filter']; 
     
    9998                                if( !$sidx ) $sidx = 1; 
    10099 
    101                                 $folder_name = str_replace( '.', $this->imap_delimiter, $context['folder'] ); 
    102                                  
     100                                $folder_name =  isset($URI['folder']) ?  $URI['folder'] : str_replace( '.', $this->imap_delimiter, $context ); 
     101                         
    103102                                $count = imap_num_msg( $this->open_mbox( $folder_name ) ); 
    104103 
     
    150149                                                        $headers = imap_fetch_overview($this->mbox, $messages, $sequenceType); 
    151150                                                        foreach ($headers as $h) { 
    152                                                                 $result[] = array ( 'messageId' => $h->message_id ); 
     151                                                                if(isset($h->message_id )) 
     152                                                                        $result[] = array ( 'messageId' => $h->message_id ); 
    153153                                                        } 
    154                                                                                                                  
    155                                                         imap_close($this->mbox); 
    156                                                         $this->mbox = false; 
     154         
    157155                                                } 
    158156                                                return $result; 
     
    298296                                                        } 
    299297                                                } 
    300                                                  
    301                                                 imap_close($this->mbox); 
    302                                                 $this->mbox = false; 
     298 
    303299                                        } 
    304300                                } 
     
    363359                                         * passados no filtro, se houverem. 
    364360                                         */ 
    365                                         if (!empty($map['messageNumber'])) { 
     361                                        if (!empty($map['messageNumber']) && is_array($messages)) { 
     362                                                                                                 
    366363                                                foreach ($messages as $k => $m) 
    367364                                                        if (!in_array($m, $map['messageNumber'])) 
     
    372369                                         * Adicionar demais atributos às mensagens para retorno 
    373370                                         */ 
    374  
     371                                        if(is_array($messages)) 
    375372                                        foreach ($messages as $k => $m) { 
    376373                                                $headers = imap_fetch_overview($this->mbox, $m, FT_UID); 
     
    383380                                        } 
    384381 
    385                                         imap_close($this->mbox); 
    386                                         $this->mbox = false; 
    387382                                         
    388383                                        /** 
     
    394389                                } 
    395390                                 
    396                                 if ($this->mbox) { 
    397                                         imap_close($this->mbox); 
    398                                         $this->mbox = false; 
    399                                 } 
    400391 
    401392                                return $result; 
     
    440431                                                ); 
    441432                                        } 
    442                                         imap_close($this->mbox); 
    443                                         $this->mbox = false; 
     433 
    444434                                } 
    445435                                 
     
    474464                                                ); 
    475465                                        } 
    476                                          
    477                                         imap_close($this->mbox); 
    478                                         $this->mbox = false; 
    479466                                 
    480467                                } else { 
     
    511498                                                        break; 
    512499                                                } 
    513                                                  
    514                                                 imap_close($this->mbox); 
    515                                                 $this->mbox = false; 
    516                                         } 
    517                                 } 
    518                                  
    519                                 if ($this->mbox) { 
    520                                         imap_close($this->mbox); 
    521                                         $this->mbox = false; 
    522                                 } 
     500         
     501                                        } 
     502                                } 
     503                                 
    523504                                 
    524505                                return $result; 
     
    537518                                        imap_setflag_full($this->mbox, $data['messageNumber'], '$Label' . $data['labelId'], ST_UID); 
    538519 
    539                                         imap_close($this->mbox); 
    540                                         $this->mbox = false; 
    541  
    542520                                        return array ('id' => $data['folderName'].'/'.$data['messageNumber'].'#'.$data['labelId']); 
    543521                                } 
     
    557535                                        $data['messageId'] = $headers[0]->message_id; 
    558536                                                         
    559                                         imap_close($this->mbox); 
    560                                         $this->mbox = false; 
    561537 
    562538                                        return ($s) ? $data : array(); 
     
    583559                                                         
    584560                                                        $s = imap_setflag_full($this->mbox, $messages[0], '$Followupflagged', ST_UID); 
    585                                                          
    586                                                         imap_close($this->mbox); 
    587                                                         $this->mbox = false; 
    588                                                          
     561                                                 
    589562                                                        /** 
    590563                                                         * Stop searching in all folders 
     
    593566                                                } 
    594567                                                 
    595                                                 imap_close($this->mbox); 
    596                                                 $this->mbox = false; 
    597568                                        } 
    598569                                } 
     
    702673                                } 
    703674 
    704                                 if($mbox_stream) imap_close($mbox_stream); 
    705  
    706675                                return $return; 
    707676                        } 
     
    723692                                        imap_clearflag_full($this->mbox, $messageNumber, '$Label' . $labelId, ST_UID); 
    724693 
    725                                         imap_close($this->mbox); 
    726                                         $this->mbox = false; 
    727694                                } 
    728695                        } 
     
    791758                                        } 
    792759 
    793                                         imap_close($this->mbox); 
    794                                         $this->mbox = false; 
    795                                          
    796760                                        /** 
    797761                                         * Se é uma busca por messageId e todos os messageIds foram econstrados: 
Note: See TracChangeset for help on using the changeset viewer.