I want to recover the value "SUBJECT" of an email
import imaplib
import os
import email
email_user = 'xxxxxxx@xxxxxxx'
email_pass = 'xxxxxxxx'
M = imaplib.IMAP4_SSL('imap.gmail.com', 993)
M.login(email_user, email_pass)
M.select('INBOX')
typ, message_numbers = M.search(None, 'ALL')
num = b'2420'
typ, data = M.fetch(num, '(RFC822)')
raw_email = data[0][1].decode('utf-8')
email_message = email.message_from_string(raw_email)
print(email_message['Subject'])
the value is
=?UTF-8?Q?=5BNAS=5FLEBARS=5D_Active_Backup_for_Business_=2D_La_t=C3=A2che_?=
=?UTF-8?Q?de_sauvegarde_DBS_=2D_SIDEXIS_sur_NAS=5FLEBARS_est_termin=C3=A9e?=
but i want this encode
[NAS_LEBARS] Active Backup for Business - La tâche de sauvegarde DBS - SIDEXIS sur NAS_LEBARS est terminée
Thanks