7

I'm trying to use the search function and am running into an issue. I can download all attachments from a gmail account and sort them according to the file extension. I have all of that code working right except when I add extra criteria to the search. Originally the search criteria was only for UNSEEN emails, which works and then flags the email as seen and moves it to the trash. I then decided to add to it. Here is the example: original:

resp, items = m.search (None, 'UNSEEN') 

new:

resp, items = m.search (None, '(FROM "email" SUBJECT "some text")', 'UNSEEN')

It results with the emails moved to the trash, still unread and none of the attachments downloaded. Anyone have any idea what I may be doing wrong here? Thanks.

Jeff
  • 103
  • 1
  • 2
  • 6
  • Your search criteria is wrong I guess.use some thing like '(FROM "email" SUBJECT "some text" UNSEEN)' – JithPS May 05 '16 at 06:19
  • I forgot all about this JithPS. I cant remember what I did about this but thanks! – Jeff Jul 09 '16 at 17:03

1 Answers1

8

To build on JithPS comment the right syntax is like this:

result, data = mail.search(None,'(FROM "email" SUBJECT "the subject" UNSEEN)')

The clauses are passed with capital letters and the criteria within quotes.

Aurasphere
  • 3,841
  • 12
  • 44
  • 71
Claudio Mazzoni
  • 168
  • 1
  • 12