duai1683
2017-03-13 05:26 浏览 43
已采纳

有没有办法用php一致地阅读电子邮件正文的部分(答复)

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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答 默认 最新

  • 已采纳
    douran7929 douran7929 2017-03-13 05:50

    Short answer - no.

    Each email client and person handles and "thinks" about replies differently.

    For example, some people "top post", others "bottom post" or "inline reply" with the original.

    Then you have others that remove the entire original post.

    You also have email clients that use a '>' for the original, some that use a ':' or even a '|' - anything is possible.

    You might be able to find some "rules" that would suit most but you will not suit all replies.

    I guess you could run a diff against the original, but then you have changed formatting as well as email clients that might have converted the original to HTML or from HTML to plain text. So that ain't going to work cleanly either.

    One option would be to auto-insert the entire reply - as is - and then alert an Admin person that an "auto reply" had been added to the ticket system. I find a human would be able to clean up the reply very quick (if needed) or simply leave it "as is" for tracking purposes.

    The convenience of the "auto reply" or "auto insert" would be enough for most people.

    Hard drive space is cheap, don't sweat the little things. You would need to build some pretty complex rules that would always be changing. That would be a nightmare to maintain.

    点赞 评论 复制链接分享

相关推荐