Correctional officer Rigoberto Sanchez during a postponed arraignment on July 3 on charges of murder and attempted murder. An attorney tries to block him using a file folder.

An unregistered, illegally modified AR-15 rifle was found inside an apartment where a Tehachapi correctional officer was shot dead in late May, allegedly by another correctional officer who the victim had taunted about his affair with the shooter’s wife, sources with knowledge of the case said Tuesday.

Investigators found a second weapon in the apartment as well — a handgun legally owned by shooting victim Edwin Lima, the sources said.

Sources also said Lima, 31, left repeated phone messages ridiculing the accused shooter, Rigoberto Sanchez, about the affair.

Sources close to the case spoke on the condition of anonymity due to its sensitive and ongoing nature.

Sanchez, 39, is charged with murder in Lima’s shooting death the night of May 28 at the apartment of Sanchez’s estranged wife. Police said in an arrest affidavit that Sanchez stood by a window and fired 20 rounds into the bedroom of the wife’s apartment on Valleyview Drive in Bakersfield, striking Lima 10 times.

The shooting happened after Sanchez argued on the phone with his wife and Lima that evening, the affidavit said. All three worked at the California Correctional Institution in Tehachapi.

The wife, Sandra Sanchez, told investigators she grabbed a handgun from Lima’s holster after the shooting, thinking her husband might still be outside, according to sources. She said she racked a round into the chamber and believes she may have inadvertently fired a round.

Bullets of different caliber were found at the scene, sources said.

According to sources, Lima had left multiple messages for Rigoberto Sanchez taunting him about the ongoing affair.

In one voice message, sources said, Lima asked, “You want to see the video of me (expletive) your wife? It’s pretty good.”

And in another message, Lima thanked Sanchez for a recent child support payment made to Sandra Sanchez. He said they used the money to go on a cruise together, sources said.

Before he left on the cruise, Lima told his own wife he was leaving to train in the mountains for his prison job and would have no cellphone service, sources said.

Sanchez was taken into custody in Mexico on June 21. He was transported to Yuma, Ariz., before being extradited back to Kern, police said.

In addition to charges related to the shooting, Sanchez faces two first-degree burglary charges apparently stemming from incidents at his wife’ s apartment on March 9 and May 27.

Sanchez is next set to appear in court July 20.