openpgp: 1E3AD15E
[www.jankratochvil.net.git] / Mailman.pm
1 # $Id$
2 # Mailman page Perl template.
3 # Copyright (C) 2003-2005 Jan Kratochvil <project-www.jankratochvil.net@jankratochvil.net>
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; exactly version 2 of June 1991 is required
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
19 package Mailman;
20 require 5.6.0;  # at least 'use warnings;' but we need some 5.6.0+ modules anyway
21 use vars qw($VERSION $CVS_ID);
22 $VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; };
23 $CVS_ID=q$Id$;
24 use strict;
25 use warnings;
26
27 use My::Web;
28 use URI::Escape;
29 require LWP::Simple;
30
31
32 our $HTML_TEST=0;       # TODO: Provide some real URLs for download/translation.
33 our $HTML_TEST_QUERY_STRING="list=html_test";
34
35 sub handler
36 {
37 my $W=My::Web->init(
38                 "title"=>"Mailman Interface",
39                 "no_job"=>1,
40                 "args_check"=>{
41                                 "email"=>'',
42                                 "pw"=>'',
43                                 "pw-conf"=>'',
44                                 "list"=>['^[-\w]+$'],
45                                 "back"=>'',
46                                 },
47                 "http_safe"=>0, # LWP downloads.
48                 # Mailman does not produce valid XHTML.
49                 "content_type"=>"text/html",
50                 );
51 My::Web->heading();
52
53
54 for my $list (@{$W->{"args"}{"list"}}) {
55         print "<h1>List <i>$list</i></h1><blockquote>\n";
56                 my $url_base=$W->{"mailman_url"}."/subscribe/$list";
57                 my $url=URI->new($url_base);
58                 $url->query_form(
59                                 "list"=>$list,
60                                 map(($_=>$W->{"args"}{$_}),qw(email pw pw-conf)),
61                                 );
62                 my $t=LWP::Simple::get($url);
63                 $t=($t=~m#^.*<body\b[^>]*>(.*?)</body>#is)[0];
64                 $t=~s#(href=")(../[^"]*)(")#$1$url_base/$2$3#gi;
65                 print $t;
66         print "</blockquote>\n";
67         }
68
69 if ($W->{"args"}{"back"}) {
70         print '<h1>'.a_href($W->{"args"}{"back"},'Back to the original page').'</h1>'."\n";
71         }
72
73
74 exit;
75 }
76 1;