Index: /sandbox/webservice/api/adapters/CatalogAdapter.php
===================================================================
--- /sandbox/webservice/api/adapters/CatalogAdapter.php	(revision 6148)
+++ /sandbox/webservice/api/adapters/CatalogAdapter.php	(revision 6148)
@@ -0,0 +1,116 @@
+<?php
+
+
+class CatalogAdapter extends Expresso {	
+	private $minArgumentSearch;
+	private $userId;
+	private $ldapCatalog;
+
+	public function __construct($id){
+		parent::__construct($id);
+		$prefs = $GLOBALS['phpgw']->preferences->read();
+		$this-> setMinArgumentSearch($prefs['expressoMail']['search_characters_number']);
+	}
+	
+	protected function setMinArgumentSearch($minArgumentSearch){
+		$this->minArgumentSearch = $minArgumentSearch;
+	}
+	
+	protected function getMinArgumentSearch(){
+		return $this-> minArgumentSearch;
+	}
+	
+	protected function getUserId(){
+		return $GLOBALS['phpgw_info']['user']['account_id'];
+	}		
+
+	
+	protected function getLdapCatalog(){
+		if(!$this->ldapCatalog) {
+			$catalog_config = CreateObject("contactcenter.bo_ldap_manager");
+			$_SESSION['phpgw_info']['expressomail']['ldap_server'] = $catalog_config ? $catalog_config->srcs[1] : null;
+			$this->ldapCatalog = CreateObject("expressoMail1_2.ldap_functions");
+		}
+	
+		return $this->ldapCatalog;
+	}
+	
+	protected function getDb(){
+		return $GLOBALS['phpgw']->db;
+	}	
+	
+	protected function getUserLdapAttrs($mail)
+	{
+		$filter="(&(phpgwAccountType=u)(mail=".$mail."))";
+		$ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
+		$justthese = array("dn", 'jpegPhoto','givenName', 'sn'); 
+		$this->getLdapCatalog()->ldapConnect(true);
+		$ds = $this->getLdapCatalog()->ds;
+		if ($ds){
+			$sr = @ldap_search($ds, $ldap_context, $filter, $justthese);	
+			if ($sr) {
+				$entry = ldap_first_entry($ds, $sr);
+				if($entry) {									
+					$givenName = @ldap_get_values_len($ds, $entry, "givenname");
+					$sn = @ldap_get_values_len($ds, $entry, "sn");
+					$contactHasImagePicture = (@ldap_get_values_len($ds, $entry, "jpegphoto") ? 1 : 0);
+					$dn = ldap_get_dn($ds, $entry);
+					return array(
+						"contactID" => urlencode($dn),
+						"contactFirstName" => $givenName[0],
+						"contactLastName" 	=> $sn[0],
+						"contactHasImagePicture" => $contactHasImagePicture 
+					);
+				}
+			}
+		}
+		return false;
+	}
+	
+	protected function getUserLdapPhoto($contactID) {		
+		$ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
+		$justthese = array("dn", 'jpegPhoto','givenName', 'sn');
+		$this->getLdapCatalog()->ldapConnect(true);
+		$ds = $this->getLdapCatalog()->ds;		
+		
+		if ($ds){
+			$resource = @ldap_read($ds, $contactID, "phpgwaccounttype=u");
+			$n_entries = @ldap_count_entries($ds, $resource);
+
+			if ( $n_entries == 1) {			
+				$first_entry = ldap_first_entry($ds, $resource);
+				$obj = ldap_get_attributes($ds, $first_entry);
+				
+				if($obj['jpegPhoto']){
+					return ldap_get_values_len( $ds, $first_entry, "jpegPhoto");
+				}
+			}								
+		}
+		return false;
+	}	
+	
+	protected function getGlobalContacts($search, $uidNumber){
+		$contacts = array();
+		$params = array ("search_for" => $search);
+ 		$result = $this->getLdapCatalog()->quicksearch($params);
+
+		foreach($result as $i => $row) {
+			if(is_int($i)) {
+				$contacts[$i] = array(
+					'contactMails'	=> array($result[$i]['mail']),
+					'contactPhones'	=> array($result[$i]['phone']),
+					'contactAlias' => "",					
+					'contactFullName' 	=> ($result[$i]['cn'] != null ? mb_convert_encoding($row['cn'],"UTF8", "ISO_8859-1") : ""),
+					'contactBirthDate'	=> "",
+					'contactNotes' 		=> ""
+				);
+				// Buscar atributos faltantes. 
+				if(is_array($this->getUserLdapAttrs($result[$i]['mail'])))
+					$contacts[$i] = array_merge($this->getUserLdapAttrs($result[$i]['mail']), $contacts[$i]);				
+			}
+		}
+		$result = array ('contacts' => $contacts);
+		$this->setResult($result);
+		return $this->getResponse();
+	}
+}
Index: /sandbox/webservice/api/adapters/MailAdapter.php
===================================================================
--- /sandbox/webservice/api/adapters/MailAdapter.php	(revision 6148)
+++ /sandbox/webservice/api/adapters/MailAdapter.php	(revision 6148)
@@ -0,0 +1,150 @@
+<?php
+
+class MailAdapter extends Expresso {
+	protected $defaultFolders;
+	protected $imap;
+
+	protected function formatMailObject($str) {
+		$str = html_entity_decode($str);
+		$str = preg_replace('/[<>\'"]/', '', $str);
+		$return = array();            
+		if(preg_match('/[[:alnum:]\._\-]+@[[:alnum:]_\-\.]+/',$str, $matches1) &&
+			preg_match('/[[:alnum:]\._\-\ ]+/',$str, $matches2)){            		            
+			return array(					            
+            		'fullName' 	  => mb_convert_encoding(str_replace($matches1[0],'', $str), "UTF8", "ISO_8859-1"),
+					'mailAddress' => $matches1[0]
+					);
+        }
+        else{            	
+           	return array('mailAddress' => $str);           	
+		}		
+    }
+    
+	protected function loadLang($lang_user){		
+		$fn = PHPGW_INCLUDE_ROOT."/expressoMail1_2/setup/phpgw_".$lang_user.'.lang';
+		if (file_exists($fn)){
+			$fp = fopen($fn,'r');
+			while ($data = fgets($fp,16000)){
+				list($message_id,$app_name,$null,$content) = explode("\t",substr($data,0,-1));
+				$_SESSION['phpgw_info']['expressomail']['lang'][$message_id] = $content;
+			}
+			fclose($fp);
+		}
+	}
+	
+		
+	protected function getImap(){
+		if($this->imap == null) {
+			$boemailadmin	= CreateObject('emailadmin.bo');
+			$emailadmin_profile = $boemailadmin->getProfileList();
+			$_SESSION['phpgw_info']['expressomail']['email_server'] = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']);
+			
+			$preferences = $GLOBALS['phpgw']->preferences->read();
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail'] = $preferences['expressoMail'];
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['outoffice'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['outoffice'];
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'] = $GLOBALS['phpgw_info']['user']['telephonenumber'];
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_cache'] = $current_config['expressoMail_enable_cache'];
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_x_origin'] = $current_config['expressoMail_use_x_origin'];
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['number_of_contacts'] = $current_config['expressoMail_Number_of_dynamic_contacts'] ? $current_config['expressoMail_Number_of_dynamic_contacts'] : "0";
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['notification_domains'] = $current_config['expressoMail_notification_domains'];
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'] : "50";
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_characters_number'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['search_characters_number'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['search_characters_number'] : "4";			
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size'] = $current_config['expressoMail_Max_attachment_size'] ? $current_config['expressoMail_Max_attachment_size']."M" : '';
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_msg_size'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['max_msg_size'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['max_msg_size'] : "0";
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['imap_max_folders'] = $current_config['expressoMail_imap_max_folders'];
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_email_per_page'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['max_email_per_page'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['max_email_per_page'] : "50";
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['extended_info']?$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['extended_info']:'0';
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['from_to_sent'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['from_to_sent'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['from_to_sent'] : "0";
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['return_recipient_deafault'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['return_recipient_deafault'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['return_recipient_deafault'] : "0";			
+			$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['quick_search_default'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['quick_search_default'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['quick_search_default'] : 1;
+			
+			
+			$this->loadLang( $GLOBALS['phpgw_info']['user']['preferences']['common']['lang']);														
+			$_SESSION['phpgw_info']['expressomail']['user']['userid'] = $GLOBALS['phpgw_info']['user']['userid'];
+			$_SESSION['phpgw_info']['expressomail']['user']['passwd'] = $GLOBALS['phpgw_info']['user']['passwd'];
+			
+			
+			$this->imap = CreateObject("expressoMail1_2.imap_functions");
+			
+			if($this->defaultFolders == null) {
+				$sent   = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']) ?
+							$this->imap->functions->getLang("Sent") : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'];
+				$spam   = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']) ?
+							$this->imap->functions->getLang("Spam"): $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'];
+				$drafts = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']) ?
+							$this->imap->functions->getLang("Drafts") : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'];
+				$trash  = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'] = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']) ?
+							$this->imap->functions->getLang("Trash") : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'];
+
+				$this->defaultFolders = array (
+						'INBOX' => 0,
+						'INBOX'.$this->imap->imap_delimiter.$spam   => 2,
+						'INBOX'.$this->imap->imap_delimiter.$sent   => 1,
+						'INBOX'.$this->imap->imap_delimiter.$drafts => 4,
+						'INBOX'.$this->imap->imap_delimiter.$trash  => 3
+					);					
+			}
+		}
+				
+		return $this->imap;
+	}
+		
+		
+	
+	protected function getMessage(){				
+		$info_msg = $this -> getImap()-> get_info_msg(
+				array( 'msg_folder'	 => urlencode($this->getParam('folderID')),
+						'msg_number' => $this->getParam('msgID')				
+				));
+
+		if($info_msg['status_get_msg_info'] == 'false'){
+			return false;
+		}
+		
+		$msg['msgID']    = $info_msg['msg_number'];
+		$msg['folderID'] = $info_msg['msg_folder'];
+		//$msg['msgDate']	 =  $info_msg['fulldate'];
+		$msg['msgDate']  =  $info_msg['msg_day']." ".$info_msg['msg_hour'];
+
+		$msg['msgFrom']['fullName'] 	= $info_msg['from']['name'];
+		$msg['msgFrom']['mailAddress'] 	= $info_msg['from']['email'];		
+		$msg['msgSender']['fullName'] 	= $info_msg['sender']['name'];
+		$msg['msgSender']['mailAddress']= $info_msg['sender']['email'];
+		
+		$toaddresses = explode(",",$info_msg['toaddress2']);
+		if(count($toaddresses) > 1) {				
+			foreach ($toaddresses as $i => $toaddress){
+				$msg['msgTo'][$i] = $this->formatMailObject($toaddress);			
+			}
+		}
+		else{
+			$msg['msgTo'][0] = $this->formatMailObject($info_msg['toaddress2']);
+		}
+			
+		$ccaddresses = explode(",",$info_msg['cc']);
+		if(count($ccaddresses) > 1) {		
+			foreach ($ccaddresses as $i => $ccaddress){
+				$msg['msgCC'][$i] = $this->formatMailObject($ccaddress);
+			}
+		}
+		else{
+			$msg['msgCC'][0] = $this->formatMailObject($info_msg['cc']);
+		}
+		
+
+		$msg['msgReplyTo'][0] = $this->formatMailObject($info_msg['reply_toaddress']);						
+		$msg['msgSubject']  = mb_convert_encoding($info_msg['subject'],"UTF8", "ISO_8859-1");		
+		$msg['msgHasAttachments'] = $info_msg['attachments'] ? "1" : "0";		
+		$msg['msgAttachments'] = $info_msg['attachments'];		
+		$msg['msgFlagged'] 	= $info_msg['Flagged'] == "F" ? "1" : "0";
+		$msg['msgForwarded']= $info_msg['Forwarded'] == "F" ? "1" : "0";
+		$msg['msgAnswered'] = $info_msg['Answered'] == "A" ? "1" : "0";
+		$msg['msgDraft']	= $info_msg['Draft'] == "X" ? "1" : "0";
+		$msg['msgSeen'] 	= $info_msg['Unseen'] == "U" ? "0" : "1";				
+		$msg['msgSize'] 	= $info_msg['Size'];
+		$msg['msgBody']     = $info_msg['body'];		
+		
+		return $msg;		
+	}
+		
+}
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: ndbox/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;  
-    }  
-  
-}  
-?>
Index: /sandbox/webservice/api/rest/mail/CleanTrashResource.php
===================================================================
--- /sandbox/webservice/api/rest/mail/CleanTrashResource.php	(revision 6146)
+++ /sandbox/webservice/api/rest/mail/CleanTrashResource.php	(revision 6148)
@@ -1,5 +1,5 @@
 <?php
 
-class CleanTrashResource extends MailServiceAdapter {
+class CleanTrashResource extends MailAdapter {
 	public function post($request){
 		// to Receive POST Params (use $this->params)
Index: /sandbox/webservice/api/rest/mail/MessagesResource.php
===================================================================
--- /sandbox/webservice/api/rest/mail/MessagesResource.php	(revision 6146)
+++ /sandbox/webservice/api/rest/mail/MessagesResource.php	(revision 6148)
@@ -1,5 +1,5 @@
 <?php
 
-class MessagesResource extends MailServiceAdapter {	
+class MessagesResource extends MailAdapter {	
 	public function post($request){
 		// to Receive POST Params (use $this->params)
Index: /sandbox/webservice/api/rest/mail/SendSupportFeedbackResource.php
===================================================================
--- /sandbox/webservice/api/rest/mail/SendSupportFeedbackResource.php	(revision 6146)
+++ /sandbox/webservice/api/rest/mail/SendSupportFeedbackResource.php	(revision 6148)
@@ -1,5 +1,5 @@
 <?php
 
-class SendSupportFeedbackResource extends MailServiceAdapter {
+class SendSupportFeedbackResource extends MailAdapter {
 	public function post($request){
 		// to Receive POST Params (use $this->params)
Index: /sandbox/webservice/api/rest/mail/FoldersResource.php
===================================================================
--- /sandbox/webservice/api/rest/mail/FoldersResource.php	(revision 6146)
+++ /sandbox/webservice/api/rest/mail/FoldersResource.php	(revision 6148)
@@ -1,5 +1,5 @@
 <?php
 
-class FoldersResource extends MailServiceAdapter {	
+class FoldersResource extends MailAdapter {	
 	public function post($request){
 		// to Receive POST Params (use $this->params)		
Index: /sandbox/webservice/api/rest/dispatch.php
===================================================================
--- /sandbox/webservice/api/rest/dispatch.php	(revision 6146)
+++ /sandbox/webservice/api/rest/dispatch.php	(revision 6148)
@@ -1,12 +1,12 @@
 <?php
 
-// load Tonic library
-require_once __DIR__.'/../library/tonic/lib/tonic.php';
+// load libraries
+require_once __DIR__.'/../library/tonic/lib/tonic.php'; 
+require_once(__DIR__."/../library/Errors.php");
+require_once(__DIR__."/../library/Expresso.php");
 
-// load Expresso classes and service adapters
-require_once("./../utils/Errors.php");
-require_once("./../utils/Expresso.php");
-require_once("./../services/MailServiceAdapter.php");
-require_once("./../services/CatalogServiceAdapter.php");
+// load adapters
+require_once("./../adapters/MailAdapter.php");
+require_once("./../adapters/CatalogAdapter.php");
 
 // Load all resources
Index: /sandbox/webservice/api/rest/core/LoginResource.php
===================================================================
--- /sandbox/webservice/api/rest/core/LoginResource.php	(revision 6061)
+++ /sandbox/webservice/api/rest/core/LoginResource.php	(revision 6148)
@@ -1,5 +1,25 @@
 <?php
 
-class LoginResource extends Expresso {	
+class LoginResource extends Expresso {
+
+	private function getUserProfile(){
+		$user_id = $GLOBALS['phpgw_info']['user']['account_id']['acl'];
+		$acl = CreateObject('phpgwapi.acl');
+		$apps = $acl->get_user_applications($user_id);
+		$contactApps = array();
+		foreach($apps as $app => $isEnabled){
+			if($isEnabled)
+				$contactApps[] = $app;
+		}
+	
+		return array(
+				'contactID'			=> $GLOBALS['phpgw_info']['user']['account_dn'],
+				'contactMails' 		=> array($GLOBALS['phpgw_info']['user']['email']),
+				'contactPhones' 	=> array($GLOBALS['phpgw_info']['user']['telephonenumber']),
+				'contactFullName'	=> $GLOBALS['phpgw_info']['user']['fullname'],
+				'contactApps'		=> $contactApps
+		);
+	}
+	
 	public function post($request){
 		// to Receive POST Params (use $this->params)
Index: /sandbox/webservice/api/rest/core/ExpressoVersionResource.php
===================================================================
--- /sandbox/webservice/api/rest/core/ExpressoVersionResource.php	(revision 6019)
+++ /sandbox/webservice/api/rest/core/ExpressoVersionResource.php	(revision 6148)
@@ -6,5 +6,5 @@
  		parent::post($request); 		 
  		
-		$result = array('expressoVersion' =>  $this->expressoVersion);
+		$result = array('expressoVersion' =>  $this->getExpressoVersion());
  		$this->setResult($result);
 
Index: /sandbox/webservice/api/rest/catalog/ContactPictureResource.php
===================================================================
--- /sandbox/webservice/api/rest/catalog/ContactPictureResource.php	(revision 6146)
+++ /sandbox/webservice/api/rest/catalog/ContactPictureResource.php	(revision 6148)
@@ -1,5 +1,5 @@
 <?php
 
-class ContactPictureResource extends CatalogServiceAdapter {	
+class ContactPictureResource extends CatalogAdapter {	
 	public function post($request){
 		// to Receive POST Params (use $this->params)
Index: /sandbox/webservice/api/rest/catalog/ContactsResource.php
===================================================================
--- /sandbox/webservice/api/rest/catalog/ContactsResource.php	(revision 6146)
+++ /sandbox/webservice/api/rest/catalog/ContactsResource.php	(revision 6148)
@@ -1,5 +1,5 @@
 <?php
 
-class ContactsResource extends CatalogServiceAdapter {	
+class ContactsResource extends CatalogAdapter {	
 	public function post($request){
 		// to Receive POST Params (use $this->params)
