#!/usr/local/bin/python3.14
# SPDX-License-Identifier: AGPL-3.0-or-later
# -*- coding: utf-8 -*-
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
#
import sys
import kopano
from MAPI.Tags import PR_IPM_SUBTREE_ENTRYID

server = kopano.server(auth_user='SYSTEM', auth_pass='')

if not len(server.options.users):
    sys.exit('Usage: %s -u username' % sys.argv[0])

user = kopano.User(server.options.users[0])
if user.store.subtree:
    sys.exit()

subtree = user.store.root.folder('IPM_SUBTREE')
if not subtree:
    sys.exit("Result: IPM_SUBTREE folder not found")

print('Result: FIXED - Setting PR_IPM_SUBTREE_ENTRYID to IPM_SUBTREE')
print('PR_IPM_SUBTREE_ENTRYID current value: ' + user.store.prop(PR_IPM_SUBTREE_ENTRYID).strval)
user.store.create_prop(PR_IPM_SUBTREE_ENTRYID, subtree.entryid.decode('hex'))
print('PR_IPM_SUBTREE_ENTRYID set to: ' + subtree.entryid)
