The giant is said to be the first US internet company to agree to such a blanket request 

Yahoo has been accused of secretly building a customised software programme to search all of its customers’ incoming emails for specific information provided by US intelligence officials.

A report on Tuesday said that according to people familiar with the with the matter, the company complied with a classified US government directive, scanning hundreds of millions of Yahoo Mail accounts at the behest of the National Security Agency or FBI.

Reuters said that a number of surveillance experts said this represented the first case to surface of a US Internet company agreeing to a spy agency’s demand by searching all arriving messages, as opposed to examining stored messages or scanning a small number of accounts in real time. 

The news agency said it was not clear what information the US intelligence officials were searching for. But they wanted Yahoo to look for a set of characters. That could mean a phrase in an email or an attachment.

The agency also said it was unable to determine what data the company had handed over, and if the intelligence officials had approached other email providers besides Yahoo.

According to two former employees, Yahoo Chief Executive Marissa Mayer's decision to obey the directive angered some senior executives and led to the June 2015 departure of Chief Information Security Officer Alex Stamos, who now holds the top security job at Facebook.

“Yahoo is a law abiding company, and complies with the laws of the United States,” the company said in a brief statement. Mr Stamos declined to comment, as did the NSA.

The demand to search Yahoo Mail accounts came in the form of a classified directive sent to the company’s legal team.

US phone and Internet companies are known to have handed over bulk customer data to intelligence agencies. But some former government officials and private surveillance experts said they had not previously seen either such a broad directive for real-time Web collection or one that required the creation of a new computer program.

“I’ve never seen that, a wiretap in real time on a ‘selector’,” said Albert Gidari, a lawyer who represented phone and Internet companies on surveillance. A selector refers to a type of search term used to zero in on specific information.

He added: “It would be really difficult for a provider to do that.”