Question

I'm working on email messaging / tickets system.

Logic:

  1. Client starts new ticket on website, which is stored in database
  2. I'm getting email about new ticket in my inbox (generated by website, with unique ID in subject line)
  3. Replying email (reply-to email address e.g. tickets@example.com)
  4. PHP cron script reads inbox, getting all messages, storing them to database and generating email to client.
  5. Client replies to email (reply-to email address - tickets@example.com with ID in subject line)

Question:

How I can read where is new reply text and old one from email? Email with reply example:

Envelope-to: tickets@example.com
From: client@example.com
To: tickets@example.com
Subject: Re: New Ticket: "Project #1" (ID: 15)
Message-ID: <70c4e4c182e6eb10c0e45feefa4ce9cg@example.com>

This is reply to message.

On 2014-05-13 09:04, Client wrote:
> This is text
> 
>  ----
>  Best Regards,
>  Client

I need to have only latest reply. Client can write reply on bottom or on top (anywhere to be honest), with any mail client, and I bet - a lot of mail clients have different formatting..

Any suggestions?

Was it helpful?

Solution

If I would need to solve this question, I would be using some kind of 'diff' system. I don't' know if that exists for PHP, but I'm confident it does.

So then more technical, if you have a way to diff the mails. I would take the original mail without the header (let's call it mail A), and also the new mail without the header (mail B). Then it's as easy as comparing mail A with B and see what the difference is. The lines that were added, are the response of the user.

Some things you will have to look for yourself, because I don't know an answer for them at this moment:

  • What if the user doesn't send the original message? You could for example only use the lines that were added from your diff, not those which were deleted.
  • What if the user changes something inline in your response? I have no idea how to solve this.

My solution would actually be to don't give the users that much freedom. Just prepare a place where the users should write their message. Something like: "Write your message between the following lines <line> <line>", or "<line>Write your message above the previous line". Then you know where to look for the text.

The more freedom you give, the more difficult it becomes for you. You can start with an easy system, and gradually improve the intelligence of the system. That's how I start most of the time: start from something simple and increase the difficulty gradually.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top