using imaplib to fetch only the headers of the emails?
imaplib, python
Solution
In your example you would do this:
typ, data = M.fetch(num, '(BODY.PEEK[HEADER])')
Here is the spec.
Problem
Hi i was wondering if someone can help me on extracting the headers of my emails in gmail. I have this code: ``` import imaplib M = imaplib.IMAP4('imap.gmail.com') M.login('myusername', 'mypassword') M.select() typ, data = M.search(None, 'ALL') for num in data[0].split(): typ, data = M.fetch(num, '(RFC822)') print 'Message %s\n%s\n' % (num, data[0][1]) M.close() M.logout() ``` However, i only want to pull out the headers of each email, not the body? Can anyone sort me out please as i have no idea?