I'm not sure about this, but don't have all spells which require a target a range? I mean, spells that can only be cast on the player don't have a range in their tooltip. Even those spells with seemingly unlimited range like mind vision do have a line in the tooltip saying "50000y range" (not sure about warlocks and their porting spell though). If this is true, why not scan the tooltip for a range, and if it's not there, it is a self-targetting spell.
If I'm wrong, just forget what I wrote.
That's actually an excellent observation; although I hate having to scan tooltips it's already being done here anyway. An exception is that "Next melee" don't have a range listed, but it's easy enough to check for that string.
I have it in SpellComplete, but it's not always accurate. There are some circumstances which make it impossible to determine the real target. The system in SpellComplete has a fairly high accuracy rate though, 90%+, and you're welcome to grab whatever code you want from it.
For example, spells that are always cast on yourself, such as life tap or battle shout. Their target will be whomever you currently have selected unless you keep a database of all these spell types and compare them.
EDIT: Or leave it up to the addon dev, they should be smart enough to know when they don't need a target.