#!/usr/local/bin/perl
# index.cgi
# List the mail messages for the user
require './mailbox-lib.pl';
&ReadParse();
&open_dsn_hash();
@folders = &list_folders_sorted();
if (defined($in{'id'})) {
# Folder ID specified .. convert to index
$idf = &find_named_folder($in{'id'}, \@folders);
$in{'folder'} = $idf->{'index'} if ($idf);
}
elsif (!defined($in{'folder'}) && $userconfig{'default_folder'}) {
# No folder specified .. find the default by preferences
$df = &find_named_folder($userconfig{'default_folder'}, \@folders);
$in{'folder'} = $df->{'index'} if ($df);
}
# Get the folder by index
($folder) = grep { $_->{'index'} == $in{'folder'} } @folders;
# Show page header
print "Refresh: $userconfig{'refresh'}\r\n"
if ($userconfig{'refresh'});
($qtotal, $qcount, $totalquota, $countquota) = &get_user_quota();
if ($totalquota) {
push(@topright, &text('mail_quota', &nice_size($qtotal),
&nice_size($totalquota)));
}
if (($folder->{'type'} == 2 || $folder->{'type'} == 4) &&
$folder->{'mode'} == 3 && defined($folder->{'user'}) &&
!$folder->{'autouser'}) {
push(@topright, "".
($folder->{'type'} == 2 ? $text{'mail_logout'}
: $text{'mail_logout2'}).
"");
}
&ui_print_header(undef, &text('index_title', $folder->{'name'}), "", undef,
1, 1, 0, join("
", @topright));
print &check_clicks_function();
# Check if this is a POP3 or IMAP inbox with no login set
if (($folder->{'type'} == 2 || $folder->{'type'} == 4) &&
$folder->{'mode'} == 3 && !$folder->{'autouser'} && !$folder->{'user'}) {
print &ui_form_start("inbox_login.cgi", "post");
print &ui_hidden("folder", $folder->{'index'}),"\n";
print &ui_table_start(
$folder->{'type'} == 2 ? $text{'mail_loginheader'}
: $text{'mail_loginheader2'}, undef, 2);
print &ui_table_row(undef, &text('mail_logindesc',
"$folder->{'server'}"), 2);
print &ui_table_row($text{'mail_loginuser'},
&ui_textbox("user", $remote_user, 30));
print &ui_table_row($text{'mail_loginpass'},
&ui_password("pass", $remote_pass, 30));
print &ui_table_end();
print &ui_form_end([ [ "login", $text{'mail_login'} ] ]);
&ui_print_footer("/", $text{'index'});
exit;
}
# Get folder-selection HTML
$sel = &folder_select(\@folders, $folder, "id", undef, 1, 1);
# Work out start from jump page
$perpage = $folder->{'perpage'} || $userconfig{'perpage'} || 20;
if ($in{'jump'} =~ /^\d+$/ && $in{'jump'} > 0) {
$in{'start'} = ($in{'jump'}-1)*$perpage;
}
# View mail in sort order
@mail = &mailbox_list_mails_sorted(
int($in{'start'}), int($in{'start'})+$perpage-1,
$folder, 1, \@error);
if ($in{'start'} >= @mail && $in{'jump'}) {
# Jumped too far!
$in{'start'} = @mail - $perpage;
@mail = &mailbox_list_mails_sorted(int($in{'start'}),
int($in{'start'})+$perpage-1,
$folder, 1, \@error);
}
# Show page flipping arrows
&show_arrows();
# Work out displayed range
$start = int($in{'start'});
$end = $in{'start'}+$perpage-1;
$end = scalar(@mail)-1 if ($end >= scalar(@mail));
# Start of form
print &ui_form_start("delete_mail.cgi", "post");
print &ui_hidden("folder", $folder->{'index'});
print &ui_hidden("mod", &modification_time($folder));
print &ui_hidden("start", $in{'start'});
# Buttons at top
if ($userconfig{'top_buttons'} && @mail) {
&show_mailbox_buttons(1, \@folders, $folder, \@mail);
@links = ( &select_all_link("d", 1),
&select_invert_link("d", 1),
&select_status_link("d", 1, $folder, \@mail, $start, $end,
1, $text{'mail_selread'}),
&select_status_link("d", 1, $folder, \@mail, $start, $end,
0, $text{'mail_selunread'}),
&select_status_link("d", 1, $folder, \@mail, $start, $end,
2, $text{'mail_selspecial'}),
);
($sortfield, $sortdir) = &get_sort_field($folder);
if ($sortfield) {
# Show un-sort link
push(@links, "$text{'mail_nosort'}");
}
print &ui_links_row(\@links);
}
# Generate mail list headers
$showto = $folder->{'show_to'};
$showfrom = $folder->{'show_from'};
if (@mail) {
@cols = ( "" );
@tds = ( "width=5" );
if ($showfrom) {
push(@cols, &field_sort_link($text{'mail_from'}, "from",
$folder, $in{'start'}));
push(@tds, $showto ? "nowrap width=15%"
: "nowrap width=30%");
}
if ($showto) {
push(@cols, &field_sort_link($text{'mail_to'}, "to",
$folder, $in{'start'}));
push(@tds, $showfrom ? "nowrap width=15%"
: "nowrap width=30%");
}
push(@cols, &field_sort_link($text{'mail_date'}, "date",
$folder, $in{'start'}));
push(@tds, "nowrap width=15%");
push(@cols, &field_sort_link($text{'mail_size'}, "size",
$folder, $in{'start'}));
push(@tds, "nowrap width=10%");
if ($folder->{'spam'}) {
push(@cols, &field_sort_link($text{'mail_level'}, "x-spam-status",
$folder, $in{'start'}));
push(@tds, "width=2%");
}
push(@cols, &field_sort_link($text{'mail_subject'}, "subject",
$folder, $in{'start'}));
push(@tds, "width=50%");
print &ui_columns_start(\@cols, "100", 0, \@tds);
}
if (@error) {
print "