3 # @file outlookmsg2html
4 # @brief Extract text from an outlook .msg or .oft 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
28 require Email::Outlook::Message;
29 require HTML::Entities;
33 # Exit with code 127 which omindex interprets as "filter not installed"
34 # and won't try further .msg files.
38 handle_mimepart(new Email::Outlook::Message($ARGV[0])->to_email_mime);
42 my ($type, $sub) = ((lc $e->content_type) =~ m,^(.*?)/(.*?)(?:;.*)?$,);
43 if ($type eq 'multipart') {
44 if ($sub eq 'alternative') {
45 # Take the first mime part which we get text from.
46 for my $s ($e->subparts) {
47 my $res = handle_mimepart($s);
52 for my $s ($e->subparts) {
53 $res += handle_mimepart($s);
57 } elsif ($type eq 'text') {
58 if ($sub eq 'plain') {
59 print "<pre>", HTML::Entities::encode_entities($e->body), "</pre>\n";
61 } elsif ($sub eq 'html') {
63 $m =~ s!</?body[^>]*>!\n!gi;
67 } elsif ($type eq 'message' && $sub eq 'rfc822') {
68 return handle_mimepart(Email::MIME->new($e->body));