diff --git a/src/java/davmail/imap/ImapConnection.java b/src/java/davmail/imap/ImapConnection.java index 3f123fd5..54cce143 100644 --- a/src/java/davmail/imap/ImapConnection.java +++ b/src/java/davmail/imap/ImapConnection.java @@ -287,8 +287,12 @@ public class ImapConnection extends AbstractConnection { } else if ("search".equalsIgnoreCase(subcommand)) { List uidList = handleSearch(tokens); - for (long uid : uidList) { - sendClient("* SEARCH " + uid); + if (uidList.isEmpty()) { + sendClient("* SEARCH"); + } else { + for (long uid : uidList) { + sendClient("* SEARCH " + uid); + } } sendClient(commandId + " OK SEARCH completed"); @@ -319,11 +323,15 @@ public class ImapConnection extends AbstractConnection { sendClient(commandId + " NO no folder selected"); } else { List uidList = handleSearch(tokens); - int currentIndex = 0; - for (ExchangeSession.Message message : currentFolder.messages) { - currentIndex++; - if (uidList.contains(message.getImapUid())) { - sendClient("* SEARCH " + currentIndex); + if (uidList.isEmpty()) { + sendClient("* SEARCH"); + } else { + int currentIndex = 0; + for (ExchangeSession.Message message : currentFolder.messages) { + currentIndex++; + if (uidList.contains(message.getImapUid())) { + sendClient("* SEARCH " + currentIndex); + } } } sendClient(commandId + " OK SEARCH completed");