0

The following code will search for a string from emails found in "inbox". My problem is that I need to search across all folders. M.selct("All") does not work.

import imaplib

M = imaplib.IMAP4_SSL('imap.gmail.com')
M.login('sh.ak@gmail.com', 'xxx')
M.select("Inbox") 

ping=M.uid('search', None, '(HEADER Subject "Monthly Report")')

This is as good as typing this in google search bar:

Subject: "Monthly Report" in:inbox

But I need the search without "in:inbox" If I type M.select("All")

I get the following error:

error: command SEARCH illegal in state AUTH, only allowed in states SELECTED

How do I search across all mail including archived?

Cœur
  • 37,241
  • 25
  • 195
  • 267
shantanuo
  • 31,689
  • 78
  • 245
  • 403

1 Answers1

1

Select the "[Gmail]/All Mail" folder and search it.

Rick Sanders
  • 541
  • 1
  • 3
  • 3