Page tree
Skip to end of metadata
Go to start of metadata

These scripts and tools are provided to help you manage your Kopano system. They are provided as a free service for Kopano users, without warranty of any kind.

Please be aware that usage is at your own risk!   Expand source  master  KSC/webapp-tools  Copy
#!/usr/bin/env python
#encoding: utf-8

import kopano
from MAPI.Util import *
import json

def opt_args():
    parser = kopano.parser('skpcfm')
    parser.add_option("--user", dest="user", action="store", help="Run script for user")
    parser.add_option("--list", dest="list", action="store_true", help="List recipients history")
    parser.add_option("--backup", dest="backup", action="store_true", help="Backup recipients history")
    parser.add_option("--restore", dest="restore", action="store_true", help="Restore recipients history")
    parser.add_option("--restore-file", dest="restorefile", action="store", help="Restore from an other file then username.json")
    parser.add_option("--remove", dest="remove", action="store", help="Remove recipients ")
    parser.add_option("--remove-all", dest="removeall", action="store_true", help="Remove complete recipients history")
    parser.add_option("--dry-run", dest="dryrun", action="store_true", help="Test script")

    return parser.parse_args()

def main():
    options, args = opt_args()

    if not options.user:
        print 'Please use:\n %s --user <username>' % (sys.argv[0])

    user = kopano.Server(options).user(options.user)
    webapp =
    webapp = json.loads(webapp)

    if options.backup:
        f = open('%s.json' %, 'w')
        f.write(json.dumps(webapp, sort_keys=True,
                           indent=4, separators=(',', ': ')))

    if options.restore:
        if options.restorefile:
            filename = options.restorefile
            filename = '%s.json' %
        with open(filename) as data_file:
            data = json.load(data_file)[SPropValue(0X6773001F, u'%s' % json.dumps(data))])

    if options.list:
        print json.dumps(webapp, sort_keys=True,
                         indent=4, separators=(',', ': '))

    if options.remove:
        newlist = json.loads('{"recipients":[]}')
        for rec in webapp['recipients']:
            if options.remove in rec['display_name'] or options.remove in rec['smtp_address'] \
                    or options.remove in rec['email_address']:
                print 'removing contact %s [%s]' % (rec['display_name'], rec['smtp_address'])

        if not options.dryrun:
  [SPropValue(0X6773001F, u'%s' % json.dumps(newlist))])


    if options.removeall:
        newlist = json.loads('{"recipients":[]}')
        if not options.dryrun:
  [SPropValue(0X6773001F, u'%s' % json.dumps(newlist))])


if __name__ == "__main__":



Usage: [options]

  -h, --help                         show this help message and exit
  -c FILE, --config=FILE             load settings from FILE
  -s SOCKET, --server-socket=SOCKET  connect to server SOCKET
  -k FILE, --ssl-key=FILE            SSL key file
  -p PASS, --ssl-pass=PASS           SSL key password
  -f NAME, --folder=NAME             run program for specific folder
  -m, --modify                       enable database modification
  --user=USER                        Run script for user
  --list                             List recipients history
  --backup                           Backup recipients history
  --restore                          Restore recipients history
  --restore-file=RESTOREFILE         Restore from an other file then
  --remove=REMOVE                    Remove recipients
  --remove-all                       Remove complete recipients history
  --dry-run                          Test script


List recipients

python --user <user>  --list


Remove recipient

Remove option is searching in display_name, smtp_address or email_address. 
python --user <user>  --remove <recipient name>

Clear history

python --user <user>  --remove-all



Remove all recipients that have in there display_name, smtp_address or email_address
python --user user  --remove



  • No labels