code: def encode_header(header, charset='utf-8'):
      
  
      # Return empty headers unchanged
      if not header:
          return header
  
      # return plain header if it does not contain non-ascii characters
      if hqre.match(header):
          return header
  
      quoted = ''
      # max_encoded = 76 - len(charset) - 7
      for c in header:
          # Space may be represented as _ instead of =20 for readability
          if c == ' ':
              quoted += '_'
          # These characters can be included verbatim
          elif hqre.match(c):
              quoted += c
          # Otherwise, replace with hex value like =E2
          else:
              quoted += "=%02X" % ord(c)
  
      return '=?%s?q?%s?=' % (charset, quoted)
docs: Will encode in quoted-printable encoding only if header
      contains non latin characters