Esempio n. 1
0
 def test_deliver_conversion(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall(
         b'MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n'
     )
     self.sock.recv(
         IsA(int)).AndReturn(b'250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     if pycompat.PY3:
         self.sock.sendall(
             b'From: [email protected]\r\nContent-Transfer-Encoding: base64\r\n\r\ndGVzdCB0ZXN0IIEK\r\n.\r\n'
         )
     else:
         self.sock.sendall(
             b'From: [email protected]\r\nContent-Transfer-Encoding: base64\r\n\r\ndGVzdCB0ZXN0IIENCg==\r\n.\r\n'
         )
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0),
                              self.queue,
                              socket_creator=self._socket_creator,
                              ehlo_as='there',
                              binary_encoder=encode_base64)
     client._connect()
     client._ehlo()
     client._deliver(result, env)
     self.assertEqual({'*****@*****.**': Reply('250', 'Ok')},
                      result.get_nowait())
Esempio n. 2
0
 def test_deliver(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 8BITMIME\r\n')
     self.sock.sendall(b'MAIL FROM:<*****@*****.**>\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.sock.sendall(b'RCPT TO:<*****@*****.**>\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.sock.sendall(b'DATA\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'354 Go ahead\r\n')
     self.sock.sendall(
         b'From: [email protected]\r\n\r\ntest test \x81\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0),
                              self.queue,
                              socket_creator=self._socket_creator,
                              ehlo_as='there')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
     self.assertEqual({'*****@*****.**': Reply('250', 'Ok')},
                      result.get_nowait())
Esempio n. 3
0
 def test_deliver_baddata(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall(
         b'MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n'
     )
     self.sock.recv(
         IsA(int)).AndReturn(b'250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall(
         b'From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'450 Yikes\r\n')
     self.sock.sendall(b'RSET\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0),
                              self.queue,
                              socket_creator=self._socket_creator,
                              ehlo_as='there')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
     with self.assertRaises(TransientRelayError):
         result.get_nowait()
Esempio n. 4
0
 def test_deliver_conversion_failure(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse('From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall('EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall('RSET\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
     result.set_exception(IsA(PermanentRelayError))
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, self.queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
 def test_deliver_conversion_failure(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall(b'EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall(b'RSET\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
     with self.assertRaises(PermanentRelayError):
         result.get_nowait()
 def test_deliver_conversion(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall(b'EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall(b'MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall(b'From: [email protected]\r\nContent-Transfer-Encoding: base64\r\n\r\ndGVzdCB0ZXN0IIENCg==\n\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='test', binary_encoder=encode_base64)
     client._connect()
     client._ehlo()
     client._deliver(result, env)
     self.assertEqual({'*****@*****.**': Reply('250', 'Ok')}, result.get_nowait())
Esempio n. 7
0
 def test_deliver_conversion(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse('From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall('EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall('MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall('From: [email protected]\r\nContent-Transfer-Encoding: base64\r\n\r\ndGVzdCB0ZXN0IIENCg==\n\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
     result.set([None])
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, self.queue, socket_creator=self._socket_creator, ehlo_as='test', binary_encoder=encode_base64)
     client._connect()
     client._ehlo()
     client._deliver(result, env)
Esempio n. 8
0
 def test_deliver_badrcpts(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse('From: [email protected]\r\n\r\ntest test\r\n')
     self.sock.sendall('EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall('MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n550 Not ok\r\n354 Go ahead\r\n')
     self.sock.sendall('.\r\nRSET\r\n')
     self.sock.recv(IsA(int)).AndReturn('550 Yikes\r\n250 Ok\r\n')
     result.set_exception(IsA(PermanentRelayError))
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, self.queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
 def test_deliver_badrcpts(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     self.sock.sendall(b'EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall(b'MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n550 Not ok\r\n354 Go ahead\r\n')
     self.sock.sendall(b'.\r\nRSET\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'550 Yikes\r\n250 Ok\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
     with self.assertRaises(PermanentRelayError):
         result.get_nowait()
Esempio n. 10
0
 def test_deliver_rset_exception(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse('From: [email protected]\r\n\r\ntest test\r\n')
     self.sock.sendall('EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall('MAIL FROM:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n250 Ok\r\n450 No!\r\n')
     result.set_exception(IsA(TransientRelayError))
     self.sock.sendall('RSET\r\n')
     self.sock.recv(IsA(int)).AndRaise(ConnectionLost)
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, self.queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._connect()
     client._ehlo()
     with self.assertRaises(ConnectionLost):
         client._deliver(result, env)
Esempio n. 11
0
 def test_deliver_conversion_failure(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 PIPELINING\r\n')
     self.sock.sendall(b'RSET\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0),
                              self.queue,
                              socket_creator=self._socket_creator,
                              ehlo_as='there')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
     with self.assertRaises(PermanentRelayError):
         result.get_nowait()
 def test_deliver(self):
     result = AsyncResult()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall(b'EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 8BITMIME\r\n')
     self.sock.sendall(b'MAIL FROM:<*****@*****.**>\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.sock.sendall(b'RCPT TO:<*****@*****.**>\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.sock.sendall(b'DATA\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'354 Go ahead\r\n')
     self.sock.sendall(b'From: [email protected]\r\n\r\ntest test \x81\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
     self.assertEqual({'*****@*****.**': Reply('250', 'Ok')}, result.get_nowait())
Esempio n. 13
0
 def test_deliver(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse('From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall('EHLO test\r\n')
     self.sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 8BITMIME\r\n')
     self.sock.sendall('MAIL FROM:<*****@*****.**>\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
     self.sock.sendall('RCPT TO:<*****@*****.**>\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
     self.sock.sendall('DATA\r\n')
     self.sock.recv(IsA(int)).AndReturn('354 Go ahead\r\n')
     self.sock.sendall('From: [email protected]\r\n\r\ntest test \x81\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
     result.set([None])
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, self.queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._connect()
     client._ehlo()
     client._deliver(result, env)