def search(self, ** args):
if "<STR_LIT>" not in args.keys():<EOL><INDENT>content_type = None<EOL><DEDENT>elif "<STR_LIT>" in args["<STR_LIT>"]:<EOL><INDENT>content_type = self.HTML<EOL>del args["<STR_LIT>"]<EOL><DEDENT>elif "<STR_LIT>" in args["<STR_LIT>"]:<EOL><INDENT>content_type = self.PLAIN<EOL>del args["<STR_LIT>"]<EOL><DEDENT>elif args["<STR_LIT>"]:<EOL><INDENT>content_type = args['<STR_LIT>']<EOL>del args["<STR_LIT>"]<EOL><DEDENT>if "<STR_LIT>" not in args.keys():<EOL><INDENT>timeout = self.TIMEOUT<EOL><DEDENT>elif "<STR_LIT>" in args:<EOL><INDENT>timeout = args["<STR_LIT>"]<EOL>del args["<STR_LIT>"]<EOL><DEDENT>fetch = False<EOL>if "<STR_LIT>" in args.keys():<EOL><INDENT>fetch = True<EOL>del args["<STR_LIT>"]<EOL><DEDENT>results = None<EOL>timer = timeout<EOL>count = <NUM_LIT:0><EOL>while count < timer:<EOL><INDENT>results = self.__imap_search(** args)<EOL>if len(results) > <NUM_LIT:0>:<EOL><INDENT>if fetch:<EOL><INDENT>msgs = {}<EOL>for msgnum in results:<EOL><INDENT>msgs[msgnum] = self.fetch_message(msgnum)<EOL><DEDENT>return msgs<EOL><DEDENT>elif not content_type:<EOL><INDENT>return results<EOL><DEDENT>else:<EOL><INDENT>return self.__imap_fetch_content_type(results,<EOL>content_type)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>time.sleep(<NUM_LIT:15>)<EOL>count += <NUM_LIT:15><EOL><DEDENT><DEDENT>if count >= timer:<EOL><INDENT>raise EmailException(<EOL>"<STR_LIT>" %<EOL>(args, timeout / <NUM_LIT>))<EOL><DEDENT>
Checks email inbox every 15 seconds that match the criteria
up until timeout.

Search criteria should be keyword args eg
TO="selenium@gmail.com".  See __imap_search docstring for list
of valid criteria. If content_type is not defined, will return
a list of msg numbers.

Options:
- fetch: will return a dict of Message objects, keyed on msgnum,
  which can be used to look at headers and other parts of the complete
  message.  (http://docs.python.org/library/email.message.html)
- timeout: will replace the default module timeout with the
  value in SECONDS.
- content_type: should be either "PLAIN" or
  "HTML". If defined returns the source of the matched messages
  as a dict of msgnum:content. If not defined we return a list
  of msg nums.