PORTLAND (AP) — A federal judge has affirmed the legality of the U.S. government’s bulk collection of phone and email data from foreign nationals living outside the country — including their contact with U.S. citizens — in denying a man’s motion to dismiss his terrorism conviction.

It was the first legal challenge to the government’s bulk data-collection program of non-U.S. citizens living overseas after revelations about massive, warrantless surveillance were made public by former National Security Agency employee Edward Snowden. The program also sweeps up information about U.S. citizens who have contact with overseas suspects. This type of surveillance played a key role in this case.