Skip to content

Commit

Permalink
Tidy up addition of bcc and cc fields
Browse files Browse the repository at this point in the history
In particular, cc and bcc should be lists not strings. The same should
apply to the 'to' field, but this is a breaking change and so will be
addressed at a later date.
  • Loading branch information
jeremyephron committed Mar 12, 2023
1 parent 3a5669d commit 963a4b3
Showing 2 changed files with 33 additions and 17 deletions.
28 changes: 22 additions & 6 deletions simplegmail/gmail.py
Original file line number Diff line number Diff line change
@@ -785,9 +785,9 @@ def _build_message_from_ref(
elif hdr['name'].lower() == 'subject':
subject = hdr['value']
elif hdr['name'].lower() == 'cc':
cc = hdr['value']
cc = hdr['value'].split(', ')
elif hdr['name'].lower() == 'bcc':
bcc = hdr['value']
bcc = hdr['value'].split(', ')

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

@@ -815,17 +815,33 @@ def _build_message_from_ref(
part['filetype'], part['data'])
attms.append(attm)

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

def _evaluate_message_payload(
self,
payload: dict,
user_id: str,
msg_id: str,
attachments: str = 'reference'
) ->List[dict]:
) -> List[dict]:
"""
Recursively evaluates a message payload.
22 changes: 11 additions & 11 deletions simplegmail/message.py
Original file line number Diff line number Diff line change
@@ -37,8 +37,8 @@ class Message(object):
label_ids: the ids of labels associated with this message. Default [].
attachments: a list of attachments for the message. Default [].
headers: a dict of header values. Default {}
cc: who the message was CCd to.
bcc: who the message was BCCd to.
cc: who the message was cc'd on the message.
bcc: who the message was bcc'd on the message.
Attributes:
_service (googleapiclient.discovery.Resource): the Gmail service object.
@@ -54,8 +54,8 @@ class Message(object):
label_ids (List[str]): the ids of labels associated with this message.
attachments (List[Attachment]): a list of attachments for the message.
headers (dict): a dict of header values.
cc (str): who the message was CCd to.
bcc (str): who the message was BCCd to.
cc (List[str]): who the message was cc'd on the message.
bcc (List[str]): who the message was bcc'd on the message.
"""

@@ -76,8 +76,8 @@ def __init__(
label_ids: Optional[List[str]] = None,
attachments: Optional[List[Attachment]] = None,
headers: Optional[dict] = None,
cc: str = '',
bcc: str = ''
cc: Optional[List[str]] = None,
bcc: Optional[List[str]] = None
) -> None:
self._service = service
self.creds = creds
@@ -91,11 +91,11 @@ def __init__(
self.snippet = snippet
self.plain = plain
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 {}
self.cc = cc
self.bcc = bcc
self.label_ids = label_ids or []
self.attachments = attachments or []
self.headers = headers or {}
self.cc = cc or []
self.bcc = bcc or []

@property
def service(self) -> 'googleapiclient.discovery.Resource':

0 comments on commit 963a4b3

Please sign in to comment.