简体   繁体   English

PHP:如何区分加密和未加密的电子邮件?

[英]PHP: How to distinguish between encrypted and unencrypted email?

I want to create a new email account which only receives encrypted email. 我想创建一个仅接收加密电子邮件的新电子邮件帐户。 Unfortunately, I cannot modify the mail server configuration so I considered checking incoming email every 2 minutes with a cronjob and automatically rejecting those messages which are not encrypted. 不幸的是,我无法修改邮件服务器的配置,因此我考虑使用cronjob每2分钟检查一次传入的电子邮件,并自动拒绝那些未加密的邮件。

So far I did this: 到目前为止,我做到了:

$body = imap_body($mbox, $i);
if (substr($body,0,27) == "-----BEGIN PGP MESSAGE-----")
    $encrypted = true;
else
    $encrypted = false;

Works, but I'm pretty sure I don't capture all encrypted email. 可以,但是我敢肯定我不会捕获所有加密的电子邮件。 I didn't find a unique option in the header which would tell me that a message is encrypted. 我没有在标头中找到一个唯一的选项,该选项可以告诉我消息是加密的。 Enigmail left a message though: Enigmail留下了一条消息:

X-Enigmail-Version: 1.5.1

This, however, does not help me in any way. 但是,这对我没有任何帮助。 Is it enough to just grep for the BEGIN PGP MESSAGE string as I did above? 像我上面所做的那样,仅grep输入BEGIN PGP MESSAGE字符串就足够了吗?

As a student of computational linguistics my first idea was to try it statistically: 作为计算语言学的学生,我的第一个想法是从统计学角度进行尝试:

As far as I know encrypted messages do not contain spaces. 据我所知,加密的消息不包含空格。 So you could tokenize the email body into words, and calculate the average length of the words. 因此,您可以将电子邮件正文标记为单词,然后计算单词的平均长度。 Try this on some other mails or texts and see how the average length differs. 在其他一些邮件或文本上尝试一下,看看平均长度有何不同。

It may be a bit extravagant, but is more effective than looking for a substring: for example someone may send a webpage or text dealing with encryption or the latest NSA leaks ;-) 它可能有点奢侈,但是比寻找子字符串更有效:例如,某人可能发送处理加密或最新NSA泄漏的网页或文本;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM