How to get more than 1000 responses from gMail using Python imaplib

377 views Asked by At

I've read a dozen of tickets here, and tried a couple of solutions, but can't get it to work.

I have a folder where my errologs are e-mailed, called [GenFail], and I do the following using python3:

try:
    rv, data = M.login(EM_ACCOUNT, "xxxxx")
except imaplib.IMAP4.error:
    print ("LOGIN FAILED!!! ")
    sys.exit(1)
rv, data = M.select("[GenFail]")
rv, data = M.uid('search', None, "ALL")
# rv,data = M.fetch(uid, '(X-GM-LABELS)')
mail_uid_list = data[0].split()

This works, but I'm always getting only the first 1000 UID's, and can't find out how to get the rest of them. Thre are 984 "threads", where some threads can have up to 100 emails, so I'd say there are in total more than 90k e-mails.

Now, I'm not trying to download all of them, would be more interested to get let's say - all from last 3 months, or just X times 1000, but can't find the solution for it.

Thanks

1

There are 1 answers

0
Balkyto On BEST ANSWER

I've spent a bunch of time googling this, and the problem is not in the code, but in the mailbox settings.

In the IMAP Access settings there's a radio button that enables blocking the access to 1000 e-mails, and there's no way around it.

Enabling it to get all, and then smart filtering is the way.