Index: /branches/2.3/expressoMail1_2/js/draw_api.js
===================================================================
--- /branches/2.3/expressoMail1_2/js/draw_api.js	(revision 6518)
+++ /branches/2.3/expressoMail1_2/js/draw_api.js	(revision 6957)
@@ -438,4 +438,11 @@
 // Action on change folders.
 function change_folder(folder, folder_name){
+    
+         if(sort_box_type == 'SORTFROM' && preferences.from_to_sent == "1" && folder.indexOf(preferences.save_in_folder) !=-1 )
+             sort_box_type = 'SORTTO';
+         
+         if(sort_box_type == 'SORTTO' && folder.indexOf(preferences.save_in_folder) == -1)
+             sort_box_type = 'SORTFROM';
+        
 	if (openTab.imapBox[0] != folder)
 	{
@@ -997,10 +1004,15 @@
 
 		td_element1.appendChild(chk_box_element);
-
-		td_element2 = createTDElement(0,1);
-		td_element3 = createTDElement(0,7,"th_resizable","left","message_header_SORTFROM_"+numBox);
-		td_element3.onclick = function () {sort_box(search_box_type,'SORTFROM');};
-		td_element3.innerHTML = get_lang("Who");
-
+                if(preferences.from_to_sent == "1" && msg_folder.indexOf(preferences.save_in_folder) !=-1 ){
+                    td_element2 = createTDElement(0,1);
+                    td_element3 = createTDElement(0,7,"th_resizable","left","message_header_SORTTO_"+numBox);
+                    td_element3.onclick = function () {sort_box(search_box_type,'SORTTO');};
+                    td_element3.innerHTML = get_lang("Who");
+                }else{    
+                    td_element2 = createTDElement(0,1);
+                    td_element3 = createTDElement(0,7,"th_resizable","left","message_header_SORTFROM_"+numBox);
+                    td_element3.onclick = function () {sort_box(search_box_type,'SORTFROM');};
+                    td_element3.innerHTML = get_lang("Who");
+                }
 		td_element4 = createTDElement(0,8,"th_resizable","left","message_header_SORTSUBJECT_"+numBox);
 		td_element4.onclick = function () {sort_box(search_box_type,'SORTSUBJECT');};
@@ -1346,9 +1358,9 @@
 		td_element3.innerHTML = '&nbsp;';
 
-		test = true;
-		if(msg_folder.indexOf(sentfolder) !=-1 ||msg_folder.indexOf(preferences.save_in_folder) !=-1 || msg_folder.replace("local_","INBOX/").indexOf(preferences.save_in_folder) !=-1)
-		    test = false;
-
-		if(headers_msgs.from.email.toLowerCase() == Element("user_email").value.toLowerCase() && !(preferences.from_to_sent == "1" && test) && !(msg_folder.substr(0,5) == "user/"))
+		var isSentFolder = false;
+                if(msg_folder.indexOf(sentfolder) !=-1 ||msg_folder.indexOf(preferences.save_in_folder) !=-1 || msg_folder.replace("local_","INBOX/").indexOf(preferences.save_in_folder) !=-1)
+		    isSentFolder = true;
+
+		if((preferences.from_to_sent == "1" && isSentFolder) || (preferences.from_to_sent == "0" && headers_msgs.from.email.toLowerCase() == Element("user_email").value.toLowerCase() && !(msg_folder.substr(0,5) == "user/")))
 		{
 			td_element3.onmouseover = function () {this.title=headers_msgs.to.email;};
@@ -1356,5 +1368,5 @@
 				td_element3.innerHTML += "<span style=\"color:red\">("+get_lang("Draft")+") </span>";
 			else{
-				if(headers_msgs.to.email != null && headers_msgs.to.email.toLowerCase() != Element("user_email").value)
+				if(headers_msgs.to.email != null  && headers_msgs.from.email.toLowerCase() == Element("user_email").value.toLowerCase())
 					td_element24.innerHTML = "<img valign='center' src ='templates/"+template+"/images/sent.gif' title='"+get_lang('Sent')+"'>";
 
@@ -1499,5 +1511,5 @@
 	}
 	else if(sort_box_type != sort){
-		if ( (sort == 'SORTFROM') || (sort == 'SORTSUBJECT') )
+		if ( (sort == 'SORTFROM') || (sort == 'SORTSUBJECT') || (sort == 'SORTTO'))
 			sort_box_reverse = 0;
 		else
@@ -1517,4 +1529,7 @@
 	switch(sort_box_type){
 		case 'SORTFROM':
+                        type_name = get_lang("Who");
+			break;
+                case 'SORTTO':   
 			type_name = get_lang("Who");
 			break;
@@ -1532,5 +1547,8 @@
 			break;
 	}
-	document.getElementById("message_header_SORTFROM_"+numBox).innerHTML 	= get_lang("Who");
+        if(document.getElementById("message_header_SORTFROM_"+numBox))
+            document.getElementById("message_header_SORTFROM_"+numBox).innerHTML = get_lang("Who");
+        else
+            document.getElementById("message_header_SORTTO_"+numBox).innerHTML 	= get_lang("Who");
 	document.getElementById("message_header_SORTSUBJECT_"+numBox).innerHTML = get_lang("Subject");
 	document.getElementById("message_header_SORTARRIVAL_"+numBox).innerHTML = get_lang("Date");
