Index: sandbox/newExpressoMail/prototype/services/ImapServiceAdapter.php
===================================================================
--- sandbox/newExpressoMail/prototype/services/ImapServiceAdapter.php	(revision 7209)
+++ sandbox/newExpressoMail/prototype/services/ImapServiceAdapter.php	(revision 7265)
@@ -76,6 +76,9 @@
 			case 'folder':
 			{
-				
-				$result = $this->getFolders();
+
+                if($context != '')
+                    $result = $this->getFolderInfo($context['folder']);
+                else
+                    $result = $this->getFolders();
 
 				foreach ($result as $res) {
@@ -86,5 +89,5 @@
 							'commonName' => mb_convert_encoding( $res['folder_name'], 'UTF-8' , 'UTF7-IMAP' ),
 							'parentFolder' => mb_convert_encoding( $res['folder_parent'], 'UTF-8' , 'UTF7-IMAP' ),
-							'messageCount' => array('unseen' => isset($res['folder_unseen']) ? $res['folder_unseen'] : null, 'total' => null)
+							'messageCount' => array('unseen' => isset($res['folder_unseen']) ? $res['folder_unseen'] : null, 'total' => $res['folder_total'])
 					);
 
@@ -104,9 +107,10 @@
 				$limit = isset($criteria['rows']) ? $criteria['rows'] : 10 ; //{10}   get how many rows we want to have into the grid
 				$sidx  = isset($criteria['sidx']) ? $criteria['sidx'] : 0; //{id}   get index row - i.e. user click to sort
-				$sord  = isset($criteria['sord']) ? $criteria['sord'] : ''; //{desc} get the direction
+				$sord  = $criteria['sord'] == "asc"? "0" : '1'; //{desc} get the direction
+                //$flag = $criteria['_search'] ? $criteria['_search'] : 'ALL';
 
 				$filter =  isset($criteria['filter']) ? $criteria['filter'] : '';
 
-				if( !$sidx ) $sidx = 1;
+				if( !$sidx ) $sidx = 'SORTARRIVAL';
 
 				$folder_name =  isset($URI['folder']) ?  $URI['folder'] : str_replace( '.', $this->imap_delimiter, isset($context['folder']) ?  $context['folder'] : 'INBOX');
@@ -207,7 +211,7 @@
 							'msg_range_begin' => $start + 1, //??
 							'msg_range_end' => $start + $limit, //$limit = $_GET['rows']; // get how many rows we want to have into the grid
-							'sort_box_type' => 'SORTARRIVAL', 
+							'sort_box_type' => $sidx,
 							'search_box_type' => 'ALL',
-							'sort_box_reverse' => 1 
+							'sort_box_reverse' => $sord
 						) 
 					);
@@ -698,6 +702,20 @@
 			case 'folder':
 			{
-
-			}
+                $mbox_stream = $this->open_mbox();
+                $path = ($data['path'] != "" ? $data['path'] : "INBOX") .$this->imap_delimiter;
+                $folders = explode($this->imap_delimiter,$data['name']);
+                $return = true;
+                for($i =0; $i < count($folders); $i++){
+                    $path .= $folders[$i] != "" ? $folders[$i] : 'Nova Pasta';
+                    $newFolder = mb_convert_encoding($path, "UTF7-IMAP","UTF-8");
+                    $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$newFolder;
+                    if(imap_createmailbox($mbox_stream,$serverString))
+                    {
+                        $return = false;
+                    }
+                    $path .= $this->imap_delimiter;
+                }
+                return $return;
+            }
 		}
 	}
@@ -790,7 +808,17 @@
 						break;
 				}
-				
 				return $s;
 			}
+            case 'folder':{
+                $newFolder = mb_convert_encoding($URI['id'], "UTF7-IMAP","UTF-8");
+                $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$newFolder;
+                $mbox_stream = $this->open_mbox();
+                if(imap_deletemailbox($mbox_stream,$serverString))
+                {
+                    return true;
+                }else{
+                    return false;
+                }
+            }
 		}
 
@@ -822,4 +850,20 @@
 		 * atributos gravados no banco de dados e nunca no IMAP.
 		 */
+        switch( $URI['concept'] )
+        {
+            case 'folder':
+            {
+                $mbox_stream = $this->open_mbox();
+                $oldFolderName = mb_convert_encoding($data['id'], "UTF7-IMAP","UTF-8");
+                $newFolderName = mb_convert_encoding($data['new'], "UTF7-IMAP","UTF-8");
+                $serverString = "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}";
+                if(imap_renamemailbox($mbox_stream,$serverString.$oldFolderName, $serverString.$newFolderName))
+                {
+                    return true;
+                }else{
+                    return false;
+                }
+            }
+        }
 	}
 
