def __imap_fetch_content_type(self, msg_nums, content_type):
if not msg_nums:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>if not content_type:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>contents = {}<EOL>self.imap_connect()<EOL>for num in msg_nums:<EOL><INDENT>status, data = self.mailbox.fetch(num, "<STR_LIT>")<EOL>for response_part in data:<EOL><INDENT>if isinstance(response_part, tuple):<EOL><INDENT>msg = email.message_from_string(response_part[<NUM_LIT:1>])<EOL>for part in msg.walk():<EOL><INDENT>if str(part.get_content_type()) == content_type:<EOL><INDENT>content = str(part.get_payload(decode=True))<EOL>contents[int(num)] = content<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>self.imap_disconnect()<EOL>return contents<EOL>
Given a message number that we found with imap_search, fetch the
whole source, dump that into an email object, and pick out the part
that matches the content type specified. Return that, if we got
multiple emails, return dict of all the parts.
@Params
msg_nums - message number to search for
content_type - content type of email message to return
@Returns
Specified content type string or dict of all content types of matched
email.