- if use_locale:
- # Get the default charset.
- try:
- lcAll = locale.setlocale(locale.LC_ALL, '').split('.')
- except locale.Error, err:
- print >> sys.stderr, "WARNING:", err
- lcAll = []
-
- if len(lcAll) == 2:
- default_charset = lcAll[1]
- else:
- try:
- default_charset = locale.getpreferredencoding()
- except locale.Error, err:
- print >> sys.stderr, "WARNING:", err
- default_charset = sys.getdefaultencoding()
- else:
- default_charset = sys.getdefaultencoding()
-
- recode_charset = 1 # recode charset of message body
-
- decode_headers = ["Subject", "From"] # A list of headers to decode
- decode_header_params = [("Content-Type", "name"),
- ("Content-Disposition", "filename")
- ] # A list of headers' parameters to decode
-
- totext_mask = [] # A list of content-types to decode
- binary_mask = [] # A list to pass through
- ignore_mask = [] # Ignore (skip, do not decode and do not include into output)
- error_mask = [] # Raise error if encounter one of these
-
-
-def init():
- from getopt import getopt, GetoptError
-
- try:
- options, arguments = getopt(sys.argv[1:], 'hVcCDPf:d:p:b:e:i:t:',
- ['help', 'version'])
- except GetoptError:
- usage(1)
-
- for option, value in options:
- if option == '-h':
- usage()
- elif option == '--help':
- usage()
- elif option == '-V':
- version()
- elif option == '--version':
- version()
- elif option == '-c':
- GlobalOptions.recode_charset = 1
- elif option == '-C':
- GlobalOptions.recode_charset = 0
- elif option == '-f':
- GlobalOptions.default_charset = value
- elif option == '-d':
- GlobalOptions.decode_headers.append(value)
- elif option == '-D':
- GlobalOptions.decode_headers = []
- elif option == '-p':
- GlobalOptions.decode_header_params.append(value.split(':', 1))
- elif option == '-P':
- GlobalOptions.decode_header_params = []
- elif option == '-t':
- GlobalOptions.totext_mask.append(value)
- elif option == '-b':
- GlobalOptions.binary_mask.append(value)
- elif option == '-i':
- GlobalOptions.ignore_mask.append(value)
- elif option == '-e':
- GlobalOptions.error_mask.append(value)
- else:
- usage(1)
-
- return arguments
+ from m_lib.defenc import default_encoding
+ recode_charset = 1 # recode charset of message body
+
+ host_name = None
+
+ decode_headers = ["From", "To", "Subject"] # A list of headers to decode
+ decode_header_params = [
+ ("Content-Type", "name"),
+ ("Content-Disposition", "filename"),
+ ] # A list of headers' parameters to decode
+
+ totext_mask = [] # A list of content-types to decode
+ binary_mask = [] # A list to pass through
+ ignore_mask = [] # Ignore (skip, do not decode and do not include into output)
+ error_mask = [] # Raise error if encounter one of these
+
+ input_filename = None
+ output_filename = None
+
+gopts = GlobalOptions
+
+
+def get_opt():
+ from getopt import getopt, GetoptError
+
+ try:
+ options, arguments = getopt(sys.argv[1:], 'hVcCDPH:f:d:p:b:e:i:t:o:',
+ ['help', 'version', 'host'])
+ except GetoptError:
+ usage(1)
+
+ for option, value in options:
+ if option in ('-h', '--help'):
+ usage()
+ elif option in ('-V', '--version'):
+ version()
+ elif option == '-c':
+ gopts.recode_charset = 1
+ elif option == '-C':
+ gopts.recode_charset = 0
+ elif option in ('-H', '--host'):
+ gopts.host_name = value
+ elif option == '-f':
+ gopts.default_encoding = value
+ elif option == '-d':
+ gopts.decode_headers.append(value)
+ elif option == '-D':
+ gopts.decode_headers = []
+ elif option == '-p':
+ gopts.decode_header_params.append(value.split(':', 1))
+ elif option == '-P':
+ gopts.decode_header_params = []
+ elif option == '-t':
+ gopts.totext_mask.append(value)
+ elif option == '-b':
+ gopts.binary_mask.append(value)
+ elif option == '-i':
+ gopts.ignore_mask.append(value)
+ elif option == '-e':
+ gopts.error_mask.append(value)
+ elif option == '-o':
+ gopts.output_filename = value
+ else:
+ usage(1)
+
+ return arguments