]> git.phdru.name Git - mimedecode.git/commitdiff
Refactor common code into _decode_headers_params
authorOleg Broytman <phd@phdru.name>
Sat, 8 Mar 2014 16:07:51 +0000 (20:07 +0400)
committerOleg Broytman <phd@phdru.name>
Sat, 8 Mar 2014 16:07:51 +0000 (20:07 +0400)
mimedecode.py

index f3362cf824121c218daf2b8a9833f7281b663705..0cec65375c69778c9c03df42dc3345896b12a3d8 100755 (executable)
@@ -97,6 +97,17 @@ def decode_header_param(msg, header, param):
 def _get_exceptions(list):
     return [x[1:].lower() for x in list[1:] if x[0]=='-']
 
+def _decode_headers_params(msg, header, decode_all_params, param_list):
+    if decode_all_params:
+        params = msg.get_params(header=header)
+        if params:
+            for param, value in params:
+                if param not in param_list:
+                    decode_header_param(msg, header, param)
+    else:
+        for param in param_list:
+            decode_header_param(msg, header, param)
+
 def decode_headers(msg):
     "Decode message headers according to global options"
 
@@ -137,26 +148,10 @@ def decode_headers(msg):
             header_list = _get_exceptions(header_list)
             for header in msg.keys():
                 if header.lower() not in header_list:
-                    if decode_all_params:
-                        params = msg.get_params(header=header)
-                        if params:
-                            for param, value in params:
-                                if param not in param_list:
-                                    decode_header_param(msg, header, param)
-                    else:
-                        for param in param_list:
-                            decode_header_param(msg, header, param)
+                    _decode_headers_params(msg, header, decode_all_params, param_list)
         else: # Decode for listed headers
             for header in header_list:
-                if decode_all_params:
-                    params = msg.get_params(header=header)
-                    if params:
-                        for param, value in params:
-                            if param not in param_list:
-                                decode_header_param(msg, header, param)
-                else:
-                    for param in param_list:
-                        decode_header_param(msg, header, param)
+                _decode_headers_params(msg, header, decode_all_params, param_list)
 
 
 def set_header(msg, header, value):