email: Improve user identification from headers

Previously, the code would scan the email headers until it found a positive
match from any of the email headers scanned. Additionally, it would attempt
to find the user from the tagged email references header. However, this
algorithm assumed that the references header was constant and predictable in
its ordering. Recent tests with Gmail prove otherwise in some tests.

This patch changes the system so that only the tagged reference header is
included in the References header, and it will scan all items in a header
(namely the References header) until both the thread and a user are
identified. If a user can be identified, the thread and user are returned.
Otherwise, the first thread hit is returned.
Merge pull request #1263 from greezybacon/issue/email-references-user

email: Improve user identification from headers

Reviewed-By: Peter Rotich <peter@osticket.com>