def get_body_from_message(message, maintype, subtype):
body = six.text_type('<STR_LIT>')<EOL>for part in message.walk():<EOL><INDENT>if part.get('<STR_LIT>', '<STR_LIT>').startswith('<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>if part.get_content_maintype() == maintype andpart.get_content_subtype() == subtype:<EOL><INDENT>charset = part.get_content_charset()<EOL>this_part = part.get_payload(decode=True)<EOL>if charset:<EOL><INDENT>try:<EOL><INDENT>this_part = this_part.decode(charset, '<STR_LIT:replace>')<EOL><DEDENT>except LookupError:<EOL><INDENT>this_part = this_part.decode('<STR_LIT:ascii>', '<STR_LIT:replace>')<EOL>logger.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>charset<EOL>)<EOL><DEDENT>except ValueError:<EOL><INDENT>this_part = this_part.decode('<STR_LIT:ascii>', '<STR_LIT:replace>')<EOL>logger.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>this_part = this_part.decode('<STR_LIT:ascii>', '<STR_LIT:replace>')<EOL><DEDENT>body += this_part<EOL><DEDENT><DEDENT>return body<EOL>
Fetchs the body message matching main/sub content type.