Change option -r to remove all headers and accept a list of exceptions:
-r *,-h1,-h2,...
+ Change option -R to accept lists of headers and parameters:
+-R h1,h2,h3:p1,p2,p3
+-R h1,h2,h3:*,-p1,-p2,-p3
+-R *,-h1,-h2,-h3:p1,p2,p3
+-R *,-h1,-h2,-h3:*,-p1,-p2,-p3
Add ChangeLog.
-Change option -R to accept lists of headers and parameters:
--R h1,h2,h3:p1,p2,p3
-Allow * and exceptions:
--R h1,h2,h3:*,-p1,-p2,-p3
--R *,-h1,-h2,-h3:p1,p2,p3
--R *,-h1,-h2,-h3:*,-p1,-p2,-p3
-
-
Publish docs in html format.
<option>-r *[,-header1,-header2,-header3...]</option>
</arg>
<arg choice="opt">
- <option>-R header:param</option>
+ <option>-R header1[,header2,header3,...]:param1[,param2,param3,...]</option>
+ <option>-R *[,-header1,-header2,-header3,...]:param1[,param2,param3,...]</option>
+ <option>-R header1[,header2,header3,...]:*[,-param1,-param2,-param3,...]</option>
+ <option>-R *[,-header1,-header2,-header3,...]:*[,-param1,-param2,-param3,...]</option>
</arg>
<arg choice="opt">
<option>-beit mask</option>
</varlistentry>
<varlistentry>
- <term>-R header:param</term>
+ <term>-R header1[,header2,header3,...]:param1[,param2,param3,...]</term>
<listitem>
<para>
- Add the pair (header, param) to a list of headers parameters to
- remove; initially the list is empty.
+ Add the parameters(s) to a list of headers parameters to remove;
+ the parameters will be decoded only for the given header(s).
+ Initially the list is empty.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>-R *[,-header1,-header2,-header3,...]:param1[,param2,param3,...]</term>
+ </varlistentry>
+
+ <varlistentry>
+ <term>-R header1[,header2,header3,...]:*[,-param1,-param2,-param3,...]</term>
+ </varlistentry>
+
+ <varlistentry>
+ <term>-R *[,-header1,-header2,-header3,...]:*[,-param1,-param2,-param3,...]</term>
+ <listitem>
+ <para>
+ Remove listed parameters (or all parameters except listed) frome
+ these headers (or from all headers except listed).
</para>
</listitem>
</varlistentry>
def usage(code=0, errormsg=''):
version(0)
sys.stdout.write("""\
-Usage: %s [-h|--help] [-V|--version] [-cCDP] [-H|--host=hostname] [-f charset] [-d header1[,h2,...]|*[,-h1,...]] [-p header1[,h2,h3,...]:param1[,p2,p3,...]] [-r header1[,h2,...]|*[,-h1,...]] [-R header:param] [-beit mask] [-o output_file] [input_file [output_file]]
+Usage: %s [-h|--help] [-V|--version] [-cCDP] [-H|--host=hostname] [-f charset] [-d header1[,h2,...]|*[,-h1,...]] [-p header1[,h2,h3,...]:param1[,p2,p3,...]] [-r header1[,h2,...]|*[,-h1,...]] [-R header1[,h2,h3,...]:param1[,p2,p3,...]] [-beit mask] [-o output_file] [input_file [output_file]]
""" % me)
if errormsg:
sys.stderr.write(errormsg + '\n')
for param in param_list:
decode_header_param(msg, header, param)
+def _remove_headers_params(msg, header, remove_all_params, param_list):
+ if remove_all_params:
+ params = msg.get_params(header=header)
+ if params:
+ if param_list:
+ for param, value in params:
+ if param not in param_list:
+ msg.del_param(param, header)
+ else:
+ value = msg[header]
+ if value is None: # No such header
+ return
+ if ';' not in value: # There are no parameters
+ return
+ del msg[header] # Delete all such headers
+ # Get the value without parameters and set it back
+ msg[header] = value.split(';')[0].strip()
+ else:
+ for param in param_list:
+ msg.del_param(param, header)
+
def decode_headers(msg):
"Decode message headers according to global options"
for header in header_list:
del msg[header]
- #for header in gopts.remove_all_params:
- # value = msg[header]
- # if value is None: # No such header
- # continue
- # if ';' not in value: # There are no parameters
- # continue
- # del msg[header] # Delete all such headers
- # # Get the value without parameters and set it back
- # msg[header] = value.split(';')[0].strip()
-
- for header, param in gopts.remove_header_params:
- msg.del_param(param, header)
+ for header_list, param_list in gopts.remove_headers_params:
+ header_list = header_list.split(',')
+ param_list = param_list.split(',')
+ remove_all_params = param_list[0] == '*' # Remove all params except listed
+ if remove_all_params:
+ param_list = _get_exceptions(param_list)
+ if header_list[0] == '*': # Remove for all headers except listed
+ header_list = _get_exceptions(header_list)
+ for header in msg.keys():
+ if header.lower() not in header_list:
+ _remove_headers_params(msg, header, remove_all_params, param_list)
+ else: # Decode for listed headers
+ for header in header_list:
+ _remove_headers_params(msg, header, remove_all_params, param_list)
for header_list in gopts.decode_headers:
header_list = header_list.split(',')
# A list of headers to remove
remove_headers = []
# A list of headers parameters to remove
- remove_header_params = []
+ remove_headers_params = []
totext_mask = [] # A list of content-types to decode
binary_mask = [] # A list to pass through
elif option == '-r':
gopts.remove_headers.append(value)
elif option == '-R':
- gopts.remove_header_params.append(value.split(':', 1))
+ gopts.remove_headers_params.append(value.split(':', 1))
elif option == '-t':
gopts.totext_mask.append(value)
elif option == '-b':
test_file msg_03.txt msg_03-1.txt -d \*,From,To,Subject,-cc
test_file msg_15.txt msg_15-1.txt -b text/html
test_file msg_15.txt msg_15-2.txt -i text/html
-test_file msg_22.txt msg_22-1.txt -r content-id
-test_file msg_29.txt msg_29-1.txt -R Content-Type:title
test_file msg_22.txt msg_22.txt -P -p Content-Type,Content-Disposition:name,filename
test_file msg_22.txt msg_22.txt -P -p \*:name,filename
test_file msg_22.txt msg_22.txt -P -p Content-Type,Content-Disposition:\*
test_file msg_22.txt msg_22.txt -P -p '*,-Content-Id:*,-x-mac-type'
+test_file msg_22.txt msg_22-1.txt -r content-id
test_file msg_16.txt msg_16-1.txt -r Received,List-Help,List-Post,List-Subscribe,List-Id,List-Unsubscribe,List-Archive
test_file msg_16.txt msg_16-2.txt -r \*,-mime-version,-content-type
-#test_file msg_18.txt msg_18-1.txt --remove-params=X-Foobar-Spoink-Defrobnit
+test_file msg_29.txt msg_29-1.txt -R Content-Type:title
+test_file msg_18.txt msg_18-1.txt -R X-Foobar-Spoink-Defrobnit:\*
if [ "$RC" -eq 0 ]; then
echo "All tests passed!"