X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=mimedecode.py;h=882034b0f4f021d91277dd9e21676114caf144aa;hb=5a0b966d01b89f668ce0cea40208d511e1bc04f7;hp=c3e3ecffc13fba23137cdc8c955ab2bffe0f861b;hpb=93b627c389e98f0ef7347035ee75a8603b6dd866;p=mimedecode.git diff --git a/mimedecode.py b/mimedecode.py index c3e3ecf..882034b 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -97,15 +97,18 @@ def decode_header_param(msg, header, param): def decode_headers(msg): "Decode message headers according to global options" + for header in gopts.remove_headers: + del msg[header] + + for header, param in gopts.remove_header_params: + msg.del_param(param, header) + for header in gopts.decode_headers: decode_header(msg, header) for header, param in gopts.decode_header_params: decode_header_param(msg, header, param) - for header in gopts.remove_headers: - del msg[header] - def set_header(msg, header, value): "Replace header" @@ -278,7 +281,7 @@ class GlobalOptions: decode_headers = ["From", "To", "Cc", "Reply-To", "Mail-Followup-To", "Subject"] - # A list of headers' parameters to decode + # A list of headers parameters to decode decode_header_params = [ ("Content-Type", "name"), ("Content-Disposition", "filename"), @@ -286,6 +289,8 @@ class GlobalOptions: # A list of headers to remove remove_headers = [] + # A list of headers parameters to remove + remove_header_params = [] totext_mask = [] # A list of content-types to decode binary_mask = [] # A list to pass through @@ -302,7 +307,8 @@ def get_opt(): from getopt import getopt, GetoptError try: - options, arguments = getopt(sys.argv[1:], 'hVcCDPH:f:d:p:r:b:e:i:t:o:', + options, arguments = getopt(sys.argv[1:], + 'hVcCDPH:f:d:p:r:R:b:e:i:t:o:', ['help', 'version', 'host']) except GetoptError: usage(1) @@ -330,6 +336,8 @@ def get_opt(): gopts.decode_header_params = [] elif option == '-r': gopts.remove_headers.append(value) + elif option == '-R': + gopts.remove_header_params.append(value.split(':', 1)) elif option == '-t': gopts.totext_mask.append(value) elif option == '-b':