Hey Tan,
Thanks for the question.
You should be able to rebuild the folders for all users in a domain, or for a single user, using the script below:
#!/usr/bin/env python3
import requests
URL = "http://localhost:17017"
ADMIN = "admin"
PASSWORD = "Admin123"
DOMAIN = "example.com"
TARGET = "domain-admin@example.com" # specific email address, or empty for all users
token = requests.post(f"{URL}/api/v1/auth/authenticate-user", json={"username": ADMIN, "password": PASSWORD}).json()["accessToken"]
h = {"Authorization": f"Bearer {token}"}
users = [{"emailAddress": TARGET}] if TARGET else requests.get(f"{URL}/api/v1/settings/sysadmin/list-users/{DOMAIN}", headers=h).json().get("userData", [])
for user in users:
email = user["emailAddress"]
folders = requests.get(f"{URL}/api/v1/folders/sysadmin/list-email-folders/{email}", headers=h).json().get("folderList", [])
restorations = [{"folder": f["path"], "email": email, "recursive": True} for f in folders if f.get("path")]
if restorations:
requests.post(f"{URL}/api/v1/settings/sysadmin/restore-folders", json={"restorations": restorations}, headers=h)
print(f"{email}: {len(restorations)} folders rebuilt")Please save this as folder_restore.py.
To run it, make sure Python is installed on the server and install the requests library first:
pip install requests
A couple of notes on how the script works:
- If TARGET is set to a specific email address, the script will rebuild folders only for that user.
- If TARGET is left empty, like TARGET = "", it will rebuild folders for all users in the specified domain.
Before running it, update the following values:
- ADMIN and PASSWORD with your system admin credentials
- DOMAIN with the domain you want to process
- TARGET with the email address of a specific user, or leave it blank to process all users in the domain
Once those values are updated, you can run the script and it will rebuild the folders for the selected user or the entire domain.
Hope this helps.
Kind Regards,
Zach Sylvester
Software Developer
SmarterTools Inc.
www.smartertools.com