osTicket/osTicket-1.7 — pull request #444 by lukakama (2013-01-10 21:10:11+00:00)
Title: ﻿Added support to In-Reply-To and References headers for sent and received ticket email replies.

Actual changes:
* For every "ticket reply alert" sent to an user:
* It is saved the email info and messageId, linking it to the originating support ticket thread
* Are added, to the sent email, In-Reply-To and Refecerences headers, both set to the messageId of the latest email received from the user (if available)
* For every incoming email, In-Reply-To and Refecerences headers are used with the sender email to lookup the messageId inside the email info table. If one is found, it is used as ticket where to append the reply, otherwise the standard subject ticket id lookup is performend.

It seems to work nicely, and allows to omit the ticket ID from the mail subject inside email support replies (as the subject alteration break gmail email threading).

I tested it with IMAP access, so I don't know if it works correctly with POP3.

Some things to review:
* I don't know if it is correct to use the "References" header for the lookup, because it seems that it can have multiple message ids inside it. Maybe it is to split-up in order to lookup each id one at time.
* Actually, I converted the email headers sent to the user to the text saved inside the "email info" table with a print_f function. I'm pretty sure that it needs to be improved to match the format of headers saved for incoming email :)