#!/usr/local/bin/perl # view_mail.cgi # View a single email message require './spam-lib.pl'; &foreign_require("mailbox", "mailbox-lib.pl"); $folder = &spam_file_folder(); &disable_indexing($folder); $force_charset = ''; &ReadParse(); &ui_print_header(undef, $mailbox::text{'view_title'}, ""); @mail = &mailbox::mailbox_list_mails_sorted($in{'idx'}, $in{'idx'}, $folder); $mail = $mail[$in{'idx'}]; &mailbox::parse_mail($mail); @sub = split(/\0/, $in{'sub'}); $subs = join("", map { "&sub=$_" } @sub); foreach $s (@sub) { # We are looking at a mail within a mail .. &mailbox::decrypt_attachments($mail); local $amail = &mailbox::extract_mail($mail->{'attach'}->[$s]->{'data'}); &mailbox::parse_mail($amail); $mail = $amail; } dbmopen(%read, "$user_config_directory/mailbox/read", 0600); if ($mailbox::userconfig{'auto_mark'}) { eval { $read{$mail->{'header'}->{'message-id'}} = 1 } if (!$read{$mail->{'header'}->{'message-id'}}); } print "
\n"; if (!@sub) { if ($in{'idx'}) { print "", "\n"; } print "",&mailbox::text('view_desc', $in{'idx'}+1, $folder->{'name'}),"\n"; if ($in{'idx'} < @mail-1) { print "", "\n"; } } else { print "$text{'view_sub'}\n"; } print "
\n"; # Check for encryption ($deccode, $decmessage) = &mailbox::decrypt_attachments($mail); @attach = @{$mail->{'attach'}}; # Find body attachment and type ($textbody, $htmlbody, $body) = &mailbox::find_body($mail); # XXX look for text/calendar body # Check for signing if (&has_command("gpg") && &foreign_check("gnupg")) { # Check for GnuPG signatures local $sig; foreach $a (@attach) { $sig = $a if ($a->{'type'} =~ /^application\/pgp-signature/); } if ($sig) { # Verify the signature against the rest of the attachment &foreign_require("gnupg", "gnupg-lib.pl"); local $rest = $sig->{'parent'}->{'attach'}->[0]; $rest->{'raw'} =~ s/\r//g; $rest->{'raw'} =~ s/\n/\r\n/g; ($sigcode, $sigmessage) = &foreign_call("gnupg", "verify_data", $rest->{'raw'}, $sig->{'data'}); @attach = grep { $_ ne $sig } @attach; } elsif ($body && $body eq $textbody && $body->{'data'} =~ /(-+BEGIN PGP SIGNED MESSAGE-+\n(Hash:\s+(\S+)\n\n)?([\000-\377]+\n)-+BEGIN PGP SIGNATURE-+\n([\000-\377]+)-+END PGP SIGNATURE-+\n)/i) { # Signature is in body text! local $sig = $1; local $text = $4; &foreign_require("gnupg", "gnupg-lib.pl"); ($sigcode, $sigmessage) = &foreign_call("gnupg", "verify_data", $sig); if ($sigcode == 0 || $sigcode == 1) { # XXX what about replying? $body->{'data'} = $text; } } } # Strip out attachments not to display as icons @attach = grep { $_ ne $body } @attach; @attach = grep { !$_->{'attach'} } @attach; print "\n"; print "\n"; print "
", "\n"; if ($in{'headers'}) { print "\n"; } else { print "\n"; } print "
$mailbox::text{'view_headers'}$mailbox::text{'view_noheaders'}$mailbox::text{'view_allheaders'}
\n"; if ($in{'headers'}) { # Show all the headers if ($mail->{'fromline'}) { print "", "\n"; } foreach $h (@{$mail->{'headers'}}) { print " ", "\n"; } } else { # Just show the most useful headers print " ", "\n"; print " ", "\n"; print " ", "\n" if ($mail->{'header'}->{'cc'}); print " ", "\n"; print " ", "\n"; if (!@sub) { print " ", "\n"; } } print "
$text{'mail_rfc'}",&mailbox::eucconv(&html_escape($mail->{'fromline'})), "
$h->[0]:",&mailbox::eucconv(&html_escape(&mailbox::decode_mimewords($h->[1]))), "
$mailbox::text{'mail_from'}",&address_link($mail->{'header'}->{'from'}),"
$mailbox::text{'mail_to'}",&address_link($mail->{'header'}->{'to'}),"
$mailbox::text{'mail_cc'}",&address_link($mail->{'header'}->{'cc'}),"
$mailbox::text{'mail_date'}",&mailbox::eucconv(&html_escape($mail->{'header'}->{'date'})), "
$mailbox::text{'mail_subject'}",&mailbox::eucconv(&html_escape(&mailbox::decode_mimewords( $mail->{'header'}->{'subject'}))),"
$text{'mail_level2'}",length($mail->{'header'}->{'x-spam-level'}),"

\n"; # Show body attachment, with properly linked URLs if ($body && $body->{'data'} =~ /\S/) { if ($body eq $textbody) { # Show plain text print "
\n";
		foreach $l (&mailbox::wrap_lines($body->{'data'},
					$mailbox::userconfig{'wrap_width'})) {
			print &mailbox::link_urls_and_escape($l),"\n";
			}
		print "

\n"; } elsif ($body eq $htmlbody) { # Attempt to show HTML print "
\n"; print &mailbox::safe_html($body->{'data'}); print "

\n"; } } # Display other attachments if (@attach) { print "\n"; print "\n"; print "
$mailbox::text{'view_attach'}
\n"; foreach $a (@attach) { local $fn; $size = (int(length($a->{'data'})/1000)+1)." Kb"; local $cb; if ($a->{'type'} eq 'message/rfc822') { push(@titles, "$mailbox::text{'view_sub'}
$size"); } elsif ($a->{'filename'}) { push(@titles, &mailbox::decode_mimewords($a->{'filename'}). "
$size"); $fn = &mailbox::decode_mimewords($a->{'filename'}); push(@detach, [ $a->{'idx'}, $fn ]); } else { push(@titles, "$a->{'type'}
$size"); $a->{'type'} =~ /\/(\S+)$/; $fn = "file.$1"; push(@detach, [ $a->{'idx'}, $fn ]); } $fn =~ s/ /_/g; $fn =~ s/\#/_/g; $fn = &html_escape($fn); if ($a->{'type'} eq 'message/rfc822') { push(@links, "view_mail.cgi?idx=$in{'idx'}$subs&sub=$a->{'idx'}"); } else { push(@links, "detach.cgi/$fn?idx=$in{'idx'}&attach=$a->{'idx'}$subs"); } push(@icons, "/mailbox/images/boxes.gif"); } &icons_table(\@links, \@titles, \@icons, 8); print "

\n"; } # Display GnuPG results if (defined($sigcode)) { print "\n"; print "\n"; print "
$mailbox::text{'view_gnupg'}
"; $sigmessage = &html_escape($sigmessage); $sigmessage = $sigmessage if ($sigcode == 4); print &mailbox::text('view_gnupg_'.$sigcode, $sigmessage),"\n"; if ($sigcode == 3) { local $url = "/$module_name/view_mail.cgi?idx=$in{'idx'}&folder=$in{'folder'}$subs"; print "

",&mailbox::text('view_recv', $sigmessage, "/gnupg/recv.cgi?id=$sigmessage&return=".&urlize($url)."&returnmsg=".&urlize($text{'view_return'})),"\n"; } print "

\n"; } if ($deccode) { print "\n"; print "\n"; print "
$text{'view_crypt'}
"; print &mailbox::text('view_crypt_'.$deccode, "
$decmessage
"); print "

\n"; } dbmclose(%read); local @sr = !@sub ? ( ) : ( "view_mail.cgi?idx=$in{'idx'}", $mailbox::text{'view_return'} ), $s = int((@mail - $in{'idx'} - 1) / $mailbox::userconfig{'perpage'}) * $mailbox::userconfig{'perpage'}; &ui_print_footer(@sub ? ( "view_mail.cgi?idx=$in{'idx'}", $mailbox::text{'view_return'} ) : ( ), "mail.cgi", $text{'mail_return'}); # address_link(address) sub address_link { local @addrs = &mailbox::split_addresses(&mailbox::decode_mimewords($_[0])); local @rv; foreach $a (@addrs) { push(@rv, &html_escape($a->[2])); } return join(" , ", @rv); }