Ignore:
Timestamp:
06/13/12 09:30:36 (12 years ago)
Author:
brunocosta
Message:

Ticket #2853 - Exibição de cotas de sub pastas IMAP.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.3/expressoMail1_2/inc/class.imap_functions.inc.php

    r6340 r6474  
    360360                    //reconstrói o email 
    361361                    $email = implode("", file($params['FILES'][0]['tmp_name'])); 
    362                     $email = preg_replace('/(?<!\r)\n/', "\r\n", $email); 
    363362                    //coloca o email na pasta selecionada 
    364363                    $status = @imap_append($this->mbox, $folder, $email); 
     
    10921091                                                                                $msg->encoding[ $msg_number ][ $values ] = 'quoted-printable';  
    10931092                                                                }  
    1094                                                                 /* 
     1093 
    10951094                                                                $body = $this->decodeBody(  
    1096                                                                                 imap_fetchbody(  
     1095                                                                        imap_fetchbody(  
    10971096                                                                                $this->mbox,  
    10981097                                                                                $msg_number,  
     
    11021101                                                                        $msg->encoding[ $msg_number ][ $values ],  
    11031102                                                                        $msg->charset[ $msg_number ][ $values ]  
    1104                                                                 ); 
    1105                                                                 */ 
    1106                                                                 $body = $this->decodeBody(  
    1107                                                                         imap_fetchbody(  
    1108                                                                                 $this->mbox,  
    1109                                                                                 $msg_number,  
    1110                                                                                 $attachment['part_in_msg'] . ".1",  
    1111                                                                                 FT_UID  
    1112                                                                         ),  
    1113                                                                         $msg->encoding[ $msg_number ][ $values ],  
    1114                                                                         $msg->charset[ $msg_number ][ $values ]  
    1115                                                                 ); 
    1116                                                                  
     1103                                                                );  
     1104 
    11171105                                                                if ( strtolower( $msg->structure[$msg_number]->parts[1]->parts[0]->subtype ) == 'plain' )  
    11181106                                                                {  
     
    15741562                            $this->db = new db_functions(); 
    15751563                             
    1576                             // TODO: testar se existe um certificado no banco e verificar qual ï¿œ o mais atual. 
     1564                            // TODO: testar se existe um certificado no banco e verificar qual é o mais atual. 
    15771565                            if(!$certificado->dados['EXPIRADO'] && !$certificado->dados['REVOGADO'] && count($certificado->erros_ssl) < 1) 
    15781566                                $this->db->insert_certificate(strtolower($certificado->dados['EMAIL']), $certificado->cert_assinante, $certificado->dados['SERIALNUMBER'], $certificado->dados['AUTHORITYKEYIDENTIFIER']); 
     
    18561844                        $i = 0; 
    18571845                        while (list($key, $val) = each($folders_list)) { 
    1858                             $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); 
    1859  
    1860                             //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); 
    1861                             $tmp_folder_id = explode("}", $val->name ); 
    1862  
    1863                             $tmp_folder_id[1] = mb_convert_encoding( $tmp_folder_id[1], "ISO-8859-1", "UTF7-IMAP" ); 
    1864  
    1865                             if( $tmp_folder_id[1]=='INBOX'.$this->imap_delimiter.'decifradas') 
     1846                                $status = imap_status($mbox_stream, $val->name, SA_UNSEEN); 
     1847 
     1848                                //$tmp_folder_id = explode("}", imap_utf7_decode($val->name)); 
     1849                                $tmp_folder_id = explode("}", $val->name ); 
     1850 
     1851                                $folderUser = trim( strpos( $tmp_folder_id[1], $this->imap_delimiter , 5 ) ); 
     1852 
     1853                            $folderUser = trim( substr( $tmp_folder_id[1], 0, $folderUser ) ); 
     1854 
     1855                            $Permission = true; 
     1856 
     1857                            if( $folderUser != "INBOX" && $folderUser != "" ) 
    18661858                            { 
    1867                                     continue; 
     1859                               $Permission = imap_getacl( $mbox_stream, $folderUser ); 
    18681860                            } 
    1869                             $result[$i]['folder_unseen'] = $status->unseen; 
    1870                             $folder_id = $tmp_folder_id[1]; 
    1871                             $result[$i]['folder_id'] = $folder_id; 
    1872  
    1873                             $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); 
    1874                             $result[$i]['folder_name'] = array_pop($tmp_folder_parent); 
    1875                             $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; 
    1876  
    1877                             if ($uid2cn && substr($folder_id,0,4) == 'user') { 
    1878                                     //$this->ldap = new ldap_functions(); 
    1879                                     if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])) { 
    1880                                             $result[$i]['folder_name'] = $cn; 
    1881                                     } 
    1882                             } 
    1883  
    1884                             $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); 
    1885                             $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; 
    1886  
    1887                             if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) 
    1888                                     $result[$i]['folder_hasChildren'] = 1; 
    1889                             else 
    1890                                     $result[$i]['folder_hasChildren'] = 0; 
    1891  
    1892                             switch ($tmp_folder_id[1]) { 
    1893                                     case $inbox: 
    1894                                     case $sent: 
    1895                                     case $drafts: 
    1896                                     case $spam: 
    1897                                     case $trash: 
    1898                                             $resultDefault[]=$result[$i]; 
    1899                                             break; 
    1900                                     default: 
    1901                                             $resultMine[]=$result[$i]; 
     1861 
     1862                            if( $Permission ) 
     1863                            { 
     1864                                $tmp_folder_id[1] = mb_convert_encoding( $tmp_folder_id[1], "ISO-8859-1", "UTF7-IMAP" ); 
     1865 
     1866                                if( $tmp_folder_id[1]=='INBOX'.$this->imap_delimiter.'decifradas') 
     1867                                { 
     1868                                        continue; 
     1869                                } 
     1870                                $result[$i]['folder_unseen'] = $status->unseen; 
     1871                                $folder_id = $tmp_folder_id[1]; 
     1872                                $result[$i]['folder_id'] = $folder_id; 
     1873 
     1874                                $tmp_folder_parent = explode($this->imap_delimiter, $folder_id); 
     1875                                $result[$i]['folder_name'] = array_pop($tmp_folder_parent); 
     1876                                $result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name']; 
     1877                         
     1878                                if ($uid2cn && substr($folder_id,0,4) == 'user') { 
     1879                                        //$this->ldap = new ldap_functions(); 
     1880                                        if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])) { 
     1881                                                $result[$i]['folder_name'] = $cn; 
     1882                                        } 
     1883                                } 
     1884 
     1885                                $tmp_folder_parent = implode($this->imap_delimiter, $tmp_folder_parent); 
     1886                                $result[$i]['folder_parent'] = $tmp_folder_parent == 'INBOX' ? '' : $tmp_folder_parent; 
     1887 
     1888                                if (($val->attributes == 32) && ($result[$i]['folder_name'] != 'Inbox')) 
     1889                                        $result[$i]['folder_hasChildren'] = 1; 
     1890                                else 
     1891                                        $result[$i]['folder_hasChildren'] = 0; 
     1892 
     1893                                switch ($tmp_folder_id[1]) { 
     1894                                        case $inbox: 
     1895                                        case $sent: 
     1896                                        case $drafts: 
     1897                                        case $spam: 
     1898                                        case $trash: 
     1899                                                $resultDefault[]=$result[$i]; 
     1900                                                break; 
     1901                                        default: 
     1902                                                $resultMine[]=$result[$i]; 
     1903                                } 
     1904 
    19021905                            } 
    19031906                            $i++; 
     
    32413244                else 
    32423245                        $folder_id = "INBOX"; 
    3243  
     3246                 
     3247                $folderQuotas = $this->get_folders_with_quota(); 
     3248                 
    32443249                if(!$this->mbox || !is_resource($this->mbox)) 
    32453250                        $this->mbox = $this->open_mbox(); 
     
    32693274                        $quotaPercent = (($quotaPercent)* 100 + .5 )* .01; 
    32703275                        } 
     3276                         
    32713277                        return array( 
    32723278                                'quota_percent' => floor($quotaPercent), 
    32733279                                'quota_used' => $quota_used, 
    3274                                 'quota_limit' =>  $quota_limit 
     3280                                'quota_limit' =>  $quota_limit, 
     3281                                'quota_folder' => $folderQuotas 
    32753282                        ); 
     3283                         
    32763284                } 
    32773285                else 
    32783286                        return array(); 
    32793287        } 
     3288 
     3289        function get_quotaroot($params){ 
     3290                if(!$this->mbox || !is_resource($this->mbox)) 
     3291                        $this->mbox = $this->open_mbox(); 
     3292 
     3293                $quota = imap_get_quotaroot($this->mbox, $params['folder']); 
     3294                if($this->mbox && is_resource($this->mbox)) 
     3295                        imap_close($this->mbox); 
     3296 
     3297                if (!$quota){ 
     3298                        return array( 
     3299                                'quota_percent' => 0, 
     3300                                'quota_used' => 0, 
     3301                                'quota_limit' =>  0, 
     3302                                'quota_root' => '' 
     3303                        ); 
     3304                } 
     3305 
     3306                // Additional Imap Class for not-implemented functions into PHP-IMAP extension. 
     3307                include_once("class.imapfp.inc.php"); 
     3308                $imapfp = new imapfp(); 
     3309 
     3310                if(!$imapfp->open($this->imap_server,$this->imap_port)) 
     3311                        return $imapfp->get_error(); 
     3312                if (!$imapfp->login($this->username,$this->password)) 
     3313                        return $imapfp->get_error(); 
     3314 
     3315                if ($imapfp->put_line($imapfp->tag." GETQUOTAROOT \"".$params['folder']."\"")) { 
     3316                        $response=$imapfp->get_server_responce(); 
     3317 
     3318                        if(substr($response,strpos($response,"$imapfp->tag ")+strlen($imapfp->tag)+1,2)!="OK") { 
     3319                                $imapfp->error= "Error : $response !<br>"; 
     3320                                return $imapfp->get_error(); 
     3321                        } 
     3322                } 
     3323                else 
     3324                { 
     3325                        $imapfp->error= "Error : Could not send User request. <br>"; 
     3326                        return $imapfp->get_error(); 
     3327                } 
     3328                $response_array = split("\r\n", $response); 
     3329                array_pop($response_array); 
     3330                array_pop($response_array); 
     3331                array_shift($response_array); 
     3332                
     3333                $response_array[0]=substr($response_array[0],strpos($response_array[0],"QUOTAROOT")); 
     3334                $quota['quota_root']=substr(str_replace("\"","",$response_array[0]),/*strlen("QUOTAROOT ... ")=*/11+strlen($params['folder'])); 
     3335                $imapfp->close(); 
     3336 
     3337                if(count($quota) && $quota['limit']) { 
     3338                        $quota_limit = $quota['limit']; 
     3339                        $quota_used  = $quota['usage']; 
     3340                        $quota_root  = $quota['quota_root']; 
     3341                        if($quota_used >= $quota_limit) 
     3342                        { 
     3343                                $quotaPercent = 100; 
     3344                        } 
     3345                        else 
     3346                        { 
     3347                        $quotaPercent = ($quota_used / $quota_limit)*100; 
     3348                        $quotaPercent = (($quotaPercent)* 100 + .5 )* .01; 
     3349                        } 
     3350                        return array( 
     3351                                'quota_percent' => floor($quotaPercent), 
     3352                                'quota_used' => $quota_used, 
     3353                                'quota_limit' =>  $quota_limit, 
     3354                                'quota_root' => $quota_root 
     3355                        ); 
     3356                } 
     3357                else 
     3358                        return array(); 
     3359        } 
    32803360 
    32813361        function send_notification($params){ 
     
    40564136            imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}".$folder)); 
    40574137        } 
    4058          
    4059         // string date ( string $format [, int $timestamp = time() ] ) 
    4060         // bool imap_append ( resource $imap_stream , string $mailbox , string $message [, string $options = NULL [, string $internal_date = NULL ]] ) 
    4061         // 'd-M-Y H:i:s O' 
    4062          
    4063         $return = array(); 
    40644138        if($timestamp){ 
    40654139            $tempDir = $_SESSION['phpgw_info']['server']['temp_dir']; 
     
    40734147            $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $source, "\\Seen"); 
    40744148        } 
    4075          
    4076         if (!empty($return['command'])) 
    4077         { 
    4078             list ($result, $msg) = explode(':',$return['command']); 
    4079             if (strtoupper($result) === 'NO') 
    4080             { 
    4081                 $return['error'] = $msg; 
    4082                 return $return; 
    4083             } 
    4084         } 
    4085          
    40864149        $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 
    40874150 
     
    41214184            if (version_compare(PHP_VERSION, '5.2.0', '>=')){ 
    41224185                if(!$source = base64_decode($source,true)) 
    4123                     return "error ".$source."Espaï¿œos ".$i; 
     4186                    return "error ".$source."Espaï¿?os ".$i; 
    41244187 
    41254188            } 
    41264189            else { 
    41274190                if(!$source = base64_decode($source)) 
    4128                     return "error ".$source."Espaï¿œos ".$i; 
     4191                    return "error ".$source."Espaï¿?os ".$i; 
    41294192            } 
    41304193 
     
    42124275                { 
    42134276                    $error[] = $ids[$index]; 
    4214                 } 
     4277            } 
    42154278                else  
    42164279                { 
    42174280                    $archived[] = $ids[$index]; 
    4218                 } 
     4281        } 
    42194282            } 
    42204283        } 
     
    42234286        { 
    42244287            $return['error'] = $error; 
    4225         } 
     4288    } 
    42264289        if (!empty($archived)) 
    42274290        { 
    42284291            $return['archived'] = $archived; 
    42294292        } 
    4230          
     4293 
    42314294        return $return; 
    42324295    } 
     
    42574320                    return $imapfp->get_error();  
    42584321 
    4259             $data = array();  
    4260             $quota_root = $this->get_quota(array('folder_id' => "INBOX"));  
    4261             $data["quota_root"] = $quota_root;  
     4322            $data = array(); 
     4323            $quota_root = $this->get_quota(array('folder_id' => "INBOX")); 
     4324            $data["quota_root"] = $quota_root; 
    42624325 
    42634326            foreach ($response_array as $idx=>$line) {  
     
    42664329                    list($folder,$size) = explode(";",$line2);  
    42674330                    $quota_used = str_replace(")","",$size);  
    4268                     $quotaPercent = (($quota_used / 1024) / $data["quota_root"]["quota_limit"])*100;  
     4331                    $quota=$this->get_quotaroot(array('folder' => $folder)); 
     4332                    $hasquota=($quota['quota_root']!=""); 
     4333                    $isroot=(strpos($quota['quota_root'],$folder)!==false); 
     4334                    $quotaPercent = ($hasquota?(($quota_used / 1024) / $quota['quota_limit'])*100:0);  
    42694335                    $folder = mb_convert_encoding($folder, "ISO_8859-1", "UTF7-IMAP");  
    42704336                    if(!preg_match('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i',$folder)){  
     
    42744340                            $folder = preg_replace('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i','', $folder);  
    42754341 
    4276                     $data[$folder] = array("quota_percent" => sprintf("%.1f",round($quotaPercent,1)), "quota_used" => $quota_used);  
     4342                    $data[$folder] = array("quota_percent" => ($hasquota?sprintf("%.1f",round($quotaPercent,1)):''), "quota_used" => $quota_used, "quota_limit" => ($isroot && $folder!=$this->functions->getLang("Inbox")?$quota['quota_limit']:''));  
    42774343            }  
    42784344            $imapfp->close();  
    42794345            return $data;  
    4280     }   
     4346    } 
     4347        function get_folders_with_quota(){  
     4348 
     4349            // Additional Imap Class for not-implemented functions into PHP-IMAP extension.  
     4350            include_once("class.imapfp.inc.php");             
     4351            $imapfp = new imapfp();  
     4352 
     4353            if(!$imapfp->open($this->imap_server,$this->imap_port))  
     4354                    return $imapfp->get_error();              
     4355            if (!$imapfp->login( $this->username,$this->password ))  
     4356                    return $imapfp->get_error();  
     4357 
     4358            $response_array = $imapfp->get_mailboxes_size();  
     4359            if ($imapfp->error)  
     4360                    return $imapfp->get_error();  
     4361 
     4362            $data = array(); 
     4363 
     4364            foreach ($response_array as $idx=>$line) {  
     4365                    $line2 = str_replace('"', "", $line);  
     4366                    $line2 = str_replace(" /vendor/cmu/cyrus-imapd/size (value.shared ",";",str_replace("* ANNOTATION ","",$line2));  
     4367                    list($folder,$size) = explode(";",$line2);  
     4368                    $quota_used = str_replace(")","",$size);  
     4369                    $quota=$this->get_quotaroot(array('folder' => $folder)); 
     4370                    $hasquota=($quota['quota_limit']!=""); 
     4371                    $isroot=(strpos($quota['quota_root'],$folder)!==false); 
     4372                    if($isroot){ 
     4373                        $quotaPercent = ($hasquota?(($quota_used / 1024) / $quota['quota_limit'])*100:0);  
     4374                        $folder = mb_convert_encoding($folder, "ISO_8859-1", "UTF7-IMAP");  
     4375                        if(preg_match('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i',$folder)){  
     4376                             $folder = preg_replace('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i','', $folder);  
     4377                             $data[$folder] = array("quota_percent" => ($hasquota?sprintf("%.1f",round($quotaPercent,1)):''), "quota_used" => $quota_used, "quota_limit" => ($isroot && $folder!=$this->functions->getLang("Inbox")?$quota['quota_limit']:''));  
     4378                             return $data; 
     4379                        }  
     4380                         
     4381                    } 
     4382            }  
     4383            $imapfp->close();  
     4384            return false;  
     4385    } 
     4386     
     4387     
    42814388} 
    42824389?> 
Note: See TracChangeset for help on using the changeset viewer.