X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=maps%2Fbin%2Fdisplay.cgi;h=533ecae8eb94911ae4a6606fc2a8d8b59a732733;hb=56890e6a4f7bd3681fdc4b6db0cdce1ef0ec5e47;hp=57ef8aa7a354cbb43261c7a64b41dfec8477b865;hpb=c769eb436f4b1c6358771b96f98fb11ca8676230;p=clearscm.git diff --git a/maps/bin/display.cgi b/maps/bin/display.cgi index 57ef8aa..533ecae 100755 --- a/maps/bin/display.cgi +++ b/maps/bin/display.cgi @@ -18,7 +18,7 @@ use warnings; use FindBin; $0 = $FindBin::Script; -use lib $FindBin::Bin; +use lib "$FindBin::Bin/../lib"; use MAPS; use MAPSWeb; @@ -32,16 +32,21 @@ use MIME::Words qw(:all); my $userid = cookie('MAPSUser'); my $sender = param('sender'); -my $msg_nbr = param('msg_nbr'); + +# CGI will replace '+' with ' ', which many mailers are starting to do, +# so add it back +$sender =~ s/ /\+/; + +my $msg_date = param('msg_date'); my $table_name = 'message'; -sub ParseEmail (@) { +sub ParseEmail(@) { my (@header) = @_; my %header; # First output the header information. Note we'll skip uninteresting stuff - foreach (@header) { + for (@header) { last if ($_ eq '' || $_ eq "\cM"); # Escape "<" and ">" @@ -59,28 +64,25 @@ sub ParseEmail (@) { } elsif (/^Content-Transfer-Encoding: base64/) { $header{base64} = 1; } # if - } # while + } # for return %header; } # ParseEmail -sub Body ($) { - my ($count) = @_; - - $count ||= 1; - - my $handle = FindEmail $sender; +sub Body($) { + my ($date) = @_; - my ($userid, $sender, $subject, $timestamp, $message); + # Find unique message using $date + my $handle = FindEmail $sender, $date; - # Need to handle multiple messages - for (my $i = 0; $i < $count; $i++) { - ($userid, $sender, $subject, $timestamp, $message) = GetEmail $handle; - } # for + my ($userid, $sender, $subject, $timestamp, $message) = GetEmail $handle; - my $parser = new MIME::Parser; + my $parser = MIME::Parser->new(); - $parser->output_to_core (1); + # For some strange reason MIME::Parser has started having some problems + # with writing out tmp files... + $parser->output_to_core(1); + $parser->tmp_to_core(1); my $entity = $parser->parse_data ($message); @@ -107,10 +109,10 @@ sub Body ($) { -bgcolor => "#ece9d8", -width => "100%"}) . "\n"; - foreach (keys (%header)) { + for (keys (%header)) { next if /base64/; - my $str = decode_mimewords ($header{$_}); + my $str = decode_mimewords($header{$_}); print Tr ([ th ({-align => "right", @@ -118,7 +120,7 @@ sub Body ($) { -width => "8%"}, "$_:") . "\n" . td ({-bgcolor => "white"}, $str) ]); - } # if + } # for print end_table; print ""; @@ -151,12 +153,12 @@ sub Body ($) { print ''; } # if } else { - foreach my $part ($entity->parts) { + for my $part ($entity->parts) { # We assume here that if this part is multipart/alternative then # there exists at least one part that is text/html and we favor # that (since we're outputing to a web page anyway... if ($part->mime_type eq 'multipart/alternative') { - foreach my $subpart ($part->parts) { + for my $subpart ($part->parts) { if ($subpart->mime_type eq 'text/html') { # There should be an easier way to get this but I couldn't find one. my $encoding = ${$subpart->{mail_inet_head}{mail_hdr_hash}{'Content-Transfer-Encoding'}[0]}; @@ -171,15 +173,27 @@ sub Body ($) { $subpart->print_body; last; } # if - } # foreach + } # for + } elsif ($part->mime_type eq 'multipart/related') { + # Sometimes parts are 'multipart/relative'... + $part->print_body; } else { if ($part->mime_type =~ /text/) { - print '
'; - $part->print_body; - print ''; + my $encoding = ''; + + $encoding = ${$part->{mail_inet_head}{mail_hdr_hash}{'Content-Transfer-Encoding'}[0]} + if $part->{mail_inet_head}{mail_hdr_hash}{'Content-Transfer-Encoding'}; + + if ($encoding =~ /base64/) { + $part->bodyhandle->print(); + } else { + print '
'; + $part->print_body; + print ''; + } # if } # if } # if - } # foreach + } # for } # if print "\n"; @@ -189,7 +203,7 @@ sub Body ($) { print end_table; } # Body -$userid = Heading ( +$userid = Heading( 'getcookie', '', "Email message from $sender", @@ -198,9 +212,9 @@ $userid = Heading ( $table_name, ); -SetContext $userid; -NavigationBar $userid; +SetContext($userid); +NavigationBar($userid); -Body $msg_nbr; +Body($msg_date); -Footing $table_name; +Footing($table_name);