2 ##--------------------------------------------------------------------------##
4 ## $Id: extract-mesg.cgi.in.dist,v 1.5 2002/09/20 03:29:28 ehood Exp $
6 ## Earl Hood earl@earlhood.com
9 ##--------------------------------------------------------------------------##
10 ## Copyright (C) 2002 Earl Hood <earl@earlhood.com>
12 ## This program is free software; you can redistribute it and/or modify
13 ## it under the terms of the GNU General Public License as published by
14 ## the Free Software Foundation; either version 2 of the License, or
15 ## (at your option) any later version.
17 ## This program is distributed in the hope that it will be useful,
18 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ## GNU General Public License for more details.
22 ## You should have received a copy of the GNU General Public License
23 ## along with this program; if not, write to the Free Software
24 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 ##--------------------------------------------------------------------------##
28 package MHArc
::extract_mesg_cgi
;
30 use lib
'@@SW_ROOT@@/lib';
35 #############################################################################
36 ## BEGIN: Config Section
37 #############################################################################
39 ## Full pathname to where raw archives are located.
40 my $mbox_archive_root = '@@MBOX_DIR@@';
42 ## Message media-type: This is the media-type this script will return
43 ## to the client when serving up the raw mail message. Note, some
44 ## browsers actually support message/rfc822, but this could potentially
45 ## cause XSS HTML email attacks, so use with caution.
46 my $message_media_type = 'text/plain';
48 #############################################################################
49 ## END: Config Section
50 #############################################################################
52 $ENV{'PATH'} = '/usr/local/bin:/bin:/usr/bin';
54 ## Query argument name to contain name of archive
55 my $argname_archive = 'a';
57 ## Query argument name to contain month
58 my $argname_month = 'm';
60 ## Query argument name to contain message-id
63 ## Mbox message separator: Try to be more strict than '^From ', but
64 ## not too strict to deal with possible variations.
65 my $msgsep = '^From \S+.*\d+:\d+:\d+';
68 my $form = MHArc
::CGI
::parse_input
();
69 my $archive = $form->{$argname_archive} || "";
70 my $month = $form->{$argname_month} || "";
71 my $id = $form->{$argname_id} || "";
74 if (($month !~ /^\d{4}(?:-\d{2})?$/) ||
77 ($archive =~ /\.\./) ||
78 (! -d
($list_dir = join('/', $mbox_archive_root,$archive)))) {
79 warn qq/Invalid arguments: a=$archive, m=$month, i=$id\n/;
80 MHArc
::CGI
::print_input_error
();
84 # Check if list has raw archive access disabled.
85 if (-e
join('/', $list_dir, '.noraw')) {
86 MHArc
::CGI
::print_forbidden
();
91 my $mbox_file = join('/', $list_dir, $month);
92 if (! -e
$mbox_file) {
96 if (! -e
$mbox_file) {
97 warn qq/"$mbox_file" does not exist\n/;
98 MHArc
::CGI
::print_input_error
();
104 if (!open(MBOX
, "gzip -dc '$mbox_file' |")) {
105 warn qq/Unable to exec "gzip -dc '$mbox_file'": $!\n/;
106 MHArc
::CGI
::print_error
();
110 if (!open(MBOX
, $mbox_file)) {
111 warn qq/Unable to open "$mbox_file": $!\n/;
112 MHArc
::CGI
::print_error
();
123 SCAN
: while (<MBOX
>) {
129 next SCAN
unless $in_header;
138 if (s/^message-id:\s*//i) {
151 MHArc
::CGI
::print_not_found_error
();
156 MHArc
::CGI
::print_content_type
($message_media_type);
165 ########################################################################
170 extract-mesg.cgi - mharc CGI program to retrieve raw version of a message
174 http://.../cgi-bin/extract-mesg.cgi?a=<archive-name>&m=<period>&i=<message-id>
178 This CGI program retrieves the raw version of a message from an
179 archive archived at a specified period and with a specified message-id.
181 The CGI program will output the retrieved message to the web client.
189 The name of the archive. Archive names are defined by C<lists.def>.
197 The period in YYYY-MM or YYYY format.
203 C<$Id: extract-mesg.cgi.in.dist,v 1.5 2002/09/20 03:29:28 ehood Exp $>
207 Earl Hood, earl@earlhood.com
209 This module is part of the mharc archiving system and comes with
210 ABSOLUTELY NO WARRANTY and may be copied only under the terms of
211 the GNU General Public License, which may be found in the MHArc