mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
IMAP: fix DELETED/UNDELETED SEARCH parameters
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@617 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
827a0bc806
commit
470008d873
@ -217,14 +217,11 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
} else if ("search".equalsIgnoreCase(subcommand)) {
|
} else if ("search".equalsIgnoreCase(subcommand)) {
|
||||||
SearchConditions conditions = new SearchConditions();
|
SearchConditions conditions = new SearchConditions();
|
||||||
conditions.append("AND (");
|
conditions.append("AND (");
|
||||||
boolean undeleted = true;
|
|
||||||
boolean or = false;
|
boolean or = false;
|
||||||
|
|
||||||
while (tokens.hasMoreTokens()) {
|
while (tokens.hasMoreTokens()) {
|
||||||
String token = tokens.nextToken();
|
String token = tokens.nextToken();
|
||||||
if ("UNDELETED".equals(token)) {
|
if ("OR".equals(token)) {
|
||||||
undeleted = true;
|
|
||||||
} else if ("OR".equals(token)) {
|
|
||||||
or = true;
|
or = true;
|
||||||
} else if (token.startsWith("OR ")) {
|
} else if (token.startsWith("OR ")) {
|
||||||
or = true;
|
or = true;
|
||||||
@ -250,7 +247,7 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
ExchangeSession.MessageList localMessages = session.searchMessages(currentFolder.folderName, query);
|
ExchangeSession.MessageList localMessages = session.searchMessages(currentFolder.folderName, query);
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for (ExchangeSession.Message message : localMessages) {
|
for (ExchangeSession.Message message : localMessages) {
|
||||||
if (((undeleted && !message.deleted) || !undeleted)
|
if ((conditions.deleted == null || message.deleted == conditions.deleted)
|
||||||
&& (conditions.flagged == null || message.flagged == conditions.flagged)
|
&& (conditions.flagged == null || message.flagged == conditions.flagged)
|
||||||
&& (conditions.answered == null || message.answered == conditions.answered)
|
&& (conditions.answered == null || message.answered == conditions.answered)
|
||||||
&& (conditions.startUid == 0 || message.getImapUid() >= conditions.startUid)
|
&& (conditions.startUid == 0 || message.getImapUid() >= conditions.startUid)
|
||||||
@ -645,6 +642,7 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
static final class SearchConditions {
|
static final class SearchConditions {
|
||||||
Boolean flagged;
|
Boolean flagged;
|
||||||
Boolean answered;
|
Boolean answered;
|
||||||
|
Boolean deleted;
|
||||||
long startUid;
|
long startUid;
|
||||||
int startIndex;
|
int startIndex;
|
||||||
final StringBuilder query = new StringBuilder();
|
final StringBuilder query = new StringBuilder();
|
||||||
@ -672,8 +670,7 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
|
|
||||||
protected void appendSearchParam(String operator, StringTokenizer tokens, String token, SearchConditions conditions) throws IOException {
|
protected void appendSearchParam(String operator, StringTokenizer tokens, String token, SearchConditions conditions) throws IOException {
|
||||||
if ("NOT".equals(token)) {
|
if ("NOT".equals(token)) {
|
||||||
conditions.append(operator).append(" NOT ");
|
appendSearchParam(operator + " NOT ", tokens, tokens.nextToken(), conditions);
|
||||||
appendSearchParam("", tokens, tokens.nextToken(), conditions);
|
|
||||||
} else if (token.startsWith("OR ")) {
|
} else if (token.startsWith("OR ")) {
|
||||||
appendOrSearchParams(token, conditions);
|
appendOrSearchParams(token, conditions);
|
||||||
} else if ("SUBJECT".equals(token)) {
|
} else if ("SUBJECT".equals(token)) {
|
||||||
@ -697,6 +694,10 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
conditions.append(operator).append("\"urn:schemas:httpmail:read\" = True");
|
conditions.append(operator).append("\"urn:schemas:httpmail:read\" = True");
|
||||||
} else if ("UNSEEN".equals(token) || "NEW".equals(token)) {
|
} else if ("UNSEEN".equals(token) || "NEW".equals(token)) {
|
||||||
conditions.append(operator).append("\"urn:schemas:httpmail:read\" = False");
|
conditions.append(operator).append("\"urn:schemas:httpmail:read\" = False");
|
||||||
|
} else if ("DELETED".equals(token)) {
|
||||||
|
conditions.deleted = !operator.endsWith(" NOT ");
|
||||||
|
} else if ("UNDELETED".equals(token)) {
|
||||||
|
conditions.deleted = Boolean.FALSE;
|
||||||
} else if ("FLAGGED".equals(token)) {
|
} else if ("FLAGGED".equals(token)) {
|
||||||
conditions.flagged = Boolean.TRUE;
|
conditions.flagged = Boolean.TRUE;
|
||||||
} else if ("UNFLAGGED".equals(token) || "NEW".equals(token)) {
|
} else if ("UNFLAGGED".equals(token) || "NEW".equals(token)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user