code: def typed_subpart_iterator(msg, maintype='text', subtype=None):
      
      for subpart in msg.walk():
          if subpart.get_content_maintype() == maintype:
              if subtype is None or subpart.get_content_subtype() == subtype:
                  yield subpart
docs: Iterate over the subparts with a given MIME type.
  
      Use `maintype' as the main MIME type to match against; this defaults to
      "text".  Optional `subtype' is the MIME subtype to match against; if
      omitted, only the main type is matched.