Index: sandbox/webservice/api/library/Errors.php
===================================================================
--- sandbox/webservice/api/library/Errors.php	(revision 5954)
+++ sandbox/webservice/api/library/Errors.php	(revision 6148)
@@ -1,5 +1,5 @@
 <?php
 
-class Errors {
+final class Errors {
 		
 	// Errors from -32000 to -32099 => Server error	:Reserved for implementation-defined server-errors.
@@ -10,4 +10,8 @@
 	const E_INTERNAL_ERROR 		= "-32603";	
 
+	const E_HTTP_NOT_FOUND		= "404";
+	const E_UNKNOWN_ERROR		= "500";
+	
+	
 	// Errors inherited from Expresso Application.	
 	const LOGIN_SUCCESS_LOGOUT 			= "1";
@@ -22,6 +26,10 @@
 	const LOGIN_LOGIN_BLOCKED 			= "99";
 	const LOGIN_INVALID_LOGIN 			= "200";
+	
 
 	const CATALOG_MIN_ARGUMENT_SEARCH	= "1001";	
+	const MAIL_NOT_SENT					= "1002";
+	const MAIL_TRASH_NOT_CLEANED		= "1003";
+	const MAIL_MESSAGE_NOT_FOUND		= "1004";
 	
 	static private $reservedErrors = array (			
@@ -30,5 +38,7 @@
 		self::E_METHOD_NOT_FOUND 	=> "Method not found",
 		self::E_INVALID_PARAMS 		=> "Invalid params",
-		self::E_INTERNAL_ERROR		=> "Internal error"	
+		self::E_INTERNAL_ERROR		=> "Internal error",
+		self::E_HTTP_NOT_FOUND		=> 'A resource matching URI "%1" was not found',
+		self::E_UNKNOWN_ERROR		=> "HTTP Unknown error"
 	);
 	
@@ -48,17 +58,39 @@
 		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::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."
 	);
 		
-	static public function get($code, $jsonrpc = "2.0"){
-				
-		$errors = self::$reservedErrors + self::$applicationErrors;
-		if($jsonrpc == "2.0")
-			return array ("code" => $code, "message" => $errors[$code]);		
-		else
-			return $errors[$code];
-	}			
+	static public function set($code, $message){
+		return array ("code" => $code, "message" => $message);
+	}
+
+	static public function get($code, $argument = false){
+		$errors = self::$reservedErrors + self::$applicationErrors;		
+		$message = $errors[$code];
+		if(!$message)
+			$message = $errors[self::E_UNKNOWN_ERROR];
+		if($argument)
+			$message = str_replace("%1", $argument, $message);		
+		
+		return array ("code" => $code, "message" => $message); 
+	}
+	
+	static public function getResponse($request, $responseException){			
+			$response = new Response($request);
+			$response->code = Response::OK;
+			$response->addHeader('content-type', 'application/json');
+			if($request->id)
+				$body['id']	= $request->id;
+			
+			$code	 = $responseException->getCode();
+			$error = Errors::get($code);			
+			$message = ($responseException->getMessage() ? $responseException->getMessage() : $error['message']);			
+			$body['error'] = array("code" => $code, "message" => $message);		
+			$response->body = json_encode($body);
+			return $response;
+	}
 		
 }
Index: sandbox/webservice/api/library/Expresso.php
===================================================================
--- sandbox/webservice/api/library/Expresso.php	(revision 6148)
+++ sandbox/webservice/api/library/Expresso.php	(revision 6148)
@@ -0,0 +1,125 @@
+<?php
+class Expresso extends Resource {
+
+	private $expressoVersion;
+	private $request;
+	private $params;
+	private $result;
+	private $error;	
+	private $id;
+	
+	function __construct($id){
+		$GLOBALS['phpgw_info'] = array(
+				'flags' => array(
+						'currentapp'        	=> 'login',
+						'noheader'              => True,
+						'disable_Template_class' => True
+				)
+		);
+		
+		include_once('../../header.inc.php');
+		$this->expressoVersion = substr($GLOBALS['phpgw_info']['server']['versions']['phpgwapi'],0,3);			
+	}
+	
+	protected function setRequest($request){
+		$this->request = $request;
+	}
+	
+	public function getRequest(){
+		return $this->request;
+	}
+	
+	protected function getExpressoVersion(){
+		return $this->expressoVersion;
+	}
+	
+	protected function setResult($result){
+		$this->result = $result;
+	}
+	
+	public function getResult(){
+		return $this->result;
+	}
+	
+	protected function setId($id){
+		$this->id = $id;
+	}
+	
+	public function getId(){
+		return $this->id;
+	}
+	
+	protected function setParams($params){		
+		$this->params = $params;
+	}
+	
+	public function getParams(){	
+		return $this->params;
+	}
+	
+	public function getParam($param){
+		return $this->params->$param;
+	}
+	
+	public function setError($error) {
+		$this-> error = $error;
+	}
+	
+	protected function getError() {
+		return $this-> error;
+	}
+	
+	public function post($request){
+		$this->setRequest($request);		
+		parse_str($request->data, &$array);		
+		$data = (object)$array;		
+		if($data){
+			if($data->params){								
+				$this->setParams(json_decode($data->params));
+			}
+			if($data->id)
+				$this->setId($data->id);
+		}
+	}	
+	
+	public function get($request){
+		$response = new Response($request);
+		$response->code = Response::OK;
+		$response->addHeader('content-type', 'text/html');		
+		$response->body = "<H4>Metodo GET nao permitido para este recurso.</H4>";		
+		return $response;
+	}
+	
+	public function getResponse(){
+		$response = new Response($this->getRequest());
+		$response->code = Response::OK;
+		$response->addHeader('content-type', 'application/json');
+
+		if($this->getId())
+			$body['id']	= $this->getId();
+		if($this->getResult())
+			$body['result']	= $this->getResult();
+		else
+			throw new ResponseException("",Errors::E_UNKNOWN_ERROR);
+		
+		$response->body = json_encode($body);
+		
+		return $response;
+	}
+	
+	protected function isLoggedIn(){
+		if($this->getParam('auth') != null) {
+			list($sessionid, $kp3) = explode(":", $this->getParam('auth'));
+			if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){									
+				return $sessionid;
+			}
+			else{
+				throw new ResponseException("",Errors::LOGIN_AUTH_INVALID);
+			}
+		}
+		else{
+			throw new ResponseException("",Errors::LOGIN_NOT_LOGGED_IN);
+		}		
+	}	
+			
+}
Index: sandbox/webservice/api/library/HttpRequest.php
===================================================================
--- sandbox/webservice/api/library/HttpRequest.php	(revision 5954)
+++ 	(revision )
@@ -1,103 +1,0 @@
-<?
-/** 
-* Access the HTTP Request 
-*/  
-class HttpRequest {  
-  
-    /** additional HTTP headers not prefixed with HTTP_ in $_SERVER superglobal */  
-    var $add_headers = array('CONTENT_TYPE', 'CONTENT_LENGTH');  
-  
-    /** 
-    * Construtor 
-    * Retrieve HTTP Body 
-    * @param Array Additional Headers to retrieve 
-    */  
-    function HttpRequest($add_headers = false) {  
-      
-        $this->retrieve_headers($add_headers);  
-        $this->body = @file_get_contents('php://input');  
-    }  
-      
-    /** 
-    * Retrieve the HTTP request headers from the $_SERVER superglobal 
-    * @param Array Additional Headers to retrieve 
-    */  
-    function retrieve_headers($add_headers = false) {  
-          
-        if ($add_headers) {  
-            $this->add_headers = array_merge($this->add_headers, $add_headers);  
-        }  
-      
-        if (isset($_SERVER['HTTP_METHOD'])) {  
-            $this->method = $_SERVER['HTTP_METHOD'];  
-            unset($_SERVER['HTTP_METHOD']);  
-        } else {  
-            $this->method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;  
-        }  
-        $this->protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : false;  
-        $this->request_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;  
-          
-        $this->headers = array();  
-        foreach($_SERVER as $i=>$val) {  
-            if (strpos($i, 'HTTP_') === 0 || in_array($i, $this->add_headers)) {  
-                $name = str_replace(array('HTTP_', '_'), array('', '-'), $i);  
-                $this->headers[$name] = $val;  
-            }  
-        }  
-    }  
-      
-    /**  
-    * Retrieve HTTP Method 
-    */  
-    function method() {  
-        return $this->method;  
-    }  
-      
-    /**  
-    * Retrieve HTTP Body 
-    */  
-    function body() {  
-        return $this->body;  
-    }  
-      
-    /**  
-    * Retrieve an HTTP Header 
-    * @param string Case-Insensitive HTTP Header Name (eg: "User-Agent") 
-    */  
-    function header($name) {  
-        $name = strtoupper($name);  
-        return isset($this->headers[$name]) ? $this->headers[$name] : false;  
-    }  
-      
-    /** 
-    * Retrieve all HTTP Headers  
-    * @return array HTTP Headers 
-    */  
-    function headers() {  
-        return $this->headers;  
-    }  
-      
-    /** 
-    * Return Raw HTTP Request (note: This is incomplete) 
-    * @param bool ReBuild the Raw HTTP Request 
-    */  
-    function raw($refresh = false) {  
-      
-        if (isset($this->raw) && !$refresh) {  
-            return $this->raw; // return cached  
-        }  
-      
-        $headers = $this->headers();  
-        $this->raw = "{$this->method}\r\n";  
-          
-        foreach($headers as $i=>$header) {  
-                $this->raw .= "$i: $header\r\n";  
-        }  
-          
-        $this->raw .= "\r\n{$this->body}";  
-          
-        return $this->raw;  
-    }  
-  
-}  
-?>
