Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attachment headers #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rasa
Copy link
Contributor

@rasa rasa commented Apr 21, 2022

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))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant