本文整理汇总了Python中slimta.envelope.Envelope类的典型用法代码示例。如果您正苦于以下问题:Python Envelope类的具体用法?Python Envelope怎么用?Python Envelope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Envelope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_message_id_header_existing
def test_add_message_id_header_existing(self):
env = Envelope()
env.parse('Message-Id: testing\r\n')
amih = AddMessageIdHeader()
self.assertEqual('testing', env.headers['Message-Id'])
amih.apply(env)
self.assertEqual('testing', env.headers['Message-Id'])
示例2: test_recipientsplit_apply
def test_recipientsplit_apply(self):
env = Envelope('[email protected]', ['[email protected]',
'[email protected]'])
env.parse(b"""\
From: [email protected]
To: [email protected]
To: [email protected]
test test\r
""")
policy = RecipientSplit()
env1, env2 = policy.apply(env)
self.assertEqual('[email protected]', env1.sender)
self.assertEqual(['[email protected]'], env1.recipients)
self.assertEqual('[email protected]', env1.headers['from'])
self.assertEqual(['[email protected]', '[email protected]'],
env1.headers.get_all('To'))
self.assertEqual(b'test test\r\n', env1.message)
self.assertEqual('[email protected]', env2.sender)
self.assertEqual(['[email protected]'], env2.recipients)
self.assertEqual('[email protected]', env2.headers['from'])
self.assertEqual(['[email protected]', '[email protected]'],
env2.headers.get_all('To'))
self.assertEqual(b'test test\r\n', env2.message)
示例3: test_add_date_header_existing
def test_add_date_header_existing(self):
env = Envelope()
env.parse('Date: testing\r\n')
adh = AddDateHeader()
self.assertEqual('testing', env.headers['Date'])
adh.apply(env)
self.assertEqual('testing', env.headers['Date'])
示例4: test_parse_nonascii_headers
def test_parse_nonascii_headers(self):
env = Envelope()
env.parse(b'Subject: \xc3\xa9\xc3\xa9\n')
try:
self.assertEqual(b'\xc3\xa9\xc3\xa9', env.headers['subject'].encode())
except UnicodeDecodeError:
self.assertEqual(b'\xc3\xa9\xc3\xa9', env.headers['subject'])
示例5: test_attempt
def test_attempt(self):
self.mox.StubOutWithMock(subprocess, 'Popen')
env = Envelope('[email protected]', ['[email protected]', '[email protected]', '[email protected]', '[email protected]'])
env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
self._mock_popen('[email protected]', 0, '')
self._mock_popen('[email protected]', 1337, 'transient')
self._mock_popen('[email protected]', 1337, '5.0.0 permanent')
subprocess.Popen(['relaytest', '-f', '[email protected]', '[email protected]'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).AndRaise(Timeout)
self.mox.ReplayAll()
m = PipeRelay(['relaytest', '-f', '{sender}', '{recipient}'])
results = m.attempt(env, 0)
self.assertEqual(4, len(results))
self.assertEqual(None, results['[email protected]'])
self.assertIsInstance(results['[email protected]'], TransientRelayError)
self.assertEqual('transient', str(results['[email protected]']))
self.assertEqual('450', results['[email protected]'].reply.code)
self.assertIsInstance(results['[email protected]'], PermanentRelayError)
self.assertEqual('5.0.0 permanent', str(results['[email protected]']))
self.assertEqual('550', results['[email protected]'].reply.code)
self.assertIsInstance(results['[email protected]'], TransientRelayError)
self.assertEqual('Delivery timed out', str(results['[email protected]']))
self.assertEqual('450', results['[email protected]'].reply.code)
示例6: test_add_headers
def test_add_headers(self):
self.data['[email protected]'] = {'add_headers': '{"X-Test-A": "one"}'}
self.data['[email protected]'] = {'add_headers': '{"X-Test-B": "two"}'}
env = Envelope('[email protected]', ['[email protected]', '[email protected]'])
env.parse(b"""\n\n""")
self.policy.apply(env)
self.assertEquals('one', env.headers['x-test-a'])
self.assertEquals('two', env.headers['x-test-b'])
示例7: test_add_date_header
def test_add_date_header(self):
env = Envelope()
env.parse('')
env.timestamp = 1234567890
adh = AddDateHeader()
self.assertEqual(None, env.headers['Date'])
adh.apply(env)
self.assertTrue(env.headers['Date'])
示例8: test_encode_7bit
def test_encode_7bit(self):
headers = Message()
headers['From'] = '[email protected]'
headers['To'] = '[email protected]'
body = bytes(bytearray(range(129, 256)))
env = Envelope(headers=headers, message=body)
with self.assertRaises(UnicodeError):
env.encode_7bit()
示例9: test_add_date_header_existing
def test_add_date_header_existing(self):
env = Envelope()
epoch = 'Thu, 01 Jan 1970 00:00:00 -0000'
env.parse(b'Date: '+epoch.encode()+b'\r\n')
adh = AddDateHeader()
self.assertEqual(epoch, env.headers['Date'])
adh.apply(env)
self.assertEqual(epoch, env.headers['Date'])
示例10: _get_envelope
def _get_envelope(self, environ):
sender = self._get_sender(environ)
recipients = self._get_recipients(environ)
env = Envelope(sender, recipients)
content_length = int(environ.get('CONTENT_LENGTH', 0))
data = environ['wsgi.input'].read(content_length)
env.parse(data)
return env
示例11: test_add_message_id_header
def test_add_message_id_header(self):
env = Envelope()
env.parse('')
env.timestamp = 1234567890
amih = AddMessageIdHeader('example.com')
self.assertEqual(None, env.headers['Message-Id'])
amih.apply(env)
pattern = r'^<[0-9a-fA-F]{32}\[email protected]>$'
self.assertRegexpMatches(env.headers['Message-Id'], pattern)
示例12: test_parse_onlyheaders
def test_parse_onlyheaders(self):
env = Envelope()
env.parse("""\
From: [email protected]
Subject: important things
""")
assert_equal('[email protected]', env.headers['from'])
assert_equal('important things', env.headers['subject'])
assert_equal('', env.message)
示例13: test_parse_onlyheaders
def test_parse_onlyheaders(self):
env = Envelope()
env.parse(b"""\
From: [email protected]
Subject: important things
""".replace(b'\n', b'\r\n'))
self.assertEqual('[email protected]', env.headers['from'])
self.assertEqual('important things', env.headers['subject'])
self.assertEqual(b'', env.message)
示例14: test_apply
def test_apply(self):
env = Envelope()
env.parse(b"""X-Spam-Status: NO\r\n\r\n""")
self.mox.StubOutWithMock(self.sa, 'scan')
self.sa.scan(env).AndReturn((True, ['one', 'two']))
self.mox.ReplayAll()
self.sa.apply(env)
self.assertEqual('YES', env.headers['X-Spam-Status'])
self.assertEqual('one, two', env.headers['X-Spam-Symbols'])
示例15: test_parse_message_object
def test_parse_message_object(self):
data = Message()
data['From'] = '[email protected]'
data['To'] = '[email protected]'
data['To'] = '[email protected]'
data.set_payload('test test\r\n')
env = Envelope()
env.parse(data)
assert_equal('[email protected]', env.headers['from'])
assert_equal(['[email protected]', '[email protected]'], env.headers.get_all('to'))
assert_equal('test test\r\n', env.message)