2 ################################################################################
4 # File: $RCSfile: display.cgi,v $
5 # Revision: $Revision: 1.1 $
6 # Description: Displays an email message
7 # Author: Andrew@DeFaria.com
8 # Created: Fri Nov 29 14:17:21 2002
9 # Modified: $Date: 2013/06/12 14:05:47 $
12 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
14 ################################################################################
19 $0 = $FindBin::Script;
21 use lib "$FindBin::Bin/../lib";
26 use CGI qw/:standard *table/;
27 use CGI::Carp "fatalsToBrowser";
31 use MIME::Words qw(:all);
33 my $userid = cookie('MAPSUser');
34 my $sender = param('sender');
35 my $msg_date = param('msg_date');
36 my $table_name = 'message';
43 # First output the header information. Note we'll skip uninteresting stuff
45 last if ($_ eq '' || $_ eq "\cM");
51 if (/^from:\s*(.*)/i) {
53 } elsif (/^subject:\s*(.*)/i) {
54 $header{Subject} = $1;
55 } elsif (/^date:\s*(.*)/i) {
57 } elsif (/^To:\s*(.*)/i) {
59 } elsif (/^Content-Transfer-Encoding: base64/) {
70 # Find unique message using $date
71 my $handle = FindEmail $sender, $date;
73 my ($userid, $sender, $subject, $timestamp, $message) = GetEmail $handle;
75 my $parser = MIME::Parser->new();
77 $parser->output_to_core(1);
79 my $entity = $parser->parse_data ($message);
81 my %header = ParseEmail @{($entity->header)[0]};
84 print start_table ({-align => "center",
90 print start_table ({-align => "center",
91 -bgcolor => "#d4d0c8",
95 -width => "100%"}) . "\n";
96 print "<tbody><tr><td>\n";
97 print start_table ({-align => "center",
101 -bgcolor => "#ece9d8",
102 -width => "100%"}) . "\n";
104 for (keys (%header)) {
107 my $str = decode_mimewords($header{$_});
110 th ({-align => "right",
111 -bgcolor => "#ece9d8",
112 -width => "8%"}, "$_:") . "\n" .
113 td ({-bgcolor => "white"}, $str)
121 print start_table ({-align => "center",
126 -width => "100%"}) . "\n";
127 print "<tbody><tr><td>\n";
128 print start_table ({-align => "center",
133 -width => "100%"}) . "\n";
134 print "<tbody><tr><td>\n";
136 my @parts = $entity->parts;
138 if (scalar @parts == 0) {
139 if ($entity->{mail_inet_head}{mail_hdr_hash}{'Content-Transfer-Encoding'} and
140 ${$entity->{mail_inet_head}{mail_hdr_hash}{'Content-Transfer-Encoding'}[0]} =~ /base64/) {
141 print $entity->{ME_Bodyhandle}{MBS_Data};
148 for my $part ($entity->parts) {
149 # We assume here that if this part is multipart/alternative then
150 # there exists at least one part that is text/html and we favor
151 # that (since we're outputing to a web page anyway...
152 if ($part->mime_type eq 'multipart/alternative') {
153 for my $subpart ($part->parts) {
154 if ($subpart->mime_type eq 'text/html') {
155 # There should be an easier way to get this but I couldn't find one.
156 my $encoding = ${$subpart->{mail_inet_head}{mail_hdr_hash}{'Content-Transfer-Encoding'}[0]};
157 if ($encoding =~ /base64/) {
158 $subpart->bodyhandle->print();
160 $subpart->print_body;
163 } elsif ($subpart->mime_type eq 'multipart/related') {
164 # This is stupid - multipart/related? When it's really just HTML?!?
165 $subpart->print_body;
169 } elsif ($part->mime_type eq 'multipart/related') {
170 # Sometimes parts are 'multipart/relative'...
173 if ($part->mime_type =~ /text/) {
176 $encoding = ${$part->{mail_inet_head}{mail_hdr_hash}{'Content-Transfer-Encoding'}[0]}
177 if $part->{mail_inet_head}{mail_hdr_hash}{'Content-Transfer-Encoding'};
179 if ($encoding =~ /base64/) {
180 $part->bodyhandle->print();
191 print "</td></tr>\n";
193 print "</td></tr>\n";
201 "Email message from $sender",
202 "Email message from $sender",
208 NavigationBar($userid);
212 Footing($table_name);