code: def get_headers(msg):
      
      headers = {}
      for k in msg.keys():
          # decode_header decodes header but does not convert charset, so these
          # may still be bytes, even in Python 3. However, if it's ASCII
          # only (hence unambiguous encoding), the header fields come back
          # as str (unicode) in Python 3.
          (header_txt, charset) = email.header.decode_header(msg[k])[0]
          if charset is not None:
              header_txt = header_txt.decode(charset)
          headers[k] = header_txt
      return headers
docs: Takes email.message.Message object initialized from unicode string,
      returns dict with header fields.