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