I have a ticket system I am working on and I want to be able to have a user reply to an email sent from the ticket system. When the user replies I want to be able to get that reply and put it into my system as a comment for that ticket.
I have a script that already can connect to a mailbox, get the email and pull all the parts that I need (header, subject, body...) and take those parts and put them where I need too.
The problem is...
Ive been trying to use different methods for this with some of php's built in functions like imap_fetchbody
and imap_fetchstructure
but it seems to either not be consistent and/or actually be able to just pull the reply to an email and nothing else.
Some of the issues is when a user reply's to an email (depending on what provider they use) attach more info into the reply thus being part of the body and creating more confusion for my script.
One semi consistent thing I have seen in the html of the body is a tag of <div class="body">...</div>
. I have seen so far gmail and yahoo have this. I have no idea how consistent this is to rely on since I have no idea if it is a standard that I can expect from all email carriers or it's just a personal preference from them.
I also understand that I could try and clean up quoted text in the email body, but again its not consistent enough.
Also I know that I could add some text in the email to try and get the user to write text in between some lines so I can find the reply, but not all users will be that consistent.
My question would be
"is there a consistent way I can rely on to be able to pull the reply from the body of an email and ONLY the reply or are there to many "scenarios" that can happen that would make it difficult?" Is it even possible?