Index: branches/2.2.0.1/expressoMail1_2/js/search.js
===================================================================
--- branches/2.2.0.1/expressoMail1_2/js/search.js	(revision 4640)
+++ branches/2.2.0.1/expressoMail1_2/js/search.js	(revision 4650)
@@ -292,5 +292,6 @@
 		var sort_type	= sortType;
 
-		
+		var is_local = border_id.match('.*_local_.*');
+
 		var args   = "$this.imap_functions.search_msg";
 		var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type="+sort_type;
@@ -302,5 +303,5 @@
     		var local_folders	= [];
 
-    		if ( preferences.use_local_messages == 1 )
+    		if ( preferences.use_local_messages == 1 && is_local)
     		{
     			temp = expresso_local_messages.list_local_folders();
@@ -312,13 +313,20 @@
 
     		
-    			if ( local_folders.length > 0 )
-    				gears = expresso_local_messages.search( local_folders, expresso_local_messages.getFilter() );
+    			if ( local_folders.length > 0 ){
+                            expresso_local_messages.setSortType(sortType);
+                            gears = expresso_local_messages.search( local_folders, expresso_local_messages.getFilter() );
+                        }
     		}
         	
-        	if( data['num_msgs'] )
+        	if( data['num_msgs'])
             {
             	allMsg['data'] 				= data['data'];
             	allMsg['num_msgs']			= data['num_msgs'];
-            	allMsg['gears_num_msgs'] 	= gears.length;
+                
+            }
+
+            if (gears.length > 0)
+            {
+                allMsg['data_gears']                    = gears;
             }
         	
@@ -327,5 +335,13 @@
 			EsearchE.mount_result( allMsg , sort_type ); 
 		};
-		cExecute(args,handler,params);
+
+                if (is_local)
+                {
+                    eval("handler('none')");
+                }
+                else
+                {
+                    cExecute(args,handler,params);
+                }
 	}
 	
@@ -354,5 +370,5 @@
         	write_msg( data['num_msgs'] + " " + get_lang("results found") );
 			
-			EsearchE.mount_result( data );
+			EsearchE.mount_result( data, 'SORTDATE' );
 		}
 	}
@@ -669,5 +685,6 @@
 			else
 			{
-				td_element1.innerHTML	= "<b>"+get_lang("Folder")+"</b>";
+                                td_element1.onclick		= function(){ EsearchE.searchFor(border_id, 'SORTBOX_REVERSE'); };
+				td_element1.innerHTML	= "<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 			}
 		}
@@ -680,5 +697,5 @@
 			else
 			{
-				//alert('Ordenando localMessage');
+				td_element1.onclick		= function(){ EsearchE.searchFor(border_id, 'SORTBOX'); };
 			}
 			td_element1.innerHTML	= ( sort_type == 'SORTBOX_REVERSE' ) ? arrow_ascendant(get_lang("Folder")) : get_lang("Folder");
@@ -697,5 +714,6 @@
 			else
 			{
-				td_element2.innerHTML	= "<b>"+get_lang("who")+"</b>";
+                                td_element2.onclick		= function(){ EsearchE.searchFor(border_id, 'SORTWHO_REVERSE'); };
+				td_element2.innerHTML	= "<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 			}
 		}
@@ -708,5 +726,5 @@
 			else
 			{
-				//alert('Ordenando localMessage');
+				td_element2.onclick		= function(){ EsearchE.searchFor(border_id, 'SORTWHO'); };
 			}
 			td_element2.innerHTML	= ( sort_type == 'SORTWHO_REVERSE' ) ? arrow_ascendant(get_lang("who")) : get_lang("who");
@@ -725,5 +743,6 @@
 			else
 			{
-				td_element3.innerHTML	= "<b>"+get_lang("subject")+"</b>";
+                                td_element3.onclick		= function(){ EsearchE.searchFor(border_id, 'SORTSUBJECT_REVERSE'); };
+				td_element3.innerHTML	= "<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 			}
 		}
@@ -736,5 +755,5 @@
 			else
 			{
-				//alert('Ordenando localMessage');
+				td_element3.onclick		= function(){ EsearchE.searchFor(border_id, 'SORTSUBJECT'); };
 			}
 			td_element3.innerHTML	= ( sort_type == 'SORTSUBJECT_REVERSE' ) ? arrow_ascendant(get_lang("subject")) : get_lang("subject");
@@ -753,5 +772,6 @@
 			else
 			{
-				td_element4.innerHTML	= "<b>"+get_lang("Date")+"</b>";
+                                td_element4.onclick		= function(){ EsearchE.searchFor(border_id, 'SORTDATE_REVERSE'); };
+				td_element4.innerHTML	= "<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 			}
 		}
@@ -764,5 +784,5 @@
 			else
 			{
-				//alert('Ordenando localMessage');
+				td_element4.onclick		= function(){ EsearchE.searchFor(border_id, 'SORTDATE'); };
 			}
 			td_element4.innerHTML	= ( sort_type == 'SORTDATE_REVERSE' ) ? arrow_ascendant(get_lang("Date")) : get_lang("Date");
@@ -781,5 +801,6 @@
 			else
 			{
-				td_element5.innerHTML	= "<b>"+get_lang("size")+"</b>";
+                                td_element5.onclick		= function(){ EsearchE.searchFor(border_id, 'SORTSIZE_REVERSE'); };
+				td_element5.innerHTML	= "<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 			}
 		}
@@ -792,5 +813,5 @@
 			else
 			{
-				//alert('Ordenando localMessage');
+				td_element5.onclick		= function(){ EsearchE.searchFor(border_id, 'SORTSIZE'); };
 			}
 			td_element5.innerHTML	= ( sort_type == 'SORTSIZE_REVERSE' ) ? arrow_ascendant(get_lang("size")) : get_lang("size");
@@ -1121,6 +1142,8 @@
 
 			// Gears - local
-			if ( local_folders.length > 0 )
-				tmp = expresso_local_messages.search( local_folders, fields );
+			if ( local_folders.length > 0 ){
+                            expresso_local_messages.setSortType('SORTDATE');
+                            tmp = expresso_local_messages.search( local_folders, fields );
+                        }
 
             if( data['num_msgs'] )
Index: branches/2.2.0.1/expressoMail1_2/js/local_messages.js
===================================================================
--- branches/2.2.0.1/expressoMail1_2/js/local_messages.js	(revision 4647)
+++ branches/2.2.0.1/expressoMail1_2/js/local_messages.js	(revision 4650)
@@ -8,4 +8,5 @@
     this.store = null;
     this.filterSerch = "";
+    this.sortType = "";
 }
 
@@ -118,5 +119,5 @@
 
 }
-        
+
 local_messages.prototype.installGears = function (){
     temp = confirm(get_lang("To use local messages you have to install google gears. Would you like to install it now?"));
@@ -926,4 +927,16 @@
 }
 
+local_messages.prototype.setSortType = function (sortType){
+    this.sortType = sortType;
+}
+
+local_messages.prototype.getSortType = function (){
+    if (this.sortType == "")
+    {
+        return 'SORTDATE';
+    }
+    return this.sortType;
+}
+
 local_messages.prototype.search = function(folders,sFilter) {
     this.init_local_messages();
@@ -1003,4 +1016,24 @@
     }
     sql += ")";
+
+    // Sort
+    if (this.getSortType().match('^SORTDATE.*')){
+        sql += " order by mail.timestamp";
+    }
+    else if (this.getSortType().match('^SORTWHO.*')){
+        sql += " order by mail.ffrom";
+    }
+    else if (this.getSortType().match('^SORTSUBJECT.*')){
+        sql += " order by mail.subject";
+    }
+    else if (this.getSortType().match('^SORTSIZE.*')){
+        sql += " order by mail.size";
+    }
+    else if (this.getSortType().match('^SORTBOX.*')){
+        sql += " order by folder.folder";
+    }
+
+    sql += this.getSortType().match('^.*_REVERSE$') ? ' asc' : ' desc';
+
     var rs = this.dbGears.execute(sql);
     var retorno = [];
