Python / imaplib - How to get message shortcuts?

I use imaplib for my project because I need to access gmails accounts. Fact: with gmail tags, each message can be on an arbitrary number of folders / fields / labels.

The problem is that I would like to get every single label from every single message.

The first solution I came up with is to use the All Mail folder to receive all messages, and then check for each message whether this message is included in each of the available folders.

However, I find this decision difficult, and I was wondering if there is a better way to do this.

Thanks!

+6
source share
2 answers

To get all the tags for a given message in gmail, you can do the following

t, d = imapconn.uid('FETCH', uid, '(X-GM-LABELS)') or t, d = imapconn.fetch(uid, '(X-GM-LABELS)') 

BTW: you can find more in the imap gmail extensions at http://code.google.com/apis/gmail/imap/

+10
source

In imap you don’t have any labels, gmail "imitates" them on imap, you can check low, in the original source of the message selected from imap, if it has any custom header with a label

+1
source

Source: https://habr.com/ru/post/888995/


All Articles