Changeset 5014 for branches


Ignore:
Timestamp:
08/31/11 16:43:08 (13 years ago)
Author:
rafaelraymundo
Message:

Ticket #2154 - Não importa mensagens quando selecionada pasta do arquivamento local

Location:
branches/2.3/expressoMail1_2
Files:
2 edited

Legend:

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

    r5000 r5014  
    326326        * com .emls gerados pelo expresso, e o arquivo pode ser um zip contendo vários emls ou um .eml. 
    327327        */ 
    328         function import_msgs($params) { 
    329                 if(!$this->mbox) 
    330                         $this->mbox = $this->open_mbox(); 
    331  
    332                 if( preg_match('/local_/',$params["folder"]) ) 
    333                 { 
    334                         // PLEASE, BE CAREFULL!!! YOU SHOULD USE EMAIL CONFIGURATION VALUES (EMAILADMIN MODULE) 
    335                         $tmp_box = mb_convert_encoding('INBOX'.$this->imap_delimiter.$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'].$this->imap_delimiter.'tmpMoveToLocal', "UTF7-IMAP", "UTF-8"); 
    336                         if ( ! imap_createmailbox( $this -> mbox,"{".$this -> imap_server."}$tmp_box" ) ) 
    337                                 return $this->functions->getLang( 'Import to Local : fail...' ); 
    338                         imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$tmp_box); 
    339                         $params["folder"] = $tmp_box; 
    340                 } 
    341                 $errors = array(); 
    342                 $invalid_format = false; 
    343                 $filename = $params['FILES'][0]['name']; 
    344                 $params["folder"] = mb_convert_encoding($params["folder"], "UTF7-IMAP","ISO_8859-1"); 
    345                 $quota = imap_get_quotaroot($this->mbox, $params["folder"]); 
    346                 if((($quota['limit'] - $quota['usage'])*1024) <= $params['FILES'][0]['size']){ 
    347                         return array( 'error' => $this->functions->getLang("fail in import:"). 
    348                                                         " ".$this->functions->getLang("Over quota")); 
    349                 } 
    350                 if(substr($filename,strlen($filename)-4)==".zip") { 
    351                         $zip = zip_open($params['FILES'][0]['tmp_name']); 
    352  
    353                         if ($zip) { 
    354                                 while ($zip_entry = zip_read($zip)) { 
    355  
    356                                         if (zip_entry_open($zip, $zip_entry, "r")) { 
    357                                                 $email = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); 
    358                                                 $status = @imap_append($this->mbox, 
    359                                                                 "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"], 
    360                                                                         $email 
    361                                                                         ); 
    362                                                 if(!$status) 
    363                                                         array_push($errors,zip_entry_name($zip_entry)); 
    364                                                 zip_entry_close($zip_entry); 
    365                                         } 
    366                                 } 
    367                                 zip_close($zip); 
    368                         } 
    369  
    370                         if ( isset( $tmp_box ) && ! sizeof( $errors ) ) 
    371                         { 
    372  
    373                                 $mc = imap_check($this->mbox); 
    374  
    375                                 $result = imap_fetch_overview( $this -> mbox, "1:{$mc -> Nmsgs}", 0 ); 
    376  
    377                                 $ids = array( ); 
    378                                 foreach ($result as $overview) 
    379                                         $ids[ ] = $overview -> uid; 
    380  
    381                                 return implode( ',', $ids ); 
    382                         } 
    383                         } 
    384                 else if(substr($filename,strlen($filename)-4)==".eml") { 
    385                         $email = implode("",file($params['FILES'][0]['tmp_name'])); 
    386                         $status = @imap_append($this->mbox, 
    387                                                                 "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"], 
    388                                                                         $email 
    389                                                                         ); 
    390                         if(!$status){ 
    391                                 array_push($errors,zip_entry_name($zip_entry)); 
    392                                 zip_entry_close($zip_entry); 
    393                         } 
    394                 } 
    395                 else 
    396                 { 
    397                         if ( isset( $tmp_box ) ) 
    398                                 imap_deletemailbox( $this->mbox,"{".$this -> imap_server."}$tmp_box" ); 
    399  
    400                         return array("error" => $this->functions->getLang("wrong file format")); 
    401                         $invalid_format = true; 
    402                 } 
    403  
    404                 if(!$invalid_format) { 
    405                         if(count($errors)>0) { 
    406                                 $message = $this->functions->getLang("fail in import:")."\n"; 
    407                                 foreach($errors as $arquivo) { 
    408                                         $message.=$arquivo."\n"; 
    409                                 } 
    410                                 return array("error" => $message); 
    411                         } 
    412                         else 
    413                                 return $this->functions->getLang("The import was executed successfully."); 
    414                 } 
     328        function import_msgs($params) 
     329        { 
     330            //abre a caixa de mensagem 
     331            if(!$this->mbox) 
     332                $this->mbox = $this->open_mbox(); 
     333 
     334            //cria o diretório temporário de importação se for para importar direto para a pasta local 
     335            if( preg_match('/local_/', $params["folder"]) ) 
     336            { 
     337                // PLEASE, BE CAREFULL!!! YOU SHOULD USE EMAIL CONFIGURATION VALUES (EMAILADMIN MODULE) 
     338                $tmp_box = mb_convert_encoding('INBOX'.$this->imap_delimiter.$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'].$this->imap_delimiter.'tmpMoveToLocal', "UTF7-IMAP", "UTF-8"); 
     339                if ( ! imap_createmailbox( $this -> mbox,"{".$this -> imap_server."}$tmp_box" ) ) 
     340                    return array( 'error' =>  $this->functions->getLang('Import to Local : fail...')); 
     341                imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$tmp_box); 
     342                $params["folder"] = $tmp_box; 
     343            } 
     344            $params["folder"] = mb_convert_encoding($params["folder"], "UTF7-IMAP","ISO_8859-1"); 
     345 
     346            //testa se o arquivo importado já não supera o tamanho da cota de disco 
     347            $quota = imap_get_quotaroot($this->mbox, $params["folder"]); 
     348            if((($quota['limit'] - $quota['usage'])*1024) <= $params['FILES'][0]['size']) 
     349                return array( 'error' => $this->functions->getLang("fail in import:") . " " . $this->functions->getLang("Over quota")); 
     350             
     351            $ids = array(); 
     352            $errors = array(); 
     353            $filename = $params['FILES'][0]['name']; 
     354             
     355            $strFileExtension = substr($filename, strlen($filename) - 4); 
     356            $folder = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"]; 
     357            switch ($strFileExtension) 
     358            { 
     359                 case ".eml": 
     360                    //reconstrói o email 
     361                    $email = implode("", file($params['FILES'][0]['tmp_name'])); 
     362                    //coloca o email na pasta selecionada 
     363                    $status = @imap_append($this->mbox, $folder, $email); 
     364                    if($status) 
     365                    { 
     366                        $status = imap_status($this->mbox, $folder, SA_UIDNEXT); 
     367                        $ids[] = $status->uidnext - 1; 
     368                    } 
     369                    else 
     370                    { 
     371                        $error[] = imap_last_error(); 
     372                    } 
     373                    break; 
     374                case ".zip": 
     375                    $zip = zip_open($params['FILES'][0]['tmp_name']); 
     376                 
     377                    if ($zip) { 
     378                        while ($zip_entry = zip_read($zip)) 
     379                        { 
     380                            $filename = zip_entry_name($zip_entry); 
     381                            if (substr($filename, strlen($filename) - 4) == '.eml') 
     382                            { 
     383                                if (zip_entry_open($zip, $zip_entry, "r")) 
     384                                { 
     385                                    $email = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); 
     386                                    $status = @imap_append($this->mbox, $folder, $email); 
     387                                    if($status) 
     388                                    { 
     389                                        $status = imap_status($this->mbox, $folder, SA_UIDNEXT); 
     390                                        $ids[] = $status->uidnext - 1; 
     391                                    } 
     392                                    else 
     393                                    { 
     394                                        $error[] = imap_last_error(); 
     395                                    } 
     396                                    zip_entry_close($zip_entry); 
     397                                } 
     398                            } 
     399                        } 
     400                        zip_close($zip); 
     401                    } 
     402                    break; 
     403                default: 
     404                    if ( isset( $tmp_box ) ) 
     405                        imap_deletemailbox( $this->mbox,"{".$this -> imap_server."}$tmp_box" ); 
     406                    $error[] = $this->functions->getLang("wrong file format"); 
     407            } 
     408             
     409            if(count($errors)>0) 
     410            { 
     411                return array("error" => $this->functions->getLang("fail in import:") . "\n" . implode("\n", $errors)); 
     412            } 
     413            else 
     414            { 
     415                return implode(",", $ids); 
     416                //return $this->functions->getLang("The import was executed successfully."); 
     417            } 
     418                             
    415419        } 
    416420        /* 
  • branches/2.3/expressoMail1_2/js/main.js

    r5011 r5014  
    27362736                if(data == 'Post-Content-Length') 
    27372737                        write_msg(get_lang('The size of this message has exceeded  the limit (%1B).', preferences.max_attachment_size ? preferences.max_attachment_size : Element('upload_max_filesize').value)); 
    2738                 else {  /* 
    2739                         * @author Rommel Cysne (rommel.cysne@serpro.gov.br) 
    2740                         * @date 2009/05/15 
    2741                         * Foi colocado um teste para verificar se a pasta selecionada, passada como parametro, 
    2742                         * eh uma pasta local (qualquer uma) 
    2743                         */ 
    2744                         var er = /^local_/; 
    2745                         if ( er.test(wfolders_tree._selected.id) ) 
    2746                         { 
    2747                                 archive_msgs('INBOX/Lixeira/tmpMoveToLocal',wfolders_tree._selected.id,data); 
    2748                                 cExecute('$this.imap_functions.delete_mailbox',function(){},'del_past=INBOX/Lixeira/tmpMoveToLocal'); 
    2749                         } 
    2750                                                  else{ 
    2751                                 write_msg(get_lang(data)); 
    2752                                 arrayJSWin["import_window"].close(); 
    2753                                 if(openTab.imapBox[0] == wfolders_tree._selected.id) 
    2754                                 { 
    2755                                         openTab.imapBox[0] = ''; 
    2756                                         change_folder(wfolders_tree._selected.id, wfolders_tree._selected.caption); 
    2757                                 } else{ 
    2758                                         refresh(); 
    2759                                 } 
    2760                         } 
    2761         } 
     2738                else 
     2739                { 
     2740                    write_msg(get_lang('The import was executed successfully.')); 
     2741                    /* 
     2742                    * @author Rommel Cysne (rommel.cysne@serpro.gov.br) 
     2743                    * @date 2009/05/15 
     2744                    * Foi colocado um teste para verificar se a pasta selecionada, passada como parametro, 
     2745                    * eh uma pasta local (qualquer uma) 
     2746                    */ 
     2747                    var er = /^local_/; 
     2748                    if ( er.test(wfolders_tree._selected.id) ) 
     2749                    { 
     2750                        var tempTrashFolder = 'INBOX' + cyrus_delimiter + trashfolder + '/tmpMoveToLocal'; 
     2751                        archive_msgs(tempTrashFolder ,wfolders_tree._selected.id, data); 
     2752                        cExecute('$this.imap_functions.delete_mailbox',function(){},'del_past=' + tempTrashFolder); 
     2753                    } 
     2754                    else{ 
     2755                        arrayJSWin["import_window"].close(); 
     2756                        if(openTab.imapBox[0] == wfolders_tree._selected.id) 
     2757                        { 
     2758                                openTab.imapBox[0] = ''; 
     2759                                change_folder(wfolders_tree._selected.id, wfolders_tree._selected.caption); 
     2760                        } else{ 
     2761                                refresh(); 
     2762                        } 
     2763                    } 
     2764                } 
    27622765        } 
    27632766 
Note: See TracChangeset for help on using the changeset viewer.