Skip to content
Browse files

More ui-libification and re-factoring

  • Loading branch information...
1 parent e444e0b commit 0e151d03a112d0e360f79258e91de7465cea3b77 @jcameron jcameron committed Oct 2, 2008
View
2 mailboxes/boxes-lib.pl
@@ -1980,7 +1980,7 @@ sub write_maildir
# Bring cache up to date
$now--;
local $lref = &read_file_lines($cachefile);
- push(@$lref, "cur/$now.$$.$hn");
+ push(@$lref, "cur/$now.$$.$main::write_maildir_count.$hn");
&flush_file_lines($cachefile);
}
}
View
43 mailboxes/folders-lib.pl
@@ -3229,5 +3229,48 @@ sub attachments_table
return @detach;
}
+# message_icons(&mail, showto, &folder)
+# Returns a list of icon images for some mail
+sub message_icons
+{
+local ($mail, $showto, $folder) = @_;
+local @rv;
+if (&mail_has_attachments($mail, $folder)) {
+ push(@rv, "<img src=images/attach.gif alt='A'>");
+ }
+local $p = int($mail->{'header'}->{'x-priority'});
+if ($p == 1) {
+ push(@rv, "<img src=images/p1.gif alt='P1'>");
+ }
+elsif ($p == 2) {
+ push(@rv, "<img src=images/p2.gif alt='P2'>");
+ }
+
+# Show icons if special or replied to
+local $read = &get_mail_read($folder, $mail);
+if ($read&2) {
+ push(@rv, "<img src=images/special.gif alt='*'>");
+ }
+if ($read&4) {
+ push(@rv, "<img src=images/replied.gif alt='R'>");
+ }
+
+if ($showto && defined(&open_dsn_hash)) {
+ # Show icons if DSNs received
+ &open_dsn_hash();
+ local $mid = $mail->{'header'}->{'message-id'};
+ if ($dsnreplies{$mid}) {
+ push(@rv, "<img src=images/dsn.gif alt='R'>");
+ }
+ if ($delreplies{$mid}) {
+ local ($bounce) = grep { /^\!/ }
+ split(/\s+/, $delreplies{$mid});
+ local $img = $bounce ? "red.gif" : "box.gif";
+ push(@rv, "<img src=images/$img alt='D'>");
+ }
+ }
+return @rv;
+}
+
1;
View
82 mailboxes/list_mail.cgi
@@ -72,96 +72,20 @@ if (@error) {
print "</font></b></center>\n";
}
-$showto = $folder->{'sent'} || $folder->{'drafts'};
-@tds = ( "width=5", "nowrap", "nowrap", "nowrap", "nowrap" );
-if (@mail) {
- # Show mailbox headers
- local @hcols;
- push(@hcols, "");
- push(@hcols, $showto ? $text{'mail_to'} : $text{'mail_from'});
- push(@hcols, $config{'show_to'} ? $showto ? ( $text{'mail_from'} ) :
- ( $text{'mail_to'} ) : ());
- push(@hcols, $text{'mail_date'});
- push(@hcols, $text{'mail_size'});
- push(@hcols, $text{'mail_subject'});
- @links = ( &select_all_link("d", 1),
- &select_invert_link("d", 1) );
- print &ui_links_row(\@links);
- print &ui_columns_start(\@hcols, 100, 0, \@tds);
- }
-
# Get the mails
@showmail = ( );
for($i=$in{'start'}; $i<@mail && $i<$in{'start'}+$perpage; $i++) {
push(@showmail, $mail[$i]);
}
@hasattach = &mail_has_attachments(\@showmail, $folder);
-# Show rows for actual mail messages
-$i = 0;
-foreach my $mail (@showmail) {
- local $idx = $mail->{'idx'};
- local $cols = 0;
- local @cols;
- local $from = $mail->{'header'}->{$showto ? 'to' : 'from'};
- $from = $text{'mail_unknown'} if ($from !~ /\S/);
- push(@cols, &view_mail_link($in{'user'}, $folder, $idx, $from));
- if ($config{'show_to'}) {
- push(@cols, &simplify_from(
- $mail->{'header'}->{$showto ? 'from' : 'to'}));
- }
- push(@cols, &simplify_date($mail->{'header'}->{'date'}));
- push(@cols, &nice_size($mail->{'size'}, 1024));
- local $tbl;
- $tbl .= "<table border=0 cellpadding=0 cellspacing=0 width=100%>".
- "<tr><td>".&simplify_subject($mail->{'header'}->{'subject'}).
- "</td> <td align=right>";
- if ($hasattach[$i]) {
- $tbl .= "<img src=images/attach.gif>";
- }
- local $p = int($mail->{'header'}->{'x-priority'});
- if ($p == 1) {
- $tbl .= "&nbsp;<img src=images/p1.gif>";
- }
- elsif ($p == 2) {
- $tbl .= "&nbsp;<img src=images/p2.gif>";
- }
- if (!$showto) {
- if ($read{$mail->{'header'}->{'message-id'}} == 2) {
- $tbl .= "&nbsp;<img src=images/special.gif>";
- }
- elsif ($read{$mail->{'header'}->{'message-id'}} == 1) {
- $tbl .= "&nbsp;<img src=images/read.gif>";
- }
- }
- $tbl .= "</td></tr></table>\n";
- push(@cols, $tbl);
-
- if (&editable_mail($mail)) {
- print &ui_checked_columns_row(\@cols, \@tds, "d", $idx);
- }
- else {
- print &ui_columns_row([ "", @cols ], \@tds);
- }
-
- if ($config{'show_body'}) {
- # Show part of the body too
- &parse_mail($mail);
- local $data = &mail_preview($mail);
- if ($data) {
- print "<tr $cb> <td colspan=",(scalar(@cols)+1),"><tt>",
- &html_escape($data),"</tt></td> </tr>\n";
- }
- }
- $i++;
- }
+# Show them
if (@mail) {
- print &ui_columns_end();
- print &ui_links_row(\@links);
+ &show_mail_table(\@showmail, $folder, 1);
}
&show_buttons(2, \@folders, $folder, \@mail, $in{'user'});
-print "</form>\n";
+print &ui_form_end();
if ($config{'arrows'} && @mail) {
# Show page flipping arrows at the bottom
&show_arrows();
View
95 mailboxes/mail_search.cgi
@@ -103,98 +103,19 @@ else {
}
@rv = reverse(@rv);
-$showto = $folder->{'sent'} || $folder->{'drafts'};
+# Show list of messages, with form
if (@rv) {
- print "<form action=delete_mail.cgi method=post>\n";
- print "<input type=hidden name=folder value='$in{'folder'}'>\n";
- print "<input type=hidden name=user value='$in{'user'}'>\n";
- if ($config{'top_buttons'}) {
- if (!$multi_folder) {
- &show_buttons(1, \@folders, $folder, \@rv, $in{'user'},
- 1);
- @links = ( &select_all_link("d", 0),
- &select_invert_link("d", 0) );
- print &ui_links_row(\@links);
- }
- }
-
- # Show mailbox headers
- local @hcols;
- push(@hcols, "");
- push(@hcols, $showto ? $text{'mail_to'} : $text{'mail_from'});
- push(@hcols, $config{'show_to'} ? $showto ? ( $text{'mail_from'} ) :
- ( $text{'mail_to'} ) : ());
- push(@hcols, $text{'mail_date'});
- push(@hcols, $text{'mail_size'});
- push(@hcols, $text{'mail_subject'});
- print &ui_columns_start(\@hcols, 100, 0, \@tds);
- }
-foreach $m (@rv) {
- local $idx = $m->{'idx'};
- local $mf = $m->{'folder'};
- local @cols;
- local $from = &simplify_from($m->{'header'}->{
- $showto ? 'to' : 'from'});
- $from = $text{'mail_unknown'} if ($from !~ /\S/);
- push(@cols, "<a href='view_mail.cgi?idx=$idx&user=$uuser&folder=$mf->{'index'}'>$from</a>");
- if ($config{'show_to'}) {
- push(@cols, &simplify_from(
- $m->{'header'}->{$showto ? 'from' : 'to'}));
- }
- push(@cols, &simplify_date($m->{'header'}->{'date'}));
- push(@cols, &nice_size($m->{'size'}, 1024));
- local $tbl;
- $tbl .= "<table border=0 cellpadding=0 cellspacing=0 width=100%>".
- "<tr><td>".&simplify_subject($m->{'header'}->{'subject'}).
- "</td> <td align=right>";
- if ($m->{'header'}->{'content-type'} =~ /multipart\/\S+/i) {
- $tbl .= "<img src=images/attach.gif>";
- }
- local $p = int($m->{'header'}->{'x-priority'});
- if ($p == 1) {
- $tbl .= "&nbsp;<img src=images/p1.gif>";
- }
- elsif ($p == 2) {
- $tbl .= "&nbsp;<img src=images/p2.gif>";
- }
- if (!$showto) {
- if ($read{$m->{'header'}->{'message-id'}} == 2) {
- $tbl .= "&nbsp;<img src=images/special.gif>";
- }
- elsif ($read{$m->{'header'}->{'message-id'}} == 1) {
- $tbl .= "&nbsp;<img src=images/read.gif>";
- }
+ print &ui_form_start("delete_mail.cgi", "post");
+ print &ui_hidden("user", $in{'user'});
+ print &ui_hidden("folder", $in{'folder'});
+ if ($config{'top_buttons'} && !$multi_folder) {
+ &show_buttons(1, \@folders, $folder, \@rv, $in{'user'}, 1);
}
- $tbl .= "</td></tr></table>\n";
- push(@cols, $tbl);
-
- if (&editable_mail($m)) {
- print &ui_checked_columns_row(\@cols, \@tds, "d", $idx);
- }
- elsif ($multi_folder) {
- print &ui_columns_row([ $mf->{'name'}, @cols ], \@tds);
- }
- else {
- print &ui_columns_row([ "", @cols ], \@tds);
- }
-
- if ($config{'show_body'}) {
- # Show part of the body too
- &parse_mail($m);
- local $data = &mail_preview($m);
- if ($data) {
- print "<tr $cb> <td colspan=",(scalar(@cols)+1),"><tt>",
- &html_escape($data),"</tt></td> </tr>\n";
- }
- }
- }
-if (@rv) {
- print &ui_columns_end();
+ &show_mail_table(\@rv, $multi_folder ? undef : $ofolder, 0);
if (!$multi_folder) {
- print &ui_links_row(\@links);
&show_buttons(2, \@folders, $folder, \@rv, $in{'user'}, 1);
}
- print "</form><p>\n";
+ print &ui_form_end();
}
else {
print "<b>$text{'search_none'}</b> <p>\n";
View
84 mailboxes/mailboxes-lib.pl
@@ -1170,5 +1170,89 @@ sub set_mail_read
$read{$mail->{'header'}->{'message-id'}} = $read;
}
+# show_mail_table(&mails, &folder, formno)
+# Output a full table of messages
+sub show_mail_table
+{
+local @mail = @{$_[0]};
+local (undef, $folder, $formno) = @_;
+
+my $showto = !$folder ? 0 :
+ $folder->{'sent'} || $folder->{'drafts'} ? 1 : 0;
+my @tds = ( "nowrap", "nowrap", "nowrap", "nowrap" );
+
+# Show mailbox headers
+local @hcols;
+if ($folder) {
+ push(@hcols, "");
+ splice(@tds, "width=5", 0, 0);
+ }
+push(@hcols, $showto ? $text{'mail_to'} : $text{'mail_from'});
+push(@hcols, $config{'show_to'} ? $showto ? ( $text{'mail_from'} ) :
+ ( $text{'mail_to'} ) : ());
+push(@hcols, $text{'mail_date'});
+push(@hcols, $text{'mail_size'});
+push(@hcols, $text{'mail_subject'});
+my @links = ( &select_all_link("d", $formno),
+ &select_invert_link("d", $formno) );
+if ($folder) {
+ print &ui_links_row(\@links);
+ }
+print &ui_columns_start(\@hcols, 100, 0, \@tds);
+
+# Show rows for actual mail messages
+my $i = 0;
+foreach my $mail (@mail) {
+ local $idx = $mail->{'idx'};
+ local $cols = 0;
+ local @cols;
+
+ # From and To columns, with links
+ local $from = $mail->{'header'}->{$showto ? 'to' : 'from'};
+ $from = $text{'mail_unknown'} if ($from !~ /\S/);
+ local $mfolder = $mail->{'folder'} || $folder;
+ push(@cols, &view_mail_link($in{'user'}, $mfolder, $idx, $from));
+ if ($config{'show_to'}) {
+ push(@cols, &simplify_from(
+ $mail->{'header'}->{$showto ? 'from' : 'to'}));
+ }
+
+ # Date and size columns
+ push(@cols, &simplify_date($mail->{'header'}->{'date'}));
+ push(@cols, &nice_size($mail->{'size'}, 1024));
+
+ # Subject with icons
+ local @icons = &message_icons($mail, $mfolder->{'sent'}, $mfolder);
+ push(@cols, &simplify_subject($mail->{'header'}->{'subject'}).
+ join("&nbsp;", @icons));
+
+ # Generate the row
+ if (!$folder) {
+ print &ui_columns_row(\@cols, \@tds);
+ }
+ elsif (&editable_mail($mail)) {
+ print &ui_checked_columns_row(\@cols, \@tds, "d", $idx);
+ }
+ else {
+ print &ui_columns_row([ "", @cols ], \@tds);
+ }
+
+ if ($config{'show_body'}) {
+ # Show part of the body too
+ &parse_mail($mail);
+ local $data = &mail_preview($mail);
+ if ($data) {
+ print "<tr $cb> <td colspan=",(scalar(@cols)+1),"><tt>",
+ &html_escape($data),"</tt></td> </tr>\n";
+ }
+ }
+ $i++;
+ }
+print &ui_columns_end();
+if ($folder) {
+ print &ui_links_row(\@links);
+ }
+}
+
1;
View
74 mailboxes/search_form.cgi
@@ -11,42 +11,48 @@ require './mailboxes-lib.pl';
&ui_print_header(undef, $text{'sform_title'}, "", undef, 0, 0, undef,
&folder_link($in{'user'}, $folder));
-print "<form action=mail_search.cgi>\n";
-print "<input type=hidden name=user value='$in{'user'}'>\n";
-print "<input type=hidden name=ofolder value='$in{'folder'}'>\n";
-print "<input type=radio name=and value=1 checked> $text{'sform_and'}\n";
-print "<input type=radio name=and value=0> $text{'sform_or'}<p>\n";
-
-print "<table>\n";
-#print "<tr> <td><b>$text{'sform_field'}</b></td> ",
-# "<td><b>$text{'sform_mode'}</b></td> ",
-# "<td><b>$text{'sform_for'}</b></td> </tr>\n";
-for($i=0; $i<=9; $i++) {
- print "<tr>\n";
- print "<td>$text{'sform_where'}</td>\n";
- print "<td><select name=field_$i>\n";
- print "<option value=''>&nbsp;\n";
- foreach $f ('from', 'subject', 'to', 'cc', 'date', 'body', 'headers', 'size') {
- print "<option value=$f>",$text{"sform_$f"},"\n";
- }
- print "</select></td>\n";
-
- print "<td><select name=neg_$i>\n";
- print "<option value=0 checked>$text{'sform_neg0'}\n";
- print "<option value=1>$text{'sform_neg1'}\n";
- print "</select></td>\n";
-
- print "<td>$text{'sform_text'}</td>\n";
- print "<td><input name=what_$i size=30></td>\n";
- print "</tr>\n";
+# Start of form
+print &ui_form_start("mail_search.cgi");
+print &ui_hidden("user", $in{'user'});
+print &ui_hidden("ofolder", $in{'folder'});
+print &ui_table_start($text{'sform_header'}, "width=100%", 2);
+
+# And/or mode
+print &ui_table_row($text{'sform_andmode'},
+ &ui_radio("and", 1, [ [ 1, $text{'sform_and'} ],
+ [ 0, $text{'sform_or'} ] ]));
+
+# Criteria table
+$ctable = &ui_columns_start([ ], 50, 1);
+
+for($i=0; $i<=4; $i++) {
+ local @cols;
+ push(@cols, $text{'sform_where'});
+ push(@cols, &ui_select("field_$i", undef,
+ [ [ undef, "&nbsp;" ],
+ map { [ $_, $_ eq 'all' ? $text{'sform_allmsg'}
+ : $text{"sform_".$_} ] }
+ ( 'from', 'subject', 'to', 'cc', 'date',
+ 'body', 'headers', 'all', 'size') ]));
+
+ push(@cols, &ui_select("neg_$i", 0,
+ [ [ 0, $text{'sform_neg0'} ],
+ [ 1, $text{'sform_neg1'} ] ]));
+
+ push(@cols, $text{'sform_text'});
+ push(@cols, &ui_textbox("what_$i", undef, 30));
+ $ctable .= &ui_columns_row(\@cols, [ map { "nowrap" } @cols ]);
}
-print "</table><br>\n";
+$ctable .= &ui_columns_end();
+print &ui_table_row(" ", $ctable, 1);
-$extra = "<option value=-1>$text{'sform_all'}\n";
-print "<input type=submit value='$text{'sform_ok'}'>\n";
-print " $text{'sform_folder'} ",&folder_select(\@folders, $folder, "folder",
- $extra);
-print "</form>\n";
+# Folder to search
+print &ui_table_row($text{'sform_folder2'},
+ &folder_select(\@folders, $folder, "folder",
+ [ [ -1, $text{'sform_all'} ] ]));
+
+print &ui_table_end();
+print &ui_form_end([ [ undef, $text{'sform_ok'} ] ]);
&ui_print_footer("list_mail.cgi?folder=$in{'folder'}&user=".
&urlize($in{'user'}), $text{'mail_return'},
View
2 mailboxes/view_mail.cgi
@@ -48,7 +48,7 @@ if ($in{'raw'}) {
}
print "\n";
print $mail->{'body'};
- exit;
+ return;
}
# Find body attachment and type

0 comments on commit 0e151d0

Please sign in to comment.
Something went wrong with that request. Please try again.