From 67bd0abfa4021f543ed1e14728bdf590aec17e81 Mon Sep 17 00:00:00 2001 From: Mark de Bruijn Date: Mon, 17 Oct 2016 16:20:04 +0200 Subject: [PATCH 1/3] Initial commit of dump_webapp_signatures.py --- dump_webapp_signatures.py | 36 ++++++++++++++++++++++++++++++++++++ readme.md | 9 +++++++++ 2 files changed, 45 insertions(+) create mode 100644 dump_webapp_signatures.py diff --git a/dump_webapp_signatures.py b/dump_webapp_signatures.py new file mode 100644 index 0000000..82da916 --- /dev/null +++ b/dump_webapp_signatures.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +import kopano +import sys +from MAPI.Util import * + +try: + import json +except ImportError: + import simplejson as json + + +def opt_args(): + parser = kopano.parser('skpcf') + parser.add_option("--user", dest="user", action="store", help="Dump signatures for user") + return parser.parse_args() + + +def main(): + options, args = opt_args() + if not options.user: + 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')) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/readme.md b/readme.md index c3e439c..8a6a7ac 100644 --- a/readme.md +++ b/readme.md @@ -50,3 +50,12 @@ python webapp_settings.py --user user --backup ```python python webapp_settings.py --user user --restore ``` + +dump_webapp_signatures.py +========================= +Dumps all the signatures in a users Webapp to seperate files, meant as companion to the script setdefaultsignature.py as delivered with Webapp (see /usr/share/doc/kopano-webapp/scripts/signatures/ on your Webapp server.) + +#### Usage: +```python +python dump_webapp_signatures.py --user user +``` From 2c4b08cf7368ced0dffb86a52acaccf23faa50dd Mon Sep 17 00:00:00 2001 From: Mark de Bruijn Date: Tue, 18 Oct 2016 09:57:42 +0200 Subject: [PATCH 2/3] dump_webapp_signatures.py: Add exception when trying to retrieve webapp settings. --- dump_webapp_signatures.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) 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() From a9bb5234122d0544660a9b2e0f71df88e26b27f2 Mon Sep 17 00:00:00 2001 From: Mark de Bruijn Date: Fri, 21 Oct 2016 16:53:56 +0200 Subject: [PATCH 3/3] Add comment about where dump_signs writes the signatures. --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index 8a6a7ac..ceccc9b 100644 --- a/readme.md +++ b/readme.md @@ -54,6 +54,7 @@ python webapp_settings.py --user user --restore dump_webapp_signatures.py ========================= Dumps all the signatures in a users Webapp to seperate files, meant as companion to the script setdefaultsignature.py as delivered with Webapp (see /usr/share/doc/kopano-webapp/scripts/signatures/ on your Webapp server.) +The files will be written in the current directory. #### Usage: ```python