From 7a543b45b10b8e242b3e5a8fad926f3eaf874214 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 11 Jul 2010 12:31:34 +0000 Subject: [PATCH] Remove duplicate code between two message counting routines in ImapStore --- src/com/fsck/k9/mail/store/ImapStore.java | 35 ++++++++--------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index 6fd014bf5..3cd652350 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -908,8 +908,8 @@ public class ImapStore extends Store return mMessageCount; } - @Override - public int getUnreadMessageCount() throws MessagingException + + private int getMessageCount(String criteria) throws MessagingException { checkOpen(); try @@ -917,7 +917,7 @@ public class ImapStore extends Store int count = 0; int start = 1; - List responses = executeSimpleCommand(String.format("SEARCH %d:* UNSEEN NOT DELETED", start)); + List responses = executeSimpleCommand(String.format("SEARCH %d:* "+criteria, start)); for (ImapResponse response : responses) { if (ImapResponseParser.equalsIgnoreCase(response.get(0), "SEARCH")) @@ -931,31 +931,20 @@ public class ImapStore extends Store { throw ioExceptionHandler(mConnection, ioe); } + + + } + + @Override + public int getUnreadMessageCount() throws MessagingException + { + return getMessageCount("UNSEEN NOT DELETED"); } @Override public int getFlaggedMessageCount() throws MessagingException { - checkOpen(); - try - { - int count = 0; - int start = 1; - - List responses = executeSimpleCommand(String.format("SEARCH %d:* FLAGGED NOT DELETED", start)); - for (ImapResponse response : responses) - { - if (ImapResponseParser.equalsIgnoreCase(response.get(0), "SEARCH")) - { - count += response.size() - 1; - } - } - return count; - } - catch (IOException ioe) - { - throw ioExceptionHandler(mConnection, ioe); - } + return getMessageCount("FLAGGED NOT DELETED"); } protected int getHighestUid()