1
# -*- coding: utf-8 -*-
3
MoinMoin - MoinMoin.mail.sendmail Tests
5
@copyright: 2003-2004 by Juergen Hermann <jh@web.de>
6
@license: GNU GPL, see COPYING for details.
9
from email.Charset import Charset, QP
10
from email.Header import Header
11
from MoinMoin.mail import sendmail
12
from MoinMoin import config
15
class TestdecodeSpamSafeEmail:
16
"""mail.sendmail: testing mail"""
26
('Firstname DOT Lastname AT example DOT net',
27
'Firstname.Lastname@example.net'),
28
('Firstname . Lastname AT exa mp le DOT n e t',
29
'Firstname.Lastname@example.net'),
30
('Firstname I DONT WANT SPAM . Lastname@example DOT net',
31
'Firstname.Lastname@example.net'),
32
('First name I Lastname DONT AT WANT SPAM example DOT n e t',
33
'FirstnameLastname@example.net'),
34
('first.last@example.com', 'first.last@example.com'),
35
('first . last @ example . com', 'first.last@example.com'),
38
def testDecodeSpamSafeMail(self):
39
"""mail.sendmail: decoding spam safe mail"""
40
for coded, expected in self._tests:
41
assert sendmail.decodeSpamSafeEmail(coded) == expected
44
class TestEncodeAddress:
45
""" Address encoding tests
47
See http://www.faqs.org/rfcs/rfc2822.html section 3.4.
48
Address Specification.
50
mailbox = name-addr / addr-spec
51
name-addr = [display-name] angle-addr
52
angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr
54
charset = Charset(config.charset)
55
charset.header_encoding = QP
56
charset.body_encoding = QP
58
def testSimpleAddress(self):
59
""" mail.sendmail: encode simple address: local@domain """
60
address = u'local@domain'
61
expected = address.encode(config.charset)
62
assert sendmail.encodeAddress(address, self.charset) == expected
64
def testComposite(self):
65
""" mail.sendmail: encode address: 'Phrase <local@domain>' """
66
address = u'Phrase <local@domain>'
67
phrase = str(Header(u'Phrase '.encode('utf-8'), self.charset))
68
expected = phrase + '<local@domain>'
69
assert sendmail.encodeAddress(address, self.charset) == expected
71
def testCompositeUnicode(self):
72
""" mail.sendmail: encode Uncode address: 'ויקי <local@domain>' """
73
address = u'ויקי <local@domain>'
74
phrase = str(Header(u'ויקי '.encode('utf-8'), self.charset))
75
expected = phrase + '<local@domain>'
76
assert sendmail.encodeAddress(address, self.charset) == expected
78
def testEmptyPhrase(self):
79
""" mail.sendmail: encode address with empty phrase: '<local@domain>' """
80
address = u'<local@domain>'
81
expected = address.encode(config.charset)
82
assert sendmail.encodeAddress(address, self.charset) == expected
84
def testEmptyAddress(self):
85
""" mail.sendmail: encode address with empty address: 'Phrase <>'
87
Let the smtp server handle this. We may raise error in such
88
case, but we don't do error checking for mail addresses.
90
address = u'Phrase <>'
91
phrase = str(Header(u'Phrase '.encode('utf-8'), self.charset))
92
expected = phrase + '<>'
93
assert sendmail.encodeAddress(address, self.charset) == expected
95
def testInvalidAddress(self):
96
""" mail.sendmail: encode invalid address 'Phrase <blah'
98
Assume that this is a simple address. This address will
99
probably cause an error when trying to send mail. Junk in, junk
102
address = u'Phrase <blah'
103
expected = address.encode(config.charset)
104
assert sendmail.encodeAddress(address, self.charset) == expected
107
coverage_modules = ['MoinMoin.mail.sendmail']