donglu1472 2019-02-23 01:37
浏览 215

如何避免获取电子邮件内容分析详细信息并仅获取电子邮件中的邮件内容

I am writing a PHP script to get email piped to the script and save it to the database.. I have succeeded in get coming emails.. But i am still struggling with how to get rid of raw contents that comes with the email.. What technique can i use to get only the message either the text version or the html version This is the example of email i receive currently

Content preview:  Mine Mine [...]

 Content analysis details:   (-0.1 points, 5.0 required)

  pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_PASS               SPF: sender matches SPF record
  0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail provider
                             (techservice4real[at]gmail.com)
  0.0 HTML_MESSAGE           BODY: HTML included in message
 -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from author's
                             domain
  0.1 DKIM_SIGNED            Message has a DKIM or DK signature, not necessarily valid
 -0.1 DKIM_VALID             Message has at least one valid DKIM or DK signature
 -0.0 RCVD_IN_MSPIKE_H2      RBL: Average reputation (+2)
                             [209.85.222.182 listed in wl.mailspike.net]
X-Spam-Flag: NO

--000000000000c1a52105822cd389
Content-Type: text/plain; charset='UTF-8'

Mine

--000000000000c1a52105822cd389
Content-Type: text/html; charset='UTF-8'

<div dir='ltr'>Mine<br></div>

--000000000000c1a52105822cd389--

This is currently the code i am using to get the email

#!/usr/local/bin/php -q
<?php 
require_once('inc/init.php');   
//chdir(dirname(__FILE__));
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);
// if(strlen($email)<1) {
//     die(); 
// }
// handle email
$lines = explode("
", $email);
// empty vars
$from = "";
$to="";
$subject = "";
$headers = "";
$message = "";
$bodyContent = "";
$myBody = "";
$splittingheaders = true;
for ($i=0; $i < count($lines); $i++) {
    if ($splittingheaders) {
        // this is a header
        $headers .= $lines[$i]."
";
        // look out for special headers
        if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
            $subject = $matches[1];
        }
        if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
            $from = $matches[1];
        }
        if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
            $to = $matches[1];
        }
    } else {
        // not a header, but message
        $message .= $lines[$i]."
";
    }
    if (trim($lines[$i])=="") {
        // empty line, header section has ended
        $splittingheaders = false;
    }
}

$data = explode("
", $message);
mail("boomztechs@gmail.com", "You Have One new Email Piped", "A New Mail Message just Piped to you) ".$message);

Your response is highly appreciated thanks..

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料