An American who vanished nearly seven years ago in Iran was working for the CIA on an unapproved intelligence-gathering mission that, when it came to light inside the government, produced one of the most serious scandals in the recent history of the CIA but all in secret, an Associated Press investigation found.