Dav: fix bug 3022451 in new search filter implementation with empty sub conditions

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1117 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-01 14:23:31 +00:00
parent ad42f58f24
commit 1038fa5d1b
6 changed files with 248 additions and 4 deletions

View File

@ -600,7 +600,14 @@ public abstract class ExchangeSession {
*
* @param buffer search filter buffer
*/
public abstract void appendTo(StringBuilder buffer);
public void appendTo(StringBuilder buffer);
/**
* True if condition is empty.
*
* @return true if condition is empty
*/
public boolean isEmpty();
}
/**
@ -616,6 +623,10 @@ public abstract class ExchangeSession {
this.operator = operator;
this.value = value;
}
public boolean isEmpty() {
return false;
}
}
/**
@ -641,6 +652,17 @@ public abstract class ExchangeSession {
conditions.add(condition);
}
}
public boolean isEmpty() {
boolean isEmpty = true;
for (Condition condition: conditions) {
if (!condition.isEmpty()) {
isEmpty = false;
break;
}
}
return isEmpty;
}
}
/**
@ -652,6 +674,11 @@ public abstract class ExchangeSession {
protected NotCondition(Condition condition) {
this.condition = condition;
}
public boolean isEmpty() {
return condition.isEmpty();
}
}
/**
@ -665,6 +692,10 @@ public abstract class ExchangeSession {
this.attributeName = attributeName;
this.operator = operator;
}
public boolean isEmpty() {
return false;
}
}
/**

View File

@ -364,7 +364,7 @@ public class DavExchangeSession extends ExchangeSession {
boolean first = true;
for (Condition condition : conditions) {
if (condition != null) {
if (condition != null && !condition.isEmpty()) {
if (first) {
buffer.append('(');
first = false;

View File

@ -244,6 +244,11 @@ public class EwsExchangeSession extends ExchangeSession {
attributeMap.get(attributeName).appendTo(buffer);
buffer.append("</t:Exists></t:Not>");
}
public boolean isEmpty() {
return false;
}
}
@Override

View File

@ -0,0 +1,81 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2010 Mickael Guessant
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package davmail.exchange;
import davmail.Settings;
import davmail.http.DavGatewayHttpClientFacade;
import junit.framework.TestCase;
import org.apache.commons.httpclient.util.URIUtil;
import org.apache.jackrabbit.webdav.client.methods.PropPatchMethod;
import org.apache.jackrabbit.webdav.property.DavProperty;
import org.apache.jackrabbit.webdav.property.DavPropertyName;
import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
import org.apache.jackrabbit.webdav.xml.Namespace;
import org.apache.log4j.Level;
import java.io.IOException;
import java.util.ArrayList;
/**
* Test contact search
*/
public class ExchangeSessionContactTest extends AbstractExchangeSessionTestCase {
@Override
public void setUp() throws IOException {
super.setUp();
}
/*
public void testSearchPrivateFlag() throws IOException {
ExchangeSession.MessageList messageList = session.searchMessages("Contacts", " AND \"http://schemas.microsoft.com/mapi/proptag/0x360003\" = 2");
assertEquals(1, messageList.size());
}
public void testSearchPrivateFlag2() throws IOException {
ExchangeSession.MessageList messageList = session.searchMessages("Contacts", " AND \"http://schemas.microsoft.com/mapi/sensitivity\" = 2");
assertEquals(1, messageList.size());
}
public void testSearchPrivateFlag3() throws IOException {
ExchangeSession.MessageList messageList = session.searchMessages("Contacts", " AND \"http://schemas.microsoft.com/exchange/sensitivity\" = 2");
assertEquals(1, messageList.size());
}
public void testSearchPrivateFlag4() throws IOException {
ExchangeSession.MessageList messageList = session.searchMessages("Contacts", " AND Cast(\"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/0x8506\" as \"boolean\") = true");
assertEquals(1, messageList.size());
}
//
public void testUnsetPrivateFlag() throws IOException {
String messageUrl = URIUtil.encodePathQuery(session.getFolderPath("Contacts") + '/' + "test test" + ".EML");
ArrayList<DavProperty> list = new ArrayList<DavProperty>();
list.add(new DefaultDavProperty(DavPropertyName.create("sensitivity", Namespace.getNamespace("http://schemas.microsoft.com/mapi/")), "0"));
PropPatchMethod propPatchMethod = new PropPatchMethod(messageUrl, list);
DavGatewayHttpClientFacade.executeMethod(session.getHttpClient(), propPatchMethod);
}
public void testSetPrivateFlag() throws IOException {
String messageUrl = URIUtil.encodePathQuery(session.getFolderPath("Contacts") + '/' + "test test" + ".EML");
ArrayList<DavProperty> list = new ArrayList<DavProperty>();
list.add(new DefaultDavProperty(DavPropertyName.create("sensitivity", Namespace.getNamespace("http://schemas.microsoft.com/mapi/")), "2"));
PropPatchMethod propPatchMethod = new PropPatchMethod(messageUrl, list);
//DavGatewayHttpClientFacade.executeMethod(session.getHttpClient(), propPatchMethod);
ExchangeSession.MessageList messageList = session.searchMessages("Contacts", " AND Cast(\"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/0x8506\" as \"boolean\") = true");
assertEquals(1, messageList.size());
} */
}

View File

@ -0,0 +1,122 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2010 Mickael Guessant
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package davmail.exchange;
import davmail.Settings;
import davmail.exchange.dav.DavExchangeSession;
import davmail.exchange.ews.EwsExchangeSession;
import davmail.http.DavGatewaySSLProtocolSocketFactory;
import junit.framework.TestCase;
import org.apache.log4j.Level;
import java.io.IOException;
import java.util.List;
/**
* Test Exchange adapter methods.
*/
public class TestExchangeAdapter extends TestCase {
ExchangeSession davSession;
ExchangeSession ewsSession;
@Override
public void setUp() throws IOException {
if (davSession == null) {
Settings.setConfigFilePath("davmail.properties");
Settings.load();
DavGatewaySSLProtocolSocketFactory.register();
davSession = new DavExchangeSession(Settings.getProperty("davmail.url"),
Settings.getProperty("davmail.username"), Settings.getProperty("davmail.password"));
ewsSession = new EwsExchangeSession(Settings.getProperty("davmail.url"),
Settings.getProperty("davmail.username"), Settings.getProperty("davmail.password"));
Settings.setLoggingLevel("httpclient.wire", Level.INFO);
}
}
public void assertEquals(ExchangeSession.Folder davFolder, ExchangeSession.Folder ewsFolder) {
assertNotNull(ewsFolder);
assertEquals(davFolder.folderPath, ewsFolder.folderPath);
assertEquals(davFolder.folderClass, ewsFolder.folderClass);
assertEquals(davFolder.hasChildren, ewsFolder.hasChildren);
assertEquals(davFolder.unreadCount, ewsFolder.unreadCount);
assertEquals(davFolder.isCalendar(), false);
assertEquals(ewsFolder.isCalendar(), false);
assertEquals(davFolder.isContact(), false);
assertEquals(ewsFolder.isContact(), false);
assertEquals(davFolder.noInferiors, false);
assertEquals(ewsFolder.noInferiors, false);
assertEquals(davFolder.getFlags(), ewsFolder.getFlags());
assertEquals(davFolder.etag.substring(0, ewsFolder.ctag.length()-1)+ 'Z', ewsFolder.etag);
assertNotNull(davFolder.ctag);
assertNotNull(ewsFolder.ctag);
// dav and ews ctags are still different: dav contentag has milliseconds info
assertEquals(davFolder.ctag.substring(0, ewsFolder.ctag.length()-1)+ 'Z', ewsFolder.ctag);
}
public void testGetInbox() throws IOException {
ExchangeSession.Folder davFolder = davSession.getFolder("INBOX");
ExchangeSession.Folder ewsFolder = ewsSession.getFolder("INBOX");
assertEquals(davFolder, ewsFolder);
}
public void testGetSubFolder() throws IOException {
ExchangeSession.Folder ewsFolder = ewsSession.getFolder("INBOX/bbbb");
}
public void testFindFolder() throws IOException {
List<ExchangeSession.Folder> davFolders = davSession.getSubFolders("", false);
Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
List<ExchangeSession.Folder> ewsFolders = ewsSession.getSubFolders("", false);
assertEquals(davFolders.size(), ewsFolders.size());
}
public void testFindPublicFolder() throws IOException {
List<ExchangeSession.Folder> davFolders = davSession.getSubFolders("/public", false);
Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
List<ExchangeSession.Folder> ewsFolders = ewsSession.getSubFolders("/public", false);
assertEquals(davFolders.size(), ewsFolders.size());
}
public void testFindFolders() throws IOException {
List<ExchangeSession.Folder> davFolders = davSession.getSubFolders("/public", null, true);
System.out.println(davFolders);
}
public void testSearchMessages() throws IOException {
ExchangeSession.MessageList messages = davSession.searchMessages("INBOX");
for (ExchangeSession.Message message:messages) {
System.out.println(message);
}
}
public void testSearchEvents() throws IOException {
List<ExchangeSession.Event> events = davSession.getAllEvents("calendar");
for (ExchangeSession.Event event:events) {
System.out.println(event);
}
}
}

View File

@ -71,9 +71,14 @@ public class TestImap extends AbstractExchangeSessionTestCase {
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
}
public void testUidSearchUndeleted() throws IOException {
public void testUidSearchDeleted() throws IOException {
writeLine(". UID SEARCH UNDELETED");
assertEquals(". OK", readFullAnswer("."));
assertEquals(". OK SEARCH completed", readFullAnswer("."));
}
public void testUidSearchUndeleted() throws IOException {
writeLine(". UID SEARCH DELETED");
assertEquals(". OK SEARCH completed", readFullAnswer("."));
}
public void testLogout() throws IOException {