Python smtpd.SMTPChannel() Examples
The following are 30
code examples of smtpd.SMTPChannel().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
smtpd
, or try the search function
.
Example #1
Source File: test_smtpd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_with_decode_data_false(self): server = DummyServer((support.HOST, 0), ('b', 0), decode_data=False) conn, addr = server.accept() channel = smtpd.SMTPChannel(server, conn, addr, decode_data=False) self.write_line(channel, b'EHLO example') for line in [ b'MAIL from: <foo@example.com> size=20 SMTPUTF8', b'MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=8BITMIME', ]: self.write_line(channel, line) self.assertEqual(channel.socket.last, self.error_response) self.write_line( channel, b'MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=UNKNOWN') self.assertEqual( channel.socket.last, b'501 Error: BODY can only be one of 7BIT, 8BITMIME\r\n') self.write_line( channel, b'MAIL from: <foo@example.com> size=20 body=8bitmime') self.assertEqual(channel.socket.last, b'250 OK\r\n')
Example #2
Source File: __init__.py From script-languages with MIT License | 6 votes |
def __init__(self, localaddr, map, debug=False, esmtp=True): self._localaddr = localaddr self._remoteaddr = None self.__smtpchannel = _SMTPChannel if esmtp else smtpd.SMTPChannel self.__debug = debug self.__messages = [] asyncore.dispatcher.__init__(self, map=map) try: self.create_socket(socket.AF_INET, socket.SOCK_STREAM) # try to re-use a server port if possible self.set_reuse_addr() self.bind(localaddr) self.listen(5) except: # cleanup asyncore.socket_map before raising self.close() raise
Example #3
Source File: test_smtplib.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def setUp(self): self.real_getfqdn = socket.getfqdn socket.getfqdn = mock_socket.getfqdn # temporarily replace sys.stdout to capture DebuggingServer output self.old_stdout = sys.stdout self.output = io.StringIO() sys.stdout = self.output self.serv_evt = threading.Event() self.client_evt = threading.Event() # Capture SMTPChannel debug output self.old_DEBUGSTREAM = smtpd.DEBUGSTREAM smtpd.DEBUGSTREAM = io.StringIO() # Pick a random unused port by passing 0 for the port number self.serv = smtpd.DebuggingServer((HOST, 0), ('nowhere', -1), decode_data=True) # Keep a note of what port was assigned self.port = self.serv.socket.getsockname()[1] serv_args = (self.serv, self.serv_evt, self.client_evt) self.thread = threading.Thread(target=debugging_server, args=serv_args) self.thread.start() # wait until server thread has assigned a port number self.serv_evt.wait() self.serv_evt.clear()
Example #4
Source File: test_smtpd.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_process_message_with_decode_data_true(self): server = smtpd.DebuggingServer((support.HOST, 0), ('b', 0), decode_data=True) conn, addr = server.accept() channel = smtpd.SMTPChannel(server, conn, addr, decode_data=True) with support.captured_stdout() as s: self.send_data(channel, b'From: test\n\nhello\n') stdout = s.getvalue() self.assertEqual(stdout, textwrap.dedent("""\ ---------- MESSAGE FOLLOWS ---------- From: test X-Peer: peer-address hello ------------ END MESSAGE ------------ """))
Example #5
Source File: test_smtpd.py From android_universal with MIT License | 6 votes |
def test_with_decode_data_false(self): server = DummyServer((support.HOST, 0), ('b', 0)) conn, addr = server.accept() channel = smtpd.SMTPChannel(server, conn, addr) self.write_line(channel, b'EHLO example') for line in [ b'MAIL from: <foo@example.com> size=20 SMTPUTF8', b'MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=8BITMIME', ]: self.write_line(channel, line) self.assertEqual(channel.socket.last, self.error_response) self.write_line( channel, b'MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=UNKNOWN') self.assertEqual( channel.socket.last, b'501 Error: BODY can only be one of 7BIT, 8BITMIME\r\n') self.write_line( channel, b'MAIL from: <foo@example.com> size=20 body=8bitmime') self.assertEqual(channel.socket.last, b'250 OK\r\n')
Example #6
Source File: test_smtpd.py From android_universal with MIT License | 6 votes |
def test_process_message_with_decode_data_true(self): server = smtpd.DebuggingServer((support.HOST, 0), ('b', 0), decode_data=True) conn, addr = server.accept() channel = smtpd.SMTPChannel(server, conn, addr, decode_data=True) with support.captured_stdout() as s: self.send_data(channel, b'From: test\n\nhello\n') stdout = s.getvalue() self.assertEqual(stdout, textwrap.dedent("""\ ---------- MESSAGE FOLLOWS ---------- From: test X-Peer: peer-address hello ------------ END MESSAGE ------------ """))
Example #7
Source File: test_smtpd.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_process_message_with_decode_data_false(self): server = smtpd.DebuggingServer((support.HOST, 0), ('b', 0), decode_data=False) conn, addr = server.accept() channel = smtpd.SMTPChannel(server, conn, addr, decode_data=False) with support.captured_stdout() as s: self.send_data(channel, b'From: test\n\nh\xc3\xa9llo\xff\n') stdout = s.getvalue() self.assertEqual(stdout, textwrap.dedent("""\ ---------- MESSAGE FOLLOWS ---------- b'From: test' b'X-Peer: peer-address' b'' b'h\\xc3\\xa9llo\\xff' ------------ END MESSAGE ------------ """))
Example #8
Source File: test_smtpd.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_process_SMTPUTF8_message_with_enable_SMTPUTF8_true(self): server = smtpd.DebuggingServer((support.HOST, 0), ('b', 0), enable_SMTPUTF8=True) conn, addr = server.accept() channel = smtpd.SMTPChannel(server, conn, addr, enable_SMTPUTF8=True) with support.captured_stdout() as s: self.send_data(channel, b'From: test\n\nh\xc3\xa9llo\xff\n', enable_SMTPUTF8=True) stdout = s.getvalue() self.assertEqual(stdout, textwrap.dedent("""\ ---------- MESSAGE FOLLOWS ---------- mail options: ['BODY=8BITMIME', 'SMTPUTF8'] b'From: test' b'X-Peer: peer-address' b'' b'h\\xc3\\xa9llo\\xff' ------------ END MESSAGE ------------ """))
Example #9
Source File: test_smtpd.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_with_decode_data_false(self): server = DummyServer((support.HOST, 0), ('b', 0), decode_data=False) conn, addr = server.accept() channel = smtpd.SMTPChannel(server, conn, addr, decode_data=False) self.write_line(channel, b'EHLO example') for line in [ b'MAIL from: <foo@example.com> size=20 SMTPUTF8', b'MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=8BITMIME', ]: self.write_line(channel, line) self.assertEqual(channel.socket.last, self.error_response) self.write_line( channel, b'MAIL from: <foo@example.com> size=20 SMTPUTF8 BODY=UNKNOWN') self.assertEqual( channel.socket.last, b'501 Error: BODY can only be one of 7BIT, 8BITMIME\r\n') self.write_line( channel, b'MAIL from: <foo@example.com> size=20 body=8bitmime') self.assertEqual(channel.socket.last, b'250 OK\r\n')
Example #10
Source File: test_smtpd.py From android_universal with MIT License | 6 votes |
def test_process_SMTPUTF8_message_with_enable_SMTPUTF8_true(self): server = smtpd.DebuggingServer((support.HOST, 0), ('b', 0), enable_SMTPUTF8=True) conn, addr = server.accept() channel = smtpd.SMTPChannel(server, conn, addr, enable_SMTPUTF8=True) with support.captured_stdout() as s: self.send_data(channel, b'From: test\n\nh\xc3\xa9llo\xff\n', enable_SMTPUTF8=True) stdout = s.getvalue() self.assertEqual(stdout, textwrap.dedent("""\ ---------- MESSAGE FOLLOWS ---------- mail options: ['BODY=8BITMIME', 'SMTPUTF8'] b'From: test' b'X-Peer: peer-address' b'' b'h\\xc3\\xa9llo\\xff' ------------ END MESSAGE ------------ """))
Example #11
Source File: test_smtplib.py From android_universal with MIT License | 6 votes |
def setUp(self): self.real_getfqdn = socket.getfqdn socket.getfqdn = mock_socket.getfqdn # temporarily replace sys.stdout to capture DebuggingServer output self.old_stdout = sys.stdout self.output = io.StringIO() sys.stdout = self.output self.serv_evt = threading.Event() self.client_evt = threading.Event() # Capture SMTPChannel debug output self.old_DEBUGSTREAM = smtpd.DEBUGSTREAM smtpd.DEBUGSTREAM = io.StringIO() # Pick a random unused port by passing 0 for the port number self.serv = smtpd.DebuggingServer((HOST, 0), ('nowhere', -1), decode_data=True) # Keep a note of what server host and port were assigned self.host, self.port = self.serv.socket.getsockname()[:2] serv_args = (self.serv, self.serv_evt, self.client_evt) self.thread = threading.Thread(target=debugging_server, args=serv_args) self.thread.start() # wait until server thread has assigned a port number self.serv_evt.wait() self.serv_evt.clear()
Example #12
Source File: test_smtplib.py From ironpython3 with Apache License 2.0 | 6 votes |
def setUp(self): self.real_getfqdn = socket.getfqdn socket.getfqdn = mock_socket.getfqdn # temporarily replace sys.stdout to capture DebuggingServer output self.old_stdout = sys.stdout self.output = io.StringIO() sys.stdout = self.output self.serv_evt = threading.Event() self.client_evt = threading.Event() # Capture SMTPChannel debug output self.old_DEBUGSTREAM = smtpd.DEBUGSTREAM smtpd.DEBUGSTREAM = io.StringIO() # Pick a random unused port by passing 0 for the port number self.serv = smtpd.DebuggingServer((HOST, 0), ('nowhere', -1)) # Keep a note of what port was assigned self.port = self.serv.socket.getsockname()[1] serv_args = (self.serv, self.serv_evt, self.client_evt) self.thread = threading.Thread(target=debugging_server, args=serv_args) self.thread.start() # wait until server thread has assigned a port number self.serv_evt.wait() self.serv_evt.clear()
Example #13
Source File: test_smtplib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def setUp(self): self.real_getfqdn = socket.getfqdn socket.getfqdn = mock_socket.getfqdn # temporarily replace sys.stdout to capture DebuggingServer output self.old_stdout = sys.stdout self.output = io.StringIO() sys.stdout = self.output self.serv_evt = threading.Event() self.client_evt = threading.Event() # Capture SMTPChannel debug output self.old_DEBUGSTREAM = smtpd.DEBUGSTREAM smtpd.DEBUGSTREAM = io.StringIO() # Pick a random unused port by passing 0 for the port number self.serv = smtpd.DebuggingServer((HOST, 0), ('nowhere', -1), decode_data=True) # Keep a note of what port was assigned self.port = self.serv.socket.getsockname()[1] serv_args = (self.serv, self.serv_evt, self.client_evt) self.thread = threading.Thread(target=debugging_server, args=serv_args) self.thread.start() # wait until server thread has assigned a port number self.serv_evt.wait() self.serv_evt.clear()
Example #14
Source File: test_smtpd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_process_message_with_decode_data_true(self): server = smtpd.DebuggingServer((support.HOST, 0), ('b', 0), decode_data=True) conn, addr = server.accept() channel = smtpd.SMTPChannel(server, conn, addr, decode_data=True) with support.captured_stdout() as s: self.send_data(channel, b'From: test\n\nhello\n') stdout = s.getvalue() self.assertEqual(stdout, textwrap.dedent("""\ ---------- MESSAGE FOLLOWS ---------- From: test X-Peer: peer-address hello ------------ END MESSAGE ------------ """))
Example #15
Source File: test_smtpd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_process_message_with_decode_data_false(self): server = smtpd.DebuggingServer((support.HOST, 0), ('b', 0), decode_data=False) conn, addr = server.accept() channel = smtpd.SMTPChannel(server, conn, addr, decode_data=False) with support.captured_stdout() as s: self.send_data(channel, b'From: test\n\nh\xc3\xa9llo\xff\n') stdout = s.getvalue() self.assertEqual(stdout, textwrap.dedent("""\ ---------- MESSAGE FOLLOWS ---------- b'From: test' b'X-Peer: peer-address' b'' b'h\\xc3\\xa9llo\\xff' ------------ END MESSAGE ------------ """))
Example #16
Source File: test_smtpd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_process_SMTPUTF8_message_with_enable_SMTPUTF8_true(self): server = smtpd.DebuggingServer((support.HOST, 0), ('b', 0), enable_SMTPUTF8=True) conn, addr = server.accept() channel = smtpd.SMTPChannel(server, conn, addr, enable_SMTPUTF8=True) with support.captured_stdout() as s: self.send_data(channel, b'From: test\n\nh\xc3\xa9llo\xff\n', enable_SMTPUTF8=True) stdout = s.getvalue() self.assertEqual(stdout, textwrap.dedent("""\ ---------- MESSAGE FOLLOWS ---------- mail options: ['BODY=8BITMIME', 'SMTPUTF8'] b'From: test' b'X-Peer: peer-address' b'' b'h\\xc3\\xa9llo\\xff' ------------ END MESSAGE ------------ """))
Example #17
Source File: test_smtplib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testSecondHELO(self): # check that a second HELO returns a message that it's a duplicate # (this behavior is specific to smtpd.SMTPChannel) smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) smtp.helo() expected = (503, 'Duplicate HELO/EHLO') self.assertEqual(smtp.helo(), expected) smtp.quit()
Example #18
Source File: test_smtpd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def setUp(self): smtpd.socket = asyncore.socket = mock_socket self.old_debugstream = smtpd.DEBUGSTREAM self.debug = smtpd.DEBUGSTREAM = io.StringIO() self.server = DummyServer((support.HOST, 0), ('b', 0), enable_SMTPUTF8=True) conn, addr = self.server.accept() self.channel = smtpd.SMTPChannel(self.server, conn, addr, enable_SMTPUTF8=True)
Example #19
Source File: test_smtpd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def setUp(self): smtpd.socket = asyncore.socket = mock_socket self.old_debugstream = smtpd.DEBUGSTREAM self.debug = smtpd.DEBUGSTREAM = io.StringIO() self.server = DummyServer((support.HOST, 0), ('b', 0), decode_data=True) conn, addr = self.server.accept() # Set decode_data to True self.channel = smtpd.SMTPChannel(self.server, conn, addr, decode_data=True)
Example #20
Source File: test_smtpd.py From android_universal with MIT License | 5 votes |
def test_process_message_with_decode_data_false(self): server = smtpd.DebuggingServer((support.HOST, 0), ('b', 0)) conn, addr = server.accept() channel = smtpd.SMTPChannel(server, conn, addr) with support.captured_stdout() as s: self.send_data(channel, b'From: test\n\nh\xc3\xa9llo\xff\n') stdout = s.getvalue() self.assertEqual(stdout, textwrap.dedent("""\ ---------- MESSAGE FOLLOWS ---------- b'From: test' b'X-Peer: peer-address' b'' b'h\\xc3\\xa9llo\\xff' ------------ END MESSAGE ------------ """))
Example #21
Source File: test_smtpd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def setUp(self): smtpd.socket = asyncore.socket = mock_socket self.old_debugstream = smtpd.DEBUGSTREAM self.debug = smtpd.DEBUGSTREAM = io.StringIO() self.server = DummyServer((support.HOST, 0), ('b', 0), decode_data=True) conn, addr = self.server.accept() # Set DATA size limit to 32 bytes for easy testing self.channel = smtpd.SMTPChannel(self.server, conn, addr, 32, decode_data=True)
Example #22
Source File: test_smtpd.py From android_universal with MIT License | 5 votes |
def setUp(self): smtpd.socket = asyncore.socket = mock_socket self.old_debugstream = smtpd.DEBUGSTREAM self.debug = smtpd.DEBUGSTREAM = io.StringIO() self.server = DummyServer((support.HOST, 0), ('b', 0), decode_data=True) conn, addr = self.server.accept() # Set DATA size limit to 32 bytes for easy testing self.channel = smtpd.SMTPChannel(self.server, conn, addr, 32, decode_data=True)
Example #23
Source File: test_smtpd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def setUp(self): smtpd.socket = asyncore.socket = mock_socket self.old_debugstream = smtpd.DEBUGSTREAM self.debug = smtpd.DEBUGSTREAM = io.StringIO() self.server = DummyServer((support.HOSTv6, 0), ('b', 0), decode_data=True) conn, addr = self.server.accept() self.channel = smtpd.SMTPChannel(self.server, conn, addr, decode_data=True)
Example #24
Source File: test_smtpd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_decode_data_default_warning(self): with self.assertWarns(DeprecationWarning): server = DummyServer((support.HOST, 0), ('b', 0)) conn, addr = self.server.accept() with self.assertWarns(DeprecationWarning): smtpd.SMTPChannel(server, conn, addr)
Example #25
Source File: test_smtpd.py From android_universal with MIT License | 5 votes |
def setUp(self): smtpd.socket = asyncore.socket = mock_socket self.old_debugstream = smtpd.DEBUGSTREAM self.debug = smtpd.DEBUGSTREAM = io.StringIO() self.server = DummyServer((support.HOST, 0), ('b', 0)) conn, addr = self.server.accept() self.channel = smtpd.SMTPChannel(self.server, conn, addr)
Example #26
Source File: test_smtpd.py From android_universal with MIT License | 5 votes |
def setUp(self): smtpd.socket = asyncore.socket = mock_socket self.old_debugstream = smtpd.DEBUGSTREAM self.debug = smtpd.DEBUGSTREAM = io.StringIO() self.server = DummyServer((support.HOST, 0), ('b', 0), enable_SMTPUTF8=True) conn, addr = self.server.accept() self.channel = smtpd.SMTPChannel(self.server, conn, addr, enable_SMTPUTF8=True)
Example #27
Source File: test_smtplib.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def testSecondHELO(self): # check that a second HELO returns a message that it's a duplicate # (this behavior is specific to smtpd.SMTPChannel) smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) smtp.helo() expected = (503, 'Duplicate HELO/EHLO') self.assertEqual(smtp.helo(), expected) smtp.quit()
Example #28
Source File: test_smtpd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_decode_data_and_enable_SMTPUTF8_raises(self): self.assertRaises( ValueError, smtpd.SMTPChannel, self.server, self.channel.conn, self.channel.addr, enable_SMTPUTF8=True, decode_data=True)
Example #29
Source File: test_smtpd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def setUp(self): smtpd.socket = asyncore.socket = mock_socket self.old_debugstream = smtpd.DEBUGSTREAM self.debug = smtpd.DEBUGSTREAM = io.StringIO() self.server = DummyServer((support.HOST, 0), ('b', 0), decode_data=True) conn, addr = self.server.accept() self.channel = smtpd.SMTPChannel(self.server, conn, addr, decode_data=True)
Example #30
Source File: test_smtplib.py From ironpython2 with Apache License 2.0 | 5 votes |
def testSecondHELO(self): # check that a second HELO returns a message that it's a duplicate # (this behavior is specific to smtpd.SMTPChannel) smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15) smtp.helo() expected = (503, 'Duplicate HELO/EHLO') self.assertEqual(smtp.helo(), expected) smtp.quit()