Resolve thread IDs using recursive DB lookups

This fixes threading problems caused by UAs/services
which cut off / strip the "References" header.