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 headers to email attachments #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion simplegmail/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import base64 # for base64.urlsafe_b64decode
import os # for os.path.exists
from typing import Optional
from typing import Optional, List, Dict

class Attachment(object):
"""
Expand All @@ -21,6 +21,7 @@ class should not be manually instantiated.
att_id: The id of the attachment.
filename: The filename associated with the attachment.
filetype: The mime type of the file.
headers: The headers of the attachment.
data: The raw data of the file. Default None.

Attributes:
Expand All @@ -30,6 +31,7 @@ class should not be manually instantiated.
id (str): The id of the attachment.
filename (str): The filename associated with the attachment.
filetype (str): The mime type of the file.
headers: The headers of the attachment.
data (bytes): The raw data of the file.

"""
Expand All @@ -42,6 +44,7 @@ def __init__(
att_id: str,
filename: str,
filetype: str,
headers: Optional[List[Dict]],
data: Optional[bytes] = None
) -> None:
self._service = service
Expand All @@ -50,6 +53,7 @@ def __init__(
self.id = att_id
self.filename = filename
self.filetype = filetype
self.headers = headers or []
self.data = data

def download(self) -> None:
Expand Down
3 changes: 2 additions & 1 deletion simplegmail/gmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def _build_message_from_ref(
elif part['part_type'] == 'attachment':
attm = Attachment(self.service, user_id, msg_id,
part['attachment_id'], part['filename'],
part['filetype'], part['data'])
part['filetype'], part['headers'], part['data'])
attms.append(attm)

return Message(
Expand Down Expand Up @@ -892,6 +892,7 @@ def _evaluate_message_payload(
'filetype': payload['mimeType'],
'filename': filename,
'attachment_id': att_id,
'headers': payload['headers'],
'data': None
}

Expand Down