Back in my self-employment days, I've once taken on a small and rather well-paid project: "A newsletter system", the spec stated.
Everything was fine, invoices were paid with each milestone reached, me was a happy developer … Until Mr. Client started demanding mail header spoofing and a bunch of other functionality eventually leading me to the conclusion that I was building quite the sophisticated spam mailer.
To make a long story short: Financial considerations made me finish what I had started. I resent having taken on the job in the first place to this day – if I had bothered to google my client's name, I would've been warned.
What strategies can I use to avoid ending up coding stuff I'd rather not see in someone's hands?