[PATCH] enforce mua checking for --mua option

Carl Chenet carl.chenet at ohmytux.com
Thu May 14 23:14:31 UTC 2009


---
 bin/reportbug      |    6 ++++++
 reportbug/utils.py |   25 ++++++++++++++++++++-----
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/bin/reportbug b/bin/reportbug
index 3fba286..0a4caa3 100755
--- a/bin/reportbug
+++ b/bin/reportbug
@@ -859,10 +859,16 @@ def main():
 
 
     if options.mua:
+        if not utils.mua_is_supported(options.mua):
+            ewrite("Specified mail user agent is not supported; exiting.\n")
+            sys.exit(1)
+
         if not utils.mua_exists(options.mua):
             ewrite("Selected mail user agent cannot be found; exiting.\n")
             sys.exit(1)
 
+        options.mua = utils.mua_name(options.mua)
+
     if options.interface:
         interface = options.interface
 
diff --git a/reportbug/utils.py b/reportbug/utils.py
index 8eda059..56618f2 100644
--- a/reportbug/utils.py
+++ b/reportbug/utils.py
@@ -760,14 +760,22 @@ MUA = {
 MUA['nmh'] = MUA['mh']
 
 MUAVERSION = {
-    'mutt' : 'mutt -v',
-    'af' : 'af -v ',
-    'mh' : '/usr/bin/mh/comp -use -file',
-    'gnus' : 'emacs --version',
+    MUA['mutt'] : 'mutt -v',
+    MUA[ 'af'] : 'af -v ',
+    MUA['mh'] : '/usr/bin/mh/comp -use -file',
+    MUA['gnus'] : 'emacs --version',
     }
-MUAVERSION['nmh'] = MUAVERSION['mh']
+
+def mua_is_supported(mua):
+    # check if the mua is supported by reportbug
+    if mua.split()[0] not in MUA:
+        return False
+    else:
+        return True
 
 def mua_exists(mua):
+    # check if the mua is available on the system
+    mua = MUA[mua.split()[0]]
     output = '/dev/null'
     if os.path.exists(output):
         try:
@@ -782,6 +790,13 @@ def mua_exists(mua):
     else:
         return True
 
+def mua_name(mua):
+    # in case the user specifies only the mua name in --mua, returns the default options
+    if mua in MUA:
+        return MUA[mua]
+    else:
+        return mua
+
 def first_run():
     return not os.path.exists(USERFILE)
 
-- 
1.5.4.3


--=-LX6JRgKIKjiQk5k2DGTp--






More information about the Reportbug-maint mailing list