Index: /trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 659)
+++ /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 660)
@@ -187,13 +187,17 @@
 	* com .emls gerados pelo expresso, e o arquivo pode ser um zip contendo vários emls ou um .eml.
 	*/
-	function import_msgs() {
-		
-		if(!$this->mbox)
-			$this->mbox = $this->open_mbox($params["folder"]);
+	function import_msgs($params) {
+		if(!$this->mbox)		
+			$this->mbox = $this->open_mbox();
 		$errors = array();
 		$invalid_format = false;
-		$filename = $_FILES['arquivo']['name'];
+		$filename = $params['FILES'][0]['name'];
+		$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($_FILES['arquivo']['tmp_name']);
+			$zip = zip_open($params['FILES'][0]['tmp_name']);
 
 			if ($zip) {
@@ -203,5 +207,5 @@
 						$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."}"."INBOX",
+								"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"],
 									$email
 									);
@@ -211,22 +215,21 @@
 					}
 				}
-
-			}
-
-			zip_close($zip);
+				zip_close($zip);
+			}
 		}
 		else if(substr($filename,strlen($filename)-4)==".eml") {
-			$email = implode("",file($_FILES['arquivo']['tmp_name']));
+			$email = implode("",file($params['FILES'][0]['tmp_name']));
 			$status = @imap_append($this->mbox,
-								"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}"."INBOX",
+								"{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$params["folder"],
 									$email
 									);
-			if(!$status)
+			if(!$status){
 				array_push($errors,zip_entry_name($zip_entry));
-			zip_entry_close($zip_entry);
+				zip_entry_close($zip_entry);
+			}
 		}
 		else 
 		{
-			echo "<script>alert(\"".lang("wrong file format")."\")</script>";
+			return array("error" => $this->functions->getLang("wrong file format"));
 			$invalid_format = true;
 		}
@@ -234,16 +237,14 @@
 		if(!$invalid_format) {
 			if(count($errors)>0) {
-				$message = lang("fail in import:")."\n";
+				$message = $this->functions->getLang("fail in import:")."\n";
 				foreach($errors as $arquivo) {
 					$message.=$arquivo."\n";
 				}
-				echo "<script>alert(\"$message\")</script>";
+				return array("error" => $message);
 			}
 			else
-				echo "<script>alert(\"".lang("messages imported successfully")."\")</script>";
-		}
-		echo "<script>location.href='/expressoMail1_2/index.php'</script>";
-	}
-	
+				return $this->functions->getLang("The import was executed successfully.");			
+		}
+	}	
 	/*
 		Remove os anexos de uma mensagem. A estratégia para isso é criar uma mensagem nova sem os anexos, mantendo apenas
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 659)
+++ /trunk/expressoMail1_2/js/main.js	(revision 660)
@@ -1513,2 +1513,121 @@
     	write_msg(get_lang('No selected message.'));
 }
+
+function import_window(){
+	var win = arrayJSWin["import_window"];
+	var form_upload = Element("form_upload");
+	if(!win) {
+		var form = document.createElement("DIV");
+		form.id  = "import_window";
+		form.style.visibility = "hidden";
+		form.style.position = "absolute";
+		form.style.background = "#eeeeee";
+		form.style.left = "0px";
+		form.style.top  = "0px"; 
+		form.style.width = "0px";
+		form.style.height = "0px";
+		document.body.appendChild(form);
+		form_upload = document.createElement("DIV");
+		form_upload.id = "form_upload";
+		form_upload.style.position = "absolute";
+		form_upload.style.top = "5px";
+		form_upload.style.left = "5px";
+		form_upload.name =  get_lang('zip mails to import');
+		form_upload.style.width = "450px";
+		form_upload.style.height = "75px";
+		form.appendChild(form_upload);	
+		form.style.width  =  form.firstChild.style.width;
+		form.style.height = form.firstChild.style.height;
+		form.style.zIndex = "10000";			
+		var title = form.firstChild.name;
+		var wHeight = form.offsetHeight + "px";
+		var wWidth =  form.offsetWidth   + "px";
+		form.style.width = form.offsetWidth - 5;
+		win = new dJSWin({
+			id: 'win_'+form.id,
+			content_id: form.id,
+			width: wWidth,
+			height: wHeight,
+			title_color: '#3978d6',
+			bg_color: '#eee',
+			title: title,
+			title_text_color: 'white',
+			button_x_img: '../phpgwapi/images/winclose.gif',
+			border: true });	
+		win.draw();
+	}
+	form_upload.innerHTML = '<form method="POST" name="form_import" enctype="multipart/form-data">'+get_lang('zip mails to import')+':<br>'+
+	'<input name="file_1" maxlength="255" size="50" id="file_1" type="file"><br>' +
+	'<input title="'+get_lang('Select a folder')+'"  value="' + get_lang('Select a folder') + '"' + 'type="button" onclick="javascript:select_import_folder()">&nbsp;' +
+	'<input title="' + get_lang('Close') + '"  value="' + get_lang('Close') + '"' +
+	' type="button" onclick="arrayJSWin[\'import_window\'].close()"></form>';	
+	win.open();
+}
+
+function import_msgs(wfolders_tree){
+	function handler(data){		
+		// Its necessary to encapsulate the data returned (IE bugfix)
+		return_import_msgs(data,wfolders_tree);		
+	}
+	var countFiles = document.form_import.countFiles;
+	if(!countFiles){
+		countFiles = document.createElement("INPUT");
+		countFiles.type = "hidden";
+		countFiles.name = "countFiles";
+		countFiles.value = "1";
+		document.form_import.appendChild(countFiles);
+	}
+	var folder = document.createElement("INPUT");
+	folder.type = "hidden";
+	folder.name = "folder";
+	folder.value = wfolders_tree._selected.id;
+	document.form_import.appendChild(folder);
+	write_msg(get_lang('You must wait while the messages will be imported...'));
+	
+	cExecuteForm('$this.imap_functions.import_msgs', document.form_import, handler);
+}
+function return_import_msgs(data, wfolders_tree){
+	if(data && data.error){
+		write_msg(data.error);
+	}
+	else{
+		if(data == 'Post-Content-Length')
+			write_msg(get_lang('The size of this message has exceeded  the limit (%1B).',Element('upload_max_filesize').value));
+		else {
+			write_msg(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();
+			}
+		}
+	}
+}
+
+function select_import_folder(){
+	//Begin: Verify if the file extension is allowed.
+	var imgExtensions = new Array("eml","zip");
+	var inputFile = document.form_import.file_1;	
+	if(!inputFile.value){
+		alert(get_lang('File extension forbidden or invalid file') + '.');
+		return false;
+	}
+	var fileExtension = inputFile.value.split(".");
+	fileExtension = fileExtension[(fileExtension.length-1)];
+	var deniedExtension = true;
+	for(var i=0; i<imgExtensions.length; i++) {
+		if(imgExtensions[i].toUpperCase() == fileExtension.toUpperCase()) {
+			deniedExtension = false;
+			break;
+		}
+	}
+	if(deniedExtension) {
+		alert(get_lang('File extension forbidden or invalid file') + '.');
+		return false;
+	}
+	arrayJSWin['import_window'].close();
+	wfolders.makeWindow('null','import');
+}
Index: /trunk/expressoMail1_2/js/wfolders.js
===================================================================
--- /trunk/expressoMail1_2/js/wfolders.js	(revision 271)
+++ /trunk/expressoMail1_2/js/wfolders.js	(revision 660)
@@ -43,4 +43,6 @@
 		else if (type == 'change_folder')
 			butt.value = get_lang('Change folder');	
+		else //default value
+			butt.value = get_lang(type);
 
 		butt.onclick = function () {
@@ -65,4 +67,7 @@
 				change_folder(wfolders_tree._selected.id, wfolders_tree._selected.caption);
 				wfolders.alert = true;
+			}
+			else if (type == 'import'){
+				import_msgs(wfolders_tree);
 			}
 		};
@@ -112,5 +117,5 @@
 			div.style.width = "275px";
 			div.style.height = "250px";
-			var title = get_lang('Select a folder:');
+			var title = get_lang('Select a folder')+":";
 			var wHeight = div.offsetHeight + "px";
 			var wWidth =  div.offsetWidth   + "px";
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 659)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 660)
@@ -2351,5 +2351,5 @@
    		'<span title="'+get_lang("Print")+'" class="message_options" onclick=print_all()>'+get_lang("Print")+'</span> | '+
 	   	'<span title="'+get_lang("Export")+'" class="message_options" onclick="export_all_selected_msgs()">'+get_lang("Export")+'</span> | ' + 
-		'<span title="'+get_lang("Import")+'" class="message_options" onclick="location.href=\'import.php\'">'+get_lang("Import")+'</span>';
+	   	'<span title="'+get_lang("Import")+'" class="message_options" onclick="import_window()">'+get_lang("Import")+'</span>';
 	
 	if (use_spam_filter) {
Index: /trunk/expressoMail1_2/js/connector.js
===================================================================
--- /trunk/expressoMail1_2/js/connector.js	(revision 630)
+++ /trunk/expressoMail1_2/js/connector.js	(revision 660)
@@ -599,5 +599,5 @@
 
 		var divFiles = Element("divFiles_"+id);		
-		if (divFiles.firstChild) {
+		if (divFiles && divFiles.firstChild) {
 			el			= document.createElement('input');
 			el.type	= 'hidden';	
