我想用PHP制作pop3客户端。 当我得到所有消息(正文+标题)时,我有一个问题,我想分割标题和正文。通常在标题之后有一个空行,然后有一个消息体。我意识到在我的邮箱中的一封电子邮件中有一个空白行标题:
Delivered-To: asd@gmail.com
Received: by 10.239.164.198 with SMTP id u6cs311361hbd;
Thu, 25 Feb 2010 08:11:16 -0800 (PST)
Received: by 10.223.6.27 with SMTP id 27mr1385919fax.31.1267114275670;
Thu, 25 Feb 2010 08:11:15 -0800 (PST)
Return-Path: <elsa@homelidays.emv2.net>
Received: from emailer112-138.emv2.net (emailer112-138.emv2.net [81.92.112.138])
by mx.google.com with ESMTP id 24si15703136fxm.76.2010.02.25.08.11.12;
Thu, 25 Feb 2010 08:11:14 -0800 (PST)
Received-SPF: pass (google.com: domain of elsa@homelidays.emv2.net designates 81.92.112.138 as permitted sender) client-ip=81.92.112.138;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of elsa@homelidays.emv2.net designates 81.92.112.138 as permitted sender) smtp.mail=elsa@homelidays.emv2.net; dkim=pass (test mode) header.i=elsa@emv2.net
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; s=emv; d=emv2.net;
h=Date:From:Reply-To:To:Message-ID:Subject:MIME-Version:Content-Type:List-Unsubscribe; i=elsa@homelidays.emv2.net;
bh=6AAaS7MBmDZ4twficXpZISS03+k=;
b=ShFzHF3jozT6joZ/O5JvKS6ECNwXfT+4XdWv+tgLCzsGFMiesKF4PxtCcrw/SnR9YyBa9I8BOUWj
MjyJqGFPaA==
DomainKey-Signature: a=rsa-sha1; c=nofws; q=dns; s=emv; d=emv2.net;
b=TyNSOdwDU8IJW1e4Iq6/TLj4QjyO/Leru+VFXAQSmJ+nVwdpHSIk7N5myHNNajhOu5yG7uQjAdoT
I6QsJNDEjw==;
Received: by emailer112-138.emv2.net id hgqgi40hu6oc for <asd@gmail.com>; Thu, 25 Feb 2010 17:10:21 +0100 (envelope-from <elsa@homelidays.emv2.net>)
Return-Path: elsa@homelidays.emv2.net
Date: Thu, 25 Feb 2010 17:10:21 +0100 (CET)
From: "Homelidays.co.uk" <elsa@homelidays.emv2.net>
Reply-To: <renter-service@homelidays.com>
To: <asd@gmail.com>
Message-ID: <34216955106.7026379.1267114221347@schr1>
Subject: Spring sunshine & Easter escapes
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=702637934216955106
X-EMV-Platform: ccc.campaigncommander.com$
X-EMV-CampagneId: 7026379$
X-EMV-MemberId: 34216955106$
List-Unsubscribe: http://trc1.emv2.com/HD?a=DNX7Cq7R8H0N8SA9MKIk7THnGHxKDTNjXw76
--702637934216955106
Content-Type: text/plain; charset=iso-8859-15
Content-Transfer-Encoding: 8bit
If you cannot see this message, please click here http://trc1.emv2.com/HM?a=DNX7Cq7R8H0N8SA9MKIk7THnGHxKDTNIDA6e
--702637934216955106
Content-Type: text/html; charset=iso-8859-15
Content-Transfer-Encoding: 8bit
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table cellspacing="0" cellpadding="0" width="650" align="center">
<tr>
... and the rest of body...
如何将正文和标题分隔的消息与空白行分开?
答案 0 :(得分:1)
要解析邮件消息,首先必须找到标题结束的位置。这将在消息的第一个空白行中。
一旦找到,您可能需要解析消息本身。这样做的原因是您提供了一个多部分消息,它由......多个部分组成。每个部分都可以有自己的内容类型。这对于HTML电子邮件以及带附件的电子邮件来说很常见。
要了解如何解析多部分消息,您需要查找边界标识符。这在标题的末尾概述:
Content-Type: multipart/alternative; boundary=702637934216955106
只需在边界上拆分消息,然后分别处理每个部分。