Caldav: implement full contact folder dump at /users/<email>/contacts/

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1970 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2012-06-13 22:16:22 +00:00
parent 3c2a5ec9cb
commit 599c0de815
3 changed files with 34 additions and 5 deletions

View File

@ -297,7 +297,18 @@ public class CaldavConnection extends AbstractConnection {
String folderPath = request.getFolderPath();
ExchangeSession.Folder folder = session.getFolder(folderPath);
if (folder.isContact()) {
sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(folder.etag), "text/vcard", (byte[]) null, true);
List<ExchangeSession.Contact> contacts = session.getAllContacts(folderPath);
ChunkedResponse response = new ChunkedResponse(HttpStatus.SC_OK, "text/vcard;charset=UTF-8");
for (ExchangeSession.Contact contact : contacts) {
String contactBody = contact.getBody();
if (contactBody != null) {
response.append(contactBody);
response.append("\n");
}
}
response.close();
} else if (folder.isCalendar() || folder.isTask()) {
List<ExchangeSession.Event> events = session.getAllEvents(folderPath);
ChunkedResponse response = new ChunkedResponse(HttpStatus.SC_OK, "text/calendar;charset=UTF-8");

View File

@ -2556,7 +2556,7 @@ public abstract class ExchangeSession {
* @throws IOException on error
*/
public List<ExchangeSession.Contact> getAllContacts(String folderPath) throws IOException {
return searchContacts(folderPath, getItemProperties(), isEqualTo("outlookmessageclass", "IPM.Contact"), 0);
return searchContacts(folderPath, ExchangeSession.CONTACT_ATTRIBUTES, isEqualTo("outlookmessageclass", "IPM.Contact"), 0);
}

View File

@ -28,6 +28,7 @@ import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.util.URIUtil;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.MultiStatus;
@ -135,13 +136,19 @@ public class TestCaldav extends AbstractDavMailTestCase {
assertEquals(HttpStatus.SC_OK, method.getStatusCode());
}
public void testPropfindCalendar() throws IOException {
//Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
PropFindMethod method = new PropFindMethod("/users/" + session.getAlias() + "/calendar/", null, 1);
public void testGetContacts() throws IOException {
GetMethod method = new GetMethod("/users/" + session.getEmail() + "/contacts/");
httpClient.executeMethod(method);
assertEquals(HttpStatus.SC_OK, method.getStatusCode());
}
public void testPropfindCalendar() throws IOException {
Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
PropFindMethod method = new PropFindMethod("/users/" + session.getEmail() + "/calendar/", null, 1);
httpClient.executeMethod(method);
assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode());
}
public void testGetOtherUserCalendar() throws IOException {
Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
@ -372,4 +379,15 @@ public class TestCaldav extends AbstractDavMailTestCase {
method.getResponseBodyAsMultiStatus();
}
public void testPropfindAddressBook() throws IOException, DavException {
DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
//davPropertyNameSet.add(DavPropertyName.create("getctag", Namespace.getNamespace("http://calendarserver.org/ns/")));
davPropertyNameSet.add(DavPropertyName.create("getetag", Namespace.getNamespace("DAV:")));
PropFindMethod method = new PropFindMethod("/users/" + session.getEmail()+"/addressbook/", davPropertyNameSet, 1);
httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT, "Address%20Book/883 CFNetwork/454.12.4 Darwin/10.8.0 (i386) (MacBookPro3%2C1)");
httpClient.executeMethod(method);
assertEquals(HttpStatus.SC_MULTI_STATUS, method.getStatusCode());
method.getResponseBodyAsMultiStatus();
}
}