aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rwxr-xr-xfetchmailconf.py34
2 files changed, 27 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index 4c99bafd..d8d14b68 100644
--- a/NEWS
+++ b/NEWS
@@ -84,6 +84,9 @@ removed from a 6.5.0 or newer release.)
--------------------------------------------------------------------------------
fetchmail-6.4.19:
+# CHANGE:
+* fetchmailconf: properly catch and report option parsing errors
+
# BUG FIX:
* LMTP: do not try to validate the last component of a UNIX-domain LMTP socket
as though it were a TCP port. Reported by Christoph Heitkamp, Gitlab issue #33.
diff --git a/fetchmailconf.py b/fetchmailconf.py
index 8722d48a..909975d1 100755
--- a/fetchmailconf.py
+++ b/fetchmailconf.py
@@ -35,13 +35,26 @@ except:
# define a dummy class to inherit from
class Frame: pass
-VERSION = "1.63.4"
+VERSION = "1.63.5"
MIN_PY = (2, 7, 13)
if sys.version_info < MIN_PY:
sys.exit("fetchmailconf: Python %s.%s.%s or later is required.\n" % MIN_PY)
#
+# Display usage information and pass status argument through to sys.exit()
+#
+def usage(status):
+ print("""
+Usage: fetchmailconf {[-d] [-f fetchmailrc]|-h|--help|-V|--version}
+ -d - dump configuration (for debugging)
+ -f fmrc - read alternate fetchmailrc file
+--help, -h - print this help text and quit
+--version, -V - print fetchmailconf version and quit
+""")
+ sys.exit(status)
+
+#
# Define the data structures the GUIs will be tossing around
#
class Configuration(object):
@@ -2185,7 +2198,12 @@ gUSiYASJpMEHhilJTEnhAlGoQqYAZQ1AiqEMZ0jDGtqQImhwwA13yMMevoQAGvGhEAWHGMOAAAA7
#
# Process options
- options, arguments = getopt.getopt(sys.argv[1:], "df:hV", ["help", "version"])
+ try:
+ options, arguments = getopt.getopt(sys.argv[1:], "df:hV", ["help", "version"])
+ except getopt.GetoptError as e:
+ usage(str(e))
+ except Exception as e:
+ raise e
dump = rcfile = None
for (switch, val) in options:
if switch == '-d':
@@ -2193,14 +2211,7 @@ gUSiYASJpMEHhilJTEnhAlGoQqYAZQ1AiqEMZ0jDGtqQImhwwA13yMMevoQAGvGhEAWHGMOAAAA7
elif switch == '-f':
rcfile = val
elif switch == '-h' or switch == '--help':
- print("""
-Usage: fetchmailconf {[-d] [-f fetchmailrc]|-h|--help|-V|--version}
- -d - dump configuration (for debugging)
- -f fmrc - read alternate fetchmailrc file
---help, -h - print this help text and quit
---version, -V - print fetchmailconf version and quit
-""")
- sys.exit(0)
+ usage(0)
elif switch == '-V' or switch == '--version':
print("fetchmailconf %s" % VERSION)
print("Running on python", sys.version)
@@ -2212,6 +2223,9 @@ welcome to redistribute it under certain conditions. Please see the file
COPYING in the source or documentation directory for details.""")
sys.exit(0)
+ if arguments:
+ usage("Extra arguments: '" + "' '".join(arguments) + "'")
+
if "DISPLAY" not in os.environ:
sys.exit("fetchmailconf must be run under X")