if method msg.get_charset evaluates to true, call the get_output_charset method on the return value of the msg.get_charset method, substitute the result for charset, otherwise if it is false, substitute the string 'utf-8' for charset.
charset = msg . get_charset ( ) . get_output_charset ( ) if msg . get_charset ( ) else 'utf-8'