Index: sandbox/webservice/api/Errors.php
===================================================================
--- sandbox/webservice/api/Errors.php	(revision 6150)
+++ sandbox/webservice/api/Errors.php	(revision 6155)
@@ -28,8 +28,16 @@
 	
 
-	const CATALOG_MIN_ARGUMENT_SEARCH	= "1001";	
-	const MAIL_NOT_SENT					= "1002";
-	const MAIL_TRASH_NOT_CLEANED		= "1003";
-	const MAIL_MESSAGE_NOT_FOUND		= "1004";
+	const CATALOG_MIN_ARGUMENT_SEARCH		= "1001";
+	const MAIL_NOT_SENT						= "1002";
+	const MAIL_TRASH_NOT_CLEANED			= "1003";
+	const MAIL_MESSAGE_NOT_FOUND			= "1004";
+	const MAIL_INVALID_NEW_FOLDER_NAME		= "1005";
+	const MAIL_INVALID_OLD_FOLDER			= "1006";
+	const MAIL_INVALID_FOLDER				= "1007";
+	const MAIL_CANNOT_DEL_DEFAULT_FOLDER	= "1008";
+	const MAIL_FOLDER_NOT_EMPTY				= "1009";
+	const MAIL_FOLDER_NOT_RENAMED			= "1010";
+	const MAIL_FOLDER_NOT_ADDED				= "1011";
+	const MAIL_FOLDER_NOT_DELETED			= "1012";
 	
 	static private $reservedErrors = array (			
@@ -47,19 +55,27 @@
 	static private $applicationErrors = array(			
 
-		self::LOGIN_SUCCESS_LOGOUT 			=> "You have been successfully logged out",
-		self::LOGIN_SESSION_EXPIRED 		=> "Sorry, your login has expired",
-		self::LOGIN_NOT_LOGGED_IN 			=> "You are not logged in",
-		self::LOGIN_COOKIES_REQUIRED 		=> "Cookies are required to login to this site.",
-		self::LOGIN_BADLOGIN 				=> "bad login or password",
-		self::LOGIN_PASSWORD_EXPIRED 		=> "Your password has expired, and you do not have access to change it",
-		self::LOGIN_AUTH_INVALID			=> "Your auth is invalid",
-		self::LOGIN_SESSION_NOT_VERIFIED	=> "Your session could not be verified.",
-		self::LOGIN_ACCOUNT_EXPIRED 		=> "Account is expired",
-		self::LOGIN_LOGIN_BLOCKED			=> "Blocked, too many attempts!",
-		self::LOGIN_INVALID_LOGIN			=> "Bad login or password",
-		self::CATALOG_MIN_ARGUMENT_SEARCH	=> "Your search argument must be longer than %1 characters.",
-		self::MAIL_NOT_SENT					=> "Your mail could not be sent.",
-		self::MAIL_TRASH_NOT_CLEANED		=> "Your trash folder could not be cleaned.",
-		self::MAIL_MESSAGE_NOT_FOUND		=> "Message not found in folder %1."
+		self::LOGIN_SUCCESS_LOGOUT				=> "You have been successfully logged out",
+		self::LOGIN_SESSION_EXPIRED				=> "Sorry, your login has expired",
+		self::LOGIN_NOT_LOGGED_IN				=> "You are not logged in",
+		self::LOGIN_COOKIES_REQUIRED			=> "Cookies are required to login to this site.",
+		self::LOGIN_BADLOGIN					=> "bad login or password",
+		self::LOGIN_PASSWORD_EXPIRED	 		=> "Your password has expired, and you do not have access to change it",
+		self::LOGIN_AUTH_INVALID				=> "Your auth is invalid",
+		self::LOGIN_SESSION_NOT_VERIFIED		=> "Your session could not be verified.",
+		self::LOGIN_ACCOUNT_EXPIRED				=> "Account is expired",
+		self::LOGIN_LOGIN_BLOCKED				=> "Blocked, too many attempts!",
+		self::LOGIN_INVALID_LOGIN				=> "Bad login or password",
+		self::CATALOG_MIN_ARGUMENT_SEARCH		=> "Your search argument must be longer than %1 characters.",
+		self::MAIL_NOT_SENT						=> "Your mail could not be sent.",
+		self::MAIL_TRASH_NOT_CLEANED			=> "Your trash folder could not be cleaned.",
+		self::MAIL_MESSAGE_NOT_FOUND			=> "Message not found in folder %1.",
+		self::MAIL_INVALID_NEW_FOLDER_NAME		=> "Invalid folder name.",
+		self::MAIL_INVALID_OLD_FOLDER			=> "Invalid old folder.",
+		self::MAIL_INVALID_FOLDER				=> "Invalid folder.",
+		self::MAIL_CANNOT_DEL_DEFAULT_FOLDER	=> "Cannot delete a default folder.",
+		self::MAIL_FOLDER_NOT_EMPTY				=> "The folder is not empty.",
+		self::MAIL_FOLDER_NOT_RENAMED			=> "The folder could not be renamed.",
+		self::MAIL_FOLDER_NOT_ADDED				=> "The folder could not be added.",
+		self::MAIL_FOLDER_NOT_DELETED			=> "The folder could not be deleted."
 	);
 		
@@ -89,5 +105,5 @@
 			$error = Errors::get($code);			
 			$message = ($responseException->getMessage() ? $responseException->getMessage() : $error['message']);			
-			$body['error'] = array("code" => $code, "message" => $message);		
+			$body['error'] = array("code" => "$code", "message" => $message);		
 			$response->body = json_encode($body);
 			return $response;
Index: sandbox/webservice/api/config/Tonic.srv
===================================================================
--- sandbox/webservice/api/config/Tonic.srv	(revision 6091)
+++ sandbox/webservice/api/config/Tonic.srv	(revision 6155)
@@ -10,4 +10,13 @@
 [/Mail/Folders]
 FoldersResource = /mail/FoldersResource.php
+
+[/Mail/RenameFolder]
+RenameFolderResource = /mail/RenameFolderResource.php
+
+[/Mail/AddFolder]
+AddFolderResource = /mail/AddFolderResource.php
+
+[/Mail/DelFolder]
+DelFolderResource = /mail/DelFolderResource.php
 
 [/Mail/Messages]
Index: sandbox/webservice/api/rest/mail/RenameFolderResource.php
===================================================================
--- sandbox/webservice/api/rest/mail/RenameFolderResource.php	(revision 6155)
+++ sandbox/webservice/api/rest/mail/RenameFolderResource.php	(revision 6155)
@@ -0,0 +1,41 @@
+<?php
+
+class RenameFolderResource extends MailAdapter {
+	public function post($request){
+		// to Receive POST Params (use $this->params)
+ 		parent::post($request);
+
+		if($this-> isLoggedIn())
+		{
+			$old_id   = $this->getParam('folderID');
+			$new_name = $this->getParam('folderName');
+
+			if(!$this->getImap()->folder_exists($old_id))
+				throw new ResponseException("",Errors::MAIL_INVALID_OLD_FOLDER);
+
+			$default_folders = array_keys($this->defaultFolders);
+			if(in_array($old_id, $default_folders))
+				throw new ResponseException("",Errors::MAIL_INVALID_OLD_FOLDER);
+
+			if(empty($new_name) || preg_match('/[\/\\\!\@\#\$\%\&\*\(\)]/', $new_name))
+				throw new ResponseException("",Errors::MAIL_INVALID_NEW_FOLDER_NAME);
+
+			$old_id_arr = explode($this->getImap()->imap_delimiter, $old_id);
+
+			$new_id     = implode($this->getImap()->imap_delimiter, array_slice($old_id_arr, 0, count($old_id_arr) - 1)) . $this->getImap()->imap_delimiter . $new_name;
+
+			$params['current'] = $old_id;
+			$params['rename']  = $new_id;
+
+			$result = $this->getImap()->ren_mailbox($params);
+			if($result != 'Ok')
+				throw new ResponseException("",Errors::MAIL_FOLDER_NOT_RENAMED);
+		}
+
+		$this->setResult(array('folderID' => $new_id));
+
+		//to Send Response (JSON RPC format)
+		return $this->getResponse();
+	}
+
+}
Index: sandbox/webservice/api/rest/mail/AddFolderResource.php
===================================================================
--- sandbox/webservice/api/rest/mail/AddFolderResource.php	(revision 6155)
+++ sandbox/webservice/api/rest/mail/AddFolderResource.php	(revision 6155)
@@ -0,0 +1,32 @@
+<?php
+
+class AddFolderResource extends MailAdapter {
+	public function post($request){
+		// to Receive POST Params (use $this->params)
+ 		parent::post($request);
+
+		if($this-> isLoggedIn())
+		{
+			$parent_id = $this->getParam('parentFolderID');
+			$parent_id = empty($parent_id) ? 'INBOX' : $parent_id;
+			$new_name  = $this->getParam('folderName');
+
+			if(empty($new_name) || preg_match('/[\/\\\!\@\#\$\%\&\*\(\)]/', $new_name))
+				throw new ResponseException("",Errors::MAIL_INVALID_NEW_FOLDER_NAME);
+
+			$new_id = $parent_id . $this->getImap()->imap_delimiter . $new_name;
+
+			$params['newp'] = $new_id;
+
+			$result = $this->getImap()->create_mailbox($params);
+			if($result != 'Ok')
+				throw new ResponseException("",Errors::MAIL_FOLDER_NOT_ADDED);
+		}
+
+		$this->setResult(array('folderID' => $new_id));
+
+		//to Send Response (JSON RPC format)
+		return $this->getResponse();
+	}
+
+}
Index: sandbox/webservice/api/rest/mail/DelFolderResource.php
===================================================================
--- sandbox/webservice/api/rest/mail/DelFolderResource.php	(revision 6155)
+++ sandbox/webservice/api/rest/mail/DelFolderResource.php	(revision 6155)
@@ -0,0 +1,42 @@
+<?php
+
+class DelFolderResource extends MailAdapter {
+	public function post($request){
+		// to Receive POST Params (use $this->params)
+ 		parent::post($request);
+
+		if($this-> isLoggedIn())
+		{
+			$params['del_past'] = $folder_id = $this->getParam('folderID');
+
+			if(!$this->getImap()->folder_exists($folder_id))
+				throw new ResponseException("",Errors::MAIL_INVALID_FOLDER);
+
+			$default_folders = array_keys($this->defaultFolders);
+			if(in_array($folder_id, $default_folders))
+				throw new ResponseException("",Errors::MAIL_CANNOT_DEL_DEFAULT_FOLDER);
+
+			$personal_folders = $this->getImap()->get_folders_list(array('noSharedFolders' => true, 'folderType' => 'personal'));
+			if(!$personal_folders){
+				return $this->getResponse();
+			}
+			foreach($personal_folders AS $personal_folder){
+				if($personal_folder['folder_id'] == $folder_id && $personal_folder['folder_hasChildren'])
+					throw new ResponseException("",Errors::MAIL_FOLDER_NOT_EMPTY);
+			}
+
+			if($this->getImap()->get_num_msgs(array('folder' => $folder_id)) > 0)
+				throw new ResponseException("",Errors::MAIL_FOLDER_NOT_EMPTY);
+
+			$result = $this->getImap()->delete_mailbox($params);
+			if($result != 'Ok')
+				throw new ResponseException("",Errors::MAIL_FOLDER_NOT_DELETED);
+		}
+
+		$this->setResult(true);
+
+		//to Send Response (JSON RPC format)
+		return $this->getResponse();
+	}
+
+}
Index: sandbox/webservice/api/rest/dispatch.php
===================================================================
--- sandbox/webservice/api/rest/dispatch.php	(revision 6149)
+++ sandbox/webservice/api/rest/dispatch.php	(revision 6155)
@@ -16,4 +16,7 @@
 require_once(__DIR__."/mail/FoldersResource.php");
 require_once(__DIR__."/mail/MessagesResource.php");
+require_once(__DIR__."/mail/AddFolderResource.php");
+require_once(__DIR__."/mail/DelFolderResource.php");
+require_once(__DIR__."/mail/RenameFolderResource.php");
 require_once(__DIR__."/mail/CleanTrashResource.php");
 require_once(__DIR__."/mail/SendSupportFeedbackResource.php");
