Blank line in email's headers
I want to make pop3 client in PHP. I have a problem when I get all message (body + headers) I want to divide headers and body. Normally after headers there is a blank line and then there is a body of message. I realized that in one e-mail in my mailbox there are headers with a blank line:
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 b开发者_高级运维gcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table cellspacing="0" cellpadding="0" width="650" align="center">
<tr>
... and the rest of body...
How can I have body and headers separated messages with blank line inside?
For parsing a mail message, first you have to find where the headers end. This will be on the first blank line in the message.
Once you have found that, you may have to parse the message itself. The reason for this is that you have presented a multi-part message, which is made of... multiple parts. Each part can have its own content type and what not. This is common for HTML e-mails, as well as e-mails with attachments.
To find out how to parse the multi-part message, you need to look for the boundary identifier. This is outlined at the end of this header:
Content-Type: multipart/alternative; boundary=702637934216955106
Just split the message on the boundary, and deal with each part separately from there.
精彩评论