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

Support CC/BCC importing on rfc822 #72

Open
wants to merge 1 commit into
base: master
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
10 changes: 10 additions & 0 deletions emails/loader/local_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,16 @@ def copy_header_to_message(self, message, name, value):
if r:
message.mail_to = r

elif name == 'cc':
r = self.decode_address_header_value(value)
if r:
message.cc = r

elif name == 'bcc':
r = self.decode_address_header_value(value)
if r:
message.bcc = r

elif name == 'from':
r = self.decode_address_header_value(value)
if r:
Expand Down
3 changes: 3 additions & 0 deletions emails/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ def _build_root_message(self, message_cls=None, **kw):
if self.cc:
self.set_header(msg, 'Cc', ", ".join([self.encode_address_header(addr) for addr in self.cc]), encode=False)

if self.bcc:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought Bcc should be used in SMTP MAIL TO command only.
Is there any reason to include it in message headers?

self.set_header(msg, 'Bcc', ", ".join([self.encode_address_header(addr) for addr in self.bcc]), encode=False)

return msg

def _build_html_part(self):
Expand Down
6 changes: 5 additions & 1 deletion emails/testsuite/loader/test_rfc822_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def test_msgloader():
data = {'charset': 'utf-8',
'subject': 'Что-то по-русски',
'mail_from': ('Максим Иванов', '[email protected]'),
'mail_to': [('Полина Сергеева', '[email protected]'),('test', '[email protected]')],
'mail_to': [('Полина Сергеева', '[email protected]'), ('test', '[email protected]')],
'cc': [('CC User', '[email protected]'), ('cc', '[email protected]')],
'bcc': [('BCC User', '[email protected]')],
'html': '<h1>Привет!</h1><p>В первых строках...',
'text': 'Привет!\nВ первых строках...',
'headers': {'X-Mailer': 'python-emails',
Expand All @@ -68,6 +70,8 @@ def test_msgloader():
assert loader.content(map_cid) == 'Y'

assert message.mail_to == data['mail_to']
assert message.cc == data['cc']
assert message.bcc == data['bcc']
assert message.subject == data['subject']
print(message._headers)
assert message._headers['sender'] == '웃'
Expand Down