def encode_7or8bit(msg):
 orig = msg.get_payload()
 if (orig is None):
  msg['Content-Transfer-Encoding'] = '7bit'
  return
 try:
  orig.encode('ascii')
 except UnicodeError:
  msg['Content-Transfer-Encoding'] = '8bit'
 else:
  msg['Content-Transfer-Encoding'] = '7bit'

def encode_7or8bit ( msg ) : orig = msg . get_payload ( ) if ( orig is None ) : msg [ 'Content-Transfer-Encoding' ] = '7bit' return try : orig . encode ( 'ascii' ) except UnicodeError : msg [ 'Content-Transfer-Encoding' ] = '8bit' else : msg [ 'Content-Transfer-Encoding' ] = '7bit'
set the content-transfer-encoding header to 7bit or 8bit .