Daniel James (left) translated for Gen David Richards
An Army interpreter serving in Afghanistan, described as a "Walter Mitty"-style fantasist, became an agent for Iran, a court has been told.
Tehran-born Daniel James, of Brighton, translated for Gen David Richards, the former UK commander in Afghanistan.
It is alleged he sent coded messages to an Iranian military attache in Kabul telling him "I am at your service".
Mr James, 45, denies two charges under the Official Secrets Act and wilful misconduct in public office.
Mark Dennis QC, prosecuting, said Mr James' role, working for the general, put him in an "unique position".
He said Mr James thought he had been snubbed for promotion and had been the victim of racism.
"During the latter part of 2006, the defendant's loyalty to this country wavered and his loyalties turned to Iran, the country of his birth.
"He turned his back on those with whom he was serving in Afghanistan and sought to become an agent for a foreign power," said Mr Dennis.
He said Mr James was attempting to provide information to insurgents fighting coalition forces.
He was arrested in December 2006, just two months after he had made contact with with Colonel Mohammad Hossein Heydari, an Iranian military assistant based at Tehran's embassy in Kabul.
Mr Dennis said: "He has been described as an extrovert, someone with somewhat grandiose ideas about himself and his own self-importance - something of a Walter Mitty character who would no doubt find his new clandestine role something exciting and special.
"Fortunately, his activities were nipped in the bud by the early discovery of what he was doing."
Mr James worked as a casino croupier, in nightclub security and as a dance instructor before joining the Territorial Army and being sent to Afghanistan in March 2006.
Mr Dennis said: "He has been described as a very flamboyant person, outgoing, extrovert but also as something of an oddball in many ways."
The court heard it was not clear whether Mr James had been accepted as an agent by Heydari or was trying to do so by sending material as samples of what he could potentially provide.
The information in the e-mails was "comparatively limited and of a somewhat imprecise and general nature", Mr Dennis said.
"The concern is not so much the actual damage done by the known disclosure of information, but in the potential damage that could have occurred if his activities had not been curtailed by his early detection and arrest," he said.
The short message was "plainly in coded form", and included six points of information for Heydari, jurors were told.
One read: "I have taken seven more pictures from those whose job is black."
Another stated: "You remember that I had said someone's sister is in the parliament, I still don't have the address, but someone who knows her for the past 4 years and gives her messages, I have (his) full details."
In a further e-mail exchange he apparently referred to the need for coded communication, the court heard.
The message, on 15 November, read: "If one day I write to you and say weather is very cold, I mean time does not allow me to be in contact with you at those times, til such time that is safe."
When he was arrested, Mr James was found to have a USB device with two "Nato Confidential" documents stored on it.
The court heard the documents, known as Situation Reports, provided a daily update on military operations in Afghanistan.
Police found a computer disc containing seven photographs of the "highly sensitive" Predator unmanned spy plane in his room at the base in Kabul, - apparently taken unofficially in a restricted area of Kandahar air base.
Mr James made no comment when told he was under arrest on suspicion of espionage, but later told a police officer: "The ADC might have set me up, he hates me... Captain Simon Briggs."
He denies two charges under the Secrets Act of communicating information useful to an enemy and a second count of collecting such information on a USB memory stick.