MCPcopy Index your code
hub / github.com/O365/python-o365 / to_api_data

Method to_api_data

O365/message.py:650–722  ·  view source on GitHub ↗

Returns a dict representation of this message prepared to be sent to the cloud :param restrict_keys: a set of keys to restrict the returned data to :type restrict_keys: dict or set :return: converted to cloud based keys :rtype: dict

(self, restrict_keys=None)

Source from the content-addressed store, hash-verified

648 self.__message_headers.append({"name": name, "value": value})
649
650 def to_api_data(self, restrict_keys=None):
651 """ Returns a dict representation of this message prepared to be sent
652 to the cloud
653
654 :param restrict_keys: a set of keys to restrict the returned
655 data to
656 :type restrict_keys: dict or set
657 :return: converted to cloud based keys
658 :rtype: dict
659 """
660
661 cc = self._cc # alias to shorten the code
662
663 message = {
664 cc('subject'): self.subject,
665 cc('body'): {
666 cc('contentType'): self.body_type,
667 cc('content'): self.body},
668 cc('importance'): cc(self.importance.value),
669 cc('flag'): self.flag.to_api_data(),
670 cc('isReadReceiptRequested'): self.is_read_receipt_requested,
671 cc('isDeliveryReceiptRequested'): self.is_delivery_receipt_requested,
672 }
673
674 if self.to:
675 message[cc('toRecipients')] = [self._recipient_to_cloud(recipient)
676 for recipient in self.to]
677 if self.cc:
678 message[cc('ccRecipients')] = [self._recipient_to_cloud(recipient)
679 for recipient in self.cc]
680 if self.bcc:
681 message[cc('bccRecipients')] = [self._recipient_to_cloud(recipient)
682 for recipient in self.bcc]
683 if self.reply_to:
684 message[cc('replyTo')] = [self._recipient_to_cloud(recipient) for
685 recipient in self.reply_to]
686 if self.attachments:
687 message[cc('attachments')] = self.attachments.to_api_data()
688 if self.sender and self.sender.address:
689 message[cc('from')] = self._recipient_to_cloud(self.sender)
690
691 if self.categories or 'categories' in (restrict_keys or {}):
692 message[cc('categories')] = self.categories
693
694 if self.object_id and not self.__is_draft:
695 # return the whole signature of this message
696
697 message[cc('id')] = self.object_id
698 if self.created:
699 message[cc('createdDateTime')] = self.created.astimezone(
700 dt.timezone.utc).isoformat()
701 if self.received:
702 message[cc('receivedDateTime')] = self.received.astimezone(
703 dt.timezone.utc).isoformat()
704 if self.sent:
705 message[cc('sentDateTime')] = self.sent.astimezone(
706 dt.timezone.utc).isoformat()
707 message[cc('hasAttachments')] = bool(self.attachments)

Callers 3

sendMethod · 0.95
save_messageMethod · 0.95
save_draftMethod · 0.95

Calls 1

_recipient_to_cloudMethod · 0.80

Tested by

no test coverage detected