email_parse.inc
Parse MIME e-mails into programmer-friendly structure.
Summary
- Introduction
- Legal Copyright (C) 2008 Stephane Lavergne http://www.imars.com/
- Functions
- email_parse Parse a MIME message into an array of constituents.
Introduction
Legal
Copyright (C) 2008 Stephane Lavergne http://www.imars.com/
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Functions
email_parse
function email_parse($from)
Parse a MIME message into an array of constituents.
Parameters
- from
- String containing the entire message, or input stream (i.e. stdin).
Returns
Arrayhash containing “envelope”, “addresses”, “ids” and “body” keys.
The “envelope” key contains an arrayhash of the message's headers, with keys lowercased. Due to the nature of this hash, for headers encountered multiple times (i.e. “Received:”) only the last occurence is stored.
The “addresses” key contains an arrayhash: for each address-type header (From, To, Reply-To, Cc, Bcc, Sender, Return-Path) found, a key in its name contains an indexed array, itself an arrayhash with “name” and “email” keys.
The “ids” key contains an arrayhash: for each ID-type header (Message-ID, References, In-Reply-To) found, a key in its name contains an indexed array listing the message IDs found in the line. (Typically, Message-Id and In-Reply-To will contain only one, and References may contain several.)
The “body” key contains an arrayhash with part-related header keys and a 'data' key holding the decoded data or an indexed array of constituent parts, themselves structured like this part. Keys are:
- type
- MIME type (i.e. 'text/plain')
- major
- MIME type, major portion only (i.e. 'text')
- minor
- MIME type, minor portion only (i.e. 'plain')
- minorLeft
- MIME type, minor portion, first part of plus-style only (i.e. for 'text/xml+xhtml', would be 'xml') (Optional.)
- minorRight
- MIME type, minor portion, second part of plus-style only (i.e. for 'text/xml+xhtml', would be 'xhtml') (Optional, provided if minorLeft is.)
- charset
- Specified character set. (Only supplied if found.)
- name
- Suggested file name from Content-Type header. (Only supplied if found.)
- disposition
- MIME content disposition. (Only supplied if found.)
- boundary
- MIME boundary string. (Only supplied if found.)
- encoding
- MIME content transfer encoding. (Defaults to '8bit'.)
- filename
- Suggested file name from Content-Disposition header. (Only supplied if found.)
- data
- String of decoded data body or Array of body arrayhashes if multipart.