A federal judge in Philadelphia denied a second bail request Wednesday from an Afghan doctor arrested last week on immigration fraud charges and accused by the government of passing coded messages for a group with terrorist ties.

U.S. District Judge Stuart Dalzell said he had "grave concerns" about the risk Hayatullah Dawari might pose to the community and the possibility that the 62-year-old could flee to his native country.

Dawari's lawyer, Nino Tinari, stressed that his client had not been formally charged with terrorist activity and contended that government lawyers were attempting to shoehorn those allegations into an immigration fraud case.

Dalzell, however, said even the underlying fraud charges were reason for worry.

"Mr. Tinari is correct that this is a fraud case," the judge said Wednesday. "But it is a fraud case in a context - a context that offers grave concerns."

Federal prosecutors allege that Dawari lied on his application for U.S. citizenship about his long-standing ties to Hezb-e-Islami Gulbuddin, a group with ties to al-Qaeda that has claimed responsibility for attacks on American forces in Afghanistan. Its founder, Gulbuddin Hekmatyar, has been designated a "global terrorist" by the Treasury Department.

Investigators monitoring phone traffic among group members uncovered that Dawari still maintained contact with some of the group's associates in the United States and in Pakistan - most recently last year in a conversation with a Pakistani associate about a shipment of books coming to Dawari's Crescentville apartment, Assistant U.S. Attorney Jennifer Arbittier Williams said.

FBI agents raided the home in January, seized the package, and later found what prosecutors have described as a "coded message that appears to order some urgent action" glued between two pages of a religious tract.

"That is not the way that normal people have legitimate conversations," Williams said.

She has declined to describe what the message said, citing national security concerns. Instead, she provided short snippets in court. "Please, use the sentence number [#] for the time being," one read, according to a government motion that did not include the number mentioned in the cipher.

Tinari described those vague excerpts as "innocuous" and maintained that the government itself doesn't fully understand what the messages mean.

"They have not yet decoded the entire message to show whether there's anything inflammatory or that poses a danger to this country," he said.

Dawari had worked as a doctor in his home country, cooperating with International Red Cross efforts as part of American military operations in Afghanistan, before moving to Philadelphia in 2008. Since his arrival here, he has become an active member of his mosque and a legal permanent resident and was seeking citizenship when he was detained by U.S. immigration authorities on separate charges.

In that case, authorities allege, Dawari failed to disclose an arrest in Russia on his residency application. Tinari said Wednesday that his client had been detained by Soviet troops while working with the Afghan mujahideen and a coalition of Western countries to end Soviet occupation of the country in the late 1980s.

"He was detained, as all other lawyers and doctors were detained by the Soviets at the time," Tinari said. "It's a misnomer to suggest he was arrested and convicted of a crime."

Dawari's immigration case is pending. He is scheduled for trial on the immigration fraud charges tied to Hezb-e-Islami next month.