A primary school deputy head teacher walked into a stranger's home and tried to rape her in cocaine-induced madness.

James Goulding, 54, had not slept for 48 hours and was 'foaming at the mouth' when he attacked the woman in her own bedroom.

The 31-year-old victim was saved by her bravery in fighting back, her screams which were heard by neighbours and the return of her partner who managed to drag Goulding away, St Albans crown court heard on Friday.

Prosecutor Sally Mealing-McLeod said the attempt rape happened at 11.30 in the morning on 7 April this year at the woman's home in Watford, Herts. "The defendant and the victim were not known to each other - they were complete strangers," she said.

The young mother's partner had left for work and she was wearing only her dressing gown in her bedroom, as she was about to shower. She heard the front door, which had not been locked, being opened.

"She thought it was her partner. When she called out his name there was no response. She looked out and saw a complete stranger at the top of the stairs. He had a sock on his hand - like a glove.

"The woman said: 'What do you want?' 'Get out of my house'

"As she said this the defendant put his finger to his lips and made a shush motion. He pushed her back into the bedroom and dragged at her dressing gown and tried to remove it.

"She shouted: 'Rape' and screamed repeatedly as he tried to get her on her back on the bed," said the prosecutor.

Bravely, the victim used her hands and feet in an attempt to get him off. Her arms were flailing around and although she punched him in the face as she failed to get him to stop.

Goudling's flies were undone and he was wearing no underwear.

The ordeal lasted for 5 minutes until her screams were heard by neighbours. They were at her front door as her partner returned. He went straight upstairs and tried to pull Goulding off. A mirror broke as he managed pushed him to the side of the room.

The prosecutor went on: "The defendant would not leave it. He kept trying to get back to her. It was a real struggle for the partner to get him out. He eventually got him out of the house. Mr Goulding fell down the stairs. The partner punched him a couple of times.

"Other neighbours assisted in restraining him until the police arrived. One noticed that the defendant's trousers were undone."

Goulding was in such a state that he had to be taken to hospital to be assessed. He was not fit to be interviewed until the next day because of the amount of drugs he had taken. At his home 3 grams of cocaine were seized.

In a prepared statement given to the police the next day he said: "I had a large quantity of cocaine and acted totally out of character. I am deeply sorry and remorseful and ashamed and apologise to the victim." He has now sent a letter of apology to his victim.

Bespectaled Goulding, a devout Roman Catholic, who lived alone in a flat in Oxhey Road, Watford pleaded guilty to the attempted rape of the woman. He was on bail for possession of cocaine at the time of the attempted rape.

He had graduated from Warwick University in English and Comparative Studies before working for the electricity board and a homeless charity. He had two drug convictions in the 1980s but after conquering a drug addiction he obtained a teaching certificate in 1995 and became a Deputy Head Teacher at a London Primary School.

At the time of the attempted rape he was not working due to sickness.

In an impact statement the victim said she was now terrified of going out and wanted to move home. She could not sleep in her bedroom and suffered nightmares.

Mustapha Hakme, defending, said Goulding was a "deeply religious man". He said he had remained free of drugs for 20 years but at the start of this year began taking 9 to 10 grams of cocaine a day. He said he was also abusing alcohol and taking heroin.

He said: "So intense was his addiction at the time he was permanently high. He had not slept for 48 hours and was experiencing a complete distortion of reality. He was a man possessed and was foaming at the mouth. He had lost self control."

A psychiatrist's report said that he had been under a "cocaine-induced psychosis."

Judge Marie Catterson told Goulding that his victim's "feelings of security in her own home have been destroyed."

She went on: "It is clear to me that on the day you were in the grip of cocaine.

"Cocaine abuse by you has had an absolutely disastrous consequences for the victim."

She said there was no option other than to impose an indefinite jail sentence for public protection. If she had not passed a sentence for public protection the judge said she would have jailed him for 7 years. The minimum term he must serve before he can apply for parole is 3 and a half years.

The effect of the sentence means that Goulding will not be released from prison until the parole board considers it is safe to free him. When he is released he must register as a sex offender for life.