From ca5e61cffb72085ff108d6e2e7fa163ff5d6238b Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sat, 8 Mar 2014 20:07:51 +0400 Subject: [PATCH] Refactor common code into _decode_headers_params --- mimedecode.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/mimedecode.py b/mimedecode.py index f3362cf..0cec653 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -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): -- 2.39.5