PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Mail » Mail_mimeDecode » Manual

The Mail_mimeDecode class provides an API to decode mail/MIME messages. This class will parse a raw mime email and return the structure. Returned structure is similar to that returned by imap_fetchstructure().

Mail_mimeDecode::Mail_mimeDecode()

Mail_mimeDecode::Mail_mimeDecode() – constructor

Synopsis

require_once 'Mail/mimeDecode.php';

void Mail_mimeDecode ( string $input )

Description

Create a new Mail_mimeDecode object.

Parameter

Note

This function can be called statically.

Mail_mimeDecode::decode()

Mail_mimeDecode::decode() – perform decoding

Synopsis

require_once 'Mail/mimeDecode.php';

object decode ( array $args = null )

Description

This function performs the decoding and returns a structure containing the message data.

Parameter

Return value

object -

Throws

Possible PEAR_Error values
Error code Error message Reason Solution
NULL " Called statically and no input given " You called the function statically and forgot to fill $args['input'] Fill $args['input'] with the content to decode or do not call the function statically.
NULL every other See the error message. The input or parts of the input does not complies to the MIME standard.

Note

This function can be called statically.

Mail_mimeDecode::uudecode()

Mail_mimeDecode::uudecode() – decode of UU-coded data

Synopsis

require_once 'Mail/mimeDecode.php';

array &uudecode ( string $input )

Description

Decodes UU-coded data. 'Unix-to-Unix'-Encoding is used to send binary files (eg. programs, graphics) over 7bit-ASCII-only media, like email.

Parameter

Return value

array - the decoded data

Note

This function can be called statically.

Mail_mimeDecode::getXML()

Mail_mimeDecode::getXML() – create XML representation of MIME parts

Synopsis

require_once 'Mail/mimeDecode.php';

string getXML ( array $decoded )

Description

getXML() converts the returned array from decode () into a valid XML document.

Parameter

Return value

string - the XML document

Note

This function can be called statically.

Example

Create a XML representation

<?php
...      
$output = $obj->decode();
$xml    = Mail_mimeDecode::getXML($output);
...
?>

Mail_mimeDecode - Example

Mail_mimeDecode - Example – decode an email

Example

Decode an email

<?php
require_once 'Mail/mimeDecode.php';
...
$params['include_bodies'] = true;
$params['decode_bodies']  = true;
$params['decode_headers'] = true;

$decoder = new Mail_mimeDecode($input);
$structure = $decoder->decode($params);
?>

This example calls the decode function statically (ie no object, straight function call) and then passes the structure to the getXML() function.

<?php

...
$params['include_bodies'] = true;
$params['decode_bodies']  = false;
$params['decode_headers'] = true;
$params['input']          = $input;
$params['crlf']           = "\r\n";

$structure = Mail_mimeDecode::decode($params);
$xml = Mail_mimeDecode::getXML($structure);

?>