A jury has ordered Apple to pay $626 million in damages after finding that iMessage, FaceTime and other Apple software infringed on another company's patents.

In a case that has been bouncing around the court system since 2012, VirnetX accused Apple of violating four of its patents, which mostly involve methods for real-time communications over the Internet.

VirnetX (VHC) has been labeled a "patent troll" because it is a patent holding company and sells just a single product. It has just 14 employees and rents office space for $5,000 a month. The company makes money by licensing patents to other firms -- and by suing businesses that it believes has infringed on its intellectual property.

VirnetX owns about 80 patents, including the four that were the basis of the Apple suit. VirnetX had previously purchased them from a company called Science Applications International Corporation.

In 2012, a jury had found Apple guilty of violating the same patents, and ordered the company to pay VirnetX $368 million. Apple appealed and won on a technicality after VirnetX failed to prove that consumers were buying iPads and other gadgets because of the software that violated VirnetX's patents.

Related: Apple's new $20 billion business

The appeals court vacated the damages, and sent the case back down to the East Texas District Court for a retrial.

But Apple (AAPL) didn't exactly get what it had hoped for. The new jury found Wednesday that Apple owed even more to VirnetX because it "willfully" violated the company's patents.

Shares of VirnetX doubled in premarket trading.

Apple has since revised its iMessage, FaceTime and VPN software so that it avoids anything covered by VirnetX's patents.

VirnetX has had mixed success in its past patent cases. It settled out of court with Microsoft for $200 million in 2010 and filed another lawsuit against the company in 2015. But it lost a patent case it brought against Cisco last year.