-
Hi folks, First, thanks, Menno, for opening this discussion thread! I am making a CUI based IMAP client with py_cui (https://github.com/Laanan/Slither/tree/master), and I am struggling to understand how to list messages with multiple flags. For example, let's say I want to display the 50 newest messages, both seen and unseen. I have tried: ` def get_messages(self, folder):
` I am also hoping someone can direct me to further reading/a good book for helping me understand the methods/best practices/strategies for making an IMAP client function the way a user would expect. Something a little more in depth than a one off tutorial, and a little more tutorialy than the, somewhat staid, RFC document. Any advice would be greatly appreciated -- thank you! -- Matt |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You would need to use the sort command instead of search and slice the list to first 50. The sort command takes a sort criteria and a set of flags similar to search. But sort does not work in all IMAP servers including GMail as mentioned in Stackoverflow An alternative (as suggested in the above link) would be to search for ALL and fetch the BODY[HEADER] or ENVELOPE only, with which you can use the date to sort the mails in python. Once sorted you may slice the list and fetch the entire mail for the first 50. This method would certainly be much slowly with large mail boxes |
Beta Was this translation helpful? Give feedback.
-
Sorry I missed the main part of the question To pass multiple search criteria with an OR condition you can do the following this link helped me get familiar with the search options : or if you prefer you can refer to the RFC Document |
Beta Was this translation helpful? Give feedback.
Sorry I missed the main part of the question
To pass multiple search criteria with an OR condition you can do the following
connection.search(['OR', 'UNSEEN', 'SEEN'])
this link helped me get familiar with the search options :
IMAP Search Criteria gist
or if you prefer you can refer to the RFC Document