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

Added content_id variable for use with cid inline images. #104

Open
wants to merge 1 commit into
base: main
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
1 change: 0 additions & 1 deletion docs/_themes
Submodule _themes deleted from 0269f3
29 changes: 20 additions & 9 deletions flask_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from __future__ import with_statement

__version__ = '0.9.1'
__version__ = '0.9.2'

import re
import blinker
Expand Down Expand Up @@ -225,15 +225,17 @@ class Attachment(object):
:param content_type: file mimetype
:param data: the raw file data
:param disposition: content-disposition (if any)
:param content_id: content-id for inline reference
"""

def __init__(self, filename=None, content_type=None, data=None,
disposition=None, headers=None):
disposition=None, headers=None, content_id=None):
self.filename = filename
self.content_type = content_type
self.data = data
self.disposition = disposition or 'attachment'
self.headers = headers or {}
self.content_id = content_id


class Message(object):
Expand Down Expand Up @@ -297,7 +299,7 @@ def __init__(self, subject='',
@property
def send_to(self):
return set(self.recipients) | set(self.bcc or ()) | set(self.cc or ())

@property
def html(self):
return self.alts.get('html')
Expand All @@ -308,7 +310,7 @@ def html(self, value):
self.alts.pop('html', None)
else:
self.alts['html'] = value

def _mimetext(self, text, subtype='plain'):
"""Creates a MIMEText object with the given subtype (default: 'plain')
If the text is unicode, the utf-8 charset is used.
Expand Down Expand Up @@ -379,13 +381,20 @@ def _message(self):
filename = filename.encode('utf8')
filename = ('UTF8', '', filename)

f.add_header('Content-Disposition',
attachment.disposition,
filename=filename)
try:
f.replace_header('Content-Disposition', attachment.disposition +';'+ ' filename=' + filename)
except KeyError:
f.add_header('Content-Disposition', attachment.disposition, filename=filename)

for key, value in attachment.headers.items():
f.add_header(key, value)

if attachment.content_id:
try:
f.replace_header('Content-ID', attachment.content_id)
except KeyError:
f.add_header('Content-ID', attachment.content_id)

msg.attach(f)
if message_policy:
msg.policy = message_policy
Expand Down Expand Up @@ -454,16 +463,18 @@ def attach(self,
content_type=None,
data=None,
disposition=None,
headers=None):
headers=None,
content_id=None):
"""Adds an attachment to the message.

:param filename: filename of attachment
:param content_type: file mimetype
:param data: the raw file data
:param disposition: content-disposition (if any)
:param content_id: content-id
"""
self.attachments.append(
Attachment(filename, content_type, data, disposition, headers))
Attachment(filename, content_type, data, disposition, headers, content_id))


class _MailMixin(object):
Expand Down