Merge pull request #55 from lavr/develop

Merge develop
This commit is contained in:
Sergey Lavrinenko 2015-07-23 22:58:01 +03:00
commit 751d04872b
7 changed files with 40 additions and 9 deletions

View File

@ -67,7 +67,7 @@ Send and get response from smtp server:
r = message.send(to=('John Brown', 'jbrown@gmail.com'),
render={'name': 'John'},
smtp={'host':'smtp.mycompany.com', 'port': 465, 'ssl': True})
smtp={'host':'smtp.mycompany.com', 'port': 465, 'ssl': True, 'user': 'john', 'password': '***'})
assert r.status_code == 250

View File

@ -136,12 +136,17 @@ class BaseMessage(object):
date = property(get_date, set_date)
message_date = date
@property
def message_id(self):
mid = self._message_id
if mid is False:
return None
return is_callable(mid) and mid() or mid
@message_id.setter
def message_id(self, value):
self._message_id = value
@property
def attachments(self):
if self._attachments is None:
@ -208,7 +213,7 @@ class MessageBuildMixin(object):
msg.preamble = self.ROOT_PREAMBLE
self.set_header(msg, 'Date', self.date, encode=False)
self.set_header(msg, 'Message-ID', self.message_id(), encode=False)
self.set_header(msg, 'Message-ID', self.message_id, encode=False)
if self._headers:
for (name, value) in self._headers.items():
@ -219,7 +224,8 @@ class MessageBuildMixin(object):
self.set_header(msg, 'Subject', subject)
self.set_header(msg, 'From', self.encode_address_header(self._mail_from), encode=False)
self.set_header(msg, 'To', self._mail_to and self.encode_address_header(self._mail_to[0]) or None, encode=False)
self.set_header(msg, 'To', self._mail_to and ", ".join([self.encode_address_header(addr)
for addr in self._mail_to]) or None, encode=False)
return msg

View File

@ -159,6 +159,10 @@ def test_message_id():
m = Message(**params)
assert not m.as_message()['Message-ID']
# Check message-id property setter
m.message_id = 'ZZZ'
assert m.as_message()['Message-ID'] == 'ZZZ'
# Check message-id exists when argument specified
m = Message(message_id=MessageID(), **params)
assert m.as_message()['Message-ID']
@ -166,3 +170,13 @@ def test_message_id():
m = Message(message_id='XXX', **params)
assert m.as_message()['Message-ID'] == 'XXX'
def test_several_recipients_in_to_header():
params = dict(html='...', mail_from='a@b.c')
m = Message(mail_to=['d@e.f', 'g@h.i'], **params)
assert m.as_message()['To'] == 'd@e.f, g@h.i'
m = Message(mail_to=[('', 'd@e.f'), ('', 'g@h.i')], **params)
assert m.as_message()['To'] == '=?utf-8?b?4pmh?= <d@e.f>, =?utf-8?b?7JuD?= <g@h.i>'

View File

@ -31,5 +31,6 @@ def test_send_letters(smtp_servers):
for tag, server in smtp_servers.items():
server.patch_message(m)
response = m.send(smtp=server.params, render=render)
print(server.params)
assert response.success or response.status_code in (421, 451) # gmail not always like test emails
server.sleep()

View File

@ -13,12 +13,11 @@ SERVERS = {
host='mx.yandex.ru', port=25),
#'mailtrap.io': dict(from_email=_from, port=25, **_mailtrap),
#'mailtrap.io-tls': dict(from_email=_from, tls=True, port=465, **_mailtrap),
# mailtrap disabled because of timeouts on Travis
'outlook.com': dict(from_email=_from, to_email='lavr@outlook.com', host='mx1.hotmail.com'),
'me.com': dict(from_email=_from, to_email='s.lavrinenko@me.com', host='mx3.mail.icloud.com'),
#'me.com': dict(from_email=_from, to_email='s.lavrinenko@me.com', host='mx3.mail.icloud.com'),
# icloud.com disabled because of timeouts on Travis
}

View File

@ -102,6 +102,15 @@ def test_image_inline():
t.save()
assert '<img src="a.gif"' in t.html
# test inline image in css
t = Transformer(html="<div style='background:url(a.gif);'></div>", local_loader=SimpleLoader(data={'a.gif': 'xxx'}))
t.load_and_transform()
t.attachment_store['a.gif'].content_disposition = 'inline'
t.synchronize_inline_images()
t.save()
assert "url(cid:a.gif)" in t.html
def test_absolute_url():
t = Transformer(html="", base_url="https://host1.tld/a/b")

View File

@ -212,12 +212,14 @@ class BaseTransformer(HTMLParser):
return url
def _attribute_value(self, el):
def attribute_value(self, el):
return el is not None \
and hasattr(el, 'attrib') \
and el.attrib.get(self.html_attribute_name) \
or None
_attribute_value = attribute_value # deprecated
def _default_attachment_check(self, el, hints):
if hints['attrib'] == 'ignore':
return False
@ -235,7 +237,7 @@ class BaseTransformer(HTMLParser):
# Default callback: skip images with data-emails="ignore" attribute
callback = lambda _, hints: hints['attrib'] != 'ignore'
attribute_value = self._attribute_value(element) or ''
attribute_value = self.attribute_value(element) or ''
# If callback returns False, skip attachment loading
if not callback(element, hints={'attrib': attribute_value}):