diff options
Diffstat (limited to 'Lib/smtpd.py')
-rwxr-xr-x | Lib/smtpd.py | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/Lib/smtpd.py b/Lib/smtpd.py index 778d6d6..db7c867 100755 --- a/Lib/smtpd.py +++ b/Lib/smtpd.py @@ -121,8 +121,9 @@ class SMTPChannel(asynchat.async_chat): }) max_command_size_limit = max(command_size_limits.values()) - def __init__(self, server, conn, addr, data_size_limit=DATA_SIZE_DEFAULT): - asynchat.async_chat.__init__(self, conn) + def __init__(self, server, conn, addr, data_size_limit=DATA_SIZE_DEFAULT, + map=None): + asynchat.async_chat.__init__(self, conn, map=map) self.smtp_server = server self.conn = conn self.addr = addr @@ -137,7 +138,7 @@ class SMTPChannel(asynchat.async_chat): self.num_bytes = 0 try: self.peer = conn.getpeername() - except socket.error as err: + except OSError as err: # a race condition may occur if the other end is closing # before we can get the peername self.close() @@ -412,7 +413,7 @@ class SMTPChannel(asynchat.async_chat): def smtp_HELP(self, arg): if arg: - extended = ' [SP <mail parameters]' + extended = ' [SP <mail-parameters>]' lc_arg = arg.upper() if lc_arg == 'EHLO': self.push('250 Syntax: EHLO hostname') @@ -475,9 +476,6 @@ class SMTPChannel(asynchat.async_chat): if not self.extended_smtp and params: self.push(syntaxerr) return - if not address: - self.push(syntaxerr) - return if self.mailfrom: self.push('503 Error: nested MAIL command') return @@ -528,15 +526,9 @@ class SMTPChannel(asynchat.async_chat): else: self.push(syntaxerr) return - if not address: - self.push(syntaxerr) - return if params and len(params.keys()) > 0: self.push('555 RCPT TO parameters not recognized or not implemented') return - if not address: - self.push('501 Syntax: RCPT TO: <address>') - return self.rcpttos.append(address) print('recips:', self.rcpttos, file=DEBUGSTREAM) self.push('250 OK') @@ -576,11 +568,11 @@ class SMTPServer(asyncore.dispatcher): channel_class = SMTPChannel def __init__(self, localaddr, remoteaddr, - data_size_limit=DATA_SIZE_DEFAULT): + data_size_limit=DATA_SIZE_DEFAULT, map=None): self._localaddr = localaddr self._remoteaddr = remoteaddr self.data_size_limit = data_size_limit - asyncore.dispatcher.__init__(self) + 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 @@ -597,7 +589,8 @@ class SMTPServer(asyncore.dispatcher): def handle_accepted(self, conn, addr): print('Incoming connection from %s' % repr(addr), file=DEBUGSTREAM) - channel = self.channel_class(self, conn, addr, self.data_size_limit) + channel = self.channel_class(self, conn, addr, self.data_size_limit, + self._map) # API for "doing something useful with the message" def process_message(self, peer, mailfrom, rcpttos, data): @@ -668,7 +661,7 @@ class PureProxy(SMTPServer): except smtplib.SMTPRecipientsRefused as e: print('got SMTPRecipientsRefused', file=DEBUGSTREAM) refused = e.recipients - except (socket.error, smtplib.SMTPException) as e: + except (OSError, smtplib.SMTPException) as e: print('got', e.__class__, file=DEBUGSTREAM) # All recipients were refused. If the exception had an associated # error code, use it. Otherwise,fake it with a non-triggering @@ -778,7 +771,7 @@ def parseargs(): if opt in ('-h', '--help'): usage(0) elif opt in ('-V', '--version'): - print(__version__, file=sys.stderr) + print(__version__) sys.exit(0) elif opt in ('-n', '--nosetuid'): options.setuid = 0 @@ -850,8 +843,7 @@ if __name__ == '__main__': nobody = pwd.getpwnam('nobody')[2] try: os.setuid(nobody) - except OSError as e: - if e.errno != errno.EPERM: raise + except PermissionError: print('Cannot setuid "nobody"; try running with -n option.', file=sys.stderr) sys.exit(1) try: |