Prevent too long IMAP commands

pull/156/head
M66B 5 years ago
parent 1d98fea2df
commit b20c12edd1

@ -1029,25 +1029,29 @@ class Core {
MessagingException ex = (MessagingException) ifolder.doCommand(new IMAPFolder.ProtocolCommand() { MessagingException ex = (MessagingException) ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override @Override
public Object doCommand(IMAPProtocol protocol) { public Object doCommand(IMAPProtocol protocol) {
Log.i("Executing uid fetch count=" + uids.size()); Log.i(folder.name + " executing uid fetch count=" + uids.size());
Response[] responses = protocol.command( List<List<Long>> chunked = Helper.chunkList(new ArrayList<>(uids), 25);
"UID FETCH " + TextUtils.join(",", uids) + " (UID)", null); for (int c = 0; c < chunked.size(); c++) {
Log.i(folder.name + " chunk #" + c + " size=" + chunked.get(c).size());
if (responses.length > 0 && responses[responses.length - 1].isOK()) { Response[] responses = protocol.command(
for (Response response : responses) "UID FETCH " + TextUtils.join(",", chunked.get(c)) + " (UID)", null);
if (response instanceof FetchResponse) {
FetchResponse fr = (FetchResponse) response; if (responses.length > 0 && responses[responses.length - 1].isOK()) {
UID uid = fr.getItem(UID.class); for (Response response : responses)
if (uid != null) if (response instanceof FetchResponse) {
uids.remove(uid.uid); FetchResponse fr = (FetchResponse) response;
} UID uid = fr.getItem(UID.class);
return null; if (uid != null)
} else { uids.remove(uid.uid);
for (Response response : responses) }
if (response.isNO() || response.isBAD() || response.isBYE()) } else {
return new MessagingException(response.toString()); for (Response response : responses)
return new MessagingException("UID FETCH failed"); if (response.isNO() || response.isBAD() || response.isBYE())
return new MessagingException(response.toString());
return new MessagingException("UID FETCH failed");
}
} }
return null;
} }
}); });
if (ex != null) if (ex != null)

@ -576,6 +576,13 @@ public class Helper {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("pro", false); return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("pro", false);
} }
public static <T> List<List<T>> chunkList(List<T> list, int size) {
List<List<T>> 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<Long> list) { static long[] toLongArray(List<Long> list) {
long[] result = new long[list.size()]; long[] result = new long[list.size()];
for (int i = 0; i < list.size(); i++) for (int i = 0; i < list.size(); i++)

Loading…
Cancel
Save