[Python-checkins] CVS: python/dist/src/Lib smtpd.py,1.7,1.8

Barry Warsaw bwarsaw@users.sourceforge.net
2001年10月04日 09:27:07 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv25377
Modified Files:
	smtpd.py 
Log Message:
Script arguments localhost:localport and remotehost:remoteport are now
optional, and default to `localhost' and ports 8025 and 25
respectively.
SMTPChannel.__init__(): Calculate __fqdn using socket.getfqdn()
instead of gethostby*() and friends. This allows us to run this
script even if we don't have access to dns (assuming the localhost is
configured properly).
Also, restore my precious page breaks. Hands off, oh Whitespace
Normalizer!
Index: smtpd.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/smtpd.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** smtpd.py	2001年08月13日 21:18:01	1.7
--- smtpd.py	2001年10月04日 16:27:04	1.8
***************
*** 2,6 ****
 """An RFC 2821 smtp proxy.
 
! Usage: %(program)s [options] localhost:port remotehost:port
 
 Options:
--- 2,6 ----
 """An RFC 2821 smtp proxy.
 
! Usage: %(program)s [options] [localhost:localport [remotehost:remoteport]]
 
 Options:
***************
*** 31,36 ****
--- 31,40 ----
 Version: %(__version__)s
 
+ If localhost is not given then `localhost' is used, and if localport is not
+ given then 8025 is used. If remotehost is not given then `localhost' is used,
+ and if remoteport is not given, then 25 is used.
 """
 
+ 
 # Overview:
 #
***************
*** 90,96 ****
 NEWLINE = '\n'
 EMPTYSTRING = ''
! 
 
 
 def usage(code, msg=''):
 print >> sys.stderr, __doc__ % globals()
--- 94,101 ----
 NEWLINE = '\n'
 EMPTYSTRING = ''
! COMMASPACE = ', '
 
 
+ 
 def usage(code, msg=''):
 print >> sys.stderr, __doc__ % globals()
***************
*** 100,104 ****
 
 
! 
 class SMTPChannel(asynchat.async_chat):
 COMMAND = 0
--- 105,109 ----
 
 
! 
 class SMTPChannel(asynchat.async_chat):
 COMMAND = 0
***************
*** 116,121 ****
 self.__rcpttos = []
 self.__data = ''
! self.__fqdn = socket.gethostbyaddr(
! socket.gethostbyname(socket.gethostname()))[0]
 self.__peer = conn.getpeername()
 print >> DEBUGSTREAM, 'Peer:', repr(self.__peer)
--- 121,125 ----
 self.__rcpttos = []
 self.__data = ''
! self.__fqdn = socket.getfqdn()
 self.__peer = conn.getpeername()
 print >> DEBUGSTREAM, 'Peer:', repr(self.__peer)
***************
*** 265,270 ****
 self.push('354 End data with <CR><LF>.<CR><LF>')
 
- 
 
 class SMTPServer(asyncore.dispatcher):
 def __init__(self, localaddr, remoteaddr):
--- 269,274 ----
 self.push('354 End data with <CR><LF>.<CR><LF>')
 
 
+ 
 class SMTPServer(asyncore.dispatcher):
 def __init__(self, localaddr, remoteaddr):
***************
*** 314,317 ****
--- 318,322 ----
 
 
+ 
 class DebuggingServer(SMTPServer):
 # Do something with the gathered message
***************
*** 328,333 ****
 print '------------ END MESSAGE ------------'
 
- 
 
 class PureProxy(SMTPServer):
 def process_message(self, peer, mailfrom, rcpttos, data):
--- 333,338 ----
 print '------------ END MESSAGE ------------'
 
 
+ 
 class PureProxy(SMTPServer):
 def process_message(self, peer, mailfrom, rcpttos, data):
***************
*** 369,374 ****
 return refused
 
- 
 
 class MailmanProxy(PureProxy):
 def process_message(self, peer, mailfrom, rcpttos, data):
--- 374,379 ----
 return refused
 
 
+ 
 class MailmanProxy(PureProxy):
 def process_message(self, peer, mailfrom, rcpttos, data):
***************
*** 449,453 ****
 
 
! 
 class Options:
 setuid = 1
--- 454,458 ----
 
 
! 
 class Options:
 setuid = 1
***************
*** 455,458 ****
--- 460,464 ----
 
 
+ 
 def parseargs():
 global DEBUGSTREAM
***************
*** 479,508 ****
 
 # parse the rest of the arguments
! try:
 localspec = args[0]
! remotespec = args[1]
! except IndexError:
! usage(1, 'Not enough arguments')
 # split into host/port pairs
 i = localspec.find(':')
 if i < 0:
! usage(1, 'Bad local spec: "%s"' % localspec)
 options.localhost = localspec[:i]
 try:
 options.localport = int(localspec[i+1:])
 except ValueError:
! usage(1, 'Bad local port: "%s"' % localspec)
 i = remotespec.find(':')
 if i < 0:
! usage(1, 'Bad remote spec: "%s"' % remotespec)
 options.remotehost = remotespec[:i]
 try:
 options.remoteport = int(remotespec[i+1:])
 except ValueError:
! usage(1, 'Bad remote port: "%s"' % remotespec)
 return options
 
 
! 
 if __name__ == '__main__':
 options = parseargs()
--- 485,518 ----
 
 # parse the rest of the arguments
! if len(args) < 1:
! localspec = 'localhost:8025'
! remotespec = 'localhost:25'
! elif len(args) < 2:
 localspec = args[0]
! remotespec = 'localhost:25'
! else:
! usage(1, 'Invalid arguments: %s' % COMMASPACE.join(args))
! 
 # split into host/port pairs
 i = localspec.find(':')
 if i < 0:
! usage(1, 'Bad local spec: %s' % localspec)
 options.localhost = localspec[:i]
 try:
 options.localport = int(localspec[i+1:])
 except ValueError:
! usage(1, 'Bad local port: %s' % localspec)
 i = remotespec.find(':')
 if i < 0:
! usage(1, 'Bad remote spec: %s' % remotespec)
 options.remotehost = remotespec[:i]
 try:
 options.remoteport = int(remotespec[i+1:])
 except ValueError:
! usage(1, 'Bad remote port: %s' % remotespec)
 return options
 
 
! 
 if __name__ == '__main__':
 options = parseargs()

AltStyle によって変換されたページ (->オリジナル) /