| 777 | |
| 778 | |
| 779 | def parseargs(): |
| 780 | global DEBUGSTREAM |
| 781 | try: |
| 782 | opts, args = getopt.getopt( |
| 783 | sys.argv[1:], 'nVhc:s:du', |
| 784 | ['class=', 'nosetuid', 'version', 'help', 'size=', 'debug', |
| 785 | 'smtputf8']) |
| 786 | except getopt.error as e: |
| 787 | usage(1, e) |
| 788 | |
| 789 | options = Options() |
| 790 | for opt, arg in opts: |
| 791 | if opt in ('-h', '--help'): |
| 792 | usage(0) |
| 793 | elif opt in ('-V', '--version'): |
| 794 | print(__version__) |
| 795 | sys.exit(0) |
| 796 | elif opt in ('-n', '--nosetuid'): |
| 797 | options.setuid = False |
| 798 | elif opt in ('-c', '--class'): |
| 799 | options.classname = arg |
| 800 | elif opt in ('-d', '--debug'): |
| 801 | DEBUGSTREAM = sys.stderr |
| 802 | elif opt in ('-u', '--smtputf8'): |
| 803 | options.enable_SMTPUTF8 = True |
| 804 | elif opt in ('-s', '--size'): |
| 805 | try: |
| 806 | int_size = int(arg) |
| 807 | options.size_limit = int_size |
| 808 | except: |
| 809 | print('Invalid size: ' + arg, file=sys.stderr) |
| 810 | sys.exit(1) |
| 811 | |
| 812 | # parse the rest of the arguments |
| 813 | if len(args) < 1: |
| 814 | localspec = 'localhost:8025' |
| 815 | remotespec = 'localhost:25' |
| 816 | elif len(args) < 2: |
| 817 | localspec = args[0] |
| 818 | remotespec = 'localhost:25' |
| 819 | elif len(args) < 3: |
| 820 | localspec = args[0] |
| 821 | remotespec = args[1] |
| 822 | else: |
| 823 | usage(1, 'Invalid arguments: %s' % COMMASPACE.join(args)) |
| 824 | |
| 825 | # split into host/port pairs |
| 826 | i = localspec.find(':') |
| 827 | if i < 0: |
| 828 | usage(1, 'Bad local spec: %s' % localspec) |
| 829 | options.localhost = localspec[:i] |
| 830 | try: |
| 831 | options.localport = int(localspec[i+1:]) |
| 832 | except ValueError: |
| 833 | usage(1, 'Bad local port: %s' % localspec) |
| 834 | i = remotespec.find(':') |
| 835 | if i < 0: |
| 836 | usage(1, 'Bad remote spec: %s' % remotespec) |