0

Here is my code:

import imaplib
from email.parser import HeaderParser
conn = imaplib.IMAP4_SSL('imap.gmail.com')
conn.login('example@gmail.com', 'password')
conn.select()
conn.search(None, 'ALL')
data = conn.fetch('1', '(BODY[HEADER])')
header_data = data[1][0][1]
newdata = header_data.decode('utf-8')
parser = HeaderParser()
msg = parser.parsestr(newdata)
print (msg.keys())

This prints out the keys(headers) : Mime-version, x-no-auto-attachment, received, date, messageID, subject, from. to, content type.

However there is 2 missing, which are X-GM-THRID and X-Gmail-Labels? Any ideas why and how can i solve this?

1 Answers1

0

I don't think those are in the email header but extensions to the FETCH command:

conn.fetch('1', '(BODY[HEADER] X-GM-THRID X-GM-Labels)')

See Gmail's documentation.

JosiahDaniels
  • 2,411
  • 20
  • 37