1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 11:12:22 -05:00

Carddav: use urlcompname value instead of path to get contact details

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1202 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-19 10:36:37 +00:00
parent 2d775713ec
commit f729eb27e5
5 changed files with 25 additions and 8 deletions

View File

@ -1196,6 +1196,7 @@ public class DavExchangeSession extends ExchangeSession {
static {
EVENT_REQUEST_PROPERTIES.add(Field.get("permanenturl").davPropertyName);
EVENT_REQUEST_PROPERTIES.add(Field.get("urlcompname").davPropertyName);
EVENT_REQUEST_PROPERTIES.add(Field.get("etag").davPropertyName);
EVENT_REQUEST_PROPERTIES.add(Field.get("contentclass").davPropertyName);
EVENT_REQUEST_PROPERTIES.add(Field.get("displayname").davPropertyName);
@ -1308,18 +1309,22 @@ public class DavExchangeSession extends ExchangeSession {
public Item getItem(String itemPath) throws IOException {
MultiStatusResponse[] responses = DavGatewayHttpClientFacade.executePropFindMethod(httpClient, URIUtil.encodePath(itemPath), 0, EVENT_REQUEST_PROPERTIES);
if (responses.length == 0) {
throw new DavMailException("EXCEPTION_EVENT_NOT_FOUND");
throw new DavMailException("EXCEPTION_ITEM_NOT_FOUND");
}
String contentClass = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "contentclass");
String urlcompname = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "urlcompname");
if ("urn:content-classes:person".equals(contentClass)) {
// retrieve Contact properties
// TODO: need to check list size
return searchContacts(itemPath.substring(0, itemPath.lastIndexOf('/')), CONTACT_ATTRIBUTES, equals("urlcompname", itemPath.substring(itemPath.lastIndexOf('/') + 1))).get(0);
List<ExchangeSession.Contact> contacts = searchContacts(itemPath.substring(0, itemPath.lastIndexOf('/')), CONTACT_ATTRIBUTES, equals("urlcompname", urlcompname));
if (contacts.isEmpty()) {
throw new DavMailException("EXCEPTION_ITEM_NOT_FOUND");
}
return contacts.get(0);
} else if ("urn:content-classes:appointment".equals(contentClass)
|| "urn:content-classes:calendarmessage".equals(contentClass)) {
return new Event(responses[0]);
} else {
throw new DavMailException("EXCEPTION_EVENT_NOT_FOUND");
throw new DavMailException("EXCEPTION_ITEM_NOT_FOUND");
}
}

View File

@ -941,7 +941,7 @@ public class EwsExchangeSession extends ExchangeSession {
String urlcompname = convertItemNameToEML(itemName);
List<EWSMethod.Item> responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW);
if (responses.isEmpty()) {
throw new DavMailException("EXCEPTION_EVENT_NOT_FOUND");
throw new DavMailException("EXCEPTION_ITEM_NOT_FOUND");
}
String itemType = responses.get(0).type;
if ("Contact".equals(itemType)) {
@ -952,7 +952,7 @@ public class EwsExchangeSession extends ExchangeSession {
|| "MeetingRequest".equals(itemType)) {
return new Event(responses.get(0));
} else {
throw new DavMailException("EXCEPTION_EVENT_NOT_FOUND");
throw new DavMailException("EXCEPTION_ITEM_NOT_FOUND");
}
}

View File

@ -5,7 +5,7 @@ EXCEPTION_AUTHENTICATION_FORM_NOT_FOUND=Authentication form not found at {0}
EXCEPTION_CONNECTION_FAILED=Unable to connect to OWA at {0}, status code {1}, check configuration
EXCEPTION_DAVMAIL_CONFIGURATION=DavMail configuration exception:\n{0}
EXCEPTION_END_OF_STREAM=End of stream reached reading content
EXCEPTION_EVENT_NOT_FOUND=Calendar event not found
EXCEPTION_ITEM_NOT_FOUND=Item not found
EXCEPTION_EXCHANGE_LOGIN_FAILED=Exchange login exception: {0}
EXCEPTION_SESSION_EXPIRED=Exchange session expired
EXCEPTION_INVALID_CALDAV_REQUEST=Invalid Caldav request: {0}

View File

@ -5,7 +5,7 @@ EXCEPTION_AUTHENTICATION_FORM_NOT_FOUND=Formulaire d''authentification non trouv
EXCEPTION_CONNECTION_FAILED=Connection OWA à {0} impossible, code retour {1}, vérifier la configuration
EXCEPTION_DAVMAIL_CONFIGURATION=Erreur de configuration DavMail :\n{0}
EXCEPTION_END_OF_STREAM=Fin de flux âtteint pendant la lecture du contenu
EXCEPTION_EVENT_NOT_FOUND=Evènement non trouvé
EXCEPTION_ITEM_NOT_FOUND=Elément non trouvé
EXCEPTION_EXCHANGE_LOGIN_FAILED=Exception lors de la connexion Exchange : {0}
EXCEPTION_INVALID_CALDAV_REQUEST=Reuqête Caldav invalide : {0}
EXCEPTION_INVALID_CONTENT_LENGTH=Longueur du contenu invalide : {0}

View File

@ -18,12 +18,14 @@
*/
package davmail.exchange;
import davmail.Settings;
import org.apache.commons.codec.binary.Base64;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
/**
@ -292,4 +294,14 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
assertEquals("mobile", contact.get("mobile"));
}
public void testSearchPublicContacts() throws IOException {
String folderPath = Settings.getProperty("davmail.publicContactFolder");
List<ExchangeSession.Contact> contacts = session.searchContacts(folderPath, ExchangeSession.CONTACT_ATTRIBUTES, null);
int count = 0;
for (ExchangeSession.Contact contact : contacts) {
System.out.println("Contact "+(++count)+ '/' +contacts.size()+session.getItem(folderPath, contact.getName()));
}
}
}