Three anonymous sources told Reuters that Yahoo developed a custom tool that allowed the NSA and FBI to scan emails in real time for specific words and phrases. The agencies could then retrieve the emails when they found something interesting.
According to the publication, Yahoo was the recipient of classified requests from the two services requiring it to develop this special software in early 2015, which the company finally deployed in May 2015.

The three sources say that while the company had initially planned to fight government requests to develop the spyware, Yahoo's legal department didn't think it would win the case, and so in the end, Yahoo CEO Marissa Mayer gave the engineering department the green light to build the real-time spying tool.
Mayer apparently hid all of this from Yahoo's CISO, Alex Stamos. Reuters reports that Yahoo's security team discovered the tool a month later, and initially thought it was a hack.
So because Mayer made the decision to develop this tool without the knowledge of Alex Stamos, Yahoo's CISO, he resigned a month later and was hired by Facebook.
According to another report from the New York Times last week, Mayer ignored security issues discovered by Alex Stamos in order to increase the security budget. The result, of course, is now well known after Yahoo was hacked in 2014, and the attackers managed to steal data from over 500 million Yahoo users.
Reuters reports that it was unable to verify what type and how much email data the NSA and FBI could have with the system developed by Yahoo.
According to the three insiders, the tool allowed organizations to create trigger words and phrases that acted as a filter for all of Yahoo's email traffic, scanning emails and attachments in real time.
