DETROIT, MI -- A lawyer for a man accused of fantasizing about attacking a Detroit church has asked a judge to order the release of all communications between Khalil Abu-Rayyan and undercover FBI agents.

Abu-Rayyan of Dearborn Heights had been under federal surveillance from May 2015 until his arrest last month, and his lawyer claims he was manipulated by an FBI agent who posed as a love interest and terrorist sympathizer.

Federal agents began watching the 21-year-old in May 2015 because of what investigators called "increasingly violent threats he has made to others about committing acts of terror and martyrdom -- including brutal acts against police officers, churchgoers and others -- on behalf of the foreign terrorist organization Islamic State of Iraq and Levant."

An undercover agent began communicating with him after he bought a .22-caliber revolver on Oct. 5, 2015 in Dearborn Heights, and was arrested two days later when police found the gun and marijuana in his car during a Dearborn traffic stop.

Abu-Rayyan has been charged in federal court with making a false statement to acquire a firearm, and possession of a firearm by a prohibited person, but a grand jury in February declined to issue any terrorism-related charges.

"The government and its agencies have publicly disclosed terrorism allegations against Mr. Rayyan, a U.S. citizen, despite no formal charges and have portrayed Mr. Rayyan as a mentally ill terrorist with excruciating detail," argued defense attorney Todd Shanker of the Federal Defenders Office in a Tuesday court filing.

"In particular, in the complaint and at the detention hearing, the government emphasized inflammatory social media postings and communications related to ISIL. Counsel's investigation has revealed, however, that the FBI used extraordinary tactics to manipulate Mr. Rayyan during its surveillance of him from May 2015 to February 2016."

Federal prosecutor's have provided the defense attorney redacted content of some of the conversations between Mr. Rayyan and an undercover FBI agent, but Shanker claims that "a large amount of information remains undisclosed."

Prosecutors provided messages going back to December 23, 2015, exchanged through the encrypted text messaging application Surespot.

"But Mr. Rayyan's communications with the undercover FBI employee pre-dated December 23, 2015, and were not limited to Surespot. During this period of surveillance, Mr. Rayyan may have also communicated with the undercover FBI employee using his personal telephone accounts with AT&T and Metro PCS, and the electronic-messaging services on websites Skype, Facebook, Twitter, and Telegram."

Shanker also points out that some screenshot images of text message threads provided to him omitted certain messages that showed up in duplicate images of the same thread, raising "serious concerns about the integrity of the other discovery."

"The government has indicated that it will turn over the unredacted contents of these communications only if the defense agrees to conduct this portion of the case under protective order," Shanker claimed.

"Additionally, the Government has stated repeatedly to defense counsel that the undisclosed discovery (as opposed to the unredacted discovery) is not being released from the case agents to the prosecutor himself, yet another important concern that may warrant a court order."

A message seeking comment on the claim that the FBI isn't releasing pieces of evidence to prosecutors was left with the U.S. Attorney's office.

Abu-Rayyan's lawyer is also asking the court to reconsider an order that he be kept in custody until trial, citing a report from a psychologist who found that he pose a "very low" level of dangerousness, and suffered from dependent personality disorder.

"Behavior with FBI undercover agent the result of deep longings for female attention in a very shy and awkward young man," wrote Farmington Hills psychologist Lyle Danuloff in a letter filed by the defense. "His verbalization was the result of an effort to keep the attention with hopes of a future. The were not the result of radicalization or representative of terrorist intentions."

Some of the text messages that prosecutors have provided to the defense seem to show Abu-Rayyan tried to discourage his fictional love interest's radical views.

"Your [sic] young and confused," he responded in one Jan. 25 message after the undercover agent told him that if "dawla asks for my life I would give it up in a heart beat."

("Dawla" is the Arabic word for state, and appears in the message to refer to the terrorist group known as the Islamic State.)

But he didn't always show a lack of enthusiasm for extremism.

Abu-Rayyan does not dispute that in July 2015, he expressed enthusiasm via Twitter for extremely violent footage of a killing spree perpetrated by ISIS, writing that the images "made my day," and re-posting the video.

Prosecutors have read in court a number of intensely violent descriptions of crimes Abu-Rayyan fantasized about in texts to the agent, including an expressed desire to "shoot up" a large Detroit church with an assault rifle.

"I would have killed every last one of them, especially the women and children," he wrote. "... I would have shown no mercy. It would have been a blood bath."

He told the agent he didn't carry out the attack because his father found and confiscated his rifle.

Shanker has said Abu-Rayyan's father denied ever coming across a rifle, and investigators never found an assault rifle in a search of the family's property.

The FBI agent, posing as a 19-year-old Detroit woman from Iraq who sympathized with the Islamic State after having relatives killed by Shia militias, feigned romantic interest in Abu-Rayyan, who responded with "whatever she wanted to hear," Shanker has claimed.

But the FBI documented disturbing social media postings from Abu-Rayyan long before an undercover agent became involved, prosecutors argued.

Prosecutors have also revealed communications with the undercover agent that indicated Abu-Rayyan is mentally ill.

"Shaytan (Satan) is talking to me," Abu-Rayyan told the FBI agent in a text message.

Shanker has said that Abu-Rayyan has suffered from depression and has been mentally disturbed, but is capable of understanding the court proceedings and assisting in his defense.

He claimed Abu-Rayyan's texts to the agent were attempts to impress a person he viewed as a love interest, to whom he expressed suicidal thoughts, and, on multiple occasions, proposed marriage.

On one occasion in December, communication between the two stopped, until the agent contacted Abu-Rayyan in a Twitter message containing an image of a broken heart and the question: "Why are you abandoning me?"

U.S. Magistrate Judge Steven Whalen in February ordered Abu-Rayyan held without bond, pending trial, pointing out that his disturbing Twitter activity pre-dated his contact with the FBI, and finding that he could not reasonably ensure the safety of the community if Abu-Rayyan was released.

Card