As you've got an email object msg
, then you can do:
message_lines = msg.get_payload().splitlines()
Then loop over each line:
for line in message_lines:
if 'Walmart' in line:
pass # do whatever
But again, be careful of what the payload is...
The other option, is to have the IMAP server do the work:
(retcode, messages) = conn.search(None, '(UNSEEN) (TEXT walmart)')
This will subset the number of messages that need to be fetched and then you can apply more complex matching if required...
What's also possible is to search by subject (if that's ultimately what you want to do):
(retcode, messages) = conn.search(None, '(UNSEEN) (SUBJECT Thanks for your Walmart.com Order)')