103 sub decode_entities
104 {
105     my $ent = shift;
106 
107     if (my @parts = $ent->parts)
108     {
109         decode_entities($_) for @parts;
110     }
111     elsif (my $body = $ent->bodyhandle)
112     {
113         my $type = $ent->head->mime_type;
114 
115         setup_decoder($ent->head);
116 
117         if ($type eq 'text/plain')
118         { print d($body->as_string); }
119         elsif ($type eq 'text/html')
120         { $parser->parse($body->as_string); }
121         else
122         { print "[Unhandled part of type $type]"; }
123     }
124 }

Example 3: The decode_entities function.

Back to Article