1#!/usr/bin/perl
2##---------------------------------------------------------------------------##
3##  File:
4##	$Id: mha-decode,v 1.8 2003/07/20 03:24:38 ehood Exp $
5##  Author:
6##      Earl Hood       mhonarc@mhonarc.org
7##  Description:
8##      Program to decode MIME messages.
9##---------------------------------------------------------------------------##
10##    MHonArc -- Internet mail-to-HTML converter
11##    Copyright (C) 1998	Earl Hood, mhonarc@mhonarc.org
12##
13##    This program is free software; you can redistribute it and/or modify
14##    it under the terms of the GNU General Public License as published by
15##    the Free Software Foundation; either version 2 of the License, or
16##    (at your option) any later version.
17##
18##    This program is distributed in the hope that it will be useful,
19##    but WITHOUT ANY WARRANTY; without even the implied warranty of
20##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21##    GNU General Public License for more details.
22##
23##    You should have received a copy of the GNU General Public License
24##    along with this program; if not, write to the Free Software
25##    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26##    02111-1307, USA
27##---------------------------------------------------------------------------##
28
29package mha_decode;
30
31use Getopt::Long;
32
33##---------------------------------------------------------------------------##
34##				Main routine				     ##
35##---------------------------------------------------------------------------##
36
37MAIN: {
38    unshift(@INC, 'lib');    # Should I leave this line in?
39
40    ## Grab options from @ARGV unique to this program
41    my %opts = ();
42    Getopt::Long::Configure('pass_through');
43    GetOptions(\%opts, 'dcd-digest');
44    my $digest_mode = $opts{'dcd-digest'} || 0;
45
46    ## Reset pass-through of options
47    Getopt::Long::Configure('no_pass_through');
48
49    ## Initialize MHonArc
50    require 'mhamain.pl' || die qq/ERROR: Unable to require "mhamain.pl"\n/;
51    unshift(@ARGV, '-noarchive', '-nolock');
52    mhonarc::initialize();
53    mhonarc::open_archive() || exit($mhonarc::CODE);
54
55    ## Set resources
56    %readmail::MIMEFilters = (
57        'application/*' => 'm2h_external::filter',
58        'audio/*'       => 'm2h_external::filter',
59        'chemical/*'    => 'm2h_external::filter',
60        'image/*'       => 'm2h_external::filter',
61        'model/*'       => 'm2h_external::filter',
62        'text/*'        => 'm2h_external::filter',
63        'video/*'       => 'm2h_external::filter',
64    );
65    %readmail::MIMEFiltersSrc = (
66        'application/*' => 'mhexternal.pl',
67        'audio/*'       => 'mhexternal.pl',
68        'chemical/*'    => 'mhexternal.pl',
69        'image/*'       => 'mhexternal.pl',
70        'model/*'       => 'mhexternal.pl',
71        'text/*'        => 'mhexternal.pl',
72        'video/*'       => 'mhexternal.pl',
73    );
74    %readmail::MIMEFiltersArgs = ('m2h_external::filter' => 'usename');
75
76    if ($digest_mode) {
77        $readmail::MIMEFilters{'message/*'}    = 'm2h_external::filter';
78        $readmail::MIMEFiltersSrc{'message/*'} = 'mhexternal.pl';
79    }
80
81    mhonarc::process_input() || exit($mhonarc::CODE);
82    mhonarc::close_archive() || exit($mhonarc::CODE);
83    exit(0);
84}
85
86##---------------------------------------------------------------------------##
871;
88
89__END__
90
91=head1 NAME
92
93mha-decode - Decode MIME messages
94
95=head1 SYNOPSIS
96
97S<B<mha-decode> [I<options>] I<mailfolder> ...>
98
99S<B<mha-decode> [I<options>] -single I<msg.822>>
100
101=head1 DESCRIPTION
102
103B<mha-decode> is a utility program that is part of the B<MHonArc>
104software package.  B<mha-decode> provides basic MIME decoding for
105mail messages.
106
107If given mail folders as input, all messages within in the mail
108folders will be decoded.  All message parts are written to files.  If a
109filename is specified for a message part, that filename will be used
110when writing the part to a file.  If no filename is specified in the
111message, a unique name will be used based upon the content-type of
112the message part.
113
114A single message can be decoded by using the C<-single> option.
115
116=head1 OPTIONS
117
118B<mha-decode> takes options available to B<mhonarc>, but only those
119options affect parsing of mail folders are applicable:
120C<-conlen>,
121C<-mhpattern>,
122C<-msgsep>,
123C<-noconlen>,
124C<-outdir>,
125C<-perlinc>,
126C<-rcfile>,
127C<-single>,
128C<-umask>.
129
130Also, B<mha-decode> supports the following additional options:
131
132=over
133
134=item C<-dcd-digest>
135
136Run in message digest mode.  When this option is specified, any
137embedded C<message/rfc822> and C<message/news> parts will be saved
138instead of recursively decoding any parts contained within.
139
140=back
141
142=head1 NOTES
143
144The documentation for B<MHonArc> is distributed in HTML format.
145Due to its size and organization, it is not suited for manpage
146format.  Consult your system administrator for where the documentation
147has been installed, or see L<"AVAILABILITY"> on where you can
148access the documentation on the web.
149
150=head1 AVAILABILITY
151
152E<lt>I<http://www.mhonarc.org/>E<gt>
153
154=head1 AUTHOR
155
156Earl Hood, mhonarc@mhonarc.org
157
158MHonArc comes with ABSOLUTELY NO WARRANTY and MHonArc may be copied only
159under the terms of the GNU General Public License, which may be found in
160the MHonArc distribution.
161
162=cut
163
164