| 1 | package MIME::Structure; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 6 | $VERSION = '0.07'; | |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Text::Balanced qw(extract_delimited); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use constant IN_HEADER => 1; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use constant IN_BODY => 2; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use constant IN_PREAMBLE => 3; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use constant IN_EPILOGUE => 4; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use constant PRINT_NONE => 0; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use constant PRINT_HEADER => 1; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | 6 | ▶ | use constant PRINT_PREAMBLE => 2; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | 6 | ▶ | use constant PRINT_BODY => 4; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use constant PRINT_EPILOGUE => 8; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | # --- Constructor, accessors, initializer | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 25 | 5 | my $cls = shift; | |||||||||||||||||||||||||||||||||
| 26 | 5 | my $self = bless { | |||||||||||||||||||||||||||||||||
| 27 | 'keep_header' => 0, | ||||||||||||||||||||||||||||||||||
| 28 | 'keep_fields' => 1, | ||||||||||||||||||||||||||||||||||
| 29 | 'print_header' => 0, | ||||||||||||||||||||||||||||||||||
| 30 | 'print_preamble' => 0, | ||||||||||||||||||||||||||||||||||
| 31 | 'print_body' => 0, | ||||||||||||||||||||||||||||||||||
| 32 | 'print_epilogue' => 0, | ||||||||||||||||||||||||||||||||||
| 33 | @_, | ||||||||||||||||||||||||||||||||||
| 34 | }, $cls; | ||||||||||||||||||||||||||||||||||
| 35 | 5 | $self->init; | |||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | 15 | ▶ | sub keep_header { @_ > 1 ? $_[0]->{'keep_header'} = $_[1] : $_[0]->{'keep_header'} } | ||||||||||||||||||||||||||||||||
|
Subroutine
keep_header: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 39 | 15 | ▶ | sub keep_fields { @_ > 1 ? $_[0]->{'keep_fields'} = $_[1] : $_[0]->{'keep_fields'} } | ||||||||||||||||||||||||||||||||
|
Subroutine
keep_fields: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 40 | 15 | ▶ | sub print { @_ > 1 ? $_[0]->{'print'} = $_[1] : $_[0]->{'print'} } | ||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub print_header { @_ > 1 ? $_[0]->{'print_header'} = $_[1] : $_[0]->{'print_header'} } | ||||||||||||||||||||||||||||||||
|
Subroutine
print_header: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub print_body { @_ > 1 ? $_[0]->{'print_body'} = $_[1] : $_[0]->{'print_body'} } | ||||||||||||||||||||||||||||||||
|
Subroutine
print_body: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub print_preamble { @_ > 1 ? $_[0]->{'print_preamble'} = $_[1] : $_[0]->{'print_preamble'} } | ||||||||||||||||||||||||||||||||
|
Subroutine
print_preamble: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub print_epilogue { @_ > 1 ? $_[0]->{'print_epilogue'} = $_[1] : $_[0]->{'print_epilogue'} } | ||||||||||||||||||||||||||||||||
|
Subroutine
print_epilogue: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | 5 | ▶ | sub init { | ||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=11 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 47 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 48 | 5 | my $print_spec = $self->{'print'}; | |||||||||||||||||||||||||||||||||
| 49 | 5 | my $print; | |||||||||||||||||||||||||||||||||
| 50 | 5 | ▶ | if (!defined $print_spec) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 51 | 5 | $print = PRINT_NONE; | |||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||
| 53 | elsif ($print_spec =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||
| 54 | 0 | $print = $print_spec; | |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($print_spec =~ /header/i) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 58 | 0 | $print |= PRINT_HEADER; | |||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ($print_spec =~ /body/i) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 61 | 0 | $print |= PRINT_BODY; | |||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($print_spec =~ /preamble/i) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 64 | 0 | $print |= PRINT_PREAMBLE; | |||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($print_spec =~ /epilogue/i) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 67 | 0 | $print |= PRINT_EPILOGUE; | |||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | 5 | ▶ | if ($self->{'print_header'}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 71 | 0 | $print |= PRINT_HEADER; | |||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||
| 73 | 5 | ▶ | if ($self->{'print_body'}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 74 | 0 | $print |= PRINT_BODY; | |||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | 5 | ▶ | if ($self->{'print_preamble'}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 77 | 0 | $print |= PRINT_PREAMBLE; | |||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||
| 79 | 5 | ▶ | if ($self->{'print_epilogue'}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | 0 | $print |= PRINT_EPILOGUE; | |||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||
| 82 | 5 | $self->{'print'} = $print; | |||||||||||||||||||||||||||||||||
| 83 | 5 | $self; | |||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | # --- Parsing | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | 15 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=30 SCAR=34.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 89 | 15 | my ($self, $fh) = @_; | |||||||||||||||||||||||||||||||||
| 90 | 15 | my ($ofs, $line) = (0, 1); | |||||||||||||||||||||||||||||||||
| 91 | 15 | my $message = { | |||||||||||||||||||||||||||||||||
| 92 | 'kind' => 'message', | ||||||||||||||||||||||||||||||||||
| 93 | 'offset' => $ofs, | ||||||||||||||||||||||||||||||||||
| 94 | 'line' => $line, | ||||||||||||||||||||||||||||||||||
| 95 | 'number' => '1', | ||||||||||||||||||||||||||||||||||
| 96 | }; | ||||||||||||||||||||||||||||||||||
| 97 | 15 | my @context = ($message); | |||||||||||||||||||||||||||||||||
| 98 | 15 | my @entities; | |||||||||||||||||||||||||||||||||
| 99 | my @boundaries; | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | # --- Parsing options | ||||||||||||||||||||||||||||||||||
| 102 | 15 | my $keep_header = $self->keep_header; | |||||||||||||||||||||||||||||||||
| 103 | 15 | my $keep_fields = $self->keep_fields; | |||||||||||||||||||||||||||||||||
| 104 | 15 | my $print = $self->print; | |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 15 | my $state = IN_HEADER; | |||||||||||||||||||||||||||||||||
| 107 | 15 | my $header = ''; | |||||||||||||||||||||||||||||||||
| 108 | 15 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 109 | 350 | my $len = length $_; | |||||||||||||||||||||||||||||||||
| 110 | 350 | $ofs += $len; | |||||||||||||||||||||||||||||||||
| 111 | 350 | $line++; | |||||||||||||||||||||||||||||||||
| 112 | 350 | ▶ | if ($state == IN_HEADER) { | ||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||
| 113 | 245 | $header .= $_; | |||||||||||||||||||||||||||||||||
| 114 | 245 | ▶ | if (/^$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 115 | # --- Parse the header that has just ended | ||||||||||||||||||||||||||||||||||
| 116 | 50 | ▶ | print $header if $print & PRINT_HEADER; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 117 | 50 | my $fields = $self->parse_header($header); | |||||||||||||||||||||||||||||||||
| 118 | # @context is (..., $parent, $entity) | ||||||||||||||||||||||||||||||||||
| 119 | # or ($parent, $entity) if in header of a part of message | ||||||||||||||||||||||||||||||||||
| 120 | # or ($entity) if in message header itself | ||||||||||||||||||||||||||||||||||
| 121 | 50 | my $entity = $context[-1]; | |||||||||||||||||||||||||||||||||
| 122 | 50 | my $parent; | |||||||||||||||||||||||||||||||||
| 123 | 50 | my $level = $entity->{'level'} = @context - 1; | |||||||||||||||||||||||||||||||||
| 124 | 50 | ▶ | if (@context > 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 125 | # Current entity is $context[-1] | ||||||||||||||||||||||||||||||||||
| 126 | 35 | $parent = $entity->{'parent'} = $context[-2]; | |||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||
| 128 | 50 | ▶ | my ($content_type) = @{ $fields->{'content-type'} || [] }; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$fields->{'content-type'} || []
MC/DC100%1/1
$fields->{'content-type'} || []
$fields->{'content-type'}
Truth table100%2/2
A
A= $fields->{'content-type'}
| |||||||||||||||||||||||||||||||||||
| 129 | 50 | ▶ | if (!defined $content_type) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 130 | 5 | ▶ | if ($parent && "$parent->{'type'}/$parent->{'subtype'}" eq 'multipart/digest') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$parent and qq[$parent->{"type"}/$parent->{"subtype"}] eq "multipart/digest"
MC/DC0%0/2
$parent and qq[$parent->{"type"}/$parent->{"subtype"}] eq "multipart/digest"
$parent
qq[$parent->{"type"}/$parent->{"subtype"}] eq "multipart/digest"
Truth table33%1/3
A and B
A= $parentB= qq[$parent->{"type"}/$parent->{"subtype"}] eq "multipart/digest"
| |||||||||||||||||||||||||||||||||||
| 131 | 0 | $content_type = 'message/rfc822' | |||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||
| 133 | else { | ||||||||||||||||||||||||||||||||||
| 134 | 5 | $content_type = 'text/plain; charset=us-ascii'; | |||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||
| 137 | 50 | my ($type, $subtype, $type_params) = parse_content_type($content_type); | |||||||||||||||||||||||||||||||||
| 138 | 50 | $entity->{'type'} = $type; | |||||||||||||||||||||||||||||||||
| 139 | 50 | $entity->{'subtype'} = $subtype; | |||||||||||||||||||||||||||||||||
| 140 | 50 | $entity->{'type_params'} = $type_params; | |||||||||||||||||||||||||||||||||
| 141 | 50 | ▶ | $entity->{'header'} = $header if $keep_header; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 142 | 50 | ▶ | $entity->{'fields'} = $fields if $keep_fields; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 143 | 50 | $entity->{'body_offset'} = $ofs; | |||||||||||||||||||||||||||||||||
| 144 | 50 | $header = ''; | |||||||||||||||||||||||||||||||||
| 145 | 50 | ▶ | ($entity->{'encoding'}) = map lc, @{ $fields->{'content-transfer-encoding'} ||= ['7bit'] }; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$fields->{"content-transfer-encoding"} ||= ["7bit"]
MC/DC100%1/1
$fields->{"content-transfer-encoding"} ||= ["7bit"]
$fields->{"content-transfer-encoding"}
Truth table100%2/2
A
A= $fields->{"content-transfer-encoding"}
| |||||||||||||||||||||||||||||||||||
| 146 | 50 | ▶ | if ($type eq 'multipart') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 147 | # --- Header is for a multipart entity | ||||||||||||||||||||||||||||||||||
| 148 | 15 | $state = IN_PREAMBLE; | |||||||||||||||||||||||||||||||||
| 149 | 15 | my $boundary = $type_params->{'boundary'}; | |||||||||||||||||||||||||||||||||
| 150 | 15 | ▶ | die "No boundary specified for multipart entity with header at $ofs" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 151 | unless defined $boundary; | ||||||||||||||||||||||||||||||||||
| 152 | 15 | push @boundaries, $boundary; | |||||||||||||||||||||||||||||||||
| 153 | 15 | $entity->{'parts'} = []; | |||||||||||||||||||||||||||||||||
| 154 | 15 | $entity->{'parts_boundary'} = $boundary; | |||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||
| 156 | else { | ||||||||||||||||||||||||||||||||||
| 157 | # --- Header is for a leaf entity | ||||||||||||||||||||||||||||||||||
| 158 | 35 | $state = IN_BODY; | |||||||||||||||||||||||||||||||||
| 159 | 35 | pop @context; # The entity whose header we just finished reading | |||||||||||||||||||||||||||||||||
| 160 | 35 | ▶ | if ($level == 0 && !($print & PRINT_BODY)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$level == 0 and not $print & 4
MC/DC50%1/2
$level == 0 and not $print & 4
$level == 0
not $print & 4
Truth table66%2/3
A and not(B)
A= $level == 0B= not $print & 4
| |||||||||||||||||||||||||||||||||||
| 161 | # Minor optimization: message is not multipart, so we | ||||||||||||||||||||||||||||||||||
| 162 | # can stop if we're not going to be printing the body | ||||||||||||||||||||||||||||||||||
| 163 | 5 | push @entities, $entity; | |||||||||||||||||||||||||||||||||
| 164 | 5 | ▶ | while (<$fh>) { $ofs += length }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 165 | 5 | last; | |||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||
| 168 | 45 | push @entities, $entity; | |||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||
| 171 | ▶ | elsif (@boundaries && /^--(.+?)(--)?$/ && $1 eq $boundaries[-1]) { | |||||||||||||||||||||||||||||||||
|
Condition66%4/6
@boundaries and /^--(.+?)(--)?$/ and $1 eq $boundaries[-1]
@boundaries and /^--(.+?)(--)?$/
MC/DC33%1/3
@boundaries and /^--(.+?)(--)?$/ and $1 eq $boundaries[-1]
@boundaries
/^--(.+?)(--)?$/
$1 eq $boundaries[-1]
Truth table50%2/4
A and B and C
A= @boundariesB= /^--(.+?)(--)?$/C= $1 eq $boundaries[-1]
| |||||||||||||||||||||||||||||||||||
| 172 | 50 | ▶ | print if $print != PRINT_NONE; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 173 | 50 | ▶ | if (defined $2) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 174 | # End of parent's parts | ||||||||||||||||||||||||||||||||||
| 175 | 15 | pop @boundaries; | |||||||||||||||||||||||||||||||||
| 176 | 15 | pop @context; | |||||||||||||||||||||||||||||||||
| 177 | 15 | $state = IN_EPILOGUE; | |||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||
| 179 | else { | ||||||||||||||||||||||||||||||||||
| 180 | # Another part begins | ||||||||||||||||||||||||||||||||||
| 181 | 35 | $state = IN_HEADER; | |||||||||||||||||||||||||||||||||
| 182 | 35 | my $part = { | |||||||||||||||||||||||||||||||||
| 183 | 'kind' => 'part', | ||||||||||||||||||||||||||||||||||
| 184 | 'offset' => $ofs, | ||||||||||||||||||||||||||||||||||
| 185 | 'line' => $line, | ||||||||||||||||||||||||||||||||||
| 186 | }; | ||||||||||||||||||||||||||||||||||
| 187 | 35 | my $parent = $context[-1]; | |||||||||||||||||||||||||||||||||
| 188 | 35 | my $parent_parts = $parent->{'parts'}; | |||||||||||||||||||||||||||||||||
| 189 | 35 | push @$parent_parts, $part; | |||||||||||||||||||||||||||||||||
| 190 | 35 | $part->{'parent'} = $parent; | |||||||||||||||||||||||||||||||||
| 191 | 35 | $part->{'number'} = $parent->{'number'} . '.' . scalar @$parent_parts; | |||||||||||||||||||||||||||||||||
| 192 | 35 | push @context, $part; | |||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||
| 195 | elsif ($state == IN_PREAMBLE) { | ||||||||||||||||||||||||||||||||||
| 196 | # A line within the preamble: ignore per RFC 2049 | ||||||||||||||||||||||||||||||||||
| 197 | 15 | ▶ | print if $print & PRINT_PREAMBLE; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||
| 199 | elsif ($state == IN_EPILOGUE) { | ||||||||||||||||||||||||||||||||||
| 200 | # A line within the epilogue: ignore per RFC 2049 | ||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | print if $print & PRINT_EPILOGUE; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||
| 203 | else { | ||||||||||||||||||||||||||||||||||
| 204 | # Normal body line | ||||||||||||||||||||||||||||||||||
| 205 | 40 | ▶ | print if $print & PRINT_BODY; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||
| 208 | # We're all done reading | ||||||||||||||||||||||||||||||||||
| 209 | 15 | ▶ | if (@context) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 210 | 0 | die "Unfinished parts!"; | |||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||
| 212 | 15 | $message->{'content_length'} = $ofs - $message->{'body_offset'}; | |||||||||||||||||||||||||||||||||
| 213 | 15 | $message->{'length'} = $ofs; | |||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||
| 215 | 15 | ▶ | return wantarray ? @entities : $message; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||
| 218 | # --- Reporting | ||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||
| 220 | 3 | ▶ | sub concise_structure { | ||||||||||||||||||||||||||||||||
|
Subroutine
concise_structure: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 221 | 3 | my ($self, $message) = @_; | |||||||||||||||||||||||||||||||||
| 222 | # (text/plain:0) | ||||||||||||||||||||||||||||||||||
| 223 | # (multipart/mixed:0 (text/plain:681) (image/gif:774)) | ||||||||||||||||||||||||||||||||||
| 224 | 3 | my $visitor; | |||||||||||||||||||||||||||||||||
| 225 | 10 | ▶ | $visitor = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 226 | 10 | my ($entity) = @_; | |||||||||||||||||||||||||||||||||
| 227 | 10 | my $type = $entity->{'type'}; | |||||||||||||||||||||||||||||||||
| 228 | 10 | my $subtype = $entity->{'subtype'}; | |||||||||||||||||||||||||||||||||
| 229 | 10 | my $number = $entity->{'number'}; | |||||||||||||||||||||||||||||||||
| 230 | 10 | my $ofs = $entity->{'offset'}; | |||||||||||||||||||||||||||||||||
| 231 | 10 | ▶ | if ($type eq 'multipart') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 232 | 3 | my $str = "($number $type/$subtype:$ofs"; | |||||||||||||||||||||||||||||||||
| 233 | 3 | $str .= ' ' . $visitor->($_) for @{ $entity->{'parts'} }; | |||||||||||||||||||||||||||||||||
| 234 | 3 | return $str . ')'; | |||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||
| 236 | else { | ||||||||||||||||||||||||||||||||||
| 237 | 7 | return "($number $type/$subtype:$ofs)"; | |||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||
| 239 | 3 | }; | |||||||||||||||||||||||||||||||||
| 240 | 3 | $visitor->($message); | |||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||
| 243 | # --- Utility functions | ||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||
| 245 | 50 | ▶ | sub parse_header { | ||||||||||||||||||||||||||||||||
|
Subroutine
parse_header: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 246 | 50 | my ($self, $str) = @_; | |||||||||||||||||||||||||||||||||
| 247 | #my $str = $$hdrref; | ||||||||||||||||||||||||||||||||||
| 248 | 50 | $str =~ s/\n(?=[ \t])//g; | |||||||||||||||||||||||||||||||||
| 249 | 50 | my @fields; | |||||||||||||||||||||||||||||||||
| 250 | 50 | ▶ | while ($str =~ /(.+)/g) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 251 | 195 | push @fields, [split /:\s+/, $1, 2]; | |||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||
| 253 | 50 | return fields2hash(\@fields); | |||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||
| 256 | 50 | ▶ | sub fields2hash { | ||||||||||||||||||||||||||||||||
|
Subroutine
fields2hash: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 257 | 50 | my ($F) = @_; | |||||||||||||||||||||||||||||||||
| 258 | 50 | my %F; | |||||||||||||||||||||||||||||||||
| 259 | 50 | foreach (@$F) { | |||||||||||||||||||||||||||||||||
| 260 | 195 | my ($name, $value) = @$_; | |||||||||||||||||||||||||||||||||
| 261 | 195 | ▶ | push @{ $F{lc $name} ||= [] }, $value; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$F{lc $name} ||= []
MC/DC0%0/1
$F{lc $name} ||= []
$F{lc $name}
Truth table50%1/2
A
A= $F{lc $name}
| |||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||
| 263 | 50 | return \%F; | |||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||
| 266 | 50 | ▶ | sub parse_content_type { | ||||||||||||||||||||||||||||||||
|
Subroutine
parse_content_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 267 | 50 | my ($str) = @_; | |||||||||||||||||||||||||||||||||
| 268 | 50 | my ($type, $subtype, $params_str) = split m{/|;\s*}, $str, 3; | |||||||||||||||||||||||||||||||||
| 269 | 50 | return (lc $type, lc $subtype, parse_params($params_str)); | |||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||
| 272 | 50 | ▶ | sub parse_params { | ||||||||||||||||||||||||||||||||
|
Subroutine
parse_params: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 273 | 50 | my ($str) = @_; | |||||||||||||||||||||||||||||||||
| 274 | 50 | ▶ | $str = '' unless defined $str; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 275 | 50 | my %param; | |||||||||||||||||||||||||||||||||
| 276 | 50 | ▶ | while ($str =~ s/^([^\s=]+)=//) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 277 | 20 | my $name = lc $1; | |||||||||||||||||||||||||||||||||
| 278 | 20 | ▶ | if ($str =~ /^"/) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 279 | 10 | my $value = extract_delimited($str, q{"}, ''); | |||||||||||||||||||||||||||||||||
| 280 | 10 | $value =~ s/^"|"$//g; | |||||||||||||||||||||||||||||||||
| 281 | 10 | $value =~ s/\\(.)|([^\\"]+)|(.)/$+/g; | |||||||||||||||||||||||||||||||||
| 282 | 10 | $param{$name} = $value; | |||||||||||||||||||||||||||||||||
| 283 | # | ||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||
| 285 | elsif ($str =~ s/^([^\s()<>@,;:\\"\/\[\]?=]+)//) { | ||||||||||||||||||||||||||||||||||
| 286 | 10 | $param{$name} = $1; | |||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||
| 288 | else { | ||||||||||||||||||||||||||||||||||
| 289 | 0 | die "Bad params: $str"; | |||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||
| 291 | 20 | ▶ | die "Bad params: $str" unless $str =~ s/^(\s*;\s*|\s*$)//; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||
| 293 | 50 | return \%param; | |||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||
| 297 | 6 | 1; | |||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||
| 299 | =pod | ||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||
| 301 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||
| 303 | MIME::Structure - determine structure of MIME messages | ||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||
| 305 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||
| 307 | use MIME::Structure; | ||||||||||||||||||||||||||||||||||
| 308 | $parser = MIME::Structure->new; | ||||||||||||||||||||||||||||||||||
| 309 | $message = $parser->parse($filehandle); | ||||||||||||||||||||||||||||||||||
| 310 | print $message->{'header'}; | ||||||||||||||||||||||||||||||||||
| 311 | $parts = $message->{'parts'}; | ||||||||||||||||||||||||||||||||||
| 312 | foreach ($parts) { | ||||||||||||||||||||||||||||||||||
| 313 | $offset = $_->{'offset'}; | ||||||||||||||||||||||||||||||||||
| 314 | $type = $_->{'type'}; | ||||||||||||||||||||||||||||||||||
| 315 | $subtype = $_->{'subtype'}; | ||||||||||||||||||||||||||||||||||
| 316 | $line = $_->{'line'}; | ||||||||||||||||||||||||||||||||||
| 317 | $header = $_->{'header'}; | ||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||
| 319 | print $parser->concise_structure($message), "\n"; | ||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||
| 321 | =cut | ||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||
| 323 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||
| 325 | =over 4 | ||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||
| 327 | =item B<new> | ||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||
| 329 | $parser = MIME::Structure->new; | ||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||
| 331 | =item B<parse> | ||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||
| 333 | $message = $parser->parse($filehandle); | ||||||||||||||||||||||||||||||||||
| 334 | ($message, @other_entities) = $parser->parse($filehandle); | ||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||
| 336 | Parses the message found in the given filehandle. | ||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||
| 338 | A MIME message takes the form of a non-empty tree, each of whose nodes is | ||||||||||||||||||||||||||||||||||
| 339 | termed an I<entity> (see RFCs 2045-2049). The root entity is the message | ||||||||||||||||||||||||||||||||||
| 340 | itself; the children of a multipart message are the parts it contains. (A | ||||||||||||||||||||||||||||||||||
| 341 | non-multipart message has no children.) | ||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||
| 343 | When called in list context, the B<parse> method returns a list of references | ||||||||||||||||||||||||||||||||||
| 344 | to hashes; each hash contains information about a single entity in the message. | ||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||
| 346 | The first hash represents the message itself; if it is a multipart message, | ||||||||||||||||||||||||||||||||||
| 347 | subsequent entities are its parts and subparts B<in the order in which they | ||||||||||||||||||||||||||||||||||
| 348 | occur in the message> -- in other words, in pre-order. If called in scalar | ||||||||||||||||||||||||||||||||||
| 349 | context, only a reference to the hash containing information about the message | ||||||||||||||||||||||||||||||||||
| 350 | itself is returned. | ||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||
| 352 | The following elements may appear in these hashes: | ||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||
| 354 | =over 4 | ||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||
| 356 | =item B<body_offset> | ||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||
| 358 | The offset, in bytes, of the entity's body. | ||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||
| 360 | =item B<content_length> | ||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||
| 362 | The length, in bytes, of the entity's body. Currently only set for the message | ||||||||||||||||||||||||||||||||||
| 363 | itself. | ||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||
| 365 | =item B<encoding> | ||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||
| 367 | The value of the entity's Content-Transfer-Encoding field. | ||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||
| 369 | =item B<fields> | ||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||
| 371 | If the B<keep_fields> option is set, this will be a reference to a hash | ||||||||||||||||||||||||||||||||||
| 372 | whose keys are the names (converted to lower case) are the names of all fields | ||||||||||||||||||||||||||||||||||
| 373 | present in the entity;s header and whose values xxx. | ||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||
| 375 | =item B<header> | ||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||
| 377 | The entity's full header as it appeared in the message, not including the final | ||||||||||||||||||||||||||||||||||
| 378 | blank line. This will be presently only if the B<keep_header> option is set. | ||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||
| 380 | =item B<kind> | ||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||
| 382 | C<message> if the entity is the message, or C<part> if it is a part within a message | ||||||||||||||||||||||||||||||||||
| 383 | (or within another part). | ||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||
| 385 | =item B<length> | ||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||
| 387 | The length, in bytes, of the entire entity, including its header and body. | ||||||||||||||||||||||||||||||||||
| 388 | Currently only set for the message itself. | ||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||
| 390 | =item B<level> | ||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||
| 392 | The level at which the entity is found. The message itself is at level 0, its | ||||||||||||||||||||||||||||||||||
| 393 | parts (if any) are at level 1, their parts are at level 2, and so on. | ||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||
| 395 | =item B<line> | ||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||
| 397 | The line number (1-based) of the first line of the message's header. The message itself always, by definition, | ||||||||||||||||||||||||||||||||||
| 398 | is at line 1. | ||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||
| 400 | =item B<number> | ||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||
| 402 | A dotted-decimal notation that indicates the entity's place within the message. | ||||||||||||||||||||||||||||||||||
| 403 | The root entity (the message itself) has number 1; its parts (if it has any any) | ||||||||||||||||||||||||||||||||||
| 404 | are numbered 1.1, 1.2, 1.3, etc., and the numbers of their parts in turn (if | ||||||||||||||||||||||||||||||||||
| 405 | they have any) are constructed in like manner. | ||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||
| 407 | =item B<offset> | ||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||
| 409 | The offset B<in bytes> of the first line of the entity's header, measured from | ||||||||||||||||||||||||||||||||||
| 410 | the first line of the message's header. The message itself always, by definition, | ||||||||||||||||||||||||||||||||||
| 411 | is at offset 0. | ||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||
| 413 | =item B<parent> | ||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||
| 415 | A reference to the hash representing the entity's parent. If the entity is | ||||||||||||||||||||||||||||||||||
| 416 | the message itself, this is undefined. | ||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||
| 418 | =item B<parts> | ||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||
| 420 | A reference to an array of the entity's parts. This will be present only if | ||||||||||||||||||||||||||||||||||
| 421 | the entity is of type B<multipart>. | ||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||
| 423 | =item B<parts_boundary> | ||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||
| 425 | The string used as a boundary to delimit the entity's parts. Present only in | ||||||||||||||||||||||||||||||||||
| 426 | multipart entities. | ||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||
| 428 | =item B<subtype> | ||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||
| 430 | The MIME media subtype of the entity's content, e.g., C<plain> or C<jpeg>. | ||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||
| 432 | =item B<type> | ||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||
| 434 | The MIME media type of the entity's content, e.g., C<text> or C<image>. | ||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||
| 436 | =item B<type_params> | ||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||
| 438 | A reference to a hash containing the attributes (if any) found in the | ||||||||||||||||||||||||||||||||||
| 439 | Content-Type: header field. For example, given the following Content-Type header: | ||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||
| 441 | Content-Type: text/html; charset=UTF-8 | ||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||
| 443 | The entity's B<type_params> element will be this: | ||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||
| 445 | $entity{'type_params'} = { | ||||||||||||||||||||||||||||||||||
| 446 | 'charset' => 'UTF-8', | ||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||
| 449 | =back | ||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||
| 451 | Besides parsing the message, this method may also be used to print the message, | ||||||||||||||||||||||||||||||||||
| 452 | or portions thereof, as it parses; the B<print> method (q.v.) may be used to | ||||||||||||||||||||||||||||||||||
| 453 | specify what to print. | ||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||
| 455 | =item B<keep_header> | ||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||
| 457 | $keep_header = $parser->keep_header; | ||||||||||||||||||||||||||||||||||
| 458 | $parser->keep_header(1); | ||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||
| 460 | Set (or get) whether headers should be remembered during parsing. | ||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||
| 462 | =item B<keep_fields> | ||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||
| 464 | Set (or get) whether fields (normalized headers) should be remembered. | ||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||
| 466 | =item B<print> | ||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||
| 468 | $print = $parser->print; | ||||||||||||||||||||||||||||||||||
| 469 | $parser->print($MIME::Structure::PRINT_HEADER | $MIME::Structure::PRINT_BODY); | ||||||||||||||||||||||||||||||||||
| 470 | $parser->print('header,body'); | ||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||
| 472 | Set (or get) what should be printed. This may be specified either as any of the | ||||||||||||||||||||||||||||||||||
| 473 | following symbolic constants, ORed together: | ||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||
| 475 | =over 4 | ||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||
| 477 | =item B<PRINT_NONE> | ||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||
| 479 | =item B<PRINT_HEADER> | ||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||
| 481 | =item B<PRINT_BODY> | ||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||
| 483 | =item B<PRINT_PREAMBLE> | ||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||
| 485 | =item B<PRINT_EPILOGUE> | ||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||
| 487 | =back | ||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||
| 489 | Or using the following string constants concatenated using any delimiter: | ||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||
| 491 | =over 4 | ||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||
| 493 | =item B<none> | ||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||
| 495 | =item B<header> | ||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||
| 497 | =item B<body> | ||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||
| 499 | =item B<preamble> | ||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||
| 501 | =item B<epilogue> | ||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||
| 503 | =back | ||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||
| 505 | =item B<print_header> | ||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||
| 507 | $print_header = $parser->print_header; | ||||||||||||||||||||||||||||||||||
| 508 | $parser->print_header(1); | ||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||
| 510 | Set (or get) whether headers should be printed. | ||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||
| 512 | =item B<print_body> | ||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||
| 514 | $print_body = $parser->print_body; | ||||||||||||||||||||||||||||||||||
| 515 | $parser->print_body(1); | ||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||
| 517 | Set (or get) whether bodies should be printed. | ||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||
| 519 | =item B<print_preamble> | ||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||
| 521 | $print_preamble = $parser->print_preamble; | ||||||||||||||||||||||||||||||||||
| 522 | $parser->print_preamble(1); | ||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||
| 524 | Set (or get) whether preambles should be printed. | ||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||
| 526 | =item B<print_epilogue> | ||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||
| 528 | $print_epilogue = $parser->print_epilogue; | ||||||||||||||||||||||||||||||||||
| 529 | $parser->print_epilogue(1); | ||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||
| 531 | Set (or get) whether epilogues should be printed. | ||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||
| 533 | =item B<entities> | ||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||
| 535 | $parser->parse; | ||||||||||||||||||||||||||||||||||
| 536 | print "$_->{type}/$_->{subtype} $_->{offset}\n" | ||||||||||||||||||||||||||||||||||
| 537 | for @{ $parser->entities }; | ||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||
| 539 | Returns a reference to an array of all the entities in a message, in the order | ||||||||||||||||||||||||||||||||||
| 540 | in which they occur in the message. Thus the first entity is always the root | ||||||||||||||||||||||||||||||||||
| 541 | entity, i.e., the message itself). | ||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||
| 543 | =item B<concise_structure> | ||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||
| 545 | $parser->parse; | ||||||||||||||||||||||||||||||||||
| 546 | print $parser->concise_structure; | ||||||||||||||||||||||||||||||||||
| 547 | # e.g., '(multipart/alternative:0 (text/html:291) (text/plain:9044))' | ||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||
| 549 | Returns a string showing the structure of a message, including the content | ||||||||||||||||||||||||||||||||||
| 550 | type and offset of each entity (i.e., the message and [if it's multipart] all | ||||||||||||||||||||||||||||||||||
| 551 | of its parts, recursively). Each entity is printed in the form: | ||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||
| 553 | "(" content-type ":" byte-offset [ " " parts... ")" | ||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||
| 555 | Offsets are B<byte> offsets of the entity's header from the beginning of the | ||||||||||||||||||||||||||||||||||
| 556 | message. (If B<parse()> was called with an I<offset> parameter, this is added | ||||||||||||||||||||||||||||||||||
| 557 | to the offset of the entity's header.) | ||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||
| 559 | N.B.: The first offset is always 0. | ||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||
| 561 | =back | ||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||
| 563 | =head1 BUGS | ||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||
| 565 | Documentation is sketchy. | ||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||
| 567 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||
| 569 | Paul Hoffman E<lt>nkuitse (at) cpan (dot) orgE<gt> | ||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||
| 571 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||
| 573 | Copyright 2008 Paul M. Hoffman. All rights reserved. | ||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||
| 575 | This program is free software; you can redistribute it | ||||||||||||||||||||||||||||||||||
| 576 | and modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||
| 578 | =cut | ||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||