The sudden resignation of former CIA Director Gen. David H. Petraeus over an extramarital affair turned heads for many reasons — not least of which was the way a few Gmail messages brought down a man who handled sensitive information for a living.