Index: /trunk/prototype/modules/mail/interceptors/Attachments.php
===================================================================
--- /trunk/prototype/modules/mail/interceptors/Attachments.php	(revision 5637)
+++ /trunk/prototype/modules/mail/interceptors/Attachments.php	(revision 6071)
@@ -5,8 +5,22 @@
 	public function encodeCreateAttachment( &$uri , &$params , &$criteria , $original ){            
             if(!isset($params['source'])) return false;
+			
 
             if(isset($_FILES[$params['source']]))
                 $params =  $_FILES[$params['source']];
-
+				
+				if($params['error'] !== 0){
+					switch ($params['error']){
+						case 1:
+							throw  new Exception('Tamanho de arquivo nao permitido!!! (php.ini)'); 
+						case 2:
+							throw  new Exception('Tamanho de arquivo nao permitido!!!'); 
+						case 3:
+							throw  new Exception('Ocorreu um erro durante o upload'); 
+						case 4:
+							throw  new Exception('Nao e um arquivo valido'); 
+					}
+				}
+				
                 $params['owner'] = Config::me('uidNumber'); 
 
Index: /trunk/prototype/modules/mail/templates/attachment.ejs
===================================================================
--- /trunk/prototype/modules/mail/templates/attachment.ejs	(revision 5785)
+++ /trunk/prototype/modules/mail/templates/attachment.ejs	(revision 6071)
@@ -1,3 +1,3 @@
-<form id="fileupload_msg<%=data.ID%>" class="fileupload" action="mailAttachment:detail" method="POST">
+<div id="fileupload_msg<%=data.ID%>" class="fileupload" style="margin : 15px 0px -15px -10px;">
   <div class="row fileupload-buttonbar">
       <div class="button-files-upload">
@@ -17,3 +17,3 @@
          </div>
         <br />
-</form>
+</div>
Index: /trunk/prototype/post.php
===================================================================
--- /trunk/prototype/post.php	(revision 5811)
+++ /trunk/prototype/post.php	(revision 6071)
@@ -3,5 +3,7 @@
  * com o source em base64 melhoria na performace.
  */
+
 $data = $_POST;
+	
 if( count($_FILES) )
 {
@@ -14,7 +16,9 @@
 				$counter = count($files);
 				$files[$name.$counter] = array('name' => $file['name'][$counter], 
-												'type' => $file['type'][$counter],
-												'source' => base64_encode(file_get_contents( $file['tmp_name'][$counter], $file['size'][$counter])),
-												'size' => $file['size'][$counter]);
+					'type' => $file['type'][$counter],
+					'source' => base64_encode(file_get_contents( $file['tmp_name'][$counter], $file['size'][$counter])),
+					'size' => $file['size'][$counter],
+					'error' => $file['error'][$counter]
+				);
 			}
 		}else
@@ -25,5 +29,10 @@
 }
 
+if(isset($data['MAX_FILE_SIZE']))
+	unset($data['MAX_FILE_SIZE']);
+	
 require_once "api/controller.php";
+
+Controller::addFallbackHandler( 0, function($e){ throw $e; } );
 
 $result = array();
@@ -33,6 +42,11 @@
 		$content = array($content);
 		
-	foreach($content as $key => $value)
-		$result[$concept][] =  isset($data['criteria']) ?  Controller::put( array( 'concept' => $concept ), $value, isset($data['criteria'])) : Controller::put( array( 'concept' => $concept ), $value);
+	foreach($content as $key => $value){
+		try{
+			$result[$concept][] = Controller::put( array( 'concept' => $concept ), $value );
+		}catch(Exception $e){
+			$result[$concept]['error'] = $e->getMessage();			
+		} 
+	}
 }	
 echo json_encode( $result );
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 6047)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 6071)
@@ -3671,16 +3671,40 @@
 	content.find(".attachment td").filter(".value").prepend(DataLayer.render("../prototype/modules/mail/templates/attachment.ejs", {ID:ID}));
 	var fileUploadMSG = $('#fileupload_msg'+ID);
-	var maxAttachmentSise = (preferences.max_attachment_size !== "" && preferences.max_attachment_size != 0) ? (parseInt(preferences.max_attachment_size.replace('M', '')) * 1048576 ) : false;
+	var maxAttachmentSize = (preferences.max_attachment_size !== "" && preferences.max_attachment_size != 0) ? (parseInt(preferences.max_attachment_size.replace('M', '')) * 1048576 ) : false;
 
 	fileUploadMSG.find(".button-files-upload").fileupload({
-		sequentialUploads: true,
+		type: 'post',
+		dataType : 'json',
+		url: "../prototype/post.php",
+		forceIframeTransport: true,
+		formData: function(form) {
+			return [
+				{
+					name : "mailAttachment[0][source]",
+					value : "files0"
+				},
+				{
+					name : "mailAttachment[0][disposition]",
+					value : $(form[0]['attDisposition'+$(form[0]['abaID']).val()]).val()
+				},
+				{
+					name: "MAX_FILE_SIZE",
+					value : maxAttachmentSize
+				}
+			];
+		},
 		add: function (e, data) {
 			
-			if(!maxAttachmentSise || data.files[0].size < maxAttachmentSise || is_ie) {
+			if(!maxAttachmentSize || data.files[0].size < maxAttachmentSize || is_ie) {
 				setTimeout(function() {
-                                        $('#attDisposition'+ID).val('attachment');
-					delete data.fileInput; 
+                    $('#attDisposition'+ID).val('attachment');
+					if(!data.fileInput){
+						$(fileUploadMSG).find("input")[0].files = data.files;
+						data['fileInput'] = $(fileUploadMSG).find("input");
+					}
+					if(!data.form)
+						data['form'] = fileUploadMSG.parents("form:first");
 					data.submit();
-				}, 5000);
+				}, 3000);
 			}		
 			var attach = {};
@@ -3690,6 +3714,7 @@
 				attach.fileName = data.files[0].name.substr(0, 32) + " ... " + data.files[0].name.substr(data.files[0].name.length-9, data.files[0].name.length);
 			attach.fileSize = formatBytes(data.files[0].size);
-			if(maxAttachmentSise && data.files[0].size > maxAttachmentSise)
-				attach.error = 'Tamanho de arquivo nao permitido!!'
+			data.files[0].size = 300;
+			if(maxAttachmentSize && data.files[0].size > maxAttachmentSize)
+				attach.error = 'Tamanho de arquivo nao permitido!!!'
 
 			var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));				
@@ -3708,5 +3733,5 @@
 			fileUploadMSG.find('.attachments-list').append(upload);
 
-			if(!maxAttachmentSise || data.files[0].size < maxAttachmentSise)
+			if(!maxAttachmentSize || data.files[0].size < maxAttachmentSize)
 			    fileUploadMSG.find('.attachments-list').find('[type=file]').addClass('hidden');	
 			else
@@ -3715,24 +3740,21 @@
 		done: function(e, data){
 			if(!!data.result && data.result != "[]" ){
-				var newAttach = jQuery.parseJSON(data.result);
-				
-				//Compatibilidade com Firefox3.6 	
-				if(newAttach === null ) newAttach = jQuery.parseJSON(data.result.text());
-				
-				var newAttach = jQuery.parseJSON(data.result);                               
-                                if(newAttach.rollback !== false)
-                                {
-                                    fileUploadMSG.find('.in-progress:first').parents('p').append('<input type="hidden" name="fileId[]" value="'+newAttach['mailAttachment'][0][0].id+'"/>').find('.status-upload').addClass('ui-icon ui-icon-check');
-                                    addAttachment(ID,newAttach['mailAttachment'][0][0].id);
-                                }
-                                else                             
-                                  fileUploadMSG.find('.in-progress:first').parents('p').find('.status-upload').append('Erro ao fazer upload!').addClass('message-attach-error');   
+				var newAttach = data.result;                             
+				if(!newAttach.mailAttachment.error){
+					if(newAttach.rollback !== false)
+					{
+						fileUploadMSG.find('.in-progress:first').parents('p').append('<input type="hidden" name="fileId[]" value="'+newAttach['mailAttachment'][0][0].id+'"/>').find('.status-upload').addClass('ui-icon ui-icon-check');
+						addAttachment(ID,newAttach['mailAttachment'][0][0].id);
+					}
+					else                             
+						fileUploadMSG.find('.in-progress:first').parents('p').find('.status-upload').append('Erro ao fazer upload!').addClass('message-attach-error');   
+				}else{
+					fileUploadMSG.find('.in-progress:first').parents('p').find('.status-upload').append(newAttach.mailAttachment.error).addClass('message-attach-error');   
+				}
                                 
 			}else {
 				fileUploadMSG.find(' .progress.on-complete:first').parents('p').find('.status-upload').append('Erro ao fazer upload!').addClass('message-attach-error');
 			}
-                        fileUploadMSG.find(' .in-progress:first').remove();
-				
-                    
+            fileUploadMSG.find(' .in-progress:first').remove();
 		}
 	}).find('[name="files[]"]').css({"height" : "20px", "width": "100px", "border-width": "0 0 0px 0px", "-moz-transform" : "none","-o-transform" : 'none'});
