Error -10000 when getting mailboxes from Mail

In my application Mail Archiver I use AppleScript to get the mailboxes from Mail. Today I’ve got a ticket from a user who gets an error -10000.

The user is on Mojave. High Sierra and Mojave have a bug where you could run out of ports after doing too many AppleScripts in a short time. Usually, a reboot resets the ports. The user has restarted his computer and the error still shows up.

I then sent him a test script to get the mailboxes:

tell application id "com.apple.mail"
	set theMailboxes to get mailboxes
	set theAccounts to get accounts
	repeat with theAccount in theAccounts
		set AccountMailboxes to mailboxes of theAccount
		set end of theMailboxes to AccountMailboxes
	end repeat
	return theMailboxes
end tell

And he there, too, get the error -10000.

Any ideas how to fix the problem?