Index: trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 1808)
+++ trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 1816)
@@ -1540,9 +1540,15 @@
 
 		$tmp = array();
-		$result = array();
+		$resultMine = array();
+		$resultDefault = array();
+
+		$trash = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'];
+        	$drafts = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'];
+	        $spam = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'];
+        	$sent = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'];
 
 		if (is_array($folders_list)) {
   			reset($folders_list);
-            $this->ldap = new ldap_functions();
+            		$this->ldap = new ldap_functions();
 
 			$i = 0;
@@ -1552,10 +1558,10 @@
   				//$tmp_folder_id = explode("}", imap_utf7_decode($val->name));
   				$tmp_folder_id = explode("}", mb_convert_encoding($val->name, "ISO_8859-1", "UTF7-IMAP" ));
-                if($tmp_folder_id[1]=='INBOX'.$this->imap_delimiter.'decifradas'){
-                    //error_log('passou', 3,'/tmp/imap_get_list.log');
-                    //imap_deletemailbox($mbox_stream,imap_utf7_encode("{".$this->imap_server."}".'INBOX/decifradas'));
-                    continue;
-                }
-                $result[$i]['folder_unseen'] = $status->unseen;
+    			        if($tmp_folder_id[1]=='INBOX'.$this->imap_delimiter.'decifradas') {
+		        	        //error_log('passou', 3,'/tmp/imap_get_list.log');
+                			//imap_deletemailbox($mbox_stream,imap_utf7_encode("{".$this->imap_server."}".'INBOX/decifradas'));
+		                	continue;
+		                }
+		                $result[$i]['folder_unseen'] = $status->unseen;
   				$folder_id = $tmp_folder_id[1];
 				$result[$i]['folder_id'] = $folder_id;
@@ -1564,7 +1570,7 @@
 				$result[$i]['folder_name'] = array_pop($tmp_folder_parent);
 				$result[$i]['folder_name'] = $result[$i]['folder_name'] == 'INBOX' ? 'Inbox' : $result[$i]['folder_name'];
-				if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($folder_id,0,4) == 'user')	{
+				if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($folder_id,0,4) == 'user') {
 					//$this->ldap = new ldap_functions();
-					if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])){
+					if ($cn = $this->ldap->uid2cn($result[$i]['folder_name'])) {
 						$result[$i]['folder_name'] = $cn;
 					}
@@ -1579,9 +1585,21 @@
 					$result[$i]['folder_hasChildren'] = 0;
 
+				switch ($tmp_folder_id[1]) {
+					case 'INBOX':
+					case 'INBOX/'.$trash:
+					case 'INBOX/'.$sent:
+					case 'INBOX/'.$drafts:
+					case 'INBOX/'.$spam:
+                		   		$resultDefault[]=$result[$i];
+					default:
+                				$resultMine[]=$result[$i];
+				}
+
 				$i++;
   			}
 		}
 
-		foreach ($result as $folder_info)
+		// Sorting resultMine
+		foreach ($resultMine as $folder_info)
 		{
 			$array_tmp[] = $folder_info['folder_id'];
@@ -1592,7 +1610,52 @@
 		foreach ($array_tmp as $key => $folder_id)
 		{
-			$result2[] = $result[$key];
-		}
-
+			$result2[] = $resultMine[$key];
+		}
+		
+		$resultDefault2=$resultDefault;
+		// Sorting resultDefault
+		foreach ($resultDefault as $key => $folder_id)
+		{
+
+			switch ($resultDefault[$key]['folder_id']) {
+				case 'INBOX': 
+					$resultDefault2[0] = $resultDefault[$key];
+					break;
+				case 'INBOX/'.$sent: 
+					$resultDefault2[1] = $resultDefault[$key];
+					break;
+				case 'INBOX/'.$drafts: 
+					$resultDefault2[2] = $resultDefault[$key];
+					break;
+				case 'INBOX/'.$spam: 
+					$resultDefault2[3] = $resultDefault[$key];
+					break;
+				case 'INBOX/'.$trash: 
+					$resultDefault2[4] = $resultDefault[$key];
+					break;
+			}
+
+/*
+			if($resultDefault[$key]['folder_id'] == 'INBOX') {
+				$resultDefault2[0] = $resultDefault[$key];
+			}
+			else if($resultDefault[$key]['folder_id'] == 'INBOX/'.$sent) {
+				$resultDefault2[1] = $resultDefault[$key];
+			}
+			else if($resultDefault[$key]['folder_id'] == 'INBOX/'.$drafts) {
+				$resultDefault2[2] = $resultDefault[$key];
+			}
+			else if($resultDefault[$key]['folder_id'] == 'INBOX/'.$spam) {
+				$resultDefault2[3] = $resultDefault[$key];
+			}
+			else if($resultDefault[$key]['folder_id'] == 'INBOX/'.$trash) {
+				$resultDefault2[4] = $resultDefault[$key];
+			}
+*/
+		}
+
+		// Merge default folders and mines
+		$result2 = array_merge($resultDefault2, $result2);
+		
 		$current_folder = "INBOX";
 		if($params && $params['folder'])
