0

I'm using Imap_tools library and I'm trying to fetch the emails in a folder 10 by 10 (for pagination and performance purposes) when I tried using limit and passing a tuple to it like so:

mails = mailbox.fetch(reverse = True, headers_only = True, mark_seen=False, limit=(10,20)) 

I got the following error

File "C:\Python39\lib\site-packages\imap_tools\mailbox.py", line 147, in fetch
    assert type(limit_range) is slice
AssertionError

Is there anyone who has a solution or a better approach? I will be thankful!

Expected it to ignore the 1st 10 Emails and fetch the second 10 Emails!

2 Answers2

0

Seems like the library is looking for a slice :
(10, 20) => slice(11, 21)
11th mail to 20th mail for a total of 10 mails, considering first mail's index is 1.

Bil11
  • 85
  • 1
  • 9
0

Built-in Function - sliсe: https://docs.python.org/3/library/functions.html#slice

Also there is example: https://github.com/ikvk/imap_tools/blob/master/examples/fetch_by_pages.py

Vladimir
  • 6,162
  • 2
  • 32
  • 36