PHP 中的电子邮件、消息线程、正则表达式可能需要

发布于 2024-12-14 03:12:34 字数 909 浏览 8 评论 0原文

我正在研究记录发送到特定地址的电子邮件的东西。我有一个 PHP 脚本,可以将信息放入 MySql 中,该脚本运行良好。

我需要能够基于类似于 Gmail 的“对话”对消息进行分组,并且已经对此进行了一些阅读。这不需要是完美的,因为消息在显示在网站上之前将被手动批准,然后可以纠正任何错误。我只是想让工作量尽可能减少,以便将新电子邮件链接到原始电子邮件应该自动完成。

我的理解是,In-Reply-To 标头可以识别原始消息,但其使用并不标准。

我在另一页上找到了这一点:

The most common forms of In-Reply-To seemed to be:

31%     NAME's message of TIME <ID@HOST>
22%     <ID@HOST>
9%      <ID@HOST> from NAME at "TIME"
8%      USER's message of TIME <ID@HOST>
7%      USER's message of TIME
6%      Your message of "TIME"
17%     hundreds of other variants (average 0.4% each?)

但是,这似乎表明假设如果有 In-Reply-To 字段,则其中找到的第一个 <> 括起来的文本并不是没有道理的是父消息的消息 ID。

那么,获得该值的最简单方法是什么?是否有一个正则表达式可以让我抓取 <> 内的任何内容(如果可用)? (根据我发现的帖子,这应该是 <> 中的第一个值吗?)

感谢您提供的任何帮助。

I'm working on something that logs e-mail messages sent to a certain address. I have a PHP script that puts the info into MySql, which is working fine.

I need to be able to group messages based on the 'conversation' similar to Gmail, and have already read up on this a bit. This doesn't need to be perfect because messages will be manually approved before being shown on the website, and any errors can be corrected then. I just want to make it the least amount of work as possible so that linking a new e-mail to the original should be done automatically.

My understanding is that the In-Reply-To header can identify the original message, but that its use is not standard.

I found this on another page:

The most common forms of In-Reply-To seemed to be:

31%     NAME's message of TIME <ID@HOST>
22%     <ID@HOST>
9%      <ID@HOST> from NAME at "TIME"
8%      USER's message of TIME <ID@HOST>
7%      USER's message of TIME
6%      Your message of "TIME"
17%     hundreds of other variants (average 0.4% each?)

However, this seems to indicate that it's not unreasonable to assume that, if there is an In-Reply-To field, then the first <> bracketed text found therein is the Message-ID of the parent message.

So, what is the easiest way to get that value? Is there a regular expression that would let me grab whatever is inside the < and > if is is available? (According to the post I found, should this be the FIRST value inside a < and > ?)

Thanks for any help you can provide.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧瑾黎汐 2024-12-21 03:12:34

您应该能够抓住反向引用中的第一个匹配项:

<(.+)>

说明:

//    Match the character “<” literally «<»
//    Match the regular expression below and capture its match into backreference number 1 «(.+)»
//       Match any single character that is not a line break character «.+»
//          Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
//    Match the character “>” literally «>»

根据 此文档 您可以编写如下内容来完成您想做的事情(如果这不是有效的 php,请原谅我):

$string ='blah blah blah <ID@HOST>';
preg_match('/<(.+)>/', $string, $match);
print_r($match);

You should be able to just grab the first match in the back-reference:

<(.+)>

Explanation:

//    Match the character “<” literally «<»
//    Match the regular expression below and capture its match into backreference number 1 «(.+)»
//       Match any single character that is not a line break character «.+»
//          Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
//    Match the character “>” literally «>»

According to this documentation you could write something like as follows to accomplish what you want to do (forgive me if this is not valid php):

$string ='blah blah blah <ID@HOST>';
preg_match('/<(.+)>/', $string, $match);
print_r($match);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文