1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
# -*- coding: utf-8 -*-
"""
MoinMoin - MoinMoin.mail.sendmail Tests
@copyright: 2003-2004 by Juergen Hermann <jh@web.de>
@license: GNU GPL, see COPYING for details.
"""
from email.charset import Charset, QP
from email.header import Header
from MoinMoin.mail import sendmail
from MoinMoin import config
class TestdecodeSpamSafeEmail:
"""mail.sendmail: testing mail"""
_tests = (
('', ''),
('AT', '@'),
('DOT', '.'),
('DASH', '-'),
('CAPS', ''),
('Mixed', 'Mixed'),
('lower', 'lower'),
('Firstname DOT Lastname AT example DOT net',
'Firstname.Lastname@example.net'),
('Firstname . Lastname AT exa mp le DOT n e t',
'Firstname.Lastname@example.net'),
('Firstname I DONT WANT SPAM . Lastname@example DOT net',
'Firstname.Lastname@example.net'),
('First name I Lastname DONT AT WANT SPAM example DOT n e t',
'FirstnameLastname@example.net'),
('first.last@example.com', 'first.last@example.com'),
('first . last @ example . com', 'first.last@example.com'),
)
def testDecodeSpamSafeMail(self):
"""mail.sendmail: decoding spam safe mail"""
for coded, expected in self._tests:
assert sendmail.decodeSpamSafeEmail(coded) == expected
class TestencodeSpamSafeEmail:
"""mail.sendmail: testing spam safe mail"""
_tests = (
('', ''),
('@', ' AT '),
('.', ' DOT '),
('-', ' DASH '),
('lower', 'lower'),
('Firstname.Lastname@example.net',
'firstname DOT lastname AT example DOT net'),
('F.Lastname@example.net',
'f DOT lastname AT example DOT net'),
)
def testEncodeSpamSafeMail(self):
"""mail.sendmail: encoding mail address to spam safe mail"""
for coded, expected in self._tests:
assert sendmail.encodeSpamSafeEmail(coded) == expected
def testEncodeSpamSafeMailAndObfuscate(self):
"""mail.sendmail: encoding mail address by an obfuscate string to spam safe mail """
for coded, expected in self._tests:
expected = expected.replace(' AT ', ' AT SYCTE ')
assert sendmail.encodeSpamSafeEmail(coded, 'SYCTE') == expected
class TestEncodeAddress:
""" Address encoding tests
See http://www.faqs.org/rfcs/rfc2822.html section 3.4.
Address Specification.
mailbox = name-addr / addr-spec
name-addr = [display-name] angle-addr
angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr
"""
charset = Charset(config.charset)
charset.header_encoding = QP
charset.body_encoding = QP
def testSimpleAddress(self):
""" mail.sendmail: encode simple address: local@domain """
address = u'local@domain'
expected = address.encode(config.charset)
assert sendmail.encodeAddress(address, self.charset) == expected
def testComposite(self):
""" mail.sendmail: encode address: 'Phrase <local@domain>' """
address = u'Phrase <local@domain>'
expected = str(address)
assert sendmail.encodeAddress(address, self.charset) == expected
def testCompositeUnicode(self):
""" mail.sendmail: encode Uncode address: 'ויקי <local@domain>' """
address = u'ויקי <local@domain>'
phrase = str(Header(u'ויקי'.encode('utf-8'), self.charset))
expected = phrase + ' ' + '<local@domain>'
assert sendmail.encodeAddress(address, self.charset) == expected
def testEmptyPhrase(self):
""" mail.sendmail: encode address with empty phrase: '<local@domain>' """
address = u'<local@domain>'
expected = 'local@domain'
assert sendmail.encodeAddress(address, self.charset) == expected
def testEmptyAddress(self):
""" mail.sendmail: encode address with empty address: 'Phrase <>'
Let the smtp server handle this. We may raise error in such
case, but we don't do error checking for mail addresses.
"""
address = u'Phrase <>'
expected = str(address)
assert sendmail.encodeAddress(address, self.charset) == expected
def testInvalidAddress(self):
""" mail.sendmail: encode invalid address 'Phrase <blah'
Assume that this is a simple address. This address will
probably cause an error when trying to send mail. Junk in, junk
out.
"""
address = u'Phrase <blah'
expected = str(address)
assert sendmail.encodeAddress(address, self.charset) == expected
coverage_modules = ['MoinMoin.mail.sendmail']
|