%# Parts that positively cannot be assembled in improper order will be.

<h2><a href="<% $RT::BaseURL %>/wws/arc/<% $list_name %>"><% $list_name %></a></h2>

<ul>
<li><&|/l&>To post a message to all the list members, send email to</&>
<a href="mailto:<% $list_name %>@lists.openfoundry.org"><% $list_name %>@lists.openfoundry.org</a></li>
<li><&|/l&>To subscribe to this mailing list, send email to</&>
<a href="mailto:<% $list_name %>-request@lists.openfoundry.org?subject=subscribe"><% $list_name %>-request@lists.openfoundry.org</a> <&|/l, 'subscribe'&>with the subject '[_1]'</&></li>
<li><&|/l&>To unsubscribe from this mailing list, send email to</&>
<a href="mailto:<% $list_name %>-unsubscribe@lists.openfoundry.org?subject=unsubscribe"><% $list_name %>-unsubscribe@lists.openfoundry.org</a> <&|/l, 'unsubscribe'&>with the subject '[_1]'</&></li>
</ul>

% if ($out =~ /empty_archives/) {
<&|/l&>The archive is currently empty.</&>
% }
% if (!$RT::Guest) {
<BR><A HREF="<% $PostURL %>"><&|/l&>Post an article</&></A>
% }
% $action =~ s/^\s*\|\s*//;
<% $action |n %>
% if ($out !~ /empty_archives/) {
<P><TABLE width="100%" cellpadding=0 cellspacing=0><TR><TD>
%     $m->print($out);
</TD></TR></TABLE></P>
% }
<%INIT>
our ($Get, $Post, $ua, $wws);

use Encode;
my $args = { map { $_ => Encode::encode_utf8($ARGS{$_}) } grep /^[_a-z]/, keys %ARGS };
$args->{quiet} = 1;

$RT::BaseURL = "/Foundry/Project/Forum/List.html";
my $out;
my $action;
my $list_name = $1 if $r->path_info =~ m{/wws/[^/]+/([^/]+)};
$session{LastListName} = $list_name ||= $session{LastListName};

if ($r->path_info =~ m{^/wws(.*)}) {
    require URI;
    my $url = URI->new('http:');
    $url->query_form(%$args, not_a_sniffer => 1);

    $out = $Get->("$1?" . $url->query);
    if ($m->notes('RV') =~ m{^\s*(<A HREF=\W/wws/(?:subrequest|subscribe|signoff)/.*</A>)\s*$}m) {
	$action = " | $1";
	$action =~ s{\bHREF="(/wws[^>]*>)}{HREF="$RT::BaseURL$1}gi;
	$action =~ s/onClick=".*?"//;
    }

    if ($r->path_info =~ m{^/wws/arc/}) {
	# Guess encoding for inline attachments without an explicit charset
	$out =~ s{
	    ((?:[\x80-\xff](?:[\x40-\xff]|[\x80-\xff][\x80-\xff]))+)
	}{
	    my $raw = Encode::encode('latin1', $1);
	    my $rv;
	    eval { $rv = Encode::decode('utf8', $raw, Encode::FB_CROAK()); 1 }
	      or eval { $rv = Encode::decode('big5', $raw, Encode::FB_CROAK()); 1 }
	      or $rv = $raw;
	    $rv;
	}exg;
    }
}
else {
    $out = $Post->( "", scalar $m->request_args );
}

my $PostURL = $1 if ($out =~ m{HREF="([^"]+/compose_mail/[^"]+)"});
unless ($out =~ s/.*<!-- end list_menu.tt2 -->//s) {
    $m->comp('/Foundry/Project/Forum/index.html', Queue => 1, %ARGS);
}
</%INIT>
