4 # @brief Extract HTML from an MHTML file
6 # Copyright (C) 2010,2015 Olly Betts
8 # Permission is hereby granted, free of charge, to any person obtaining a copy
9 # of this software and associated documentation files (the "Software"), to
10 # deal in the Software without restriction, including without limitation the
11 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 # sell copies of the Software, and to permit persons to whom the Software is
13 # furnished to do so, subject to the following conditions:
15 # The above copyright notice and this permission notice shall be included in
16 # all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 # Exit with code 127 which omindex interprets as "filter not installed"
33 # and won't try further .msg files.
38 my $parser = new MIME::Parser;
39 # Keep data in memory rather than spraying files onto disk.
40 $parser->output_to_core(1);
41 $parser->tmp_to_core(1);
42 open IN, '<', $in or die "Couldn't open '$in' ($?)\n";
43 my $mhtml = $parser->parse(\*IN) or die "Failed to parse '$in' as MHTML\n";
45 for my $sub ($mhtml->parts) {
46 my $head = $sub->head;
47 if ($head->mime_type eq 'text/html') {
48 # FIXME: Ideally we use the charset specified, though in practice it's
49 # likely to just be whatever the page specifies.
50 # my $charset = $head->mime_attr('content-type.charset');
51 print $sub->bodyhandle()->as_string;