mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-05 00:23:09 +02:00
Prevent too long IMAP commands
This commit is contained in:
@@ -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);
|
||||
Log.i(folder.name + " executing uid fetch count=" + uids.size());
|
||||
List<List<Long>> 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);
|
||||
}
|
||||
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");
|
||||
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)
|
||||
|
||||
@@ -576,6 +576,13 @@ public class Helper {
|
||||
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) {
|
||||
long[] result = new long[list.size()];
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
|
||||
Reference in New Issue
Block a user