code: def get_charset(message, default='ASCII'):
      
  
      charset = message.get_content_charset()
  
      if not charset:
          charset = message.get_charset()
  
      if not charset:
          charset = default
  
      try:
          codecs.lookup(charset)
      except LookupError:
          charset = default
  
      return charset
docs: Get the message charset