#!/usr/local/bin/perl # view_mail.cgi # View a single email message require './mailboxes-lib.pl'; $force_charset = ''; &ReadParse(); &can_user($in{'user'}) || &error($text{'mail_ecannot'}); if (&is_user($in{'user'})) { @uinfo = &get_mail_user($in{'user'}); @uinfo || &error($text{'view_eugone'}); } $uuser = &urlize($in{'user'}); @folders = &list_user_folders($in{'user'}); $folder = $folders[$in{'folder'}]; @mail = &mailbox_list_mails($in{'idx'}, $in{'idx'}, $folder); $mail = $mail[$in{'idx'}]; &parse_mail($mail, undef, $in{'raw'}); @sub = split(/\0/, $in{'sub'}); $subs = join("", map { "&sub=$_" } @sub); foreach $s (@sub) { # We are looking at a mail within a mail .. local $amail = &extract_mail($mail->{'attach'}->[$s]->{'data'}); &parse_mail($amail, undef, $in{'raw'}); $mail = $amail; } dbmopen(%read, "$module_config_directory/$in{'user'}.read", 0600); eval { $read{$mail->{'header'}->{'message-id'}} = 1 } if (!$read{$mail->{'header'}->{'message-id'}}); if ($in{'raw'}) { # Special mode - viewing whole raw message print "Content-type: text/plain\n\n"; if ($mail->{'fromline'}) { print $mail->{'fromline'},"\n"; } if (defined($mail->{'rawheaders'})) { #$mail->{'rawheaders'} =~ s/(\S)\t/$1\n\t/g; print $mail->{'rawheaders'}; } else { foreach $h (@{$mail->{'headers'}}) { #$h->[1] =~ s/(\S)\t/$1\n\t/g; print "$h->[0]: $h->[1]\n"; } } print "\n"; print $mail->{'body'}; exit; } # Find body attachment and type ($textbody, $htmlbody, $body) = &find_body($mail, $config{'view_html'}); $body = $htmlbody if ($in{'body'} == 2); $body = $textbody if ($in{'body'} == 1); @attach = @{$mail->{'attach'}}; # Show pre-body HTML if ($body && $body eq $htmlbody) { $headstuff = &head_html($body->{'data'}); } &mail_page_header($text{'view_title'}, $headstuff, undef, &folder_link($in{'user'}, $folder)); print &check_clicks_function(); &show_arrows(); print "
\n"; dbmclose(%read); local @sr = !@sub ? ( ) : ( "view_mail.cgi?idx=$in{'idx'}", $text{'view_return'} ), $s = int((@mail - $in{'idx'} - 1) / $config{'perpage'}) * $config{'perpage'}; &mail_page_footer(@sub ? ( "view_mail.cgi?idx=$in{'idx'}&folder=$in{'folder'}&user=$uuser", $text{'view_return'} ) : ( ), "list_mail.cgi?folder=$in{'folder'}&user=$uuser", $text{'mail_return'}, "", $text{'index_return'}); # show_mail_buttons(pos, submode) sub show_mail_buttons { local $spacer = " \n"; if (!$_[1]) { print ""; print $spacer; if (!$folder->{'sent'} && !$folder->{'drafts'}) { $m = $read{$mail->{'header'}->{'message-id'}}; print ""; print ""; print $spacer; } } if (&is_user($in{'user'})) { print ""; print $spacer; } print ""; print $spacer; if (&is_user($in{'user'})) { print ""; print ""; print $spacer; } print ""; print $spacer; # Show spam report buttons @modules = &get_available_module_infos(1); ($hasspam) = grep { $_->{'dir'} eq "spam" } @modules; if (&foreign_installed("spam") && $config{'spam_buttons'} =~ /mail/ && &spam_report_cmd($in{'user'})) { if ($hasspam) { print ""; } if ($config{'spam_del'}) { print "\n"; } else { print "\n"; } } print "
\n";
}
print "",&text('view_desc', $in{'idx'}+1,
$folder->{'name'}),"\n";
if ($in{'idx'} < @mail-1) {
print "",
"
\n";
}
}
else {
print "$text{'view_sub'}\n";
}
print "