Very true. SM is WTF'able. I do think that with all this massive knowledge, why not implement a new free open-source webmail application? I would assume that a more updated IMAP-capable client is available, and if not, why not write one since the standard is so familiar? Cuz you don't wanna. So deal with what was chosen, or make the change. I've had pretty much no pain ever with changing IMAP "webmail" applications. Like a good abstraction layer, thusly exists IMAP/POP/SMTP/etc.
<semi-sarcastic nerding>
As much as I hate typing it every time (thanks keyboard shortcuts/autocomplete) I use the old fashioned $GLOBALS array every time. Pretty obvious where that's from. Those other super globals also autocomplete rather well and so I use them too. Also, I usually have a nice common library. Then sub- and end-libraries. In the very end libraries (which usually follow a specific naming convention) I typically don't leave a cookie-crumb back to the start. That's what the name is for. And I like to eat cookies.
</just saying>