WHEN David Miranda, the Brazilian partner of Glenn Greenwald, an American journalist, was stopped and questioned by the police for nine hours in Heathrow airport last month, tempers in his home country flared. The law invoked by his detainers does not require them to give grounds for their actions. But then it is only supposed to be used against suspected terrorists, which Mr Miranda clearly is not. What he did do was carry materials relating to Mr Greenwald's reporting on documents passed to him by Edward Snowden, a former contractor for America's National Security Agency (NSA) and now a fugative whistleblower. Mr Miranda was set free to continue his journey to Rio de Janeiro, where he and Mr Greenwald live, but only after his laptop and hard drive were confiscated. The incident angered Brazil's government, already incensed by the revelations, co-written by Mr Greenwald and published on July 7th by O Globo, a Brazilian newspaper, that the NSA had allegedly been monitoring Brazilian citizens' telecoms and internet activity for a decade.

On September 1st the row escalated further. TV Globo, the paper's sister television network, aired a programme presenting documents provided by Mr Greenwald that suggest the NSA had spied not only on ordinary Latin American citizens but on Enrique Peña Nieto and Dilma Rousseff (pictured), the presidents of Mexico and Brazil, respectively. Among them was an NSA slide dated June 2012 displaying passages of what were said to be text messages sent by Mr Peña, who was still a presidential candidate at the time, in which he mentioned planned ministerial appointments. Though no content purporting to come from Ms Rousseff was shown, the programme detailed how the NSA filtered electronic communications and tracked e-mail, telephone calls and text messages sent between people close to her.

Mexico's response has been relatively muted, possibly because the two countries do not want to draw attention to the intelligence already shared in their joint efforts to combat drug-trafficking. America's ambassador to the country, Anthony Wayne, was summoned and given a diplomatic note demanding a thorough investigation. "Without assuming the information that came out in the media is accurate, Mexico's government rejects and condemns any espionage activity on Mexican citizens that violate international law," said the foreign ministry. "This type of practice is contrary to the Charter of the United Nations and the International Court of Justice."

The fall-out in Brazil could be more substantial. The American ambassador, Thomas Shannon, was hauled in and told to provide a detailed written response to the allegations by the end of the week. Ms Rousseff is said to be considering calling off a state visit to Washington planned for next month, which was intended to highlight the growing ties between the Americas' two largest economies. Her foreign minister, Luiz Alberto Figueiredo, said that the final decision would depend on the explanation offered by the United States government.

Ms Rousseff and her senior advisors are considering passing a law stripping its licence to operate in Brazil from any company that co-operates with American snooping. Other possibilities are to construct underwater cables linking it to Europe and Africa to carry internet traffic currently routed through the United States, and to develop a national e-mail system that could replace Gmail, Hotmail and so on, which would not have to comply with American government orders to hand over data. Trade may also be affected. Brazil is in the market for fighter jets and the row has hit the chances of the American contender, Boeing, in the battle to win the order, which is worth more than $4 billion.

Correction: We originally said Mr Greenwald was British. He is, in fact, an American working for the Guardian, a British newspaper.