Skip to content

Instantly share code, notes, and snippets.

@dominicpratt
Created March 5, 2019 14:10
Show Gist options
  • Save dominicpratt/091739b2b5166b681f7c36b62ee742f8 to your computer and use it in GitHub Desktop.
Save dominicpratt/091739b2b5166b681f7c36b62ee742f8 to your computer and use it in GitHub Desktop.
Fix broken entryids in sent folder and all users
import sys
import os
import uuid
import kopano
import mysql.connector
USER="root"
PASSWORD=""
HOST="localhost"
DB="kopano"
cnx = mysql.connector.connect(user=USER, password=PASSWORD,
host=HOST,
database=DB)
cursor = cnx.cursor()
cursor.execute("select user_name from stores WHERE user_name LIKE '%@%';")
users = cursor.fetchall()
for x in users:
print "Fixing:",x[0]
storeguid=kopano.Server().user(x[0]).store
hierarchyid=kopano.Server().user(x[0]).folder("Gesendete Objekte")
query = ("SELECT id FROM hierarchy WHERE parent=%d AND type=5" % hierarchyid.hierarchyid)
cursor = cnx.cursor()
cursor.execute(query)
result = []
for (id,) in cursor:
result.append(id)
for id in result:
newentryid = '00000000' + storeguid.guid + '0100000005000000' + uuid.uuid4().hex.upper() + '00000000'
query = ("UPDATE indexedproperties SET val_binary = UNHEX('%s') WHERE tag = 4095 AND hierarchyid = %d" % (newentryid, id))
cursor.execute(query)
cnx.commit()
cnx.close()
os.system("/usr/sbin/kopano-srvadm --clear-cache all")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment