Skip to content

Commit

Permalink
Message: expose headers
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyephron committed Mar 11, 2023
1 parent 982fec4 commit e9e6c81
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="simplegmail",
version="4.0.0",
version="4.0.1",
url="https://github.com/jeremyephron/simplegmail",
author="Jeremy Ephron",
author_email="jeremyephron@gmail.com",
Expand Down
7 changes: 5 additions & 2 deletions simplegmail/gmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def _build_message_from_ref(
self,
user_id: str,
message_ref: dict,
attachments: Union['ignore', 'reference', 'download'] = 'reference',
attachments: Union['ignore', 'reference', 'download'] = 'reference'
) -> Message:
"""
Creates a Message object from a reference.
Expand Down Expand Up @@ -725,6 +725,7 @@ def _build_message_from_ref(
sender = ''
recipient = ''
subject = ''
msg_hdrs = {}
for hdr in headers:
if hdr['name'] == 'Date':
try:
Expand All @@ -737,6 +738,8 @@ def _build_message_from_ref(
recipient = hdr['value']
elif hdr['name'] == 'Subject':
subject = hdr['value']

msg_hdrs[hdr['name']] = hdr['value']

parts = self._evaluate_message_payload(
payload, user_id, message_ref['id'], attachments
Expand Down Expand Up @@ -764,7 +767,7 @@ def _build_message_from_ref(

return Message(self.service, user_id, msg_id, thread_id, recipient,
sender, subject, date, snippet, plain_msg, html_msg, label_ids,
attms)
attms, msg_hdrs)

def _evaluate_message_payload(
self,
Expand Down
8 changes: 5 additions & 3 deletions simplegmail/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

class Message(object):
"""
The Message class for emails in your Gmail mailbox. This class should not be
manually constructed. Contains all information about the associated
The Message class for emails in your Gmail mailbox. This class should not
be manually constructed. Contains all information about the associated
message, and can be used to modify the message's labels (e.g., marking as
read/unread, archiving, moving to trash, starring, etc.).
Expand Down Expand Up @@ -66,7 +66,8 @@ def __init__(
plain: Optional[str] = None,
html: Optional[str] = None,
label_ids: Optional[List[str]] = None,
attachments: Optional[List[Attachment]] = None
attachments: Optional[List[Attachment]] = None,
headers: Optional[dict] = None
) -> None:
self._service = service
self.user_id = user_id
Expand All @@ -81,6 +82,7 @@ def __init__(
self.html = html
self.label_ids = label_ids if label_ids is not None else []
self.attachments = attachments if attachments is not None else []
self.headers = headers if headers else {}

def __repr__(self) -> str:
"""Represents the object by its sender, recipient, and id."""
Expand Down

0 comments on commit e9e6c81

Please sign in to comment.