Commits

Greg Ward committed 7628560

Remove now-unnecessary EximDebugSMTP class.
This makes issue #1 obsolete by removing the use of netcat.

  • Participants
  • Parent commits 8070356

Comments (0)

Files changed (1)

src/eximunit/smtp.py

         return line
 
 
-class EximDebugSMTP(smtplib.SMTP):
-    """SMTP client which is backed by a fake Exim SMTP session."""
-
-    def __init__(self, from_host, debug, *args, **kwargs):
-        kwargs['host'] = 'localhost'
-        self.from_host = from_host
-        self.set_debuglevel(debug)
-        # the super constructor calls _get_socket, so call it last
-        smtplib.SMTP.__init__(self, *args, **kwargs)
-
-    def _get_socket(self, host, port, timeout):
-        if host != 'localhost':
-            raise Exception('Exim sessions are only supported to localhost, '
-                            'not %s' % host)
-        return self._get_exim_socket()
-
-    def _get_exim_socket(self):
-        # first, spawn nc wrapping the exim debug session on a spare local port
-        # TODO redirect exim stderr to a file we can fish it out of
-        port = findFreePorts()[0]
-        exim_cmd = '/usr/sbin/exim4 -bhc %s 2>exim-debug.log' % self.from_host
-        nc_cmd = ['nc', '-l', '-p', str(port), '-s', '127.0.0.1',
-                  '-c', exim_cmd]
-        if self.debuglevel > 0:
-            print("Spawning exim on port %s with incoming address %s" %
-                  (port, self.from_host))
-        child = subprocess.Popen(nc_cmd, stdout=subprocess.PIPE)
-         # TODO maybe just fork nc?
-        threading.Thread(target=child.communicate).start()
-        time.sleep(2)           # give exim a moment to sort itself out
-
-        # now connect and discard the first few lines (the header about
-        # this being a fake session)
-        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        s.connect(('localhost', port))
-        # skip the introductory 'not real' message, leaving it
-        # just before reading the 220 and the banner
-        while s.recv(1) != "!":
-            pass
-        s.recv(2)               # two newlines after 'not for real!'
-        return s
-
 if __name__ == '__main__':
     smtp = run_exim('127.0.0.1', 1)
     smtp.helo('localhost')