Board Thread:Lore Discussion/@comment-26213507-20150928140042/@comment-1600847-20151006224545

"...  and then allowed to escape. After the war, contact was established and he has proven his worth as an asset. T he so-called  Markarth Incident  was particularly valuable from the point of view of our strategic goals in  Skyrim, although it resulted in Ulfric becoming generally uncooperative to direct contact."

That would mean he was working for them, but had a change of heart after the Markarth Incident and stopped working for the Thalmor after that point.