code: def _encodeHeader(headerValue):
      
      try:
          return headerValue.encode('ascii', 'strict')
      except UnicodeError:
          encoded = headerValue.encode("utf-8")
          return header.Header(encoded, "UTF-8").encode()
docs: Encodes a header value.
  
      Returns ASCII if possible, else returns an UTF-8 encoded e-mail header.