Index: /sandbox/webservice/.project
===================================================================
--- /sandbox/webservice/.project	(revision 5595)
+++ /sandbox/webservice/.project	(revision 5595)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>webservice</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.wst.validation.validationbuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.dltk.core.scriptbuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.php.core.PHPNature</nature>
+	</natures>
+</projectDescription>
Index: /sandbox/webservice/api/http_request.class.php
===================================================================
--- /sandbox/webservice/api/http_request.class.php	(revision 5595)
+++ /sandbox/webservice/api/http_request.class.php	(revision 5595)
@@ -0,0 +1,103 @@
+<?
+/** 
+* Access the HTTP Request 
+*/  
+class http_request {  
+  
+    /** 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 http_request($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/webservice.php
===================================================================
--- /sandbox/webservice/api/webservice.php	(revision 5595)
+++ /sandbox/webservice/api/webservice.php	(revision 5595)
@@ -0,0 +1,94 @@
+<?php
+include_once("http_request.class.php");
+
+$public_functions = array(
+	"Expresso.login",
+	"Expresso.logout",
+	"Mail.getUserFolders",
+	"Mail.getUserMessages"
+);
+
+$GLOBALS['phpgw_info'] = array(
+	'flags' => array(
+			'currentapp'            => 'login',
+			'noheader'              => True,
+			'disable_Template_class' => True,
+			'public_functions'       => $public_functions
+	)
+);
+
+include_once('../header.inc.php');
+
+// NO COOKIES!!!!
+unset($_COOKIE);
+switch ($_SERVER['REQUEST_METHOD']) {
+	case 'GET':
+	case 'POST':		
+		execute($_REQUEST);
+	break;
+	
+	default:
+	exit();	
+}
+
+function execute($request){	
+	if(empty($request)) {
+		$request = array();
+		$http_request = new http_request();
+		$content_type = $http_request->header('Content-Type');
+		$accept = $http_request->header('Accept');
+		$content = $http_request->body();	
+	
+		if (($content_type == 'application/x-www-form-urlencoded') 
+			&& ($accept == 'application/json') && $content != null) {
+		
+			$req_obj = json_decode($content);
+			$request['params'] 	= (array)$req_obj->params;
+			$request['method'] 	= $req_obj->method;
+			$request ['format']	= "json-rpc";
+			$request['id'] 		= $req_obj->id;
+		}
+	}
+		
+	list($params, $method, $format, $id) = array_values($request);
+
+	if(verifyMethod($method)){
+		$method = explode(".", $method);	
+		include_once("./".$format."/".$method[0].".php");
+		$obj = new $method[0]($id);	
+		$response = $obj->$method[1]($params);	
+	}
+	else{
+		$response = array(
+				'result'	=> null,
+				'error'		=> "Available Resources: ". implode(", ", $GLOBALS['phpgw_info']['flags']['public_functions']),
+				'id'		=> $id
+		);		
+	}
+	dispatch($response, $format);
+}
+
+function verifyMethod($method) {
+	if(array_search( $method, $GLOBALS['phpgw_info']['flags']['public_functions']) !== FALSE){
+		return true;
+	}
+	else {
+		return false;
+	}
+}
+
+function dispatch($response, $format){
+	$e_response = false;
+	switch($format){		
+		case 'json-rpc':
+			$e_response = @json_encode($response);
+			break;
+		case 'xml-rpc':
+			$e_response = @xmlrpc_encode($response);
+			break;
+		default:
+			$e_response = false;	
+			break;
+	}	
+	echo $e_response;	
+}
Index: /sandbox/webservice/api/json-rpc/Catalog.php
===================================================================
--- /sandbox/webservice/api/json-rpc/Catalog.php	(revision 5595)
+++ /sandbox/webservice/api/json-rpc/Catalog.php	(revision 5595)
@@ -0,0 +1,49 @@
+<?php
+
+include_once("Expresso.php");
+
+class Catalog extends Expresso {	
+	var $ldap;
+	var $db;
+		    
+	private function getLdap(){
+		if($this->ldap == null) {
+			
+		}
+				
+		return $this->ldap;
+	}
+	
+	private function getDb(){
+		if($this->ldap == null) {
+			
+		}	
+		return $this->db;		
+	}
+	
+	
+	public function getUserContacts($params){
+		if($this->isLoggedIn($params)) {
+			
+		}
+			
+		$this->result = array (
+			'contacts' => $contacts
+		);
+			
+		return $this->getResponse();
+	}	
+	
+	public function getGlobalContacts($params){
+		
+		if($this->isLoggedIn($params)) {
+			
+		}
+			
+		$this->result = array (
+			'contacts' => $contacts
+		);
+			
+		return $this->getResponse();
+	}
+}
Index: /sandbox/webservice/api/json-rpc/Mail.php
===================================================================
--- /sandbox/webservice/api/json-rpc/Mail.php	(revision 5595)
+++ /sandbox/webservice/api/json-rpc/Mail.php	(revision 5595)
@@ -0,0 +1,298 @@
+<?php
+
+include_once("Expresso.php");
+
+class Mail extends Expresso {
+	var $defaultFolders;
+	var $imap;
+	
+	private 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);           	
+		}		
+    }
+    
+	private 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);
+		}
+	}
+	
+		
+	private 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'];			
+			include_once(PHPGW_INCLUDE_ROOT."/expressoMail1_2/inc/class.imap_functions.inc.php");
+			$this->imap = new imap_functions();
+			
+			if($this->defaultFolders == null) {				
+				$sent = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']) ?
+					$this->imap->functions->getLang("Sent") : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'];
+				$spam = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'])	?
+					$this->imap->functions->getLang("Spam"): $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'];
+				$drafts = empty($_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']) ?
+					$this->imap->functions->getLang("Drafts") : $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'];
+				$trash = 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;
+	}
+		
+	public function getUserFolders($params){
+		if($this->isLoggedIn($params)) {
+			$imap_folders =  $this->getImap()->get_folders_list();
+		}
+		if(!$imap_folders){
+			return $this->getResponse();
+		}
+		
+		$all_folders    = array();
+		$user_folders   = array();
+		$shared_folders = array();
+			
+		foreach ($imap_folders as $i => $imap_folder) {
+			if(is_int($i)) {
+				$folder = array();
+				$folder['folderName'] 	  = mb_convert_encoding($imap_folder['folder_name'], "UTF8", "ISO_8859-1");
+				if($folder['folderName'] == 'INBOX') {
+					$folder['folderName'] = $this->getImap()->functions->getLang("Inbox");
+				}
+				$folder['folderParentID'] = mb_convert_encoding($imap_folder['folder_parent'],'UTF8','ISO-8859-1');
+				$folder['folderHasChildren'] = $imap_folder['folder_hasChildren'];
+				$folder['qtdUnreadMessages'] = $imap_folder['folder_unseen'];
+				$folder['qtdMessages'] = $this->getImap()->get_num_msgs(array("folder" => $imap_folder['folder_id']));
+				$folder['folderID'] = mb_convert_encoding($imap_folder['folder_id'],'UTF8','ISO-8859-1');
+															
+				if(substr($folder['folderID'], 0, 4) == 'user'){
+					$folder['folderType'] = "6";
+					$shared_folders[] = $folder;
+				}else if(array_key_exists($folder['folderID'], $this->defaultFolders) !== false) {
+					$folder_type = $this->defaultFolders[$folder['folderID']];						
+					$folder['folderType'] = $folder_type;
+					$default_folders[] = $folder;
+				}
+				else{	
+					$folder['folderType'] = "5";
+					$user_folders[] = $folder;
+				}
+			}
+		}
+		
+		$all_folders = array_merge($default_folders, $user_folders, $shared_folders);
+		$quota_folders = $this->getImap()->get_quota_folders();
+		$soma = 0;
+		foreach($all_folders as $i => $folder){
+			$folder_name = mb_convert_encoding($folder['folderName'],"ISO_8859-1", "UTF8");
+			$folder_id   = mb_convert_encoding($folder['folderID'],"ISO_8859-1", "UTF8");
+			if($folder_id == 'INBOX') {				
+				$j = $this->getImap()->functions->getLang("Inbox"); 
+			}else {
+				$j = str_replace("INBOX".$this->getImap()->imap_delimiter,"",$folder_id);			
+			}
+			$all_folders[$i]['diskSizeUsed'] 	= $quota_folders[$j]['quota_used'];
+			$all_folders[$i]['diskSizePercent'] = $quota_folders[$j]['quota_percent']/100;
+			$soma = $soma + $all_folders[$i]['diskSizePercent'];
+		}
+			
+		$this->result = array (
+			'debug' => $soma,
+			'folders' => $all_folders,
+			'diskSizeUsed'     => $imap_folders['quota_used']*1024, 
+			'diskSizeLimit'    => $imap_folders['quota_limit']*1024,
+			'diskSizePercent'  => $imap_folders['quota_percent']/100
+		);
+			
+		return $this->getResponse();
+	}	
+	
+	private function getMessage($params){
+		
+		$params['folderID'];
+		$params['msgID'];
+		$msg_number = $params['msg_number'];
+		$msg_folder = ($params['msg_folder']);
+		
+		$info_msg = $this -> getImap()-> get_info_msg(
+				array( 'msg_folder'	 => urlencode($params['folderID']),
+						'msg_number' => $params['msgID']				
+				));
+		
+		$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;		
+	}
+	/*
+	 * TODO: Implementar método para carregar mensagens
+	 */
+	public function getUserMessages($params){		
+
+		if($this->isLoggedIn($params)) {
+			
+			if($params['folderID'] && $params['msgID'] > 0) {
+				$msg = $this->getMessage($params);
+				$this->result = array (	'messages' => array($msg));
+				return $this->getResponse();
+			}
+			
+			$max_email_per_page = intval($params['resultsPerPage'] ? $params['resultsPerPage'] : 
+					$this->getImap()->prefs['max_email_per_page']);
+			
+			$current_page = intval($params['page'] ? $params['page'] : 1);
+			
+			$msg_range_begin = ($max_email_per_page * ($current_page - 1)) + 1;
+			$msg_range_end = $msg_range_begin + ($max_email_per_page  - 1);			
+			
+			$this->getImap()->prefs['preview_msg_subject'] = "1";
+			
+			
+			$imap_msgs = $this->getImap()-> get_range_msgs2(	
+					array(	"folder"			=> $params['folderID'], 
+							"msg_range_begin" 	=> $msg_range_begin,
+							"msg_range_end"	 	=> $msg_range_end,
+							"search_box_type"	=> "ALL",
+							"sort_box_reverse"	=> "1",
+							"sort_box_type"		=> "SORTARRIVAL"					
+					));
+		}
+		if(!$imap_msgs){
+			return $this->getResponse();
+		}
+		
+		$all_msgs = array();
+
+		foreach($imap_msgs as $i => $imap_msg) {			
+			if(!is_int($i)) {
+				continue;
+			}
+			$msg = array();
+			$msg['msgID'] = $imap_msg['msg_number'];
+			$msg['folderID'] =  $imap_msgs['folder'];
+			$msg['msgDate']	= gmdate('d/m/Y H:i', $imap_msg['timestamp']);			
+			$msg['msgFrom']['fullName'] = $imap_msg['from']['name'];
+			$msg['msgFrom']['mailAddress'] = $imap_msg['from']['email'];			
+			$msg['msgTo'][0]['fullName'] = $imap_msg['to']['name']; 
+			$msg['msgTo'][0]['mailAddress'] = $imap_msg['to']['email'];					
+			$msg['msgReplyTo'][0] = $this->formatMailObject($imap_msg['reply_toaddress']);
+			$msg['msgSubject']  = mb_convert_encoding($imap_msg['subject'],"UTF8", "ISO_8859-1");
+			
+			$msg['msgHasAttachments'] = $imap_msg['attachment'] ? "1" : "0";
+
+			$msg['msgFlagged'] 	= $imap_msg['Flagged'] == "F" ? "1" : "0";
+			$msg['msgForwarded']= $imap_msg['Forwarded'] == "F" ? "1" : "0";
+			$msg['msgAnswered'] = $imap_msg['Answered'] == "A" ? "1" : "0";
+			$msg['msgDraft']	= $imap_msg['Draft'] == "X" ? "1" : "0";												
+			$msg['msgSeen'] 	= $imap_msg['Unseen'] == "U" ? "0" : "1";
+			
+			$msg['ContentType']	= $imap_msg['ContentType'];
+			$msg['msgSize'] 	= $imap_msg['Size'];
+						
+			$msg['msgBodyResume'] = substr(base64_decode($imap_msg['msg_sample']['body']), 2);
+			$msg['msgBodyResume'] = str_replace("\r\n", "", $msg['msgBodyResume']);			
+			$msg['msgBodyResume'] = str_replace(chr(160)," ", $msg['msgBodyResume']);
+			$msg['msgBodyResume'] = preg_replace('/\s\s+/', '', $msg['msgBodyResume']);
+			$msg['msgBodyResume'] = mb_convert_encoding($msg['msgBodyResume'],"UTF8", "ISO_8859-1");            
+            
+			$all_msgs[] = $msg;
+		}
+		$this->result = array (
+			'messages' 	  => $all_msgs,
+			'timeZone'	  => $imap_msgs['offsetToGMT'],
+			'totalUnseen' => $imap_msgs['tot_unseen']			
+		);		
+							
+		return $this->getResponse();
+	}
+}
Index: /sandbox/webservice/api/json-rpc/Expresso.php
===================================================================
--- /sandbox/webservice/api/json-rpc/Expresso.php	(revision 5595)
+++ /sandbox/webservice/api/json-rpc/Expresso.php	(revision 5595)
@@ -0,0 +1,86 @@
+<?php
+
+class Expresso {
+
+	var $result;
+	var $error;
+	var $id;
+
+	
+	function __construct($id){		
+		$this->result 	= null;
+		$this->error 	= null;						
+		$this-> id 		= $id;
+	}
+
+	protected function getResponse(){	
+		return  array(
+				'result'	=> $this->result,
+				'error'		=> $this->error,
+				'id'		=> $this->id
+		);
+	}	
+		
+	
+	protected function isLoggedIn($params){
+		list($sessionid, $kp3) = explode(":", $params['auth']);
+		if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){									
+			return true;
+		}
+		else{
+			$this-> error = "You are not logged in";
+			return false;
+		}		
+	}	
+	
+	
+	public function login($params){
+		if(!$this-> isLoggedIn($params)) 
+		{				
+			if($params['auth'] != "") 
+			{	
+				$this->error  = "Your auth is invalid";
+				
+			}
+			elseif($sessionid = $GLOBALS['phpgw']->session->create($params['user'], $params['password']))					
+			{
+				$this->error  = null;
+				$this->result = array('auth' =>  $sessionid.":".$GLOBALS['phpgw']->session->kp3);
+			}
+			else
+			{				
+				$this-> error = $GLOBALS['phpgw']->session->reason;
+			}			
+		}
+		else
+		{
+			$this->result = array('auth' =>  $params['auth']);
+		}
+		
+		return $this->getResponse();	
+	}	
+	
+	public function logout($params){			
+		
+		if($this->isLoggedIn($params))
+		{
+			if (file_exists($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id']))	
+			{
+				$dh = opendir($GLOBALS['phpgw_info']['server']['temp_dir']. SEP . $_SESSION['phpgw_session']['session_id']);
+				while ($file = readdir($dh)) 
+				{
+					if ($file != '.' && $file != '..') 
+					{
+						unlink($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id'].SEP.$file);
+					}
+				}
+				rmdir($GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$_SESSION['phpgw_session']['session_id']);
+			}
+			$GLOBALS['phpgw']->hooks->process('logout');
+			$GLOBALS['phpgw']->session->destroy($_SESSION['phpgw_session']['session_id'], $GLOBALS['kp3']);
+			$this->result = true;
+		}
+		
+		return $this->getResponse();
+	}	
+}
Index: /sandbox/webservice/.settings/org.eclipse.php.core.prefs
===================================================================
--- /sandbox/webservice/.settings/org.eclipse.php.core.prefs	(revision 5595)
+++ /sandbox/webservice/.settings/org.eclipse.php.core.prefs	(revision 5595)
@@ -0,0 +1,3 @@
+#Thu Mar 01 11:19:32 BRT 2012
+eclipse.preferences.version=1
+include_path=0;/webservice
