Yahoo has scanned hundreds of millions of their customers' incoming emails to comply on a classified U.S. government directive. They searched for specific information provided by officials from the National Security Agency (NSA) or the FBI, said the two former employees.

According to some surveillance experts, it was the first case where a US internet company agreed to a spy agency's request to search all incoming emails instead of checking the stored messages or scanning a few number of accounts in real time.

While it is known that the agency wants Yahoo to search for a set of characters, it is not clear what exact information the intelligence officials were looking for, according to an unidentified source. The source added that the officials might be looking for a phrase in an email or maybe an attachment, Reuters reported.

The two former employees confirmed that Chief Executive Marissa Mayer's decision to comply with the NSA or FBI's directive raised some senior executives' eyebrows and made Chief Information Security Officer Alex Stamos leave the company in June 2015. Stamos is now with Facebook Inc., holding the same position.

In response to Reuter's questions, the company said that "Yahoo is a law abiding company, and complies with the laws of the United States." The company did not give any comment. It is unclear if the FBI has asked other email providers for the same request.

On the other hand, the internet giant previously fought - and lost - a court battle which is forcing the company to comply with Prism, a secret surveillance program. The program was leaked by a whistle blower named Edward Snowden. Prism let NSA acquire emails, photos, video chats and documents, as reported by CNet.

The court battle happened before Mayer became CEO in 2012. Yahoo is still recovering from a data breach that happened in 2014 where more than 500 million email users were affected.