tags:

views:

40

answers:

2

Hey bit of a beginners question here, I have connected to an imap server using the imaplib and fetched a email, it returns the following:

[('1 (BODY[HEADER.FIELDS (SUBJECT)] {62}', "Subject: Gmail is different. Here's what you need to know.\r\n\r\n"), ')']

My question is how do I select just the subject element ("Subject: Gmail is...").

I have tried a few combinations but yet to be successful.

Thanks for any help!

+2  A: 
a[0][1]

where a is the string.

thebackhand
A: 
    email=[('1 (BODY[HEADER.FIELDS (SUBJECT)] {62}', "Subject: Gmail is different. Here's what you need to know.\r\n\r\n"), ')']
    for subj in (subject for element in email for subject in element if subject.startswith("Subject")):
        print subj
""" Output
    Subject: Gmail is different. Here's what you need to know.
"""
Tony Veijalainen