NAME

MIME::Structure - determine structure of MIME messages

SYNOPSIS

use MIME::Structure;
$parser = MIME::Structure->new;
$root = $parser->parse($filehandle);
print $root->{'header'};
$parts = $root->{'parts'};
foreach ($parts) {
    $offset_within_message = $_->{'offset'};
    $type = $_->{'type'};
    $subtype = $_->{'subtype'};
    $line = $_->{'line'};
    $header = $_->{'header'};
}
print $root->concise_structure, "\n";

METHODS

new
$parser = MIME::Structure->new;
parse
$root = $parser->parse;
$root = $parser->parse($cur_offset, $cur_line);
root
$parser->parse;
$root = $parser->root;
keep_header
$keep_header = $parser->keep_header;
$parser->keep_header(1);

Set (or get) whether headers should be remembered during parsing.

unfold_header
$unfold_header = $parser->unfold_header;
$parser->unfold_header(1);

Set (or get) whether headers should be unfolded.

print
$print = $parser->print;
$parser->print($MIME::Structure::PRINT_HEADER | $MIME::Structure::PRINT_BODY);
$parser->print('header,body');

Set (or get) what should be printed. This may be specified either as any of the following symbolic constants, ORed together:

Or using the following string constants concatenated using any delimiter:

none
body
preamble
epilogue
$print_header = $parser->print_header;
$parser->print_header(1);

Set (or get) whether headers should be printed.

$print_body = $parser->print_body;
$parser->print_body(1);

Set (or get) whether bodies should be printed.

$print_preamble = $parser->print_preamble;
$parser->print_preamble(1);

Set (or get) whether preambles should be printed.

$print_epilogue = $parser->print_epilogue;
$parser->print_epilogue(1);

Set (or get) whether epilogues should be printed.

concise_structure
$parser->parse;
print $parser->concise_structure;
# e.g., '(multipart/alternative:0 (text/html:291) (text/plain:9044))'

Returns a string showing the structure of a message, including the content type and offset of each entity (i.e., the message and [if it's multipart] all of its parts, recursively). Each entity is printed in the form:

"(" content-type ":" byte-offset [ " " parts... ")"

Offsets are byte offsets of the entity's header from the beginning of the message. (If parse() was called with an offset parameter, this is added to the offset of the entity's header.)

N.B.: The first offset is always 0.

BUGS

Documentation is sketchy.

AUTHOR

Paul Hoffman <nkuitse (at) cpan (dot) org>

COPYRIGHT

Copyright 2008 Paul M. Hoffman. All rights reserved.

This program is free software; you can redistribute it and modify it under the same terms as Perl itself.