Scott Pruitt, President Donald Trump's pick to lead the Environmental Protection Agency (EPA) and the Attorney General of Oklahoma, has spent two years avoiding requests to release more than 3,000 emails between his office and fossil fuel companies.

On Thursday, one day before the Senate is due to vote on Pruitt's confirmation, an Oklahoma judge ordered their release.

Pruitt's office now has to turn the emails over to the plaintiffs in a lawsuit or to the court, thanks to Judge Aletia Haynes Timmons' ruling. The office has until Tuesday to comply. At that point, barring any surprise votes or changes in Senate schedule, Pruitt will likely have already been confirmed as EPA administrator.

Here's how things got to this point:

More than a dozen "open records requests" seeking the emails had been filed in Oklahoma, dating back to January 2015, but Pruitt and his office did not respond to them.

A lawsuit filed February 7, 2017 by The Center for Media and Democracy, represented by the American Civil Liberties Union, sought to force Pruitt to release the emails, alleging that withholding them violated state law. On Thursday, the judge sided with the plaintiffs.

Critics see Pruitt, a longtime opponent of environmental efforts at the EPA, as an ally of polluting industries.

Those alleged alliances have been at the center of a contentious confirmation debate in the Senate, which is expected to vote on his confirmation tomorrow.

Elizabeth Warren, the Democratic Senator from Massachussets, criticized her Republican colleagues on Twitter for moving forward on the confirmation vote before the emails' release: