I am trying to extract mails from gmail using python. I noticed that I can get mails from "[Gmail]/All Mail", "[Gmail]/Drafts","[Gmail]/Spam" and so on. However, is there any method to retrieve mails that are labeled with "Primary", "Social", "Promotions" etc.? These tags are under the "categories" label, and I don't know how to access it.
By the way, I am using imaplib in python. Do I need to access the "categories" with some pop library?
Unfortunately the categories are not exposed to IMAP.  You can work around that by using filters in Gmail to apply normal user labels.  (Filter on, e.g., category:social.)
How to extract mail in "categories" label in gmail?