Index: /sandbox/expressoServiceImap/prototype/modules/attach_message/attach_message.js
===================================================================
--- /sandbox/expressoServiceImap/prototype/modules/attach_message/attach_message.js	(revision 6486)
+++ /sandbox/expressoServiceImap/prototype/modules/attach_message/attach_message.js	(revision 6509)
@@ -1,131 +1,3 @@
-// $.storage = new $.store();
- 
-isOffline = /[A-z0-9-_\/\.]*:offline\?(.*)/;
-breakParams = /[&=]/;
-dots = /\./gi;
-dashes = /\//gi;
-flags = [ 'Attachment', 'Forwarded' ,'Recent', 'Unseen',  'Answered',  'Draft',  'Deleted', 'Flagged', 'Followupflag', 'Label' ];
-months = ['Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec'];
-
 var BASE_PATH = '../prototype/';
-//BASE_PATH = '../';
-//encontra os pais de todas as pastas e cria uma nova estrutura adicionando os filhos a um array no atributo 'children' do respectivo pai
-unorphanize = function(root, element) {
-	var ok = false;
-	for (var i=0; i<root.length; i++) {
-		if (root[i].id == element.parentFolder) {
-			element.children = new Array(); 
-			root[i].children.push(element);
-			return true;
-		} else if (ok = unorphanize(root[i].children, element)) {
-			break;
-		}
-	}
-
-	return ok;
-}
-
-/* --- helpers --- */
-bytes2Size = function(bytes) {
-	var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
-	if (bytes == 0) return 'n/a';
-	var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
-	var size = (i<2) ? Math.round((bytes / Math.pow(1024, i))) : Math.round((bytes / Math.pow(1024, i)) * 100)/100;
-	return  size + ' ' + sizes[i];
-}
-
-flags2Class = function(cellvalue, options, rowObject) {
-	var classes = '';	
-	cellvalue = cellvalue.split(',');
-	cell = {
-			Unseen: parseInt(cellvalue[0])  ? 'Unseen' : 'Seen', 
-			Answered: parseInt(cellvalue[1]) ? 'Answered' : (parseInt(cellvalue[2]) ? 'Forwarded' : ''), 
-			Flagged: parseInt(cellvalue[3]) ? 'Flagged' : '',
-			Recent: parseInt(cellvalue[4])  ? 'Recent' : '', 			
-			Draft: parseInt(cellvalue[5]) ? 'Draft' : ''		
-		};
-	for(var flag in cell){
-		classes += '<span class="flags '+ (cell[flag]).toLowerCase() + '"' + (cell[flag] != "" ? 'title="'+ get_lang(cell[flag])+'"' : '')+'> </span>';	
-	}
-	if(rowObject.labels){	
-		var titles = [];
-		var count = 0;
-		 for(i in rowObject.labels){
-			titles[count] = " "+rowObject.labels[i].name;
-			count++;
-		}
-		titles = titles.join();
-		classes += '<span class="flags labeled" title="'+titles+'"> </span>';
-	}else{
-		classes += '<span class="flags"> </span>';
-	}
-	
-	if(rowObject.followupflagged){		
-		if(rowObject.followupflagged.followupflag.id < 7){
-			var nameFollowupflag = get_lang(rowObject.followupflagged.followupflag.name);
-		}else{
-			var nameFollowupflag = rowObject.followupflagged.followupflag.name;
-		}
-		if(rowObject.followupflagged.isDone == 1){
-			classes += '<span class="flags followupflagged" title="'+nameFollowupflag+'" style="background:'+rowObject.followupflagged.backgroundColor+';"><img style=" margin-left:-3px;" src="../prototype/modules/mail/img/flagChecked.png"></span>';
-		}else{			
-			classes += '<span class="flags followupflagged" title="'+nameFollowupflag+'" style="background:'+rowObject.followupflagged.backgroundColor+';"><img src="../prototype/modules/mail/img/flagEditor.png"></span>';
-		}
-		
-	}
-
-	return classes;
-}
-
-NormaliseFrom = function(cellvalue, options, rowObject) {
-	rowObject['flags'] = rowObject['flags'].split(",");
-	if(rowObject['flags'][rowObject['flags'].length-1] ==  1){
-		return get_lang(special_folders["Drafts"]);
-	}
-	return cellvalue;	
-}
-
-NormaliseSubject = function(cellvalue, options, rowObject) {
-	return html_entities(cellvalue);
-}
-
-date2Time = function (timestamp) {
-	date = new Date();
-	if( typeof timestamp === "string" )
-	    timestamp = parseInt( timestamp, 10 );
-	dat = new Date(timestamp);
-	if ((date.getTime() - timestamp) < (24*60*60*1000)) {
-		return '<span class="timable" title="'+dat.getTime()+'"></span>';
-	} else {
-		date = new Date(timestamp);
-		if(is_ie){
-			var b = date.toString().split(' ');
-			var c = b[2] + "/" + months.indexOf(b[1]) + "/" + b[5];
-			return '<span class="datable">' + c + '</span>';
-		}else{
-			var b = date.toISOString().split("T")[0].split("-");
-			var c = b[2] + "/" + b[1] + "/" + b[0];
-			return '<span class="datable">' + c + '</span>';
-		}
-	}
-}
-
-changeTabIndex = function (elements) {
-//	jQuery('#foldertree').attr('tabIndex', '1').focus();
-}
-
-selectedMessagesCount = function() {
-	var byte_size = 0, total_messages = 0;
-	for (var folder in selectedMessages) {
-		for (var message in selectedMessages[folder]) {
-			if (selectedMessages[folder][message]) {
-				byte_size += parseInt(onceOpenedMessages[folder][message].size);
-				total_messages++;
-			}
-		}
-	}
-	$("#selected_messages_number").html(total_messages).next().html(bytes2Size(byte_size));
-	return total_messages;
-}
 
 var msgAttacherGrid = $("#message_attacher_grid"), msgsTotal = $("#selected_messages_number");
Index: /sandbox/expressoServiceImap/expressoMail1_2/index.php
===================================================================
--- /sandbox/expressoServiceImap/expressoMail1_2/index.php	(revision 6237)
+++ /sandbox/expressoServiceImap/expressoMail1_2/index.php	(revision 6509)
@@ -29,19 +29,20 @@
 		<link rel="stylesheet" type="text/css" href="../prototype/plugins/fullcalendar/fullcalendar.print.css"></link>
 		<link rel="stylesheet" type="text/css" href="../prototype/plugins/icalendar/jquery.icalendar.css"></link>
-		
-		<script type="text/javascript" src="../prototype/plugins/jquery/jquery.min.js"></script>
 		<link href="../prototype/modules/filters/filters.css" rel="stylesheet" type="text/css">
-		<script type="text/javascript" src="../prototype/plugins/jquery/jquery-ui.min.js"></script>
-		<script src="../prototype/plugins/json2/json2.js" language="javascript"></script>
-		<script src="../prototype/plugins/ejs/ejs.js" language="javascript"></script>
-		<script src="../prototype/plugins/store/jquery.store.js" language="javascript"></script>
-		<script src="../prototype/plugins/farbtastic/farbtastic.js" language="javascript"></script>
-		<script src="../prototype/api/datalayer.js" language="javascript"></script>					
-		<script type="text/javascript" src="../prototype/plugins/scrollto/jquery.scrollTo.js"></script>
+
+		<script language="javascript" src="../prototype/plugins/jquery/jquery.min.js"></script>
+		<script language="javascript" src="../prototype/plugins/jquery/jquery-ui.min.js"></script>
+		<script language="javascript" src="../prototype/plugins/json2/json2.js"></script>
+		<script language="javascript" src="../prototype/plugins/ejs/ejs.js"></script>
+		<script language="javascript" src="../prototype/plugins/store/jquery.store.js"></script>
+		<script language="javascript" src="../prototype/plugins/farbtastic/farbtastic.js"></script>
+		<script language="javascript" src="../prototype/api/datalayer.js"></script>					
+		<script language="javascript" src="../prototype/plugins/scrollto/jquery.scrollTo.js"></script>
 		<script language="javascript">DataLayer.dispatchPath = "../prototype/";</script>					
-		<script src="../library/ckeditor/ckeditor.js" language="javascript" charset="utf-8"></script> 
-		<script src="../library/ckeditor/adapters/jquery.js" language="javascript"></script> 
-		<script src="../prototype/plugins/lazy/jquery.lazy.js" language="javascript"></script> 
-		
+		<script language="javascript" src="../library/ckeditor/ckeditor.js" charset="utf-8"></script> 
+		<script language="javascript" src="../library/ckeditor/adapters/jquery.js"></script> 
+		<script language="javascript" src="../prototype/plugins/lazy/jquery.lazy.js"></script> 
+		<script language="javascript" src="../prototype/modules/attach_message/common.js"></script>
+
 		<link rel="Stylesheet" type="text/css" href="../prototype/plugins/jquery/jquery-ui.css" />					
 		
@@ -68,5 +69,5 @@
 		
 		<script type="text/javascript" src="../prototype/modules/calendar/js/timezone.js"></script>
-        <script type="text/javascript" src="../prototype/plugins/dateFormat/dateFormat.js"></script>
+		<script type="text/javascript" src="../prototype/plugins/dateFormat/dateFormat.js"></script>
 		<script type="text/javascript" src="../prototype/modules/calendar/js/calendar.date.js"></script>
 		<script type="text/javascript" src="../prototype/modules/calendar/js/calendar.codecs.js"></script>
Index: /sandbox/expressoServiceImap/expressoMail1_2/js/draw_api.js
===================================================================
--- /sandbox/expressoServiceImap/expressoMail1_2/js/draw_api.js	(revision 6486)
+++ /sandbox/expressoServiceImap/expressoMail1_2/js/draw_api.js	(revision 6509)
@@ -3885,91 +3885,4 @@
 		})
 	});
-	
-	DataLayer.codec( 'folder', 'tree', {
-
-		    encoder: function( data ){
-		
-			if( preferences.use_local_messages == 1 || expresso_offline)
-			{
-			    var folders = expresso_local_messages.list_local_folders();
-			    
-			    var stripParents = /^(.*)\/([^\/]*)/;
-
-			    $.each( folders, function( i, folder ){
-				    
-				    if(typeof(folder) == 'undefined')  return;
-				      
-				    var id = 'local_messages/' + folder[0];
-
-				    var parts = stripParents.exec( id );
-				
-				    data[data.length] = { 'id' : id,
-							  'commonName' : parts[2],
-							  'parentFolder' : parts[1] };
-			    });
-			}
-
-			var trees = [[],[],[]],
-
-			root = { inbox: /^INBOX/, share: /^user/, local: /^local_messages/ };
-
-			for (var i = 0; i < data.length; i++ )
-			{
-			    var index = root.inbox.test(data[i].id) ? 0 :
-					root.share.test(data[i].id) ? 1 :
-					root.local.test(data[i].id) ? 2 :
-					'false';
-
-			    if( isNaN(index) ) continue;
-
-			    if (!unorphanize(trees[index], data[i]))
-			    {
-				data[i].children = [];
-				trees[index].push(data[i]);
-			    }
-			}
-
-			return( { folders: trees } );
-		    }
-	    } );
-
-	    current_folder = 'INBOX';
-
-	    DataLayer.codec( 'message', 'jqGrid', {
-
-		  encoder: function( data, crit ){
-
-			if( !crit.criteria.properties.context.folder.indexOf( 'local_messages/' ) )
-			{
-			    var msgs = expresso_local_messages.get_local_range_msgs( crit.criteria.properties.context.folder.replace(dots, "/").replace("local_messages/", ""),
-										      crit.offset + 1, crit.limit, "SORTARRIVAL", crit.orderDesc, "ALL", 1, 1 );
-
-			    for( var i = 0; i < msgs.length; i++ )
-			    {
-				  msgs[i].size = msgs[i].Size;
-				  msgs[i].timestamp = msgs[i].udate * 1000;
-				  msgs[i].flags = [];
-
-				  for( var ii = 0; ii < flags.length; ii++ )
-				      if( f = $.trim( msgs[i][ flags[ii] ] ) )
-					  msgs[i].flags[ msgs[i].flags.length ] =  f;
-
-				  msgs[i].flags = msgs[i].flags.join(',');
-			    }
-
-			    return( {"rows": msgs, 
-				      "records": msgs.length,
-				      "page": crit.page, 
-				      "total": Math.ceil( msgs.num_msgs / crit.limit )} );
-			}
-
-			return( data );
-		  },
-		  criteria: function( crit ){
-
-			return { criteria: { properties: {context:{folder: current_folder || 'INBOX'}}, offset: crit.rows * ( crit.page - 1 ), limit: crit.rows, orderDesc: crit.sord == "desc" } };
-
-		  }
-	    });
 
 	return ID;
