我学习Perl并为家人做一个自制项目(订阅项目)。使用Net :: POP3的Perl应用程序连接到我的邮箱并将我的所有电子邮件保存到文件(Mail.txt)。当我打开这个文件时,我看到了很多垃圾,如下所示。我能做些什么来消除这个?感谢。
Return-Path: Received: from [unix socket] by embro.tpn.terra.com (LMTP); Sun, 11 Oct 2009 04:09:50 +0000 (UTC) X-Abaca-Spam: 153 X-Terra-Karma: -2% X-Terra-Hash: 2c7d32f717e807b11af5c0871edb9e93 Received-SPF: pass (embro.tpn.terra.com: domain of linuxquestions.org designates 208.101.3.244 as permitted sender) client-ip=208.101.3.244; envelope-from=forum@linuxquestions.org; helo=sql02.linuxquestions.org; Received: from sql02.linuxquestions.org (smtp.linuxquestions.org [208.101.3.244]) by embro.tpn.terra.com (Postfix) with ESMTP id 14EA1580000A2 for ; Sun, 11 Oct 2009 04:09:49 +0000 (UTC) Received: from web02.linuxquestions.org (web02-be.linuxquestions.org [10.13.156.4]) by sql02.linuxquestions.org (8.13.8/8.13.8) with ESMTP id n9B49mXe005694 for ; Sun, 11 Oct 2009 00:09:48 -0400 DomainKey-Signature: a=rsa-sha1; s=smtp; d=linuxquestions.org; c=simple; q=dns; b=Le/RccpkHMfH426hLwlLkIbCujr0LiWKM32ryuZ1fWwYU6VjCTocd30N/JAg+w77d 54VJkNnpA18iQxJ/yfKyQ== Received: from web02.linuxquestions.org (localhost.localdomain [127.0.0.1]) by web02.linuxquestions.org (8.13.8/8.13.8) with ESMTP id n9B49m2f027957 for ; Sun, 11 Oct 2009 00:09:48 -0400 Received: (from nobody@localhost) by web02.linuxquestions.org (8.13.8/8.13.8/Submit) id n9B49mNn027956; Sun, 11 Oct 2009 00:09:48 -0400 Date: Sun, 11 Oct 2009 00:09:48 -0400 To: nathanpc@terra.com.br Subject: "What programs would you like to see ported to Linux?" update From: "LinuxQuestions.org" Auto-Submitted: auto-generated Message-ID: X-Priority: 3 X-Mailer: LQ Mailer Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Status: O Dear nathanpc,
答案 0 :(得分:5)
这不是垃圾。这是电子邮件标题。例如,使用Mail :: Message来解析它。像这样:
my $msg_obj = Mail::Message->read($rawdata); my $body = $msg_obj->body;
答案 1 :(得分:1)
你知道,我确实建议Mail::POP3Client抽象出详细信息:
Body( MESSAGE_NUMBER )
获取指定消息的正文,可以是行数组,也可以是字符串,具体取决于上下文。
BodyToFile( FILE_HANDLE, MESSAGE_NUMBER )
获取指定消息的正文并将其写入给定的文件句柄。
答案 2 :(得分:0)
电子邮件标题包含直到第一个完全空白行的所有文本。所以,如果你确实想要扔掉它们(而不是像前面的例子那样用一个好的模块来解析它们),那就扔掉所有东西,包括第一个空行。
如果您正在查看包含多条消息的mbox格式邮箱文件,则可以通过查找以“From”五个字符开头的行来标识下一条消息标题的开头(请注意尾随空格 - 此是它与“From:”标题区别开来的。