Index: /trunk/prototype/modules/mail/templates/attachment.ejs
===================================================================
--- /trunk/prototype/modules/mail/templates/attachment.ejs	(revision 5604)
+++ /trunk/prototype/modules/mail/templates/attachment.ejs	(revision 5626)
@@ -11,9 +11,9 @@
 
      <span tabindex="-1" class="message-attach-link button small ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"><span class="icon-plus ui-button-text">Anexar mensagens</span></span>
-       <div id="fileupload-progress"></div>
+    </div>
+     
          <div class="files-list">
             <ul class="attachments-list"></ul>
          </div>
-       </div>
-        <br>
+        <br />
 </form>
Index: /trunk/expressoMail1_2/templates/default/expressomail.css
===================================================================
--- /trunk/expressoMail1_2/templates/default/expressomail.css	(revision 5604)
+++ /trunk/expressoMail1_2/templates/default/expressomail.css	(revision 5626)
@@ -138,5 +138,6 @@
 
 form.fileupload { margin: 14px 0 0 -13px; float: left; margin-bottom: -20px; }
-form.fileupload .files-list { margin-left: 5px;}
+form.fileupload .files-list { margin-left: 5px; margin-top: -14px; padding: 0.2em 0.7em; }
+form.fileupload .files-list .delete-upload { top: 7px}
 ul.attachments-list { padding: 0; }
 .button-files-upload { float:left; }
@@ -144,5 +145,5 @@
 form.fileupload .ui-button .ui-button-text { line-height: 2; }
 form.fileupload .ui-button { margin-left: 5px; }
-
+form.fileupload .message-add-original-att { margin-left: 0px; }
 .button.add.button-add-attachment{margin: -9px 0 0 8px;}
 .button.upload{margin-bottom: 4px;}
@@ -154,7 +155,7 @@
 .row.fileupload-buttonbar{margin-top: -14px; padding: 0.2em 0.7em;}
 
-.archive-attach.name{width: 200px;}
+.archive-attach.name{width: 310px;}
 .archive-attach.name label{display: block; position: absolute; left: 136px; top: 194px;}
-.size{min-width: 60px; max-width: 60px;}
+.size{min-width: 65px;}
 
 .message-attach.name{width: 200px;}
Index: /trunk/expressoMail1_2/js/abas.js
===================================================================
--- /trunk/expressoMail1_2/js/abas.js	(revision 5620)
+++ /trunk/expressoMail1_2/js/abas.js	(revision 5626)
@@ -4,5 +4,4 @@
 var partMsgs = new Array(); 
 var msgAttachments = new Array();
-var imgAttachmentFlag = new Array(); 
 var uidsSave = new Array(); 
 
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 5622)
+++ /trunk/expressoMail1_2/js/main.js	(revision 5626)
@@ -1689,49 +1689,5 @@
                   
 			if (Element("attachments_" + border_ID))
-                        {
-                            
-                                var fileUploadMSG = $('#fileupload_msg'+new_border_ID);
-				var attachments = document.getElementById("attachments_" + border_ID).getElementsByTagName("a");			
-				for (var i = 0; i < attachments.length; i++){
-					if((attachments[i].tagName=="SPAN") || (attachments[i].tagName=="IMG") || ((attachments[i].href.indexOf("javascript:download_local_attachment")==-1)&&(attachments[i].href.indexOf("javascript:download_attachments")==-1)))
-						continue;
-                                      
-                                            var arrayAtt = attachments[i].href.replace("javascript:download_attachments(", "").replace(")", "").split(',');                                 
-                                            var att = new Object();
-                                            var regex = new RegExp( "'", "g" );
-                                            att.folder = arrayAtt[0].replace(regex,"");
-                                            att.uid = arrayAtt[1].replace(regex,"");
-                                            att.part = arrayAtt[3].replace(regex,"");
-                                            att.type = 'imapPart';
-                                            var idATT = JSON.stringify(att);
-                                            addAttachment( new_border_ID , idATT);  
-
-                                            var attach = {};
-                                            attach.fileName = arrayAtt[5].replace(regex,"");
-                                            
-                                            if(attach.fileName.length > 10)
-                                                attach.fileName = attach.fileName.substr(0, 18) + "..." + attach.fileName.substr(attach.fileName.length-9, attach.fileName.length);
-                            
-                                            attach.fileSize =  attachments[i].text.substring(( attachments[i].text.lastIndexOf('(')+1), attachments[i].text.lastIndexOf(')'));
-                                            
-                                            var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));
-                                            upload.find('.status-upload').remove();
-                                            upload.find('.in-progress').remove(); 
-                                            upload.find('p').append('<input type="hidden" name="fileId[]" value=\''+idATT+'\'/>');
-                                            fileUploadMSG.find('.attachments-list').append(upload);
-			        					
-				}
-                                $('.attachments-list').find('.button.close').button({
-					icons: {
-						primary: "ui-icon-close"
-					},
-					text: false
-				}).click(function(){
-					var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
-					fileUploadMSG.find(' .attachments-list').find('input[value="'+idAttach+'"]');
-                                        delAttachment(new_border_ID,idAttach); 
-					$(this).parent().remove();
-				});	
-			}
+                            addOriginalAttachments(new_border_ID,border_ID);
 			
 			// Insert the signature automaticaly at message body if use_signature preference is set
@@ -1830,49 +1786,6 @@
 
 			if (Element("attachments_" + border_ID))
-                        {
-                            
-                                var fileUploadMSG = $('#fileupload_msg'+new_border_ID);
-				var attachments = document.getElementById("attachments_" + border_ID).getElementsByTagName("a");			
-				for (var i = 0; i < attachments.length; i++){
-					if((attachments[i].tagName=="SPAN") || (attachments[i].tagName=="IMG") || ((attachments[i].href.indexOf("javascript:download_local_attachment")==-1)&&(attachments[i].href.indexOf("javascript:download_attachments")==-1)))
-						continue;
-                                      
-                                            var arrayAtt = attachments[i].href.replace("javascript:download_attachments(", "").replace(")", "").split(',');                                 
-                                            var att = new Object();
-                                            var regex = new RegExp( "'", "g" );
-                                            att.folder = arrayAtt[0].replace(regex,"");
-                                            att.uid = arrayAtt[1].replace(regex,"");
-                                            att.part = arrayAtt[3].replace(regex,"");
-                                            att.type = 'imapPart';
-                                            var idATT = JSON.stringify(att);
-                                            addAttachment( new_border_ID , idATT);  
-
-                                            var attach = {};
-                                            attach.fileName = arrayAtt[5].replace(regex,"");
-                                            
-                                            if(attach.fileName.length > 10)
-                                                attach.fileName = attach.fileName.substr(0, 18) + "..." + attach.fileName.substr(attach.fileName.length-9, attach.fileName.length);
-                            
-                                            attach.fileSize =  attachments[i].text.substring(( attachments[i].text.lastIndexOf('(')+1), attachments[i].text.lastIndexOf(')'));
-                                            
-                                            var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));
-                                            upload.find('.status-upload').remove();
-                                            upload.find('.in-progress').remove(); 
-                                            upload.find('p').append('<input type="hidden" name="fileId[]" value=\''+idATT+'\'/>');
-                                            fileUploadMSG.find('.attachments-list').append(upload);
-			        					
-				}
-                                $('.attachments-list').find('.button.close').button({
-					icons: {
-						primary: "ui-icon-close"
-					},
-					text: false
-				}).click(function(){
-					var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
-					fileUploadMSG.find(' .attachments-list').find('input[value="'+idAttach+'"]');
-                                        delAttachment(new_border_ID,idAttach); 
-					$(this).parent().remove();
-				});	
-			}
+                               addOriginalAttachments(new_border_ID,border_ID);
+                         
 			RichTextEditor.setInitData(new_border_ID, data.body, 'edit');
       
@@ -1936,39 +1849,105 @@
 
 function useOriginalAttachments(new_border_ID,old_id_border)
-{
+{   
 	if (Element("attachments_" + old_id_border))
         {
-                var fileUploadMSG = $('#fileupload_msg'+new_border_ID);
-                var attachments = document.getElementById("attachments_" + old_id_border).getElementsByTagName("a");			
-                for (var i = 0; i < attachments.length; i++){
-                        if((attachments[i].tagName=="SPAN") || (attachments[i].tagName=="IMG") || ((attachments[i].href.indexOf("javascript:download_local_attachment")==-1)&&(attachments[i].href.indexOf("javascript:download_attachments")==-1)))
-                                continue;
-
-                            var arrayAtt = attachments[i].href.replace("javascript:download_attachments(", "").replace(")", "").split(',');                                 
-                            var att = new Object();
-                            var regex = new RegExp( "'", "g" );
-                            att.folder = arrayAtt[0].replace(regex,"");
-                            att.uid = arrayAtt[1].replace(regex,"");
-                            att.part = arrayAtt[3].replace(regex,"");
-                            att.type = 'imapPart';
-                            var idATT = JSON.stringify(att);
-                            addAttachment( new_border_ID , idATT);  
-
-                            var attach = {};
-                            attach.fileName = arrayAtt[5].replace(regex,"");
-
-                            if(attach.fileName.length > 10)
-                                attach.fileName = attach.fileName.substr(0, 18) + "..." + attach.fileName.substr(attach.fileName.length-9, attach.fileName.length);
-
-                            attach.fileSize =  attachments[i].text.substring(( attachments[i].text.lastIndexOf('(')+1), attachments[i].text.lastIndexOf(')'));
-
-                            var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));
-                            upload.find('.status-upload').remove();
-                            upload.find('.in-progress').remove(); 
-                            upload.find('p').append('<input type="hidden" name="fileId[]" value=\''+idATT+'\'/>');
-                            fileUploadMSG.find('.attachments-list').append(upload);
-
-                }
-                $('.attachments-list').find('.button.close').button({
+                var fileUploadMSG = $('#fileupload_msg'+new_border_ID);         
+                var orignialAtt = fileUploadMSG.find('.fileupload-buttonbar').append(' <span tabindex="-1" class="message-add-original-att button small ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"><span class="icon-plus ui-button-text">Anexar arquivos originais</span></span>');
+                var attachments = document.getElementById("attachments_" + old_id_border).getElementsByTagName("a");	
+		
+                orignialAtt.find('.message-add-original-att').click(function(event ){
+                    
+                    for (var i = 0; i < attachments.length; i++){
+                            if((attachments[i].tagName=="SPAN") || (attachments[i].tagName=="IMG") || ((attachments[i].href.indexOf("javascript:download_local_attachment")==-1)&&(attachments[i].href.indexOf("javascript:download_attachments")==-1)))
+                                    continue;
+
+                                var arrayAtt = attachments[i].href.replace("javascript:download_attachments(", "").replace(")", "").split(',');                                 
+                                var att = new Object();
+                                var regex = new RegExp( "'", "g" );
+                                att.folder = arrayAtt[0].replace(regex,"");
+                                att.uid = arrayAtt[1].replace(regex,"");
+                                att.part = arrayAtt[3].replace(regex,"");
+                                att.type = 'imapPart';
+                                var idATT = JSON.stringify(att);
+                                addAttachment( new_border_ID , idATT);  
+
+                                var attach = {};
+                                attach.fileName =  attachments[i].text.substring(0, attachments[i].text.lastIndexOf('('));
+
+                                if(attach.fileName.length > 45)
+                                    attach.fileName = attach.fileName.substr(0, 32) + " ... " + attach.fileName.substr(attach.fileName.length-9, attach.fileName.length);
+
+                                attach.fileSize =  attachments[i].text.substring(( attachments[i].text.lastIndexOf('(')+1), attachments[i].text.lastIndexOf(')'));
+
+                                var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));
+                                upload.find('.status-upload').remove();
+                                upload.find('.in-progress').remove(); 
+                                upload.append('<input type="hidden" name="fileId[]" value=\''+idATT+'\'/>');
+                                upload.find('.button.close').button({
+                                        icons: {
+                                                primary: "ui-icon-close"
+                                        },
+                                        text: false
+                                        
+                                }).click(function(){
+                                        var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
+                                        var content_body = RichTextEditor.getData('body_'+new_border_ID);
+                                        var imagens = content_body.match(/<img[^>]*>/g);
+                                        var att = JSON.parse(idAttach);
+                                        if(imagens != null)
+                                        {   
+                                            for (var x = 0; x < imagens.length; x++)
+                                                if(imagens[x].indexOf('src="./inc/get_archive.php?msgFolder='+att.folder+'&amp;msgNumber='+att.uid+'&amp;indexPart='+att.part) !== -1)
+                                                    content_body = content_body.replace(imagens[x],'');
+
+                                             RichTextEditor.setData('body_'+new_border_ID,content_body);    
+                                        }       
+
+                                        fileUploadMSG.find('.attachments-list').find('input[value="'+idAttach+'"]');
+                                        delAttachment(new_border_ID,idAttach); 
+                                        $(this).parent().remove();
+                                });
+                                
+                                fileUploadMSG.find('.attachments-list').append(upload);
+
+                    }
+
+                   $(this).remove();
+                 });
+
+         }
+                
+}
+
+function addOriginalAttachments(new_border_ID,old_id_border)
+{   
+    var fileUploadMSG = $('#fileupload_msg'+new_border_ID);
+    var attachments = document.getElementById("attachments_" + old_id_border).getElementsByTagName("a");			
+    for (var i = 0; i < attachments.length; i++){
+            if((attachments[i].tagName=="SPAN") || (attachments[i].tagName=="IMG") || ((attachments[i].href.indexOf("javascript:download_local_attachment")==-1)&&(attachments[i].href.indexOf("javascript:download_attachments")==-1)))
+                    continue;
+
+                var arrayAtt = attachments[i].href.replace("javascript:download_attachments(", "").replace(")", "").split(',');                                 
+                var att = new Object();
+                var regex = new RegExp( "'", "g" );
+                att.folder = arrayAtt[0].replace(regex,"");
+                att.uid = arrayAtt[1].replace(regex,"");
+                att.part = arrayAtt[3].replace(regex,"");
+                att.type = 'imapPart';
+                var idATT = JSON.stringify(att);
+                addAttachment( new_border_ID , idATT);  
+
+                var attach = {};
+                attach.fileName =  attachments[i].text.substring(0, attachments[i].text.lastIndexOf('('));
+
+                if(attach.fileName.length > 45)
+                    attach.fileName = attach.fileName.substr(0, 32) + " ... " + attach.fileName.substr(attach.fileName.length-9, attach.fileName.length);
+
+                attach.fileSize =  attachments[i].text.substring(( attachments[i].text.lastIndexOf('(')+1), attachments[i].text.lastIndexOf(')'));
+
+                var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));
+                upload.find('.status-upload').remove();
+                upload.find('.in-progress').remove(); 
+                upload.find('.button.close').button({
                         icons: {
                                 primary: "ui-icon-close"
@@ -1977,10 +1956,26 @@
                 }).click(function(){
                         var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
+                        var content_body = RichTextEditor.getData('body_'+new_border_ID);
+                        var imagens = content_body.match(/<img[^>]*>/g);
+                        var att = JSON.parse(idAttach);
+                        if(imagens != null)
+                        {   
+                            for (var x = 0; x < imagens.length; x++)
+                                if(imagens[x].indexOf('src="./inc/get_archive.php?msgFolder='+att.folder+'&amp;msgNumber='+att.uid+'&amp;indexPart='+att.part) !== -1)
+                                    content_body = content_body.replace(imagens[x],'');
+
+                             RichTextEditor.setData('body_'+new_border_ID,content_body);    
+                        }       
+
                         fileUploadMSG.find(' .attachments-list').find('input[value="'+idAttach+'"]');
                         delAttachment(new_border_ID,idAttach); 
                         $(this).parent().remove();
                 });	
-        }
-	
+
+
+                upload.append('<input type="hidden" name="fileId[]" value=\''+idATT+'\'/>');
+                fileUploadMSG.find('.attachments-list').append(upload);
+
+    }	                
 }
 
@@ -3235,10 +3230,10 @@
 		
 		//$.ajax({ url: "../expressoCalendar/index.php", async: false});
-		$.ajax({ url: "../prototype/modules/calendar/js/calendar.date.js", async: false});
-		$.ajax({ url: "../prototype/modules/calendar/js/helpers.js", async: false});
+		$.ajax({url: "../prototype/modules/calendar/js/calendar.date.js", async: false});
+		$.ajax({url: "../prototype/modules/calendar/js/helpers.js", async: false});
 		//$.ajax({ url: "../prototype/modules/calendar/js/timezone.js", async: false});
 		//$.ajax({ url: "../prototype/modules/calendar/js/calendar.codecs.js", async: false});
-		$.ajax({ url: "../prototype/plugins/encoder/encoder.js", async: false});
-		$.ajax({ url: "../prototype/plugins/dateFormat/dateFormat.js", async: false});
+		$.ajax({url: "../prototype/plugins/encoder/encoder.js", async: false});
+		$.ajax({url: "../prototype/plugins/dateFormat/dateFormat.js", async: false});
 
 		
@@ -3576,2 +3571,15 @@
       
 });
+
+function formatBytes(bytes) {
+	if (bytes >= 1000000000) {
+		return (bytes / 1000000000).toFixed(2) + ' GB';
+	}
+	if (bytes >= 1000000) {
+		return (bytes / 1000000).toFixed(2) + ' MB';
+	}
+	if (bytes >= 1000) {
+		return (bytes / 1000).toFixed(2) + ' KB';
+	}
+	return bytes + ' B';
+};
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 5625)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 5626)
@@ -4205,19 +4205,12 @@
 				attach.fullFileName = file.name;
 				attach.fileName = file.name;
-				if(file.name.length > 10)
-					attach.fileName = file.name.substr(0, 18) + "..." + file.name.substr(file.name.length-9, file.name.length);
+				if(file.name.length > 50)
+					attach.fileName = file.name.substr(0, 32) + " ... " + file.name.substr(file.name.length-9, file.name.length);
 				attach.fileSize = formatBytes(file.size);
 				if(maxAttachmentSise && file.size > maxAttachmentSise)
 					attach.error = 'Tamanho de arquivo nao permitido!!'
-								
-				fileUploadMSG.find('.attachments-list').append(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));
-
-				if(!maxAttachmentSise || file.size < maxAttachmentSise){
-					fileUploadMSG.find('.fileinput-button.new').append(data.fileInput[0]).removeClass('new');
-					fileUploadMSG.find('.attachments-list').find('[type=file]').addClass('hidden');	
-				}else
-					fileUploadMSG.find(' .fileinput-button.new').removeClass('new');
 				
-				fileUploadMSG.find(' .attachments-list').find('.button.close').button({
+                                var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));				
+				upload.find('.button.close').button({
 					icons: {
 						primary: "ui-icon-close"
@@ -4230,4 +4223,12 @@
 					$(this).parent().remove();
 				});
+                                
+                                fileUploadMSG.find('.attachments-list').append(upload);
+
+				if(!maxAttachmentSise || file.size < maxAttachmentSise){
+					fileUploadMSG.find('.fileinput-button.new').append(data.fileInput[0]).removeClass('new');
+					fileUploadMSG.find('.attachments-list').find('[type=file]').addClass('hidden');	
+				}else
+					fileUploadMSG.find(' .fileinput-button.new').removeClass('new');
 
 		})},
@@ -4274,11 +4275,26 @@
                                                         var attach = {};
                                                         attach.fileName = att.name
+                                                        if(attach.fileName.length > 45)
+                                                                attach.fileName = attach.fileName.substr(0, 32) + " ... " + attach.fileName.substr(attach.fileName.length-9, attach.fileName.length);
+
                                                         attach.fileSize = formatBytes(onceOpenedMessages[folder_name][message_number].size);
                                                         var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));
                                                         upload.find('.status-upload').remove();
                                                         upload.find('.in-progress').remove(); 
-                                                        upload.find('p').append('<input type="hidden" name="fileId[]" value=\''+idATT+'\'/>');
-                                                        fileUploadMSG.find('.attachments-list').append(upload);
+                                                        upload.append('<input type="hidden" name="fileId[]" value=\''+idATT+'\'/>');
                                                         
+                                                        upload.find('.button.close').button({
+                                                            icons: {
+                                                                            primary: "ui-icon-close"
+                                                                    },
+                                                                    text: false
+                                                            }).click(function(){
+                                                                    var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
+                                                                    fileUploadMSG.find(' .attachments-list').find('input[value="'+idAttach+'"]');
+                                                                    delAttachment(ID,idAttach); 
+                                                                    $(this).parent().remove();
+                                                        });	
+                                                        
+                                                        fileUploadMSG.find('.attachments-list').append(upload);   
 						}
 
@@ -4287,17 +4303,4 @@
 				
 				jQuery('#message-attach-dialog').dialog('close');
-				
-				//botao fechar
-				$('.attachments-list').find('.button.close').button({
-					icons: {
-						primary: "ui-icon-close"
-					},
-					text: false
-				}).click(function(){
-					var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
-					fileUploadMSG.find(' .attachments-list').find('input[value="'+idAttach+'"]');
-                                        delAttachment(ID,idAttach); 
-					$(this).parent().remove();
-				});	
 				
 			});
