def get_subject ( self , msg ) : text , encoding = decode_header ( msg [ 'subject' ] ) [ - 1 ] try : text = text . decode ( encoding ) # If it's already decoded, ignore error except AttributeError : pass return text
python mail subject decode
Extracts the subject line from an EmailMessage object .
def get_subject(self, msg):
        """Extracts the subject line from an EmailMessage object."""

        text, encoding = decode_header(msg['subject'])[-1]

        try:
            text = text.decode(encoding)

        # If it's already decoded, ignore error
        except AttributeError:
            pass

        return text