THERESA May has been foiled in the European Courts after her snooper’s charter was declared illegal.

The European Court of Justice said the Government’s plans for “general and indiscriminate retention” of everyone’s emails would leave people feeling as if “their private lives are the subject of constant surveillance”.

Embarrassingly for May, the case had originally been taken to court by her Brexit minister David Davis when he was still a backbencher.

In their ruling, the 15 judges on the ECJ said the security services could only intercept targeted communications and location data in order to combat serious crime and terrorism.

Rather than automatically keep all communications, there would need to be prior authorisation by a court or independent body for each official request.

The Government was taken to court by Davis, and Labour’s Tom Watson, with the support of Liberty, the Law Society, the Open Rights Group and Privacy International. They had challenged the legality of the Data Retention and Investigatory Powers Act (DRIPA) 2014, saying the laws failed to meet the EU’s required standards on data retention.

The UK courts agreed with the MPs, and the government then went to the Court of Appeal, who referred the decision to the ECJ for clarification.

Yesterday’s judgement means it will now go back to the Court of Appeal and certain defeat for May.

Before he was in the cabinet Davis had argued that the laws had been pushed through parliament in one day, and that the Government was abusing its power.

“It can be misused by states. Large quantities of data attract criminals and fraudsters. Limited storing is necessary,” Davis said ahead of the case’s first day in the ECJ back in April. “The British Government is retaining far more than is necessary and treating the entire nation as suspects, and that’s not consistent with British laws.”

Davis withdrew from the case after May made him a government minister.

DRIPA expires at the end of the month, but much of that act has been put into the Investigatory Powers Act, which was passed in parliament at the end of last month and due to come into force by the start of 2017. However, the ECJ judgement is only binding as long as the UK remains in the EU, and there would be little stop the government bringing back the legislation after Brexit.

In their ruling, the court said electronic communications allow “very precise conclusions to be drawn concerning the private lives of persons whose data has been retained”.

It added: “The interference by national legislation that provides for the retention of traffic data and location data with that right must therefore be considered to be particularly serious.

“The fact that the data is retained without the users of electronic communications services being informed of the fact is likely to cause the persons concerned to feel that their private lives are the subject of constant surveillance. Consequently, only the objective of fighting serious crime is capable of justifying such interference.”

Responding to the ruling, Watson said: “At a time when we face a real and ever-present terrorist threat, the security forces may require access to personal information none of us would normally hand over. That’s why it’s absolutely vital that proper safeguards are put in place to ensure this power is not abused, as it has been in the recent past.

“Most of us can accept that our privacy may occasionally be compromised in the interests of keeping us safe, but no-one would consent to giving the police or the government the power to arbitrarily seize our phone records or emails to use as they see fit. It’s for judges, not ministers, to oversee these powers.”

SNP MP Joanna Cherry said: “This decision of the European Court of Justice vindicates the stance which the SNP took against the indiscriminate collection of data authorised by the Investigatory Powers Act. The UK Government must now heed our concerns and amend the act to make it lawful.”

A Home Office spokesperson said: “We are disappointed with the judgment from the European court of justice and will be considering its potential implications.

“The Government will be putting forward robust arguments to the Court of Appeal about the strength of our regime for communications data retention and access.”