コード例 #1
0
 def test_disconnect_failure(self):
     self.sock.sendall(b'QUIT\r\n')
     self.sock.recv(IsA(int)).AndRaise(socket_error(None, None))
     self.sock.close()
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._disconnect()
コード例 #2
0
 def test_disconnect(self):
     self.sock.sendall(b'QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._disconnect()
コード例 #3
0
 def test_deliver_multircpt(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope(
         '*****@*****.**',
         ['*****@*****.**', '*****@*****.**', '*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     self.sock.sendall(b'LHLO 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\nRCPT TO:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n'
     )
     self.sock.recv(IsA(int)).AndReturn(
         b'250 Ok\r\n250 Ok\r\n550 Nope\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'250 Ok\r\n450 Yikes\r\n')
     result.set({
         '*****@*****.**': None,
         '*****@*****.**': IsA(PermanentRelayError),
         '*****@*****.**': IsA(TransientRelayError)
     })
     self.sock.sendall(b'RSET\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Ok\r\n')
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr',
                              self.queue,
                              socket_creator=self._socket_creator,
                              ehlo_as='test')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
コード例 #4
0
 def test_deliver_conversion(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall(b'LHLO 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')
     result.set({'*****@*****.**': None})
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr',
                              self.queue,
                              socket_creator=self._socket_creator,
                              ehlo_as='test',
                              binary_encoder=encode_base64)
     client._connect()
     client._ehlo()
     client._deliver(result, env)
コード例 #5
0
 def test_lhlo(self):
     self.sock.sendall(b'LHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 TEST\r\n')
     self.sock.sendall(b'LHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'420 Goodbye\r\n')
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._ehlo()
     with self.assertRaises(TransientRelayError):
         client._ehlo()
コード例 #6
0
 def test_deliver_conversion_failure(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall(b'LHLO 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')
     result.set_exception(IsA(PermanentRelayError))
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
コード例 #7
0
 def test_lhlo(self):
     self.sock.sendall(b'LHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 TEST\r\n')
     self.sock.sendall(b'LHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'420 Goodbye\r\n')
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._ehlo()
     with self.assertRaises(TransientRelayError):
         client._ehlo()
コード例 #8
0
 def test_disconnect_failure(self):
     self.sock.sendall(b'QUIT\r\n')
     self.sock.recv(IsA(int)).AndRaise(socket_error(None, None))
     self.sock.close()
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._disconnect()
コード例 #9
0
 def test_disconnect(self):
     self.sock.sendall(b'QUIT\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'221 Goodbye\r\n')
     self.sock.close()
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._disconnect()
コード例 #10
0
 def test_deliver_badrcpts(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     self.sock.sendall(b'LHLO 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\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')
     result.set_exception(IsA(PermanentRelayError))
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
コード例 #11
0
 def test_deliver_rset_exception(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     self.sock.sendall(b'LHLO 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\n450 No!\r\n')
     result.set_exception(IsA(TransientRelayError))
     self.sock.sendall(b'RSET\r\n')
     self.sock.recv(IsA(int)).AndRaise(ConnectionLost)
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._ehlo()
     with self.assertRaises(ConnectionLost):
         client._deliver(result, env)
コード例 #12
0
 def test_deliver_conversion_failure(self):
     result = self.mox.CreateMockAnything()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall(b'LHLO 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')
     result.set_exception(IsA(PermanentRelayError))
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
 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('LHLO 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 = LmtpRelayClient(None, self.queue, socket_creator=self._socket_creator, ehlo_as='test', binary_encoder=encode_base64)
     client._connect()
     client._ehlo()
     client._deliver(result, env)
コード例 #14
0
 def test_deliver_badpipeline(self):
     result = self.mox.CreateMockAnything()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     self.sock.sendall(b'LHLO 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'550 Not ok\r\n250 Ok\r\n354 Go ahead\r\n')
     result.set_exception(IsA(PermanentRelayError))
     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 = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
コード例 #15
0
 def test_deliver(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall(b'LHLO 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')
     result.set({'*****@*****.**': None})
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
コード例 #16
0
 def test_deliver_rset_exception(self):
     result = self.mox.CreateMockAnything()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test\r\n')
     self.sock.sendall(b'LHLO 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\n450 No!\r\n')
     result.set_exception(IsA(TransientRelayError))
     self.sock.sendall(b'RSET\r\n')
     self.sock.recv(IsA(int)).AndRaise(ConnectionLost)
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._ehlo()
     with self.assertRaises(ConnectionLost):
         client._deliver(result, env)
 def test_deliver_multircpt(self):
     result = self.mox.CreateMock(AsyncResult)
     env = Envelope('*****@*****.**', ['*****@*****.**', '*****@*****.**', '*****@*****.**'])
     env.parse('From: [email protected]\r\n\r\ntest test\r\n')
     self.sock.sendall('LHLO 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\nRCPT TO:<*****@*****.**>\r\nRCPT TO:<*****@*****.**>\r\nDATA\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n250 Ok\r\n550 Nope\r\n250 Ok\r\n354 Go ahead\r\n')
     self.sock.sendall('From: [email protected]\r\n\r\ntest test\r\n.\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n450 Yikes\r\n')
     result.set([None, IsA(PermanentRelayError), IsA(TransientRelayError)])
     self.sock.sendall('RSET\r\n')
     self.sock.recv(IsA(int)).AndReturn('250 Ok\r\n')
     self.mox.ReplayAll()
     client = LmtpRelayClient(None, self.queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
コード例 #18
0
 def test_deliver_conversion(self):
     result = self.mox.CreateMockAnything()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall(b'LHLO 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')
     result.set({'*****@*****.**': Reply('250', 'Ok')})
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there', binary_encoder=encode_base64)
     client._connect()
     client._ehlo()
     client._deliver(result, env)
コード例 #19
0
 def test_deliver(self):
     result = self.mox.CreateMockAnything()
     env = Envelope('*****@*****.**', ['*****@*****.**'])
     env.parse(b'From: [email protected]\r\n\r\ntest test \x81\r\n')
     self.sock.sendall(b'LHLO 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')
     result.set({'*****@*****.**': Reply('250', 'Ok')})
     self.mox.ReplayAll()
     client = LmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, ehlo_as='there')
     client._connect()
     client._ehlo()
     client._deliver(result, env)
 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('LHLO 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 = LmtpRelayClient(None, self.queue, socket_creator=self._socket_creator, ehlo_as='test')
     client._connect()
     client._ehlo()
     client._deliver(result, env)