Yes, a lot of this was helpful. But certain parts fail silently when run as a mail rule. And they don't when run using Script Editor, so there's something going wrong with the environment when running as a mail rule, but I don't know what, because it fails silently.
Here's the thread where I go...