0

This may be a newbie question, but I can't figure out why I can't successfully pass parameterized search criteria to imaplib.

Setup code is:

M = imaplib.IMAP4_SSL("imap.gmail.com", 993)
M.login("usrname", "passwd") 
typ, data = self.M.select()   # Select default mailbox

The following works:

typ, data = M.uid('search', None, '(SENTSINCE 01-Jan-2010)')

But if I try to pass the search criteria as a string I get

imaplib.error: UID command error: BAD ['Could not parse command']

This is the code that fails:

f = "'(SENTSINCE 01-Jan-1994)'"
typ, data = M.uid('search', None, f)

I've tried numerous syntax, read RFC3501. Is this a charset problem?

richmill
  • 1
  • 1
  • 2
  • try to remove one set of quotes in your string `f` – mata Jul 07 '12 at 19:33
  • Yup - that did it I'm embarrassed to say.. imaplib and gmail are very particular about syntax for criterion and I had two other problems in my actual code (a superfluous space and missing quotes). All three issues gave the BAD parse error but in none of my testing did I fix all three at the same time. Would like to understand how the parentheses work in this situation so any pointers to the core docs on that would be appreciated. – richmill Jul 09 '12 at 19:05
  • 1
    please clarify this question, the original bug, and the actual answer as an answer. i am having a similar problem and have been searching for an answer for many months... – jml Jun 17 '13 at 19:02

1 Answers1

0

You need to put the date within quotes and your code for that will be :

typ, data = M.uid('search', None, '(SENTSINCE "01-Jan-2010")')
PJay
  • 2,557
  • 1
  • 14
  • 12