Index: /branches/2.3/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /branches/2.3/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 5000)
+++ /branches/2.3/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 5014)
@@ -326,91 +326,95 @@
 	* com .emls gerados pelo expresso, e o arquivo pode ser um zip contendo vários emls ou um .eml.
 	*/
-	function import_msgs($params) {
-		if(!$this->mbox)
-			$this->mbox = $this->open_mbox();
-
- 		if( preg_match('/local_/',$params["folder"]) )
-		{
-			// PLEASE, BE CAREFULL!!! YOU SHOULD USE EMAIL CONFIGURATION VALUES (EMAILADMIN MODULE)
-			$tmp_box = mb_convert_encoding('INBOX'.$this->imap_delimiter.$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'].$this->imap_delimiter.'tmpMoveToLocal', "UTF7-IMAP", "UTF-8");
-			if ( ! imap_createmailbox( $this -> mbox,"{".$this -> imap_server."}$tmp_box" ) )
-				return $this->functions->getLang( 'Import to Local : fail...' );
-			imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$tmp_box);
-			$params["folder"] = $tmp_box;
-		}
-		$errors = array();
-		$invalid_format = false;
-		$filename = $params['FILES'][0]['name'];
-		$params["folder"] = mb_convert_encoding($params["folder"], "UTF7-IMAP","ISO_8859-1");
-		$quota = imap_get_quotaroot($this->mbox, $params["folder"]);
-		if((($quota['limit'] - $quota['usage'])*1024) <= $params['FILES'][0]['size']){
-			return array( 'error' => $this->functions->getLang("fail in import:").
-							" ".$this->functions->getLang("Over quota"));
-		}
-		if(substr($filename,strlen($filename)-4)==".zip") {
-			$zip = zip_open($params['FILES'][0]['tmp_name']);
-
-			if ($zip) {
-				while ($zip_entry = zip_read($zip)) {
-
-					if (zip_entry_open($zip, $zip_entry, "r")) {
-						$email = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
-						$status = @imap_append($this->mbox,
-								"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"],
-									$email
-									);
-						if(!$status)
-							array_push($errors,zip_entry_name($zip_entry));
-						zip_entry_close($zip_entry);
-					}
-				}
-				zip_close($zip);
-			}
-
-			if ( isset( $tmp_box ) && ! sizeof( $errors ) )
-			{
-
-				$mc = imap_check($this->mbox);
-
-				$result = imap_fetch_overview( $this -> mbox, "1:{$mc -> Nmsgs}", 0 );
-
-				$ids = array( );
-				foreach ($result as $overview)
-					$ids[ ] = $overview -> uid;
-
-				return implode( ',', $ids );
-			}
-			}
-		else if(substr($filename,strlen($filename)-4)==".eml") {
-			$email = implode("",file($params['FILES'][0]['tmp_name']));
-			$status = @imap_append($this->mbox,
-								"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"],
-									$email
-									);
-			if(!$status){
-				array_push($errors,zip_entry_name($zip_entry));
-				zip_entry_close($zip_entry);
-			}
-		}
-		else
-		{
-			if ( isset( $tmp_box ) )
-				imap_deletemailbox( $this->mbox,"{".$this -> imap_server."}$tmp_box" );
-
-			return array("error" => $this->functions->getLang("wrong file format"));
-			$invalid_format = true;
-		}
-
-		if(!$invalid_format) {
-			if(count($errors)>0) {
-				$message = $this->functions->getLang("fail in import:")."\n";
-				foreach($errors as $arquivo) {
-					$message.=$arquivo."\n";
-				}
-				return array("error" => $message);
-			}
-			else
-				return $this->functions->getLang("The import was executed successfully.");
-		}
+        function import_msgs($params)
+        {
+            //abre a caixa de mensagem
+            if(!$this->mbox)
+                $this->mbox = $this->open_mbox();
+
+            //cria o diretório temporário de importação se for para importar direto para a pasta local
+            if( preg_match('/local_/', $params["folder"]) )
+            {
+                // PLEASE, BE CAREFULL!!! YOU SHOULD USE EMAIL CONFIGURATION VALUES (EMAILADMIN MODULE)
+                $tmp_box = mb_convert_encoding('INBOX'.$this->imap_delimiter.$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'].$this->imap_delimiter.'tmpMoveToLocal', "UTF7-IMAP", "UTF-8");
+                if ( ! imap_createmailbox( $this -> mbox,"{".$this -> imap_server."}$tmp_box" ) )
+                    return array( 'error' =>  $this->functions->getLang('Import to Local : fail...'));
+                imap_reopen($this->mbox, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$tmp_box);
+                $params["folder"] = $tmp_box;
+            }
+            $params["folder"] = mb_convert_encoding($params["folder"], "UTF7-IMAP","ISO_8859-1");
+
+            //testa se o arquivo importado já não supera o tamanho da cota de disco
+            $quota = imap_get_quotaroot($this->mbox, $params["folder"]);
+            if((($quota['limit'] - $quota['usage'])*1024) <= $params['FILES'][0]['size'])
+                return array( 'error' => $this->functions->getLang("fail in import:") . " " . $this->functions->getLang("Over quota"));
+            
+            $ids = array();
+            $errors = array();
+            $filename = $params['FILES'][0]['name'];
+            
+            $strFileExtension = substr($filename, strlen($filename) - 4);
+            $folder = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"];
+            switch ($strFileExtension)
+            {
+                 case ".eml":
+                    //reconstrói o email
+                    $email = implode("", file($params['FILES'][0]['tmp_name']));
+                    //coloca o email na pasta selecionada
+                    $status = @imap_append($this->mbox, $folder, $email);
+                    if($status)
+                    {
+                        $status = imap_status($this->mbox, $folder, SA_UIDNEXT);
+                        $ids[] = $status->uidnext - 1;
+                    }
+                    else
+                    {
+                        $error[] = imap_last_error();
+                    }
+                    break;
+                case ".zip":
+                    $zip = zip_open($params['FILES'][0]['tmp_name']);
+                
+                    if ($zip) {
+                        while ($zip_entry = zip_read($zip))
+                        {
+                            $filename = zip_entry_name($zip_entry);
+                            if (substr($filename, strlen($filename) - 4) == '.eml')
+                            {
+                                if (zip_entry_open($zip, $zip_entry, "r"))
+                                {
+                                    $email = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
+                                    $status = @imap_append($this->mbox, $folder, $email);
+                                    if($status)
+                                    {
+                                        $status = imap_status($this->mbox, $folder, SA_UIDNEXT);
+                                        $ids[] = $status->uidnext - 1;
+                                    }
+                                    else
+                                    {
+                                        $error[] = imap_last_error();
+                                    }
+                                    zip_entry_close($zip_entry);
+                                }
+                            }
+                        }
+                        zip_close($zip);
+                    }
+                    break;
+                default:
+                    if ( isset( $tmp_box ) )
+                        imap_deletemailbox( $this->mbox,"{".$this -> imap_server."}$tmp_box" );
+                    $error[] = $this->functions->getLang("wrong file format");
+            }
+            
+            if(count($errors)>0)
+            {
+                return array("error" => $this->functions->getLang("fail in import:") . "\n" . implode("\n", $errors));
+            }
+            else
+            {
+                return implode(",", $ids);
+                //return $this->functions->getLang("The import was executed successfully.");
+            }
+                            
 	}
         /*
Index: /branches/2.3/expressoMail1_2/js/main.js
===================================================================
--- /branches/2.3/expressoMail1_2/js/main.js	(revision 5011)
+++ /branches/2.3/expressoMail1_2/js/main.js	(revision 5014)
@@ -2736,28 +2736,31 @@
 		if(data == 'Post-Content-Length')
 			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));
-		else {	/*
-			* @author Rommel Cysne (rommel.cysne@serpro.gov.br)
-			* @date 2009/05/15
-			* Foi colocado um teste para verificar se a pasta selecionada, passada como parametro,
-			* eh uma pasta local (qualquer uma)
-			*/
-			var er = /^local_/;
-			if ( er.test(wfolders_tree._selected.id) )
-			{
-				archive_msgs('INBOX/Lixeira/tmpMoveToLocal',wfolders_tree._selected.id,data);
-				cExecute('$this.imap_functions.delete_mailbox',function(){},'del_past=INBOX/Lixeira/tmpMoveToLocal');
-			}
-						 else{
-				write_msg(get_lang(data));
-				arrayJSWin["import_window"].close();
-				if(openTab.imapBox[0] == wfolders_tree._selected.id)
-				{
-					openTab.imapBox[0] = '';
-					change_folder(wfolders_tree._selected.id, wfolders_tree._selected.caption);
-				} else{
-					refresh();
-				}
-			}
-	}
+		else
+                {
+                    write_msg(get_lang('The import was executed successfully.'));
+                    /*
+                    * @author Rommel Cysne (rommel.cysne@serpro.gov.br)
+                    * @date 2009/05/15
+                    * Foi colocado um teste para verificar se a pasta selecionada, passada como parametro,
+                    * eh uma pasta local (qualquer uma)
+                    */
+                    var er = /^local_/;
+                    if ( er.test(wfolders_tree._selected.id) )
+                    {
+                        var tempTrashFolder = 'INBOX' + cyrus_delimiter + trashfolder + '/tmpMoveToLocal';
+                        archive_msgs(tempTrashFolder ,wfolders_tree._selected.id, data);
+                        cExecute('$this.imap_functions.delete_mailbox',function(){},'del_past=' + tempTrashFolder);
+                    }
+                    else{
+                        arrayJSWin["import_window"].close();
+                        if(openTab.imapBox[0] == wfolders_tree._selected.id)
+                        {
+                                openTab.imapBox[0] = '';
+                                change_folder(wfolders_tree._selected.id, wfolders_tree._selected.caption);
+                        } else{
+                                refresh();
+                        }
+                    }
+                }
 	}
 
