X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=maps%2Fbin%2Fdisplay.cgi;h=533ecae8eb94911ae4a6606fc2a8d8b59a732733;hb=6ee4bd4718471ce8ba4a8416a0bee09b082e0f13;hp=28d46dd9c0d2270a34550b9d99929dddb8c3dda9;hpb=fc660883a0ead878621680ab6945a53f0ecdd043;p=clearscm.git diff --git a/maps/bin/display.cgi b/maps/bin/display.cgi index 28d46dd..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) = @_; +sub Body($) { + my ($date) = @_; - $count ||= 1; + # Find unique message using $date + my $handle = FindEmail $sender, $date; - my $handle = FindEmail $sender; + my ($userid, $sender, $subject, $timestamp, $message) = GetEmail $handle; - my ($userid, $sender, $subject, $timestamp, $message); - - # Need to handle multiple messages - for (my $i = 0; $i < $count; $i++) { - ($userid, $sender, $subject, $timestamp, $message) = GetEmail $handle; - } # for + my $parser = MIME::Parser->new(); - my $parser = new MIME::Parser; - - $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,10 +173,17 @@ 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/) { - my $encoding = ${$part->{mail_inet_head}{mail_hdr_hash}{'Content-Transfer-Encoding'}[0]}; + 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 { @@ -184,7 +193,7 @@ sub Body ($) { } # if } # if } # if - } # foreach + } # for } # if print "\n"; @@ -194,7 +203,7 @@ sub Body ($) { print end_table; } # Body -$userid = Heading ( +$userid = Heading( 'getcookie', '', "Email message from $sender", @@ -203,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);