I need someone to parse incoming emails using Delphi and the Indy iMap components (which could be in Text or HTML format and may or nor have attachments, and save the content to a database.
We already have tested code to connect with email server (e.g. Google, Office365 or standard iMap) and physically receive the messages.
I now need this to be extended so that certain data from the message can be saved to a database (in this case MS SQL Express).
Content to be saved includes the basic email metadata, e.g. Sender, date, subject and the message content. If the message content is in text format we would like to convert it to HTML (e.g. page breaks etc) so that all records in the database for the content are stored in HTML.
Most of the incoming emails will be from existing customers, so it is necessary to lookup the customer from their email address and store the customerID with the email in the database. If they do not exist then a new contact should be created and the new contactID stored.
In all cases, the email may relate to an existing case in the database, so this should be looked-up based on email subject line (maybe containing the case ID) and if so, the caseID should be stored with the email in the DB. If not a new case should be created and its ID stored with the email in the DB.
When the email body is imported to the database we only want to save the current message. Any other threads that are included in the message must be removed as we don't want to store a whole lot of duplicated information in the database. HOWEVER, if there is information that is FORWARDED as part of the message body that should be retained. This is probably the only part of the task that is novel.
As you can tell, this is part of a bigger project. Ideally I would like all of this functionality to be in a separate unit that can be linked into the main program. The technology in use is Delphi XE4 (although exact version probably not important), Intaweb, Indy and IWBootstrap. Given that this functionality is mainly in the "back-end" of the program, a working knowledge of Delphi (pascal) and Indy email components would probably be sufficient to complete the task.
We have complete database design and some starter code available for your use.