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

Carddav: implement range search

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1305 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-27 20:34:43 +00:00
parent 6e9ed2e942
commit 479fc3fbf5
10 changed files with 66 additions and 43 deletions

View File

@ -2517,7 +2517,7 @@ public abstract class ExchangeSession {
* @throws IOException on error * @throws IOException on error
*/ */
public List<ExchangeSession.Contact> getAllContacts(String folderPath) throws IOException { public List<ExchangeSession.Contact> getAllContacts(String folderPath) throws IOException {
return searchContacts(folderPath, ITEM_PROPERTIES, isEqualTo("outlookmessageclass", "IPM.Contact")); return searchContacts(folderPath, ITEM_PROPERTIES, isEqualTo("outlookmessageclass", "IPM.Contact"), 0);
} }
@ -2527,10 +2527,11 @@ public abstract class ExchangeSession {
* @param folderPath Exchange folder path * @param folderPath Exchange folder path
* @param attributes requested attributes * @param attributes requested attributes
* @param condition Exchange search query * @param condition Exchange search query
* @param maxCount maximum item count
* @return list of contacts * @return list of contacts
* @throws IOException on error * @throws IOException on error
*/ */
public abstract List<Contact> searchContacts(String folderPath, Set<String> attributes, Condition condition) throws IOException; public abstract List<Contact> searchContacts(String folderPath, Set<String> attributes, Condition condition, int maxCount) throws IOException;
/** /**
* Search calendar messages in provided folder. * Search calendar messages in provided folder.

View File

@ -649,7 +649,7 @@ public class DavExchangeSession extends ExchangeSession {
} else if (status == HttpStatus.SC_NOT_FOUND) { } else if (status == HttpStatus.SC_NOT_FOUND) {
LOGGER.debug("Contact not found at " + encodedHref + ", searching permanenturl by urlcompname"); LOGGER.debug("Contact not found at " + encodedHref + ", searching permanenturl by urlcompname");
// failover, search item by urlcompname // failover, search item by urlcompname
MultiStatusResponse[] responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, DavExchangeSession.this.isEqualTo("urlcompname", convertItemNameToEML(itemName)), FolderQueryTraversal.Shallow); MultiStatusResponse[] responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, DavExchangeSession.this.isEqualTo("urlcompname", convertItemNameToEML(itemName)), FolderQueryTraversal.Shallow, 1);
if (responses.length == 1) { if (responses.length == 1) {
encodedHref = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "permanenturl"); encodedHref = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "permanenturl");
LOGGER.warn("Contact found, permanenturl is " + encodedHref); LOGGER.warn("Contact found, permanenturl is " + encodedHref);
@ -862,7 +862,7 @@ public class DavExchangeSession extends ExchangeSession {
} else if (status == HttpStatus.SC_NOT_FOUND) { } else if (status == HttpStatus.SC_NOT_FOUND) {
LOGGER.debug("Event not found at " + encodedHref + ", searching permanenturl by urlcompname"); LOGGER.debug("Event not found at " + encodedHref + ", searching permanenturl by urlcompname");
// failover, search item by urlcompname // failover, search item by urlcompname
MultiStatusResponse[] responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, DavExchangeSession.this.isEqualTo("urlcompname", convertItemNameToEML(itemName)), FolderQueryTraversal.Shallow); MultiStatusResponse[] responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, DavExchangeSession.this.isEqualTo("urlcompname", convertItemNameToEML(itemName)), FolderQueryTraversal.Shallow, 1);
if (responses.length == 1) { if (responses.length == 1) {
encodedHref = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "permanenturl"); encodedHref = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "permanenturl");
LOGGER.warn("Event found, permanenturl is " + encodedHref); LOGGER.warn("Event found, permanenturl is " + encodedHref);
@ -1007,7 +1007,7 @@ public class DavExchangeSession extends ExchangeSession {
FolderQueryTraversal mode = (!isPublic && recursive) ? FolderQueryTraversal.Deep : FolderQueryTraversal.Shallow; FolderQueryTraversal mode = (!isPublic && recursive) ? FolderQueryTraversal.Deep : FolderQueryTraversal.Shallow;
List<Folder> folders = new ArrayList<Folder>(); List<Folder> folders = new ArrayList<Folder>();
MultiStatusResponse[] responses = searchItems(folderPath, FOLDER_PROPERTIES, and(isTrue("isfolder"), isFalse("ishidden"), condition), mode); MultiStatusResponse[] responses = searchItems(folderPath, FOLDER_PROPERTIES, and(isTrue("isfolder"), isFalse("ishidden"), condition), mode, 0);
for (MultiStatusResponse response : responses) { for (MultiStatusResponse response : responses) {
Folder folder = buildFolder(response); Folder folder = buildFolder(response);
@ -1165,7 +1165,7 @@ public class DavExchangeSession extends ExchangeSession {
@Override @Override
public MessageList searchMessages(String folderPath, Set<String> attributes, Condition condition) throws IOException { public MessageList searchMessages(String folderPath, Set<String> attributes, Condition condition) throws IOException {
MessageList messages = new MessageList(); MessageList messages = new MessageList();
MultiStatusResponse[] responses = searchItems(folderPath, attributes, and(isFalse("isfolder"), isFalse("ishidden"), condition), FolderQueryTraversal.Shallow); MultiStatusResponse[] responses = searchItems(folderPath, attributes, and(isFalse("isfolder"), isFalse("ishidden"), condition), FolderQueryTraversal.Shallow, 0);
for (MultiStatusResponse response : responses) { for (MultiStatusResponse response : responses) {
Message message = buildMessage(response); Message message = buildMessage(response);
@ -1180,11 +1180,11 @@ public class DavExchangeSession extends ExchangeSession {
* @inheritDoc * @inheritDoc
*/ */
@Override @Override
public List<ExchangeSession.Contact> searchContacts(String folderPath, Set<String> attributes, Condition condition) throws IOException { public List<ExchangeSession.Contact> searchContacts(String folderPath, Set<String> attributes, Condition condition, int maxCount) throws IOException {
List<ExchangeSession.Contact> contacts = new ArrayList<ExchangeSession.Contact>(); List<ExchangeSession.Contact> contacts = new ArrayList<ExchangeSession.Contact>();
MultiStatusResponse[] responses = searchItems(folderPath, attributes, MultiStatusResponse[] responses = searchItems(folderPath, attributes,
and(isEqualTo("outlookmessageclass", "IPM.Contact"), isFalse("isfolder"), isFalse("ishidden"), condition), and(isEqualTo("outlookmessageclass", "IPM.Contact"), isFalse("isfolder"), isFalse("ishidden"), condition),
FolderQueryTraversal.Shallow); FolderQueryTraversal.Shallow, maxCount);
for (MultiStatusResponse response : responses) { for (MultiStatusResponse response : responses) {
contacts.add(new Contact(response)); contacts.add(new Contact(response));
} }
@ -1194,7 +1194,7 @@ public class DavExchangeSession extends ExchangeSession {
@Override @Override
public List<ExchangeSession.Event> searchEvents(String folderPath, Set<String> attributes, Condition condition) throws IOException { public List<ExchangeSession.Event> searchEvents(String folderPath, Set<String> attributes, Condition condition) throws IOException {
List<ExchangeSession.Event> events = new ArrayList<ExchangeSession.Event>(); List<ExchangeSession.Event> events = new ArrayList<ExchangeSession.Event>();
MultiStatusResponse[] responses = searchItems(folderPath, attributes, and(isFalse("isfolder"), isFalse("ishidden"), condition), FolderQueryTraversal.Shallow); MultiStatusResponse[] responses = searchItems(folderPath, attributes, and(isFalse("isfolder"), isFalse("ishidden"), condition), FolderQueryTraversal.Shallow, 0);
for (MultiStatusResponse response : responses) { for (MultiStatusResponse response : responses) {
String instancetype = getPropertyIfExists(response.getProperties(HttpStatus.SC_OK), "instancetype"); String instancetype = getPropertyIfExists(response.getProperties(HttpStatus.SC_OK), "instancetype");
Event event = new Event(response); Event event = new Event(response);
@ -1216,7 +1216,8 @@ public class DavExchangeSession extends ExchangeSession {
return events; return events;
} }
protected MultiStatusResponse[] searchItems(String folderPath, Set<String> attributes, Condition condition, FolderQueryTraversal folderQueryTraversal) throws IOException { protected MultiStatusResponse[] searchItems(String folderPath, Set<String> attributes, Condition condition,
FolderQueryTraversal folderQueryTraversal, int maxCount) throws IOException {
String folderUrl = getFolderPath(folderPath); String folderUrl = getFolderPath(folderPath);
StringBuilder searchRequest = new StringBuilder(); StringBuilder searchRequest = new StringBuilder();
searchRequest.append("SELECT ") searchRequest.append("SELECT ")
@ -1233,7 +1234,7 @@ public class DavExchangeSession extends ExchangeSession {
} }
DavGatewayTray.debug(new BundleMessage("LOG_SEARCH_QUERY", searchRequest)); DavGatewayTray.debug(new BundleMessage("LOG_SEARCH_QUERY", searchRequest));
return DavGatewayHttpClientFacade.executeSearchMethod( return DavGatewayHttpClientFacade.executeSearchMethod(
httpClient, URIUtil.encodePath(folderUrl), searchRequest.toString()); httpClient, URIUtil.encodePath(folderUrl), searchRequest.toString(), maxCount);
} }
protected static final Set<String> EVENT_REQUEST_PROPERTIES = new HashSet<String>(); protected static final Set<String> EVENT_REQUEST_PROPERTIES = new HashSet<String>();
@ -1268,7 +1269,7 @@ public class DavExchangeSession extends ExchangeSession {
} catch (HttpNotFoundException e) { } catch (HttpNotFoundException e) {
LOGGER.debug(itemPath + " not found, searching by urlcompname"); LOGGER.debug(itemPath + " not found, searching by urlcompname");
// failover: try to get event by displayname // failover: try to get event by displayname
responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, isEqualTo("urlcompname", emlItemName), FolderQueryTraversal.Shallow); responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, isEqualTo("urlcompname", emlItemName), FolderQueryTraversal.Shallow, 1);
if (responses.length == 0) { if (responses.length == 0) {
throw new HttpNotFoundException(itemPath + " not found"); throw new HttpNotFoundException(itemPath + " not found");
} }
@ -1278,7 +1279,7 @@ public class DavExchangeSession extends ExchangeSession {
String urlcompname = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "urlcompname"); String urlcompname = getPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "urlcompname");
if ("urn:content-classes:person".equals(contentClass)) { if ("urn:content-classes:person".equals(contentClass)) {
// retrieve Contact properties // retrieve Contact properties
List<ExchangeSession.Contact> contacts = searchContacts(folderPath, CONTACT_ATTRIBUTES, isEqualTo("urlcompname", urlcompname)); List<ExchangeSession.Contact> contacts = searchContacts(folderPath, CONTACT_ATTRIBUTES, isEqualTo("urlcompname", urlcompname), 1);
if (contacts.isEmpty()) { if (contacts.isEmpty()) {
LOGGER.warn("Item found, but unable to build contact"); LOGGER.warn("Item found, but unable to build contact");
throw new HttpNotFoundException(itemPath + " not found"); throw new HttpNotFoundException(itemPath + " not found");
@ -1454,7 +1455,7 @@ public class DavExchangeSession extends ExchangeSession {
Set<String> attributes = new HashSet<String>(); Set<String> attributes = new HashSet<String>();
attributes.add("roamingdictionary"); attributes.add("roamingdictionary");
MultiStatusResponse[] responses = searchItems("/users/" + getEmail() + "/NON_IPM_SUBTREE", attributes, isEqualTo("messageclass", "IPM.Configuration.OWA.UserOptions"), DavExchangeSession.FolderQueryTraversal.Deep); MultiStatusResponse[] responses = searchItems("/users/" + getEmail() + "/NON_IPM_SUBTREE", attributes, isEqualTo("messageclass", "IPM.Configuration.OWA.UserOptions"), DavExchangeSession.FolderQueryTraversal.Deep, 1);
if (responses.length == 1) { if (responses.length == 1) {
byte[] roamingdictionary = getBinaryPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "roamingdictionary"); byte[] roamingdictionary = getBinaryPropertyIfExists(responses[0].getProperties(HttpStatus.SC_OK), "roamingdictionary");
if (roamingdictionary != null) { if (roamingdictionary != null) {

View File

@ -55,6 +55,7 @@ public abstract class EWSMethod extends PostMethod {
protected Disposal deleteType; protected Disposal deleteType;
protected Set<AttributeOption> methodOptions; protected Set<AttributeOption> methodOptions;
protected ElementOption unresolvedEntry; protected ElementOption unresolvedEntry;
protected int maxCount;
protected Set<FieldUpdate> updates; protected Set<FieldUpdate> updates;
@ -343,6 +344,7 @@ public abstract class EWSMethod extends PostMethod {
protected void writeSoapBody(Writer writer) throws IOException { protected void writeSoapBody(Writer writer) throws IOException {
startChanges(writer); startChanges(writer);
writeShape(writer); writeShape(writer);
writeIndexedPageItemView(writer);
writeRestriction(writer); writeRestriction(writer);
writeParentFolderId(writer); writeParentFolderId(writer);
writeToFolderId(writer); writeToFolderId(writer);
@ -358,7 +360,15 @@ public abstract class EWSMethod extends PostMethod {
endChanges(writer); endChanges(writer);
} }
private void writeAttachmentId(Writer writer) throws IOException { protected void writeIndexedPageItemView(Writer writer) throws IOException {
if (maxCount > 0) {
writer.write("<m:IndexedPageItemView MaxEntriesReturned=\"");
writer.write(String.valueOf(maxCount));
writer.write("\" Offset=\"0\" BasePoint=\"Beginning\"/>");
}
}
protected void writeAttachmentId(Writer writer) throws IOException {
if (attachmentId != null) { if (attachmentId != null) {
if ("CreateAttachment".equals(methodName)) { if ("CreateAttachment".equals(methodName)) {
writer.write("<m:AttachmentShape>"); writer.write("<m:AttachmentShape>");

View File

@ -269,7 +269,7 @@ public class EwsExchangeSession extends ExchangeSession {
@Override @Override
public MessageList searchMessages(String folderPath, Set<String> attributes, Condition condition) throws IOException { public MessageList searchMessages(String folderPath, Set<String> attributes, Condition condition) throws IOException {
MessageList messages = new MessageList(); MessageList messages = new MessageList();
List<EWSMethod.Item> responses = searchItems(folderPath, attributes, condition, FolderQueryTraversal.SHALLOW); List<EWSMethod.Item> responses = searchItems(folderPath, attributes, condition, FolderQueryTraversal.SHALLOW, 0);
for (EWSMethod.Item response : responses) { for (EWSMethod.Item response : responses) {
Message message = buildMessage(response); Message message = buildMessage(response);
@ -280,8 +280,8 @@ public class EwsExchangeSession extends ExchangeSession {
return messages; return messages;
} }
protected List<EWSMethod.Item> searchItems(String folderPath, Set<String> attributes, Condition condition, FolderQueryTraversal folderQueryTraversal) throws IOException { protected List<EWSMethod.Item> searchItems(String folderPath, Set<String> attributes, Condition condition, FolderQueryTraversal folderQueryTraversal, int maxCount) throws IOException {
FindItemMethod findItemMethod = new FindItemMethod(folderQueryTraversal, BaseShape.ID_ONLY, getFolderId(folderPath)); FindItemMethod findItemMethod = new FindItemMethod(folderQueryTraversal, BaseShape.ID_ONLY, getFolderId(folderPath), maxCount);
for (String attribute : attributes) { for (String attribute : attributes) {
findItemMethod.addAdditionalProperty(Field.get(attribute)); findItemMethod.addAdditionalProperty(Field.get(attribute));
} }
@ -922,10 +922,10 @@ public class EwsExchangeSession extends ExchangeSession {
} }
@Override @Override
public List<ExchangeSession.Contact> searchContacts(String folderPath, Set<String> attributes, Condition condition) throws IOException { public List<ExchangeSession.Contact> searchContacts(String folderPath, Set<String> attributes, Condition condition, int maxCount) throws IOException {
List<ExchangeSession.Contact> contacts = new ArrayList<ExchangeSession.Contact>(); List<ExchangeSession.Contact> contacts = new ArrayList<ExchangeSession.Contact>();
List<EWSMethod.Item> responses = searchItems(folderPath, attributes, condition, List<EWSMethod.Item> responses = searchItems(folderPath, attributes, condition,
FolderQueryTraversal.SHALLOW); FolderQueryTraversal.SHALLOW, maxCount);
for (EWSMethod.Item response : responses) { for (EWSMethod.Item response : responses) {
contacts.add(new Contact(response)); contacts.add(new Contact(response));
@ -938,7 +938,7 @@ public class EwsExchangeSession extends ExchangeSession {
List<ExchangeSession.Event> events = new ArrayList<ExchangeSession.Event>(); List<ExchangeSession.Event> events = new ArrayList<ExchangeSession.Event>();
List<EWSMethod.Item> responses = searchItems(folderPath, attributes, List<EWSMethod.Item> responses = searchItems(folderPath, attributes,
condition, condition,
FolderQueryTraversal.SHALLOW); FolderQueryTraversal.SHALLOW, 0);
for (EWSMethod.Item response : responses) { for (EWSMethod.Item response : responses) {
events.add(new Event(response)); events.add(new Event(response));
} }
@ -968,7 +968,7 @@ public class EwsExchangeSession extends ExchangeSession {
executeMethod(getItemMethod); executeMethod(getItemMethod);
item = getItemMethod.getResponseItem(); item = getItemMethod.getResponseItem();
} else { } else {
List<EWSMethod.Item> responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, isEqualTo("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW); List<EWSMethod.Item> responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, isEqualTo("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW, 0);
if (!responses.isEmpty()) { if (!responses.isEmpty()) {
item = responses.get(0); item = responses.get(0);
} }
@ -1039,10 +1039,9 @@ public class EwsExchangeSession extends ExchangeSession {
@Override @Override
public void deleteItem(String folderPath, String itemName) throws IOException { public void deleteItem(String folderPath, String itemName) throws IOException {
String urlcompname = convertItemNameToEML(itemName); EWSMethod.Item item = getEwsItem(folderPath, itemName);
List<EWSMethod.Item> responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, isEqualTo("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW); if (item != null) {
if (!responses.isEmpty()) { DeleteItemMethod deleteItemMethod = new DeleteItemMethod(new ItemId(item), DeleteType.HardDelete);
DeleteItemMethod deleteItemMethod = new DeleteItemMethod(new ItemId(responses.get(0)), DeleteType.HardDelete);
executeMethod(deleteItemMethod); executeMethod(deleteItemMethod);
} }
} }
@ -1050,15 +1049,15 @@ public class EwsExchangeSession extends ExchangeSession {
@Override @Override
public void processItem(String folderPath, String itemName) throws IOException { public void processItem(String folderPath, String itemName) throws IOException {
String urlcompname = convertItemNameToEML(itemName); String urlcompname = convertItemNameToEML(itemName);
List<EWSMethod.Item> responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, isEqualTo("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW); EWSMethod.Item item = getEwsItem(folderPath, itemName);
if (!responses.isEmpty()) { if (item != null) {
HashMap<String, String> localProperties = new HashMap<String, String>(); HashMap<String, String> localProperties = new HashMap<String, String>();
localProperties.put("processed", "1"); localProperties.put("processed", "1");
localProperties.put("read", "1"); localProperties.put("read", "1");
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly, UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
ConflictResolution.AlwaysOverwrite, ConflictResolution.AlwaysOverwrite,
SendMeetingInvitationsOrCancellations.SendToNone, SendMeetingInvitationsOrCancellations.SendToNone,
new ItemId(responses.get(0)), buildProperties(localProperties)); new ItemId(item), buildProperties(localProperties));
executeMethod(updateItemMethod); executeMethod(updateItemMethod);
} }
} }

View File

@ -29,11 +29,12 @@ public class FindItemMethod extends EWSMethod {
* @param baseShape base item shape * @param baseShape base item shape
* @param parentFolderId parent folder id * @param parentFolderId parent folder id
*/ */
public FindItemMethod(FolderQueryTraversal traversal, BaseShape baseShape, FolderId parentFolderId) { public FindItemMethod(FolderQueryTraversal traversal, BaseShape baseShape, FolderId parentFolderId, int maxCount) {
super("Item", "FindItem"); super("Item", "FindItem");
this.traversal = traversal; this.traversal = traversal;
this.baseShape = baseShape; this.baseShape = baseShape;
this.parentFolderId = parentFolderId; this.parentFolderId = parentFolderId;
this.maxCount = maxCount;
} }
} }

View File

@ -291,10 +291,12 @@ public final class DavGatewayHttpClientFacade {
* @param httpClient http client instance * @param httpClient http client instance
* @param path <i>encoded</i> searched folder path * @param path <i>encoded</i> searched folder path
* @param searchRequest (SQL like) search request * @param searchRequest (SQL like) search request
* @param maxCount max item count
* @return Responses enumeration * @return Responses enumeration
* @throws IOException on error * @throws IOException on error
*/ */
public static MultiStatusResponse[] executeSearchMethod(HttpClient httpClient, String path, String searchRequest) throws IOException { public static MultiStatusResponse[] executeSearchMethod(HttpClient httpClient, String path, String searchRequest,
int maxCount) throws IOException {
String searchBody = "<?xml version=\"1.0\"?>\n" + String searchBody = "<?xml version=\"1.0\"?>\n" +
"<d:searchrequest xmlns:d=\"DAV:\">\n" + "<d:searchrequest xmlns:d=\"DAV:\">\n" +
" <d:sql>" + StringUtil.xmlEncode(searchRequest) + "</d:sql>\n" + " <d:sql>" + StringUtil.xmlEncode(searchRequest) + "</d:sql>\n" +
@ -312,6 +314,9 @@ public final class DavGatewayHttpClientFacade {
} }
}; };
searchMethod.setRequestEntity(new StringRequestEntity(searchBody, "text/xml", "UTF-8")); searchMethod.setRequestEntity(new StringRequestEntity(searchBody, "text/xml", "UTF-8"));
if (maxCount > 0) {
searchMethod.addRequestHeader("Range", "rows=0-"+(maxCount-1));
}
return executeMethod(httpClient, searchMethod); return executeMethod(httpClient, searchMethod);
} }

View File

@ -1408,7 +1408,7 @@ public class LdapConnection extends AbstractConnection {
Map<String, Map<String, String>> results = new HashMap<String, Map<String, String>>(); Map<String, Map<String, String>> results = new HashMap<String, Map<String, String>>();
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, contactReturningAttributes, condition); List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, contactReturningAttributes, condition, 0);
for (ExchangeSession.Contact contact : contacts) { for (ExchangeSession.Contact contact : contacts) {
if (contact.get("imapUid") != null) { if (contact.get("imapUid") != null) {

View File

@ -39,7 +39,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
if (itemName != null) { if (itemName != null) {
return (ExchangeSession.Contact) session.getItem("testcontactfolder", itemName); return (ExchangeSession.Contact) session.getItem("testcontactfolder", itemName);
} else { } else {
List<ExchangeSession.Contact> contacts = session.searchContacts("testcontactfolder", ExchangeSession.CONTACT_ATTRIBUTES, null); List<ExchangeSession.Contact> contacts = session.searchContacts("testcontactfolder", ExchangeSession.CONTACT_ATTRIBUTES, null, 0);
itemName = contacts.get(0).itemName; itemName = contacts.get(0).itemName;
return contacts.get(0); return contacts.get(0);
} }

View File

@ -32,16 +32,22 @@ import java.util.Set;
public class TestExchangeSessionSearchContact extends AbstractExchangeSessionTestCase { public class TestExchangeSessionSearchContact extends AbstractExchangeSessionTestCase {
public void testSearchPublicContacts() throws IOException { public void testSearchPublicContacts() throws IOException {
String folderPath = Settings.getProperty("davmail.publicContactFolder"); String folderPath = Settings.getProperty("davmail.publicContactFolder");
List<ExchangeSession.Contact> contacts = session.searchContacts(folderPath, ExchangeSession.CONTACT_ATTRIBUTES, null); List<ExchangeSession.Contact> contacts = session.searchContacts(folderPath, ExchangeSession.CONTACT_ATTRIBUTES, null, 0);
int count = 0; int count = 0;
for (ExchangeSession.Contact contact : contacts) { for (ExchangeSession.Contact contact : contacts) {
System.out.println("Contact " + (++count) + '/' + contacts.size() + session.getItem(folderPath, contact.getName())); System.out.println("Contact " + (++count) + '/' + contacts.size() + session.getItem(folderPath, contact.getName()));
} }
} }
public void testSearchPublicContactsRange() throws IOException {
String folderPath = Settings.getProperty("davmail.publicContactFolder");
List<ExchangeSession.Contact> contacts = session.searchContacts(folderPath, ExchangeSession.CONTACT_ATTRIBUTES, null, 10);
assertEquals(10, contacts.size());
}
public void testSearchPublicContactsWithPicture() throws IOException { public void testSearchPublicContactsWithPicture() throws IOException {
String folderPath = Settings.getProperty("davmail.publicContactFolder"); String folderPath = Settings.getProperty("davmail.publicContactFolder");
List<ExchangeSession.Contact> contacts = session.searchContacts(folderPath, ExchangeSession.CONTACT_ATTRIBUTES, session.isTrue("haspicture")); List<ExchangeSession.Contact> contacts = session.searchContacts(folderPath, ExchangeSession.CONTACT_ATTRIBUTES, session.isTrue("haspicture"), 0);
int count = 0; int count = 0;
for (ExchangeSession.Contact contact : contacts) { for (ExchangeSession.Contact contact : contacts) {
System.out.println("Contact " + (++count) + '/' + contacts.size() + contact.getBody()); System.out.println("Contact " + (++count) + '/' + contacts.size() + contact.getBody());
@ -50,7 +56,7 @@ public class TestExchangeSessionSearchContact extends AbstractExchangeSessionTes
} }
public void testSearchContacts() throws IOException { public void testSearchContacts() throws IOException {
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, ExchangeSession.CONTACT_ATTRIBUTES, null); List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, ExchangeSession.CONTACT_ATTRIBUTES, null, 0);
for (ExchangeSession.Contact contact : contacts) { for (ExchangeSession.Contact contact : contacts) {
System.out.println(session.getItem(ExchangeSession.CONTACTS, contact.getName())); System.out.println(session.getItem(ExchangeSession.CONTACTS, contact.getName()));
} }
@ -59,7 +65,7 @@ public class TestExchangeSessionSearchContact extends AbstractExchangeSessionTes
public void testSearchContactsUidOnly() throws IOException { public void testSearchContactsUidOnly() throws IOException {
Set<String> attributes = new HashSet<String>(); Set<String> attributes = new HashSet<String>();
attributes.add("uid"); attributes.add("uid");
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, attributes, null); List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, attributes, null, 0);
for (ExchangeSession.Contact contact : contacts) { for (ExchangeSession.Contact contact : contacts) {
System.out.println(contact); System.out.println(contact);
} }
@ -68,9 +74,9 @@ public class TestExchangeSessionSearchContact extends AbstractExchangeSessionTes
public void testSearchContactsByUid() throws IOException { public void testSearchContactsByUid() throws IOException {
Set<String> attributes = new HashSet<String>(); Set<String> attributes = new HashSet<String>();
attributes.add("uid"); attributes.add("uid");
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, attributes, null); List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, attributes, null, 0);
for (ExchangeSession.Contact contact : contacts) { for (ExchangeSession.Contact contact : contacts) {
System.out.println(session.searchContacts(ExchangeSession.CONTACTS, attributes, session.isEqualTo("uid", contact.get("uid")))); System.out.println(session.searchContacts(ExchangeSession.CONTACTS, attributes, session.isEqualTo("uid", contact.get("uid")), 0));
} }
} }

View File

@ -112,7 +112,7 @@ public class TestDavExchangeSession extends AbstractExchangeSessionTestCase {
Set<String> attributes = new HashSet<String>(); Set<String> attributes = new HashSet<String>();
attributes.add("permanenturl"); attributes.add("permanenturl");
attributes.add("roamingxmlstream"); attributes.add("roamingxmlstream");
MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/calendar", attributes, davSession.and(davSession.isFalse("isfolder"), davSession.isEqualTo("messageclass", "IPM.Configuration.CategoryList")), DavExchangeSession.FolderQueryTraversal.Shallow); MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/calendar", attributes, davSession.and(davSession.isFalse("isfolder"), davSession.isEqualTo("messageclass", "IPM.Configuration.CategoryList")), DavExchangeSession.FolderQueryTraversal.Shallow, 0);
String value = (String) responses[0].getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingxmlstream")).getValue(); String value = (String) responses[0].getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingxmlstream")).getValue();
String propertyList = new String(Base64.decodeBase64(value.getBytes()), "UTF-8"); String propertyList = new String(Base64.decodeBase64(value.getBytes()), "UTF-8");
System.out.println(propertyList); System.out.println(propertyList);
@ -127,7 +127,7 @@ public class TestDavExchangeSession extends AbstractExchangeSessionTestCase {
Set<String> attributes = new HashSet<String>(); Set<String> attributes = new HashSet<String>();
attributes.add("permanenturl"); attributes.add("permanenturl");
attributes.add("roamingxmlstream"); attributes.add("roamingxmlstream");
MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/calendar", attributes, davSession.and(davSession.isFalse("isfolder"), davSession.isEqualTo("messageclass", "IPM.Configuration.Calendar")), DavExchangeSession.FolderQueryTraversal.Shallow); MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/calendar", attributes, davSession.and(davSession.isFalse("isfolder"), davSession.isEqualTo("messageclass", "IPM.Configuration.Calendar")), DavExchangeSession.FolderQueryTraversal.Shallow, 0);
String value = (String) responses[0].getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingxmlstream")).getValue(); String value = (String) responses[0].getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingxmlstream")).getValue();
String propertyList = new String(Base64.decodeBase64(value.getBytes()), "UTF-8"); String propertyList = new String(Base64.decodeBase64(value.getBytes()), "UTF-8");
System.out.println(propertyList); System.out.println(propertyList);
@ -145,7 +145,7 @@ public class TestDavExchangeSession extends AbstractExchangeSessionTestCase {
attributes.add("roamingxmlstream"); attributes.add("roamingxmlstream");
attributes.add("displayname"); attributes.add("displayname");
MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + '/', attributes, davSession.and(davSession.isTrue("ishidden")), DavExchangeSession.FolderQueryTraversal.Deep); MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + '/', attributes, davSession.and(davSession.isTrue("ishidden")), DavExchangeSession.FolderQueryTraversal.Deep, 0);
for (MultiStatusResponse response : responses) { for (MultiStatusResponse response : responses) {
System.out.println(response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("messageclass")).getValue() + ": " System.out.println(response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("messageclass")).getValue() + ": "
+ response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("displayname")).getValue()); + response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("displayname")).getValue());
@ -171,7 +171,7 @@ public class TestDavExchangeSession extends AbstractExchangeSessionTestCase {
attributes.add("roamingdictionary"); attributes.add("roamingdictionary");
attributes.add("displayname"); attributes.add("displayname");
MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/non_ipm_subtree", attributes, davSession.and(davSession.isTrue("ishidden")), DavExchangeSession.FolderQueryTraversal.Deep); MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/non_ipm_subtree", attributes, davSession.and(davSession.isTrue("ishidden")), DavExchangeSession.FolderQueryTraversal.Deep, 0);
for (MultiStatusResponse response : responses) { for (MultiStatusResponse response : responses) {
System.out.println(response.getHref() + ' ' + response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("messageclass")).getValue() + ": " System.out.println(response.getHref() + ' ' + response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("messageclass")).getValue() + ": "
+ response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("displayname")).getValue()); + response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("displayname")).getValue());