I think its the USA PATRIOT Act that gives the right to do this kind of data mining. This actually amended a handful of other Acts such as -
- Wiretap Statute (Title III):
- Electronic Communications Privacy Act
- Computer Fraud and Abuse Act
- Foreign Intelligence Surveillance Act
- Family Education Rights and Privacy Act
- Pen Register and Trap and Trace Statute
- Money Laundering Act
- Immigration and Nationality Act
- Money Laundering Control Act
- Bank Secrecy Act
- Right to Financial Privacy Act
- Fair Credit Reporting Act
This is as per USA PATRIOT Act as reflected upon in the article - The USA PATRIOT Act