mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
IMAP: implement deleted/undeleted search as condition instead of post filter
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1118 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
1038fa5d1b
commit
273bc920e7
@ -1005,7 +1005,8 @@ public class ImapConnection extends AbstractConnection {
|
||||
if ("NOT".equals(token)) {
|
||||
String nextToken = tokens.nextToken();
|
||||
if ("DELETED".equals(token)) {
|
||||
conditions.deleted = Boolean.FALSE;
|
||||
// conditions.deleted = Boolean.FALSE;
|
||||
return session.isNull("deleted");
|
||||
} else {
|
||||
return session.not(appendSearchParam(tokens, nextToken, conditions));
|
||||
}
|
||||
@ -1032,9 +1033,11 @@ public class ImapConnection extends AbstractConnection {
|
||||
} else if ("UNSEEN".equals(token) || "NEW".equals(token)) {
|
||||
return session.isFalse("read");
|
||||
} else if ("DELETED".equals(token)) {
|
||||
conditions.deleted = Boolean.TRUE;
|
||||
// conditions.deleted = Boolean.TRUE;
|
||||
return session.equals("deleted", "1");
|
||||
} else if ("UNDELETED".equals(token) || "NOT DELETED".equals(token)) {
|
||||
conditions.deleted = Boolean.FALSE;
|
||||
// conditions.deleted = Boolean.FALSE;
|
||||
return session.isNull("deleted");
|
||||
} else if ("FLAGGED".equals(token)) {
|
||||
conditions.flagged = Boolean.TRUE;
|
||||
} else if ("UNFLAGGED".equals(token) || "NEW".equals(token)) {
|
||||
|
73
src/test/davmail/AbstractDavMailTestCase.java
Normal file
73
src/test/davmail/AbstractDavMailTestCase.java
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import davmail.exchange.ExchangeSession;
|
||||
import davmail.http.DavGatewaySSLProtocolSocketFactory;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* DavMail generic test case.
|
||||
* Loads DavMail settings
|
||||
*/
|
||||
public class AbstractDavMailTestCase extends TestCase {
|
||||
protected static boolean loaded;
|
||||
protected static String url;
|
||||
protected static String certificateHash;
|
||||
protected static String username;
|
||||
protected static String password;
|
||||
protected static ExchangeSession session;
|
||||
|
||||
@Override
|
||||
public void setUp() throws IOException {
|
||||
if (!loaded) {
|
||||
loaded = true;
|
||||
|
||||
if (url == null) {
|
||||
// try to load settings from current folder davmail.properties
|
||||
File file = new File("davmail.properties");
|
||||
if (file.exists()) {
|
||||
Settings.setConfigFilePath("davmail.properties");
|
||||
}
|
||||
// Load current settings
|
||||
Settings.load();
|
||||
} else {
|
||||
Settings.setDefaultSettings();
|
||||
Settings.setProperty("davmail.url", url);
|
||||
Settings.setProperty("davmail.server.certificate.hash", certificateHash);
|
||||
Settings.setProperty("davmail.username", username);
|
||||
Settings.setProperty("davmail.password", password);
|
||||
}
|
||||
|
||||
|
||||
DavGatewaySSLProtocolSocketFactory.register();
|
||||
// force server mode
|
||||
Settings.setProperty("davmail.server", "true");
|
||||
|
||||
// enable WIRE debug log
|
||||
//Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
|
||||
// enable EWS support
|
||||
//Settings.setProperty("davmail.enableEws", "true");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -18,58 +18,25 @@
|
||||
*/
|
||||
package davmail.exchange;
|
||||
|
||||
import davmail.AbstractDavMailTestCase;
|
||||
import davmail.Settings;
|
||||
import davmail.exchange.dav.DavExchangeSession;
|
||||
import davmail.exchange.ews.EwsExchangeSession;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import davmail.Settings;
|
||||
import davmail.http.DavGatewaySSLProtocolSocketFactory;
|
||||
import org.apache.log4j.Level;
|
||||
|
||||
/**
|
||||
* Exchange session test case.
|
||||
* Open a session to default DavMail server as found in user davmail.properties,
|
||||
* except if url is not null
|
||||
*/
|
||||
public class AbstractExchangeSessionTestCase extends TestCase {
|
||||
protected static String url;
|
||||
protected static String certificateHash;
|
||||
protected static String username;
|
||||
protected static String password;
|
||||
public class AbstractExchangeSessionTestCase extends AbstractDavMailTestCase {
|
||||
protected static ExchangeSession session;
|
||||
|
||||
@Override
|
||||
public void setUp() throws IOException {
|
||||
super.setUp();
|
||||
if (session == null) {
|
||||
if (url == null) {
|
||||
// try to load settings from current folder davmail.properties
|
||||
File file = new File("davmail.properties");
|
||||
if (file.exists()) {
|
||||
Settings.setConfigFilePath("davmail.properties");
|
||||
}
|
||||
// Load current settings
|
||||
Settings.load();
|
||||
} else {
|
||||
Settings.setDefaultSettings();
|
||||
Settings.setProperty("davmail.url", url);
|
||||
Settings.setProperty("davmail.server.certificate.hash", certificateHash);
|
||||
Settings.setProperty("davmail.username", username);
|
||||
Settings.setProperty("davmail.password", password);
|
||||
}
|
||||
|
||||
|
||||
DavGatewaySSLProtocolSocketFactory.register();
|
||||
// force server mode
|
||||
Settings.setProperty("davmail.server", "true");
|
||||
|
||||
// enable WIRE debug log
|
||||
//Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
|
||||
// enable EWS support
|
||||
//Settings.setProperty("davmail.enableEws", "true");
|
||||
|
||||
// open session, get username and password from davmail.properties
|
||||
// Note: those properties should *not* exist in normal production mode,
|
||||
// they are not used by DavMail, just by this test case
|
||||
|
@ -18,8 +18,9 @@
|
||||
*/
|
||||
package davmail.imap;
|
||||
|
||||
import davmail.AbstractDavMailTestCase;
|
||||
import davmail.DavGateway;
|
||||
import davmail.Settings;
|
||||
import davmail.exchange.AbstractExchangeSessionTestCase;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
@ -27,7 +28,7 @@ import java.net.Socket;
|
||||
/**
|
||||
* IMAP tests, an instance of DavMail Gateway must be available
|
||||
*/
|
||||
public class TestImap extends AbstractExchangeSessionTestCase {
|
||||
public class TestImap extends AbstractDavMailTestCase {
|
||||
static Socket clientSocket;
|
||||
static BufferedWriter socketWriter;
|
||||
static BufferedReader socketReader;
|
||||
@ -50,6 +51,8 @@ public class TestImap extends AbstractExchangeSessionTestCase {
|
||||
public void setUp() throws IOException {
|
||||
super.setUp();
|
||||
if (clientSocket == null) {
|
||||
// start gateway
|
||||
DavGateway.start();
|
||||
clientSocket = new Socket("localhost", Settings.getIntProperty("davmail.imapPort"));
|
||||
socketWriter = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
|
||||
socketReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
|
||||
@ -71,6 +74,16 @@ public class TestImap extends AbstractExchangeSessionTestCase {
|
||||
assertEquals(". OK [READ-WRITE] SELECT completed", readFullAnswer("."));
|
||||
}
|
||||
|
||||
public void testFetchFlags() throws IOException {
|
||||
writeLine(". UID FETCH 1:* (FLAGS)");
|
||||
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
|
||||
}
|
||||
|
||||
public void testStoreDelete() throws IOException {
|
||||
writeLine(". UID STORE 10 +FLAGS (\\Deleted)");
|
||||
readFullAnswer(".");
|
||||
}
|
||||
|
||||
public void testUidSearchDeleted() throws IOException {
|
||||
writeLine(". UID SEARCH UNDELETED");
|
||||
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
||||
@ -81,6 +94,11 @@ public class TestImap extends AbstractExchangeSessionTestCase {
|
||||
assertEquals(". OK SEARCH completed", readFullAnswer("."));
|
||||
}
|
||||
|
||||
public void testStoreUndelete() throws IOException {
|
||||
writeLine(". UID STORE 10 -FLAGS (\\Deleted)");
|
||||
readFullAnswer(".");
|
||||
}
|
||||
|
||||
public void testLogout() throws IOException {
|
||||
writeLine(". LOGOUT");
|
||||
assertEquals("* BYE Closing connection", socketReader.readLine());
|
||||
|
Loading…
Reference in New Issue
Block a user