Get cached message count

pull/184/head
M66B 4 years ago
parent 920d9091b3
commit e338a110c0

@ -1659,6 +1659,28 @@ public class IMAPFolder extends Folder implements UIDFolder, ResponseHandler {
}
}
public synchronized int getCachedCount() {
synchronized (messageCacheLock) {
if (messageCache == null)
return -1;
try {
int count = 0;
int size = messageCache.size();
for (int i = 1; i <= size; i++) {
Message message = messageCache.getMessage(i);
if (message != null && !message.isExpunged())
count++;
}
return count;
} catch (Throwable ex) {
eu.faircode.email.Log.e(ex);
return -1;
}
}
}
/**
* Get the new message count.
*/

@ -29,6 +29,7 @@ import androidx.documentfile.provider.DocumentFile;
import androidx.preference.PreferenceManager;
import com.sun.mail.gimap.GmailMessage;
import com.sun.mail.imap.IMAPFolder;
import com.sun.mail.imap.IMAPMessage;
import com.sun.mail.util.ASCIIUtility;
import com.sun.mail.util.BASE64DecoderStream;
@ -2286,6 +2287,13 @@ public class MessageHelper {
static int getMessageCount(Folder folder) {
try {
// Prevent pool lock
if (folder instanceof IMAPFolder) {
int count = ((IMAPFolder) folder).getCachedCount();
Log.i(folder.getFullName() + " total count=" + count);
return count;
}
int count = 0;
for (Message message : folder.getMessages())
if (!message.isExpunged())

Loading…
Cancel
Save