Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _prepare_message(self, addresses, subject, contents, attachments, headers):
""" Prepare a MIME message """
if self.is_closed:
raise YagConnectionClosed('Login required again')
if isinstance(contents, text_type):
contents = [contents]
if isinstance(attachments, text_type):
attachments = [attachments]
# merge contents and attachments for now.
if attachments is not None:
for a in attachments:
if not os.path.isfile(a):
raise TypeError("'{0}' is not a valid filepath".format(a))
contents = attachments if contents is None else contents + attachments
has_included_images, content_objects = self._prepare_contents(contents)
msg = MIMEMultipart()
if headers is not None:
# Strangely, msg does not have an update method, so then manually.