diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index fdc49ba1ff..06f3916ad9 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1029,25 +1029,29 @@ class Core { MessagingException ex = (MessagingException) ifolder.doCommand(new IMAPFolder.ProtocolCommand() { @Override public Object doCommand(IMAPProtocol protocol) { - Log.i("Executing uid fetch count=" + uids.size()); - Response[] responses = protocol.command( - "UID FETCH " + TextUtils.join(",", uids) + " (UID)", null); - - if (responses.length > 0 && responses[responses.length - 1].isOK()) { - for (Response response : responses) - if (response instanceof FetchResponse) { - FetchResponse fr = (FetchResponse) response; - UID uid = fr.getItem(UID.class); - if (uid != null) - uids.remove(uid.uid); - } - return null; - } else { - for (Response response : responses) - if (response.isNO() || response.isBAD() || response.isBYE()) - return new MessagingException(response.toString()); - return new MessagingException("UID FETCH failed"); + Log.i(folder.name + " executing uid fetch count=" + uids.size()); + List> chunked = Helper.chunkList(new ArrayList<>(uids), 25); + for (int c = 0; c < chunked.size(); c++) { + Log.i(folder.name + " chunk #" + c + " size=" + chunked.get(c).size()); + Response[] responses = protocol.command( + "UID FETCH " + TextUtils.join(",", chunked.get(c)) + " (UID)", null); + + if (responses.length > 0 && responses[responses.length - 1].isOK()) { + for (Response response : responses) + if (response instanceof FetchResponse) { + FetchResponse fr = (FetchResponse) response; + UID uid = fr.getItem(UID.class); + if (uid != null) + uids.remove(uid.uid); + } + } else { + for (Response response : responses) + if (response.isNO() || response.isBAD() || response.isBYE()) + return new MessagingException(response.toString()); + return new MessagingException("UID FETCH failed"); + } } + return null; } }); if (ex != null) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index ad5b61dcd1..3ceec374a4 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -576,6 +576,13 @@ public class Helper { return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("pro", false); } + public static List> chunkList(List list, int size) { + List> result = new ArrayList<>(list.size() / size); + for (int i = 0; i < list.size(); i += size) + result.add(list.subList(i, i + size < list.size() ? i + size : list.size())); + return result; + } + static long[] toLongArray(List list) { long[] result = new long[list.size()]; for (int i = 0; i < list.size(); i++)