解析电子邮件“已接收:"标头 [英] Parsing email "Received:" headers

查看:71
本文介绍了解析电子邮件“已接收:"标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要根据RFC 5321解析 Received:电子邮件标题,我们需要提取邮件经过的域\ IP.此外,我们需要确定IP是否是内部IP.已经有一个可以提供帮助的库了,尤其是在C \ C ++中.

We need to parse Received: email headers according to RFC 5321. We need to extract domain\IPs through which the mail has traversed.Also, we need to figure if an IP is an internal IP. Is there already a library which can help out , especially in C\C++.

例如,

Received: from server.mymailhost.com (mail.mymailhost.com [126.43.75.123])
    by pilot01.cl.msu.edu (8.10.2/8.10.2) with ESMTP id NAA23597;
    Fri, 12 Jul 2002 16:11:20 -0400 (EDT)

我们需要提取"by"服务器.

We need to extract the "by" server.

谢谢

推荐答案

已接收"行使用的格式是在RFC 2821中定义的,而regex无法对其进行解析.

The format used by 'Received' lines is defined in RFC 2821, and regex can't parse it.

(您仍然可以尝试,对于由已知软件生成的有限头文件,您可能会成功,但是当您将其附加到现实邮件中发现的一系列奇怪的东西上时,它将失败.)

(You can try anyway, and for a limited subset of headers produced by known software you might succeed, but when you attach this to the range of strange stuff found in real-world mail it will fail.)

使用现有的RFC 2821解析器,您应该可以,但否则应该会遇到故障,并编写软件来解决该问题.不要在其周围建立任何重要的基础,例如安全系统.

Use an existing RFC 2821 parser and you should be OK, but otherwise you should expect failure, and write the software to cope with it. Don't base anything important like a security system around it.

我们需要提取"by"服务器.

We need to extract the "by" server.

'from'更可能被使用."by"行中给出的主机名与主机本身一样,因此不能保证它将是可公开解析的FQDN.当然,您不会在那里获得有效的(TCP-Info).

'from' is more likely to be of use. The hostname given in a 'by' line is as seen by the host itself, so there is no guarantee it will be a publically resolvable FQDN. And of course you don't tend to get valid (TCP-Info) there.

这篇关于解析电子邮件“已接收:"标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆