Index: trunk/prototype/rest/catalog/DynamicContactsResource.php
===================================================================
--- trunk/prototype/rest/catalog/DynamicContactsResource.php	(revision 6578)
+++ trunk/prototype/rest/catalog/DynamicContactsResource.php	(revision 6605)
@@ -182,5 +182,13 @@
 
 	$this->secured();
-	
+
+	//verificar se a preferencia de contatos dinamicos nao esta ativada
+	if(!$this->isEnabledDynamicContacts(Config::me("uidNumber")) ){
+		$response = new Response($request);
+		$this->createException($request, $response, Response::UNAUTHORIZED, 'Resource unauthorized', 'disabled dynamic contacts preference');
+		return $response;
+	}
+
+
 	if (count($_POST) == 0) {
 	    $response = new Response($request);
@@ -236,5 +244,5 @@
 		//se a quantidade de contatos dinamicos de usuario exceder o limite maximo definido nas preferencias do administrador,
 		//remover o contato dinamico mais antigo
-		if($numberOfDynamicContacts >= $numberOfMessages){
+		if($numberOfMessages > 0 && $numberOfDynamicContacts >= $numberOfMessages){
 			$id = $dynamicContacts[0]['id'];
 			$delete = Controller::delete(array('concept' => 'dynamicContact', 'id' => $id));
@@ -280,4 +288,24 @@
     }
 
+    private function isEnabledDynamicContacts($user){
+
+	$sql = 'SELECT preference_value '.
+		'FROM phpgw_preferences '.
+		'WHERE preference_app = \'expressoMail\' AND '.
+			'preference_owner = ' . $user;
+
+	$preference = Controller::service('PostgreSQL')->execResultSql($sql, true);
+
+	if(count($preference) > 0 && isset($preference['preference_value'])){
+		$preference = unserialize( $preference['preference_value'] );
+
+		if(isset($preference['use_dynamic_contacts'])){
+			$preference = $preference['use_dynamic_contacts'];
+			return ($preference == '1');
+		}
+	}
+	return false;
+    }
+
 }
 
Index: trunk/prototype/rest/catalog/UserContactsResource.php
===================================================================
--- trunk/prototype/rest/catalog/UserContactsResource.php	(revision 6592)
+++ trunk/prototype/rest/catalog/UserContactsResource.php	(revision 6605)
@@ -24,4 +24,11 @@
 	$this->secured();
 
+        //verificar se a preferencia de contatos dinamicos nao esta ativada
+        if(!$this->isEnabledDynamicContacts(Config::me("uidNumber")) ){
+                $response = new Response($request);
+                $this->createException($request, $response, Response::UNAUTHORIZED, 'Resource unauthorized', 'disabled dynamic contacts preference');
+                return $response;
+        }
+
 	$response = new Response($request);
 	$response->addHeader('Content-type', 'aplication/json');
@@ -478,4 +485,24 @@
     }
 
+    private function isEnabledDynamicContacts($user){
+
+        $sql = 'SELECT preference_value '.
+                'FROM phpgw_preferences '.
+                'WHERE preference_app = \'expressoMail\' AND '.
+                        'preference_owner = ' . $user;
+
+        $preference = Controller::service('PostgreSQL')->execResultSql($sql, true);
+
+        if(count($preference) > 0 && isset($preference['preference_value'])){
+                $preference = unserialize( $preference['preference_value'] );
+
+                if(isset($preference['use_dynamic_contacts'])){
+                        $preference = $preference['use_dynamic_contacts'];
+                        return ($preference == '1');
+                }
+        }
+        return false;
+    }
+
 }
 
Index: trunk/prototype/rest/catalog/DynamicContactResource.php
===================================================================
--- trunk/prototype/rest/catalog/DynamicContactResource.php	(revision 6528)
+++ trunk/prototype/rest/catalog/DynamicContactResource.php	(revision 6605)
@@ -23,4 +23,11 @@
 
 	$this->secured();
+
+        //verificar se a preferencia de contatos dinamicos nao esta ativada
+        if(!$this->isEnabledDynamicContacts(Config::me("uidNumber")) ){
+                $response = new Response($request);
+                $this->createException($request, $response, Response::UNAUTHORIZED, 'Resource unauthorized', 'disabled dynamic contacts preference');
+                return $response;
+        }
 
 	$response = new Response($request);
@@ -172,4 +179,12 @@
 	
 	$this->secured();
+
+        //verificar se a preferencia de contatos dinamicos nao esta ativada
+        if(!$this->isEnabledDynamicContacts(Config::me("uidNumber")) ){
+                $response = new Response($request);
+                $this->createException($request, $response, Response::UNAUTHORIZED, 'Resource unauthorized', 'disabled dynamic contacts preference');
+                return $response;
+        }
+
 
 	$post = $request->dataDecoded;
@@ -260,4 +275,11 @@
 	$this->secured();
 
+        //verificar se a preferencia de contatos dinamicos nao esta ativada
+        if(!$this->isEnabledDynamicContacts(Config::me("uidNumber")) ){
+                $response = new Response($request);
+                $this->createException($request, $response, Response::UNAUTHORIZED, 'Resource unauthorized', 'disabled dynamic contacts preference');
+                return $response;
+        }
+
 	$response = new Response($request);
 	$response->addHeader('Content-type', 'aplication/json');
@@ -307,4 +329,23 @@
     }
 
+    private function isEnabledDynamicContacts($user){
+
+        $sql = 'SELECT preference_value '.
+                'FROM phpgw_preferences '.
+                'WHERE preference_app = \'expressoMail\' AND '.
+                        'preference_owner = ' . $user;
+
+        $preference = Controller::service('PostgreSQL')->execResultSql($sql, true);
+
+        if(count($preference) > 0 && isset($preference['preference_value'])){
+                $preference = unserialize( $preference['preference_value'] );
+
+                if(isset($preference['use_dynamic_contacts'])){
+                        $preference = $preference['use_dynamic_contacts'];
+                        return ($preference == '1');
+                }
+        }
+        return false;
+    }
 }
 
