diff --git a/dump_webapp_signatures.py b/dump_webapp_signatures.py index 82da916..85d6a77 100644 --- a/dump_webapp_signatures.py +++ b/dump_webapp_signatures.py @@ -1,6 +1,5 @@ #!/usr/bin/env python import kopano -import sys from MAPI.Util import * try: @@ -21,16 +20,19 @@ def main(): print 'Please use:\n %s --user ' % (sys.argv[0]) else: user = kopano.Server(options=options).user(options.user) - settings = json.loads(user.store.prop(PR_EC_WEBACCESS_SETTINGS_JSON).value) - if len(settings['settings']['zarafa']['v1']['contexts']['mail']): - if 'signatures' in settings['settings']['zarafa']['v1']['contexts']['mail']: - for item in settings['settings']['zarafa']['v1']['contexts']['mail']['signatures']['all']: - name = settings['settings']['zarafa']['v1']['contexts']['mail']['signatures']['all'][item]['name'] - filename = '%s-%s-%s.html' % (user.name, name.replace(' ', '-'), item) - print 'Dumping: \'%s\' to \'%s\' ' % (name, filename) - with open(filename, 'w') as outfile: - outfile.write(settings['settings']['zarafa']['v1']['contexts']['mail']['signatures']['all'][item]['content'].encode('utf-8')) - + try: + settings = json.loads(user.store.prop(PR_EC_WEBACCESS_SETTINGS_JSON).value) + except Exception as e: + print 'Could not load WebApp settings for user %s (Error: %s)' % (user.name, repr(e)) + else: + if len(settings['settings']['zarafa']['v1']['contexts']['mail']): + if 'signatures' in settings['settings']['zarafa']['v1']['contexts']['mail']: + for item in settings['settings']['zarafa']['v1']['contexts']['mail']['signatures']['all']: + name = settings['settings']['zarafa']['v1']['contexts']['mail']['signatures']['all'][item]['name'] + filename = '%s-%s-%s.html' % (user.name, name.replace(' ', '-'), item) + with open(filename, 'w') as outfile: + print 'Dumping: \'%s\' to \'%s\' ' % (name, filename) + outfile.write(settings['settings']['zarafa']['v1']['contexts']['mail']['signatures']['all'][item]['content'].encode('utf-8')) if __name__ == '__main__': - main() \ No newline at end of file + main()