simplegmail icon indicating copy to clipboard operation
simplegmail copied to clipboard

Add attachment headers

Open rasa opened this issue 3 years ago • 0 comments

My editor removed trailing spaces, sorry 'bout that.

Example usage:

from simplegmail import Gmail

gmail = Gmail()

messages = gmail.get_unread_inbox()

message = messages[0]
if message.attachments:
    for attm in message.attachments:
        print('File: ' + attm.filename)
        if '[email protected]' in attm.headers.get('From'):
            attm.save()  # downloads and saves each attachment under its name
        for k, v in attm.headers.items():
            # RFC 5322 allows for duplicate header keys. See https://www.rfc-editor.org/rfc/rfc5322#section-3.6
            if isinstance(v, list):
                v = ', '.join(v)
            print('%s: %s' % (k, v))

rasa avatar Apr 21 '22 15:04 rasa