def get_subject_from_headers(headers):
"""
Get the subject of an email
:param `Message` headers: The SMTP headers of the email
:rtype: str
:return: The subject of the email
"""
subject = ''
subject_part = []
if 'Subject' in headers and headers['Subject'] is not None:
try:
decodefrag = decode_header(headers['Subject'])
except HeaderParseError:
return subject
for line, encoding in decodefrag:
enc = 'utf-8' if encoding is None or encoding == 'unknown' else encoding
subject_part.append(utils.decode_every_charset_in_the_world(line, enc))
subject = ''.join(subject_part)[:1023]
return subject
评论列表
文章目录