def header_encode(header, charset='iso-8859-1', keep_eols=False, maxlinelen=76, eol=NL):
 if (not header):
  return header
 if (not keep_eols):
  header = fix_eols(header)
 quoted = []
 if (maxlinelen is None):
  max_encoded = 100000
 else:
  max_encoded = (((maxlinelen - len(charset)) - MISC_LEN) - 1)
 for c in header:
  if (c == ' '):
   _max_append(quoted, '_', max_encoded)
  elif (not hqre.match(c)):
   _max_append(quoted, c, max_encoded)
  else:
   _max_append(quoted, ('=%02X' % ord(c)), max_encoded)
 joiner = (eol + ' ')
 return joiner.join([('=?%s?q?%s?=' % (charset, line)) for line in quoted])

def header_encode ( header , charset = 'iso-8859-1' , keep_eols = False , maxlinelen = 76 , eol = NL ) : if ( not header ) : return header if ( not keep_eols ) : header = fix_eols ( header ) quoted = [ ] if ( maxlinelen is None ) : max_encoded = 100000 else : max_encoded = ( ( ( maxlinelen - len ( charset ) ) - MISC_LEN ) - 1 ) for c in header : if ( c == ' ' ) : _max_append ( quoted , '_' , max_encoded ) elif ( not hqre . match ( c ) ) : _max_append ( quoted , c , max_encoded ) else : _max_append ( quoted , ( '=%02X' % ord ( c ) ) , max_encoded ) joiner = ( eol + ' ' ) return joiner . join ( [ ( '=?%s?q?%s?=' % ( charset , line ) ) for line in quoted ] )
encode a single header line with quoted-printable encoding .