what is the reason behind this request? ( if you don't mind me asking ) as I am not sure how well such a script would work. Typically a user would only get created at the point of creating a ticket, so its likely trying to clean them via "do they have a ticket" will not work well.

Hi Gary,
We have spam that comes in from our email account that results in a ticket created. We delete the tickets when they come in, but we do not always delete the user account. As a result, we probably have several thousand user accounts that are actually spam. Let me know if this helps explain the situation.

If marked as spam the user's email address is retained to block further attempts from that address.
I think marking a ticket as spam should remove the ticket and any attachments, but that it not the way it works currently.