Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fetching E-mails 10 by 10 or n by n using Imap_tools python

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading