<p><a href="<%$Page%>?<%$querystring%>">&lt;-- Back to the folder list</a></p>
%	my $total = scalar keys %$MessageList;
% if ($total < 1) {
<p><i>There are no messages in this folder.</i></p>
% } else {
<p>Click on the "<b>Import</b>" link next to the message you wish to import.</p>
%	if ($AllowMultiple) {
<p>Tick the boxes and click "Multi-Import" to import multiple messages at
once - they will be imported in the order that they appear here.</p>
<form action="<%$Page%>" method="post">
%		foreach (keys %ARGS) {
<input type="hidden" name="<%$_%>" value="<%$ARGS{$_}%>" />
%		}
%	}
%	my $start = (defined $Offset) ? $Offset : 0;
%	$start = $PerPage*int($start / $PerPage);
%	$start = 0 if ($start < 0);#>
%	my $end = $start + $PerPage - 1;
%	$end = $total - 1 if ($end >= $total);
<p>Showing folder: <b><%$Folder%></b></p>
<table border="1" cellspacing="0" cellpadding="2">
<tr><th colspan="5">Showing message <%$start+1%>-<%$end+1%> of <%$total%>
% if (($start > 0) || ($end < $total-1)) { #>
<br />
%	if ($start > 0) {
<a href="<%$Page%>?Folder=<%$Folder%>&amp;Offset=<%$start-$PerPage%>&amp;PerPage=<%$PerPage%>&amp;SortBy=<%$SortBy%>&amp;<%$querystring%>">&lt;&lt;Previous <%$PerPage%></a>
%		$m->out (' | ') if ($end < $total-1); #>
%	}
%	if ($end < $total-1) { #>
<a href="<%$Page%>?Folder=<%$Folder%>&amp;Offset=<%$start+$PerPage%>&amp;PerPage=<%$PerPage%>&amp;SortBy=<%$SortBy%>&amp;<%$querystring%>">Next <%$PerPage%> &gt;&gt;</a>
%	}
% }
</th>
% if ($AllowMultiple) {
<th rowspan="2">
<input type="button" value="Check All" onclick="setCheckbox(this.form, '', true);return false;" class="button" /><br />
<input type="button" value="Clear All" onclick="setCheckbox(this.form, '', false);return false;" class="button" />
</th>
% }
</tr>
<tr><th>&nbsp;</th><th>Received</th><th>From</th><th>Subject</th><th>Size</th>
</tr>
%	my @list = ();
%	if ($SortBy == 0) {
%		@list = sort { $MessageList->{$b}->{'TIME'} <=> $MessageList->{$a}->{'TIME'} } keys %$MessageList;
%	} elsif ($SortBy == 1) {
%		@list = sort { $MessageList->{$a}->{'TIME'} <=> $MessageList->{$b}->{'TIME'} } keys %$MessageList;
%	} else {
%		@list = sort { $a <=> $b } keys %$MessageList;
%	}
%	for (my $pos = $start; $pos <= $end; $pos++) { #>
%		my $received = ''.localtime($MessageList->{$list[$pos]}->{'TIME'});
%		my $from = $MessageList->{$list[$pos]}->{'FROM'};
%		$from = $1 if ($from =~ /\"(.+?)\"/);
<tr>
<td><a href="<%$Page%>?Folder=<%$Folder%>&amp;Offset=<%$Offset%>&amp;MessageId=<%$list[$pos]%>&amp;PerPage=<%$PerPage%>&amp;SortBy=<%$SortBy%>&amp;<%$querystring%>">Import</a></td>
<td><%$received%></td>
<td><%$from%></td>
<td><b><%$MessageList->{$list[$pos]}->{'FLAGS'} =~ /\\Seen/ ? '' : '(NEW)'%></b>
<i><%$MessageList->{$list[$pos]}->{'FLAGS'} =~ /\\Answered/ ? '(replied)' : ''%></i>
<%$MessageList->{$list[$pos]}->{'SUBJECT'}%></td>
<td style="text-align: right;"><%$MessageList->{$list[$pos]}->{'RFC822.SIZE'}%></td>
%	if ($AllowMultiple) {
<td style="text-align: center;"><input type="checkbox" name="BulkImport" value="<%$list[$pos]%>" /></td>
%	}
</tr>
%	}
%	if ($AllowMultiple) {
<tr><td colspan="5">&nbsp;</td><td><input type="submit" class="button" value="Multi-Import" /></td></tr>
%	}
</table>
%	if ($AllowMultiple) {
</form>
%	}

<br />
<form action="<%$Page%>" method="get">
<table border="0" style="border: solid black 1px; margin-left: auto; margin-right: 0px;" cellspacing="0" cellpadding="2">
<tr><td><label for="PerPage">Messages per page</label>:</td><td><input type="text" name="PerPage" id="PerPage" class="input" value="<%$PerPage%>" size="4" /></td></tr>
<tr><td><label for="SortBy">Sort by</label>:</td><td><select class="input" name="SortBy" id="SortBy">
%	my %sorts = ('0' => 'Received, descending', '1' => 'Received, ascending');
%	foreach (sort keys %sorts) {
<option value="<%$_%>"
%		$m->out ('selected="selected"') if ($SortBy eq $_);
><%$sorts{$_}%></option>
%	}
</select></td></tr>
<tr><td>&nbsp;</td><td><input type="submit" class="button" value=" Change " /></td></tr>
</table>
<input type="hidden" name="Folder" value="<%$Folder%>" />
%	foreach (keys %newargs) {
<input type="hidden" name="<%$_%>" value="<%$newargs{$_}%>" />
%	}
</form>
% }

<p><a href="<%$Page%>?<%$querystring%>">&lt;-- Back to the folder list</a></p>

<%INIT>
my %newargs = %ARGS; foreach ('Page','Folder','MessageList','Offset','PerPage','SortBy') { delete $newargs{$_}; }
my $querystring = $m->comp ('/Elements/QueryString', %newargs);
</%INIT>
<%ARGS>
$Page => undef
$Folder => undef
$MessageList => undef
$Offset => 0
$PerPage => 20
$SortBy => 0
$AllowMultiple => 0
</%ARGS>
