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 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式