Sharedwww / cgi-bin / openwebmail / openwebmail-read.plOpen in CoCalc
Author: William A. Stein
1
#!/usr/bin/perl
2
#
3
# openwebmail-read.pl - message reading program
4
#
5
6
use vars qw($SCRIPT_DIR);
7
if ( $0 =~ m!^(\S*)/[\w\d\-\.]+\.pl! ) { $SCRIPT_DIR=$1 }
8
if ($SCRIPT_DIR eq '' && open(F, '/etc/openwebmail/openwebmail_path.conf')) {
9
$_=<F>; close(F); if ( $_=~/^(\S*)/) { $SCRIPT_DIR=$1 }
10
}
11
if ($SCRIPT_DIR eq '') { print "Content-type: text/html\n\nSCRIPT_DIR not set in /etc/openwebmail/openwebmail_path.conf !\n"; exit 0; }
12
push (@INC, $SCRIPT_DIR);
13
14
foreach (qw(ENV BASH_ENV CDPATH IFS TERM)) {delete $ENV{$_}}; $ENV{PATH}='/bin:/usr/bin'; # secure ENV
15
umask(0002); # make sure the openwebmail group can write
16
17
use strict;
18
use Fcntl qw(:DEFAULT :flock);
19
use CGI qw(-private_tempfiles :standard);
20
use CGI::Carp qw(fatalsToBrowser carpout);
21
use MIME::Base64;
22
use MIME::QuotedPrint;
23
24
require "modules/dbm.pl";
25
require "modules/suid.pl";
26
require "modules/filelock.pl";
27
require "modules/tool.pl";
28
require "modules/datetime.pl";
29
require "modules/lang.pl";
30
require "modules/htmlrender.pl";
31
require "modules/htmltext.pl";
32
require "modules/enriched.pl";
33
require "modules/mime.pl";
34
require "modules/tnef.pl";
35
require "modules/mailparse.pl";
36
require "modules/spamcheck.pl";
37
require "modules/viruscheck.pl";
38
require "auth/auth.pl";
39
require "quota/quota.pl";
40
require "shares/ow-shared.pl";
41
require "shares/iconv.pl";
42
require "shares/maildb.pl";
43
require "shares/cut.pl";
44
require "shares/getmsgids.pl";
45
require "shares/getmessage.pl";
46
require "shares/lockget.pl";
47
require "shares/mailfilter.pl";
48
49
# common globals
50
use vars qw(%config %config_raw);
51
use vars qw($thissession);
52
use vars qw($domain $user $userrealname $uuid $ugid $homedir);
53
use vars qw(%prefs %style %icontext);
54
use vars qw($quotausage $quotalimit);
55
56
# extern vars
57
use vars qw(%lang_folders %lang_sizes %lang_wdbutton %lang_text %lang_err); # defined in lang/xy
58
use vars qw(%charset_convlist); # defined in iconv.pl
59
use vars qw($_STATUS); # defined in maildb.pl
60
61
# local globals
62
use vars qw($folder);
63
use vars qw($sort $page $longpage);
64
use vars qw($searchtype $keyword);
65
use vars qw($escapedfolder $escapedkeyword);
66
67
use vars qw(%smilies);
68
%smilies = (
69
":)" => "FaceHappy",
70
":>" => "FaceHappy",
71
";)" => "FaceWinking",
72
";>" => "FaceWinking",
73
";(" => "FaceSad",
74
";<" => "FaceSad",
75
":(" => "FaceSad",
76
":<" => "FaceSad",
77
">:)" => "FaceDevilish",
78
">;)" => "FaceDevilish",
79
"8)" => "FaceGrinning",
80
"8>" => "FaceGrinning",
81
":D" => "FaceGrinning",
82
";D" => "FaceGrinning",
83
"8D" => "FaceGrinning",
84
":d" => "FaceTasty",
85
";d" => "FaceTasty",
86
"8d" => "FaceTasty",
87
":P" => "FaceNyah",
88
";P" => "FaceNyah",
89
"8P" => "FaceNyah",
90
":p" => "FaceNyah",
91
";p" => "FaceNyah",
92
"8p" => "FaceNyah",
93
":O" => "FaceStartled",
94
";O" => "FaceStartled",
95
"8O" => "FaceStartled",
96
":o" => "FaceStartled",
97
";o" => "FaceStartled",
98
"8o" => "FaceStartled",
99
":/" => "FaceIronic",
100
";/" => "FaceIronic",
101
"8/" => "FaceIronic",
102
":\\" => "FaceIronic",
103
";\\" => "FaceIronic",
104
"8\\" => "FaceIronic",
105
":|" => "FaceStraight",
106
";|" => "FaceWry",
107
"8|" => "FaceKOed",
108
":X" => "FaceYukky",
109
";X" => "FaceYukky" );
110
111
########## MAIN ##################################################
112
openwebmail_requestbegin();
113
$SIG{PIPE}=\&openwebmail_exit; # for user stop
114
$SIG{TERM}=\&openwebmail_exit; # for user stop
115
$SIG{CHLD}='IGNORE'; # prevent zombie
116
117
userenv_init();
118
119
if (!$config{'enable_webmail'}) {
120
openwebmailerror(__FILE__, __LINE__, "$lang_text{'webmail'} $lang_err{'access_denied'}");
121
}
122
123
$folder = param('folder') || 'INBOX';
124
$page = param('page') || 1;
125
$longpage = param('longpage') || 0;
126
$sort = param('sort') || $prefs{'sort'} || 'date';
127
$searchtype = param('searchtype') || 'subject';
128
$keyword = param('keyword') || '';
129
130
$escapedfolder = ow::tool::escapeURL($folder);
131
$escapedkeyword = ow::tool::escapeURL($keyword);
132
133
my $action = param('action')||'';
134
if ($action eq "readmessage") {
135
readmessage(param('message_id')||'');
136
} elsif ($action eq "rebuildmessage") {
137
rebuildmessage(param('partialid')||'');
138
} else {
139
openwebmailerror(__FILE__, __LINE__, "Action $lang_err{'has_illegal_chars'}");
140
}
141
142
openwebmail_requestend();
143
########## END MAIN ##############################################
144
145
########## READMESSAGE ###########################################
146
sub readmessage {
147
my $messageid = $_[0];
148
149
# filtermessage in background, hope junk is removed before displayed to user
150
filtermessage($user, 'INBOX', \%prefs) if ($folder eq 'INBOX');
151
152
my (@validfolders, $inboxusage, $folderusage);
153
getfolders(\@validfolders, \$inboxusage, \$folderusage);
154
155
my $quotahit_deltype='';
156
if ($quotalimit>0 && $quotausage>$quotalimit &&
157
($config{'delmail_ifquotahit'}||$config{'delfile_ifquotahit'}) ) {
158
$quotausage=(ow::quota::get_usage_limit(\%config, $user, $homedir, 1))[2]; # get uptodate usage
159
if ($quotausage>$quotalimit) {
160
if ($config{'delmail_ifquotahit'} && $folderusage > $quotausage*0.5) {
161
$quotahit_deltype='quotahit_delmail';
162
cutfoldermails(($quotausage-$quotalimit*0.9)*1024, $user, @validfolders);
163
} elsif ($config{'delfile_ifquotahit'}) {
164
$quotahit_deltype='quotahit_delfile';
165
my $webdiskrootdir=$homedir.absolute_vpath("/", $config{'webdisk_rootpath'});
166
cutdirfiles(($quotausage-$quotalimit*0.9)*1024, $webdiskrootdir);
167
}
168
$quotausage=(ow::quota::get_usage_limit(\%config, $user, $homedir, 1))[2]; # get uptodate usage
169
}
170
}
171
172
my $escapedmessageid = ow::tool::escapeURL($messageid);
173
174
# Determine message's number and previous and next message IDs.
175
my ($totalsize, $newmessages, $r_messageids)=getinfomessageids($user, $folder, $sort, $searchtype, $keyword);
176
my ($message_num, $message_total, $messageid_prev, $messageid_next)=(-1, 0, '', '');
177
foreach my $i (0..$#{$r_messageids}) {
178
if (${$r_messageids}[$i] eq $messageid) {
179
$message_num = $i+1;
180
$message_total = $#{$r_messageids}+1;
181
$messageid_prev = ${$r_messageids}[$i-1] if ($i > 0);
182
$messageid_next = ${$r_messageids}[$i+1] if ($i < $#{$r_messageids});
183
last;
184
}
185
}
186
if ($message_num<0) { # message id not found
187
print redirect(-location=>"$config{'ow_cgiurl'}/openwebmail-main.pl?action=listmessages&page=$page&sessionid=$thissession&sort=$sort&keyword=$escapedkeyword&searchtype=$searchtype&folder=$escapedfolder");
188
return;
189
}
190
191
my %message = %{&getmessage($user, $folder, $messageid)};
192
193
$page=int($message_num/($prefs{'msgsperpage'}||10)+0.999999)||$page;
194
195
my $headers = param('headers') || $prefs{'headers'} || 'simple';
196
my $attmode = param('attmode') || 'simple';
197
my $printfriendly = param('printfriendly') ||'';
198
199
my $showhtmlastext=$prefs{'showhtmlastext'};
200
$showhtmlastext=param('showhtmlastext') if (param('showhtmlastext') ne "");
201
202
my $convfrom=param('convfrom')||lc($message{'charset'});
203
if ($convfrom eq '' && $prefs{'charset'} eq 'utf-8') {
204
# assume msg is from sender using same language as the recipient's browser
205
$convfrom=$ow::lang::languagecharsets{ow::lang::guess_language()};
206
}
207
$convfrom="none.$prefs{'charset'}" if ($convfrom!~/^none\./ && !is_convertable($convfrom, $prefs{'charset'}));
208
my $readcharset=$prefs{'charset'}; # charset choosed by user to read current message
209
$readcharset=$1 if ($convfrom=~/^none\.(.+)$/); # read msg with no conversion
210
211
my $urlparm="sessionid=$thissession&amp;folder=$escapedfolder&amp;".
212
"page=$page&amp;longpage=$longpage&amp;".
213
"sort=$sort&amp;keyword=$escapedkeyword&amp;searchtype=$searchtype";
214
my $main_url = "$config{'ow_cgiurl'}/openwebmail-main.pl?$urlparm";
215
my $read_url = "$config{'ow_cgiurl'}/openwebmail-read.pl?$urlparm";
216
my $send_url = "$config{'ow_cgiurl'}/openwebmail-send.pl?$urlparm";
217
my $read_url_with_id = "$read_url&amp;message_id=$escapedmessageid";
218
my $send_url_with_id = "$send_url&amp;message_id=$escapedmessageid".
219
"&amp;showhtmlastext=$showhtmlastext&amp;compose_caller=read";
220
221
my ($html, $temphtml, @tmp);
222
my $templatefile="readmessage.template";
223
$templatefile="printmessage.template" if ($printfriendly eq 'yes');
224
225
# temporarily switch lang/charset if user want original charset
226
if ($readcharset ne $prefs{'charset'}) {
227
@tmp=($prefs{'language'}, $prefs{'charset'});
228
($prefs{'language'}, $prefs{'charset'})=('en', $readcharset);
229
loadlang($prefs{'language'});
230
}
231
$html=applystyle(readtemplate($templatefile));
232
if ($#tmp>=1) {
233
($prefs{'language'}, $prefs{'charset'})=@tmp;
234
}
235
236
if ( $lang_folders{$folder} ) {
237
$html =~ s/\@\@\@FOLDER\@\@\@/$lang_folders{$folder}/;
238
} else {
239
$html =~ s/\@\@\@FOLDER\@\@\@/$folder/;
240
}
241
242
my $is_htmlmsg=0;
243
244
my $from = $message{from}||'';
245
my $replyto = $message{'reply-to'}||'';
246
my $to = $message{to}||'';
247
my $notificationto = $message{'disposition-notification-to'}||'';
248
my $cc = $message{cc}||'';
249
my $bcc = $message{bcc}||'';
250
my $subject = $message{subject}||'';
251
my $body = $message{"body"} || '';
252
if ($message{'content-type'} =~ /^text/i) {
253
if ($message{'content-transfer-encoding'} =~ /^quoted-printable/i) {
254
$body= decode_qp($body);
255
} elsif ($message{'content-transfer-encoding'} =~ /^base64/i) {
256
$body= decode_base64($body);
257
} elsif ($message{'content-transfer-encoding'} =~ /^x-uuencode/i) {
258
$body= ow::mime::uudecode($body);
259
}
260
261
}
262
263
if (is_convertable($convfrom, $readcharset) ) {
264
($from,$replyto,$to,$cc,$bcc,$subject,$body)
265
=iconv($convfrom, $readcharset, $from,$replyto,$to,$cc,$bcc,$subject,$body);
266
}
267
268
# web-ified headers
269
foreach ($from, $replyto, $to, $cc, $bcc, $subject) { $_=ow::htmltext::str2html($_); }
270
271
if ($message{'content-type'} =~ m#^message/partial#i &&
272
$message{'content-type'} =~ /;\s*id="(.+?)";?/i ) { # is this a partial msg?
273
my $escapedpartialid=ow::tool::escapeURL($1);
274
# display rebuild link
275
$body = qq|<table width="100%"><tr><td>|.
276
qq|$lang_text{'thisispartialmsg'}&nbsp; |.
277
qq|<a href="$read_url_with_id&amp;action=rebuildmessage&amp;partialid=$escapedpartialid&amp;attmode=$attmode&amp;headers=$headers">[$lang_text{'msgrebuild'}]</a>|.
278
qq|</td></tr></table>|;
279
} elsif ($message{'content-type'} =~ m#^text/(html|enriched)#i) { # convert html msg into table
280
my $subtype=$1;
281
$body = ow::enriched::enriched2html($body) if ($subtype eq 'enriched');
282
if ($showhtmlastext) { # html -> text -> html
283
$body = ow::htmltext::html2text($body);
284
$body = ow::htmltext::text2html($body);
285
# change color for quoted lines
286
$body =~ s!^(&gt;.*<br>)$!<font color=#009900>$1</font>!img;
287
$body =~ s/<a href=/<a class=msgbody href=/ig;
288
} elsif ($subtype eq 'html') { # html rendering
289
$body = ow::htmlrender::html4nobase($body);
290
$body = ow::htmlrender::html4noframe($body);
291
$body = ow::htmlrender::html4link($body);
292
$body = ow::htmlrender::html4disablejs($body) if ($prefs{'disablejs'});
293
$body = ow::htmlrender::html4disableembcode($body) if ($prefs{'disableembcode'});
294
$body = ow::htmlrender::html4disableemblink($body, $prefs{'disableemblink'}, "$config{'ow_htmlurl'}/images/backgrounds/Transparent.gif") if ($prefs{'disableemblink'} ne 'none');
295
$body = ow::htmlrender::html4mailto($body, "$config{'ow_cgiurl'}/openwebmail-send.pl", "$urlparm&amp;action=composemessage&amp;message_id=$escapedmessageid&amp;compose_caller=read");
296
}
297
$body = ow::htmlrender::html2table($body);
298
$is_htmlmsg=1;
299
} else { # body other than html, enriched is displayed as pure text
300
# remove odds space or blank lines
301
$body =~ s/(\r?\n){2,}/\n\n/g;
302
$body =~ s/^\s+//;
303
$body =~ s/\n\s*$/\n/;
304
305
# remove bbs control char
306
$body =~ s/\x1b\[(\d|\d\d|\d;\d\d)?m//g if ($from=~/bbs/i || $body=~/bbs/i);
307
if ($prefs{'usesmileicon'}) {
308
$body =~ s/(^|\D)(>?)([:;8])[-^]?([\(\)\>\<\|PpDdOoX\\\/])([\s\<])/$1 SMILY_$smilies{"$2$3$4"}\.png $5/g;
309
$body = ow::htmltext::text2html($body);
310
$body =~ s/SMILY_(.+?\.png)/<img border="0" width="12" height="12" src="$config{'ow_htmlurl'}\/images\/smilies\/$1">/g;
311
} else {
312
$body = ow::htmltext::text2html($body);
313
}
314
# change color for quoted lines
315
$body =~ s!^(&gt;.*<br>)$!<font color=#009900>$1</font>!img;
316
$body =~ s/<a href=/<a class=msgbody href=/ig;
317
}
318
319
# Set up the message to go to after move.
320
my $messageaftermove = $messageid_next || $messageid_prev;;
321
my $escapedmessageaftermove = ow::tool::escapeURL($messageaftermove);
322
323
if ($config{'quota_module'} ne "none") {
324
$temphtml='';
325
my $overthreshold=($quotalimit>0 && $quotausage/$quotalimit>$config{'quota_threshold'}/100);
326
if ($config{'quota_threshold'}==0 || $overthreshold) {
327
$temphtml = "$lang_text{'quotausage'}: ".lenstr($quotausage*1024,1);
328
}
329
if ($overthreshold) {
330
$temphtml.=" (".(int($quotausage*1000/$quotalimit)/10)."%) ";
331
}
332
} else {
333
$temphtml="&nbsp;";
334
}
335
$html =~ s/\@\@\@QUOTAUSAGE\@\@\@/$temphtml/;
336
337
$html =~ s/\@\@\@MESSAGETOTAL\@\@\@/$message_total/;
338
339
$temphtml = iconlink("backtofolder.gif", "$lang_text{'backto'} ".($lang_folders{$folder}||$folder), qq|accesskey="B" href="$main_url&amp;action=listmessages"|);
340
341
$temphtml .= "&nbsp;\n";
342
343
# quota or spool over the limit
344
my $inboxsize_k=(-s (get_folderpath_folderdb($user, 'INBOX'))[0])/1024;
345
my $limited=(($quotalimit>0 && $quotausage>$quotalimit) || # quota
346
($config{'spool_limit'}>0 && $inboxsize_k>$config{'spool_limit'})); # spool
347
348
if (!$limited) {
349
if ($folder eq 'saved-drafts') {
350
$temphtml .= iconlink("editdraft.gif", $lang_text{'editdraft'}, qq|accesskey="E" href="$send_url_with_id&amp;action=composemessage&amp;composetype=editdraft&amp;convfrom=$convfrom"|);
351
} elsif ($folder eq 'sent-mail') {
352
$temphtml .= iconlink("editdraft.gif", $lang_text{'editdraft'}, qq|accesskey="E" href="$send_url_with_id&amp;action=composemessage&amp;composetype=editdraft&amp;convfrom=$convfrom"|).
353
iconlink("forward.gif", $lang_text{'forward'}, qq|accesskey="F" href="$send_url_with_id&amp;action=composemessage&amp;composetype=forward&amp;convfrom=$convfrom"|).
354
iconlink("forwardasatt.gif", $lang_text{'forwardasatt'}, qq|accesskey="M" href="$send_url_with_id&amp;action=composemessage&amp;composetype=forwardasatt"|).
355
iconlink("forwardasorig.gif",$lang_text{'forwardasorig'},qq|accesskey="O" href="$send_url_with_id&amp;action=composemessage&amp;composetype=forwardasorig&amp;convfrom=$convfrom"|);
356
} else {
357
$temphtml .= iconlink("compose.gif", $lang_text{'composenew'}, qq|accesskey="C" href="$send_url_with_id&amp;action=composemessage"|).
358
iconlink("reply.gif", $lang_text{'reply'}, qq|accesskey="R" href="$send_url_with_id&amp;action=composemessage&amp;composetype=reply&amp;convfrom=$convfrom"|).
359
iconlink("replyall.gif", $lang_text{'replyall'}, qq|accesskey="A" href="$send_url_with_id&amp;action=composemessage&amp;composetype=replyall&amp;convfrom=$convfrom"|).
360
iconlink("forward.gif", $lang_text{'forward'}, qq|accesskey="F" href="$send_url_with_id&amp;action=composemessage&amp;composetype=forward&amp;convfrom=$convfrom"|).
361
iconlink("forwardasatt.gif", $lang_text{'forwardasatt'}, qq|accesskey="M" href="$send_url_with_id&amp;action=composemessage&amp;composetype=forwardasatt"|).
362
iconlink("forwardasorig.gif",$lang_text{'forwardasorig'},qq|accesskey="O" href="$send_url_with_id&amp;action=composemessage&amp;composetype=forwardasorig&amp;convfrom=$convfrom"|);
363
}
364
$temphtml .= "&nbsp;\n";
365
}
366
367
$temphtml .= iconlink("print.gif", $lang_text{'printfriendly'}, qq|href=#here onClick="javascript:window.open('$read_url_with_id&amp;action=readmessage&amp;headers=$headers&amp;attmode=simple&amp;convfrom=$convfrom&amp;printfriendly=yes','_print', 'width=720,height=360,resizable=yes,menubar=yes,scrollbars=yes')"|);
368
$temphtml .= "&nbsp;\n";
369
370
if ($config{'enable_calendar'}) {
371
$temphtml .= iconlink("calendar.gif", $lang_text{'calendar'}, qq|accesskey="K" href="$config{'ow_cgiurl'}/openwebmail-cal.pl?action=$prefs{'calendar_defaultview'}&amp;sessionid=$thissession&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid"|);
372
}
373
if ($config{'enable_webdisk'}) {
374
$temphtml .= iconlink("webdisk.gif", $lang_text{'webdisk'}, qq|accesskey="E" href="$config{'ow_cgiurl'}/openwebmail-webdisk.pl?action=showdir&amp;sessionid=$thissession&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid"|);
375
}
376
if ( $config{'enable_sshterm'}) {
377
if ( -r "$config{'ow_htmldir'}/applet/mindterm2/mindterm.jar" ) {
378
$temphtml .= iconlink("sshterm.gif" ,"$lang_text{'sshterm'} ", qq|accesskey="T" href="#" onClick="window.open('$config{ow_htmlurl}/applet/mindterm2/ssh2.html', '_applet', 'width=400,height=100,top=2000,left=2000,resizable=no,menubar=no,scrollbars=no');"|);
379
} elsif ( -r "$config{'ow_htmldir'}/applet/mindterm/mindtermfull.jar" ) {
380
$temphtml .= iconlink("sshterm.gif" ,"$lang_text{'sshterm'} ", qq|accesskey="T" href="#" onClick="window.open('$config{ow_htmlurl}/applet/mindterm/ssh.html', '_applet', 'width=400,height=100,top=2000,left=2000,resizable=no,menubar=no,scrollbars=no');"|);
381
}
382
}
383
if ( $config{'enable_preference'}) {
384
$temphtml .= iconlink("prefs.gif", $lang_text{'userprefs'}, qq|accesskey="O" href="$config{'ow_cgiurl'}/openwebmail-prefs.pl?action=editprefs&amp;sessionid=$thissession&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid&amp;sort=$sort&amp;page=$page&amp;prefs_caller=read"|);
385
}
386
$temphtml .= iconlink("logout.gif","$lang_text{'logout'} $prefs{'email'}", qq|accesskey="Q" href="$main_url&amp;action=logout"|) . qq| \n|;
387
388
$html =~ s/\@\@\@LEFTMENUBARLINKS\@\@\@/$temphtml/;
389
390
$temphtml='';
391
if ($config{'enable_learnspam'} &&
392
$folder ne 'saved-drafts' && $folder ne 'sent-mail' &&
393
$folder ne 'spam-mail' && $folder ne 'virus-mail') {
394
my $url=qq|accesskey="Z" href="$main_url&amp;action=movemessage&amp;message_ids=$escapedmessageid&amp;message_id=$escapedmessageaftermove&amp;destination=LEARNSPAM&amp;headers=$headers&amp;attmode=$attmode|;
395
$url .= qq|&amp;messageaftermove=1| if ($messageaftermove && $prefs{'viewnextaftermsgmovecopy'});
396
$url .= qq|" |;
397
$url .= qq|onClick="return confirm($lang_text{'msgmoveconf'})"| if ($prefs{'confirmmsgmovecopy'});
398
$temphtml .= iconlink("learnspam.gif", $lang_text{'learnspam'}, $url);
399
}
400
if ($folder ne 'mail-trash') {
401
my $trashfolder='mail-trash';
402
$trashfolder='DELETE' if ($quotalimit>0 && $quotausage>=$quotalimit);
403
my $url=qq|accesskey="Z" href="$main_url&amp;action=movemessage&amp;message_ids=$escapedmessageid&amp;message_id=$escapedmessageaftermove&amp;destination=$trashfolder&amp;headers=$headers&amp;attmode=$attmode|;
404
$url .= qq|&amp;messageaftermove=1| if ($messageaftermove && $prefs{'viewnextaftermsgmovecopy'});
405
$url .= qq|" |;
406
$url .= qq|onClick="return confirm($lang_text{'msgmoveconf'})"| if ($prefs{'confirmmsgmovecopy'});
407
$temphtml .= iconlink("totrash.gif", $lang_text{'totrash'}, $url);
408
}
409
$temphtml .= "&nbsp;\n";
410
411
$html =~ s/\@\@\@RIGHTMENUBARLINKS\@\@\@/$temphtml/;
412
413
my $gif;
414
$temphtml='';
415
if ($messageid_prev ne '') {
416
$gif="left.s.gif"; $gif="right.s.gif" if ($ow::lang::RTL{$prefs{'language'}});
417
$temphtml .= iconlink($gif, "&lt;", qq|accesskey="U" href="$read_url&amp;message_id=|.ow::tool::escapeURL($messageid_prev).qq|&amp;action=readmessage&amp;headers=$headers&amp;attmode=$attmode"|);
418
} else {
419
$gif="left-grey.s.gif"; $gif="right-grey.s.gif" if ($ow::lang::RTL{$prefs{'language'}});
420
$temphtml .= iconlink($gif, "-", "");
421
}
422
$temphtml.=qq|$message_num|;
423
if ($messageid_next ne '') {
424
my $gif="right.s.gif"; $gif="left.s.gif" if ($ow::lang::RTL{$prefs{'language'}});
425
$temphtml .= iconlink($gif, "&gt;", qq|accesskey="D" href="$read_url&amp;message_id=|.ow::tool::escapeURL($messageid_next).qq|&amp;action=readmessage&amp;headers=$headers&amp;attmode=$attmode"|);
426
} else {
427
my $gif="right-grey.s.gif"; $gif="left-grey.s.gif" if ($ow::lang::RTL{$prefs{'language'}});
428
$temphtml .= iconlink($gif, "-", "");
429
}
430
$html =~ s/\@\@\@MESSAGECONTROL\@\@\@/$temphtml/g;
431
432
$temphtml = iconlink("gotop.gif", "^", qq|href="#"|);
433
$html =~ s/\@\@\@TOPCONTROL\@\@\@/$temphtml/;
434
435
436
my ($htmlconv, $htmlstat, $htmlmove);
437
438
# charset conversion menu
439
if(defined($charset_convlist{$prefs{'charset'}}) ) {
440
my (@cflist, %cflabels, %allsets, $cf);
441
foreach (values %ow::lang::languagecharsets, keys %charset_convlist) {
442
$allsets{$_}=1 if (!defined($allsets{$_}));
443
}
444
445
$cf="none.".lc($message{'charset'}); # readmsg with orig charset and no conversion
446
push(@cflist, $cf); $cflabels{$cf}=(lc($message{'charset'})||$lang_text{'none'})." *";
447
delete $allsets{$cf};
448
449
$cf="none.$prefs{'charset'}"; # readmsg with prefs charset and no conversion
450
if (!defined($cflabels{$cf})) {
451
push(@cflist, $cf); $cflabels{$cf}=$prefs{'charset'};
452
delete $allsets{$prefs{'charset'}};
453
}
454
455
$cf=lc($message{'charset'}); # readmsg with prefs charset and conversion
456
if ($cf ne "" && $cf ne $prefs{'charset'} && is_convertable($cf, $prefs{'charset'})) {
457
push(@cflist, $cf); $cflabels{$cf}="$cf > $prefs{'charset'}";
458
delete $allsets{$cf};
459
}
460
foreach $cf (@{$charset_convlist{$prefs{'charset'}}}) {
461
if (!defined($cflabels{$cf})) {
462
push(@cflist, $cf); $cflabels{$cf}="$cf > $prefs{'charset'}";
463
delete $allsets{$cf};
464
}
465
}
466
467
foreach (sort keys %allsets) { # readmsg with other charset and no conversion
468
$cf="none.$_";
469
next if (defined($cflabels{$cf}));
470
push(@cflist, $cf); $cflabels{$cf}=$_;
471
}
472
473
$htmlconv = start_form(-action=>"$config{'ow_cgiurl'}/openwebmail-read.pl").
474
ow::tool::hiddens(action=>'readmessage',
475
page=>$page,
476
sort=>$sort,
477
keyword=>$keyword,
478
searchtype=>$searchtype,
479
folder=>$folder,
480
headers=>param('headers') ||$prefs{'headers'} || 'simple',
481
attmode=>param('attmode') || 'simple',
482
sessionid=>$thissession,
483
message_id=>param('message_id')||'');
484
$htmlconv = qq|<table cellspacing=0 cellpadding=0 border=0><tr>$htmlconv|.
485
qq|<td nowrap>$lang_text{'charset'}&nbsp;</td><td>|.
486
popup_menu(-name=>'convfrom',
487
-values=>\@cflist,
488
-labels=>\%cflabels,
489
-default=>$convfrom,
490
-onChange=>'javascript:submit();',
491
-accesskey=>'I', # i18n
492
-override=>'1').
493
qq|</td>|.end_form().qq|</tr></table>|;
494
}
495
496
# reply with stationary selection
497
if ( $folder ne 'saved-drafts' && $folder ne 'sent-mail' &&
498
$config{'enable_stationery'} ) {
499
my (@stationery,%escstat);
500
push(@stationery, $lang_text{'statreply'});
501
502
my $statbookfile=dotpath('stationery.book');
503
if ( -f $statbookfile ) {
504
open (STATBOOK, $statbookfile) or
505
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_open'} $statbookfile! ($!)");
506
while (<STATBOOK>) {
507
my ($name, $content) = split(/\@\@\@/, $_, 2);
508
chomp($name); chomp($content);
509
push(@stationery,ow::tool::escapeURL($name));
510
$escstat{ow::tool::escapeURL($name)} = $name;
511
}
512
close (STATBOOK) or
513
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_close'} $statbookfile! ($!)");
514
}
515
516
$htmlstat = startform(-action=>"$config{'ow_cgiurl'}/openwebmail-send.pl",
517
-name=>'ReplyWith').
518
ow::tool::hiddens(sessionid=>$thissession,
519
message_id=>$messageid,
520
folder=>$folder,
521
sort=>$sort,
522
page=>$page,
523
convfrom=>$convfrom,
524
action=>'composemessage',
525
composetype=>'reply',
526
compose_caller=>'read').
527
qq|<table cellspacing=0 cellpadding=0 border=0><tr vlign=center>$htmlstat<td>|.
528
popup_menu(-name=>'statname',
529
-values=>\@stationery,
530
-labels=>\%escstat,
531
-onChange=>'JavaScript:document.ReplyWith.submit();',
532
-override=>'1').
533
qq|</td><td>|.
534
iconlink("editst.s.gif", $lang_text{'editstat'}, qq|href="$config{'ow_cgiurl'}/openwebmail-prefs.pl?action=editstat&amp;sessionid=$thissession&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid&amp;sort=$sort&amp;page=$page"|).
535
qq|</td>|.end_form().qq|</tr></table>|;
536
}
537
538
# move control menu
539
$htmlmove = start_form(-action=>"$config{'ow_cgiurl'}/openwebmail-main.pl",
540
-name=>'moveform').
541
ow::tool::hiddens(action=>'movemessage',
542
sessionid=>$thissession,
543
page=>$page,
544
sort=>$sort,
545
keyword=>$keyword,
546
searchtype=>$searchtype,
547
folder=>$folder,
548
headers=>$headers,
549
message_ids=>$messageid,
550
message_id=>$messageaftermove);
551
if ($messageaftermove && $prefs{'viewnextaftermsgmovecopy'}) {
552
$htmlmove .= ow::tool::hiddens(messageaftermove=>'1');
553
}
554
555
my @movefolders;
556
# option to del message directly from folder
557
if ($quotalimit>0 && $quotausage>=$quotalimit) {
558
@movefolders=('DELETE');
559
} else {
560
foreach (@validfolders) {
561
push (@movefolders, $_) if ($_ ne $folder);
562
}
563
push(@movefolders, 'LEARNSPAM', 'LEARNHAM') if ($config{'enable_learnspam'});
564
push(@movefolders, 'FORWARD', 'DELETE');
565
}
566
my $defaultdestination;
567
if ($quotalimit>0 && $quotausage>=$quotalimit) {
568
$defaultdestination='DELETE';
569
} elsif ($folder eq 'mail-trash' || $folder eq 'spam-mail' || $folder eq 'virus-mail') {
570
$defaultdestination='saved-messages';
571
} elsif ($folder eq 'sent-mail' || $folder eq 'saved-drafts') {
572
$defaultdestination='mail-trash';
573
} else {
574
my $smartdestination;
575
if ($prefs{'smartdestination'}) {
576
my $subject=$message{'subject'}; $subject=~s/\s//g;
577
foreach (@movefolders) {
578
next if ($_ eq "DELETE");
579
if ($subject=~/\Q$_\E/i || $message{'from'}=~/\Q$_\E/i) {
580
$smartdestination=$_; last;
581
}
582
}
583
}
584
$defaultdestination=$smartdestination || $prefs{'defaultdestination'} || 'mail-trash';
585
$defaultdestination='mail-trash' if ( $folder eq $defaultdestination);
586
}
587
588
$htmlmove = qq|<table cellspacing=0 cellpadding=0 border=0><tr>$htmlmove<td nowrap>|.
589
popup_menu(-name=>'destination',
590
-values=>\@movefolders,
591
-default=>$defaultdestination,
592
-labels=>\%lang_folders,
593
-accesskey=>'T', # target folder
594
-override=>'1');
595
if ($prefs{'confirmmsgmovecopy'}) {
596
$htmlmove .= submit(-name=>'movebutton',
597
-value=>$lang_text{'move'},
598
-onClick=>"return confirm($lang_text{'msgmoveconf'})");
599
if (!$limited) {
600
$htmlmove .= submit(-name=>'copybutton',
601
-value=>$lang_text{'copy'},
602
-onClick=>"return confirm($lang_text{'msgcopyconf'})");
603
}
604
} else {
605
$htmlmove .= submit(-name=>'movebutton',
606
-value=>$lang_text{'move'});
607
if (!$limited) {
608
$htmlmove .= submit(-name=>'copybutton',
609
-value=>$lang_text{'copy'});
610
}
611
}
612
$htmlmove .= qq|</td></tr>|.end_form().qq|</table>|;
613
614
if ($prefs{'ctrlposition_msgread'} eq "top") {
615
templateblock_enable($html, 'CONTROLBAR1');
616
templateblock_disable($html, 'CONTROLBAR2');
617
$html =~ s/\@\@\@CONVFROMMENU1\@\@\@/$htmlconv/;
618
$html =~ s/\@\@\@STATIONERYMENU1\@\@\@/$htmlstat/;
619
$html =~ s/\@\@\@MOVECONTROLS1\@\@\@/$htmlmove/;
620
} else {
621
templateblock_disable($html, 'CONTROLBAR1');
622
templateblock_enable($html, 'CONTROLBAR2');
623
$html =~ s/\@\@\@CONVFROMMENU2\@\@\@/$htmlconv/;
624
$html =~ s/\@\@\@STATIONERYMENU2\@\@\@/$htmlstat/;
625
$html =~ s/\@\@\@MOVECONTROLS2\@\@\@/$htmlmove/;
626
}
627
628
if ($headers eq "all") {
629
$temphtml = ow::mime::decode_mimewords($message{header});
630
if (is_convertable($convfrom, $readcharset) ) {
631
($temphtml)=iconv($convfrom, $readcharset, $temphtml);
632
}
633
$temphtml = ow::htmltext::text2html($temphtml);
634
$temphtml =~ s/\n([-\w]+?:)/\n<B>$1<\/B>/g;
635
} else {
636
$temphtml = "<B>$lang_text{'date'}:</B> $message{date}";
637
if ($printfriendly ne "yes") {
638
# enable download the whole message
639
my $dlicon;
640
if ($message{'x-mailer'}=~/Open WebMail/) {
641
$dlicon="download.s.ow.gif";
642
} else {
643
$dlicon="download.s.gif";
644
}
645
$temphtml .= qq|&nbsp; | . iconlink($dlicon, "$lang_text{'download'} $subject.msg", qq|href="$config{'ow_cgiurl'}/openwebmail-viewatt.pl/Unknown.msg?action=viewattachment&amp;sessionid=$thissession&amp;message_id=$escapedmessageid&amp;folder=$escapedfolder&amp;attachment_nodeid=all&amp;convfrom=$convfrom"|). qq|\n|;
646
}
647
$temphtml .= "<BR>\n";
648
649
my ($ename, $eaddr)=ow::tool::email2nameaddr($message{from});
650
$temphtml .= qq|<B>$lang_text{'from'}:</B> <a href="http://www.google.com/search?q=$eaddr" title="google $lang_text{'search'}..." target="_blank">$from</a>&nbsp; \n|;
651
if ($printfriendly ne "yes") {
652
$temphtml .= qq|&nbsp;|. iconlink("import.s.gif", "$lang_text{'importadd'} $eaddr", qq|href="$config{'ow_cgiurl'}/openwebmail-abook.pl?action=addaddress&amp;sessionid=$thissession&amp;sort=$sort&amp;page=$page&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid&amp;realname=|.ow::tool::escapeURL($ename).qq|&amp;email=|.ow::tool::escapeURL($eaddr).qq|&amp;usernote=_reserved_" onclick="return confirm('$lang_text{importadd} $eaddr ?');"|) . qq|\n|;
653
if ($config{'enable_userfilter'}) {
654
$temphtml .= qq|&nbsp;|. iconlink("blockemail.gif", "$lang_text{'blockemail'} $eaddr", qq|href="$config{'ow_cgiurl'}/openwebmail-prefs.pl?action=addfilter&amp;sessionid=$thissession&amp;sort=$sort&amp;page=$page&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid&amp;priority=20&amp;ruletype=from&amp;include=include&amp;text=$eaddr&amp;destination=mail-trash&amp;enable=1" onclick="return confirm('$lang_text{blockemail} $eaddr ?');"|) . qq|\n|;
655
if ($message{smtprelay} !~ /^\s*$/) {
656
$temphtml .= qq|&nbsp; |.iconlink("blockrelay.gif", "$lang_text{'blockrelay'} $message{smtprelay}", qq|href="$config{'ow_cgiurl'}/openwebmail-prefs.pl?action=addfilter&amp;sessionid=$thissession&amp;sort=$sort&amp;page=$page&amp;folder=$escapedfolder&amp;message_id=$escapedmessageid&amp;priority=20&amp;ruletype=smtprelay&amp;include=include&amp;text=$message{smtprelay}&amp;destination=mail-trash&amp;enable=1" onclick="return confirm('$lang_text{blockrelay} $message{smtprelay} ?');"|) . qq|\n|;
657
}
658
}
659
}
660
$temphtml .= "<BR>";
661
662
if ($replyto ne '') {
663
$temphtml .= "<B>$lang_text{'replyto'}:</B> $replyto<BR>\n";
664
}
665
666
my $dotstr=qq| <a href="$read_url_with_id&amp;action=readmessage&amp;attmode=$attmode&amp;receivers=all"><b>.....</b></a>|;
667
if ($to ne '') {
668
$to=substr($to,0,90).$dotstr if (length($to)>96 && param('receivers') ne "all");
669
$temphtml .= qq|<B>$lang_text{'to'}:</B> $to<BR>\n|;
670
}
671
if ($cc ne '') {
672
$cc=substr($cc,0,90).$dotstr if (length($cc)>96 && param('receivers') ne "all");
673
$temphtml .= qq|<B>$lang_text{'cc'}:</B> $cc<BR>\n|;
674
}
675
if ($bcc ne '') {
676
$bcc=substr($bcc,0,90).$dotstr if (length($bcc)>96 && param('receivers') ne "all");
677
$temphtml .= qq|<B>$lang_text{'bcc'}:</B> $bcc<BR>\n|;
678
}
679
680
if ($subject ne '') {
681
$temphtml .= qq|<B>$lang_text{'subject'}:</B> $subject\n|;
682
}
683
684
if ($printfriendly ne "yes") {
685
if ($message{'priority'} eq 'urgent') {# display import icon
686
$temphtml .= qq|&nbsp;|. iconlink("important.gif", "", "");
687
}
688
if ($message{'status'} =~ /a/i) { # display read and answered icon
689
$temphtml .= qq|&nbsp; |. iconlink("read.a.gif", "", "");
690
}
691
}
692
}
693
$html =~ s/\@\@\@HEADERS\@\@\@/$temphtml/;
694
695
if ($headers eq "all") {
696
$temphtml = qq|<a href="$read_url_with_id&amp;action=readmessage&amp;attmode=$attmode&amp;headers=simple&amp;convfrom=$convfrom">$lang_text{'simplehead'}</a>|;
697
} else {
698
$temphtml = qq|<a href="$read_url_with_id&amp;action=readmessage&amp;attmode=$attmode&amp;headers=all&amp;convfrom=$convfrom">$lang_text{'allhead'}</a>|;
699
}
700
$html =~ s/\@\@\@HEADERSTOGGLE\@\@\@/$temphtml/;
701
702
if ( $#{$message{attachment}}>=0 ||
703
$message{'content-type'}=~/^multipart/i ) {
704
if ($attmode eq "all") {
705
$temphtml = qq|<a href="$read_url_with_id&amp;action=readmessage&amp;headers=$headers&amp;attmode=simple&amp;convfrom=$convfrom">$lang_text{'simpleattmode'}</a>|;
706
} else {
707
$temphtml = qq|<a href="$read_url_with_id&amp;action=readmessage&amp;headers=$headers&amp;attmode=all&amp;convfrom=$convfrom">$lang_text{'allattmode'}</a>|;
708
}
709
} else {
710
$temphtml="&nbsp;";
711
}
712
$html =~ s/\@\@\@ATTMODETOGGLE\@\@\@/$temphtml/;
713
714
$temphtml=$body;
715
# Note: attachment count >=0 is not necessary to be multipart!!!
716
if ( $attmode eq 'all' ) {
717
$temphtml .= hr() if ( $#{$message{attachment}}>=0 );
718
} else {
719
$temphtml="" if ( $message{'content-type'} =~ /^multipart/i );
720
}
721
722
my $onlyone_att=0;
723
$onlyone_att=1 if ($#{$message{attachment}}==0);
724
725
foreach my $attnumber (0 .. $#{$message{attachment}}) {
726
next unless (defined(%{$message{attachment}[$attnumber]}));
727
728
my $attcharset=$convfrom;
729
# if convfrom eq msgcharset, we try to get attcharset from attheader since it may differ from msgheader
730
# but if convfrom ne msgcharset, which means user has spsecified other charset in interpreting the msg
731
# which means the charset in attheader may be wrong either, then we use convfrom as attcharset
732
if ($convfrom eq lc($message{'charset'})) {
733
$attcharset=lc(${$message{attachment}[$attnumber]}{filenamecharset})||
734
lc(${$message{attachment}[$attnumber]}{charset})||
735
$convfrom;
736
}
737
738
if ( $attmode eq 'all' ) {
739
if ( ${$message{attachment}[$attnumber]}{filename}=~/\.(?:jpg|jpeg|gif|png|bmp)$/i
740
&& !$prefs{'showimgaslink'} ) {
741
$temphtml .= image_att2table($message{attachment}, $attnumber, $attcharset, $readcharset,
742
$escapedmessageid, "&amp;convfrom=$convfrom");
743
} else {
744
$temphtml .= misc_att2table($message{attachment}, $attnumber, $attcharset, $readcharset,
745
$escapedmessageid, "&amp;convfrom=$convfrom", 0);
746
}
747
748
} else { # attmode==simple
749
# handle case to skip to next text/html attachment
750
if ( defined(%{$message{attachment}[$attnumber+1]}) &&
751
(${$message{attachment}[$attnumber+1]}{boundary} eq
752
${$message{attachment}[$attnumber]}{boundary}) ) {
753
754
# skip to next text/(html|enriched) attachment in the same alternative group
755
if ( (${$message{attachment}[$attnumber]}{subtype} =~ /alternative/i) &&
756
(${$message{attachment}[$attnumber+1]}{subtype} =~ /alternative/i) &&
757
(${$message{attachment}[$attnumber+1]}{'content-type'} =~ /^text/i) &&
758
(${$message{attachment}[$attnumber+1]}{filename}=~ /^Unknown\./ ) ) {
759
next;
760
}
761
# skip to next attachment if this=unknow.(txt|enriched) and next=unknow.(html|enriched)
762
if ( (${$message{attachment}[$attnumber]}{'content-type'}=~ /^text\/(?:plain|enriched)/i ) &&
763
(${$message{attachment}[$attnumber]}{filename}=~ /^Unknown\./ ) &&
764
(${$message{attachment}[$attnumber+1]}{'content-type'} =~ /^text\/(?:html|enriched)/i) &&
765
(${$message{attachment}[$attnumber+1]}{filename}=~ /^Unknown\./ ) ) {
766
next;
767
}
768
}
769
770
# handle display of attachments in simple mode
771
if ( ${$message{attachment}[$attnumber]}{'content-type'}=~ /^text/i ) {
772
if ( ${$message{attachment}[$attnumber]}{filename}=~ /^Unknown\./ ||
773
$onlyone_att ) {
774
my $content;
775
if ( ${$message{attachment}[$attnumber]}{'content-type'}=~ /^text\/html/i ) {
776
$content=html_att2table($message{attachment}, $attnumber, $attcharset, $readcharset,
777
$escapedmessageid, $showhtmlastext);
778
$is_htmlmsg=1;
779
} elsif ( ${$message{attachment}[$attnumber]}{'content-type'}=~ /^text\/enriched/i ) {
780
$content=enriched_att2table($message{attachment}, $attnumber, $attcharset, $readcharset,
781
$showhtmlastext);
782
$is_htmlmsg=1;
783
} else {
784
$content=text_att2table($message{attachment}, $attnumber, $attcharset, $readcharset);
785
}
786
$temphtml .= $content;
787
} else {
788
# show misc attachment only if it is not referenced by other html
789
if ( ${$message{attachment}[$attnumber]}{referencecount}==0 ) {
790
$temphtml .= misc_att2table($message{attachment}, $attnumber, $attcharset, $readcharset,
791
$escapedmessageid, "&amp;convfrom=$convfrom");
792
}
793
}
794
} elsif ( ${$message{attachment}[$attnumber]}{'content-type'}=~ /^message\/external\-body/i ) {
795
# attachment external reference, not an real message
796
$temphtml .= misc_att2table($message{attachment}, $attnumber, $attcharset, $readcharset,
797
$escapedmessageid);
798
} elsif ( ${$message{attachment}[$attnumber]}{'content-type'}=~ /^message\/partial/i ) {
799
# fragmented message
800
$temphtml .= misc_att2table($message{attachment}, $attnumber, $attcharset, $readcharset,
801
$escapedmessageid);
802
} elsif ( ${$message{attachment}[$attnumber]}{'content-type'}=~ /^message/i ) {
803
# always show message/... attachment
804
$temphtml .= message_att2table($message{attachment}, $attnumber, $attcharset, $readcharset,
805
$style{"window_dark"});
806
} elsif ( ${$message{attachment}[$attnumber]}{filename}=~ /\.(?:jpg|jpeg|gif|png|bmp)$/i ) {
807
# show image only if it is not referenced by other html
808
if ( ${$message{attachment}[$attnumber]}{referencecount}==0 ) {
809
if (!$prefs{'showimgaslink'}) {
810
$temphtml .= image_att2table($message{attachment}, $attnumber, $attcharset, $readcharset,
811
$escapedmessageid, "&amp;convfrom=$convfrom");
812
} else {
813
$temphtml .= misc_att2table($message{attachment}, $attnumber, $attcharset, $readcharset,
814
$escapedmessageid, "&amp;convfrom=$convfrom");
815
}
816
}
817
} elsif ( ${$message{attachment}[$attnumber]}{filename}=~ /\.(?:midi?|wav|mp3|ra|au|snd)$/i ) {
818
# show sound only if it is not referenced by other html
819
if ( ${$message{attachment}[$attnumber]}{referencecount}==0 ) {
820
$temphtml .= misc_att2table($message{attachment}, $attnumber, $attcharset, $readcharset,
821
$escapedmessageid, "&amp;convfrom=$convfrom");
822
}
823
} else {
824
# show misc attachment only if it is not referenced by other html
825
if ( ${$message{attachment}[$attnumber]}{referencecount}==0 ) {
826
$temphtml .= misc_att2table($message{attachment}, $attnumber, $attcharset, $readcharset,
827
$escapedmessageid, "&amp;convfrom=$convfrom", 1);
828
}
829
}
830
831
}
832
}
833
$html =~ s/\@\@\@BODY\@\@\@/$temphtml/;
834
835
if ($is_htmlmsg) {
836
$temphtml=qq|<a href="$read_url_with_id&amp;action=readmessage&amp;headers=$headers&amp;attmode=simple&amp;convfrom=$convfrom&amp;showhtmlastext=|;
837
if ($showhtmlastext) {
838
$temphtml.=qq|0">+html+</a>|;
839
} else {
840
$temphtml.=qq|1">-html-</a>|;
841
}
842
$html =~ s!\@\@\@SHOWHTMLASTEXTLABEL\@\@\@!$temphtml!;
843
} else {
844
$html =~ s/\@\@\@SHOWHTMLASTEXTLABEL\@\@\@/&nbsp;/;
845
}
846
847
# if this is unread message, confirm to transmit read receipt if requested
848
if ($message{status} !~ /R/i && $notificationto ne '') {
849
if ($prefs{'sendreceipt'} eq 'ask') {
850
$html.=qq|<script language="JavaScript">\n<!--\n|.
851
qq|replyreceiptconfirm('$send_url_with_id&amp;action=replyreceipt', 0);\n|.
852
qq|//-->\n</script>\n|;
853
} elsif ($prefs{'sendreceipt'} eq 'yes') {
854
$html.=qq|<script language="JavaScript">\n<!--\n|.
855
qq|replyreceiptconfirm('$send_url_with_id&amp;action=replyreceipt', 1);\n|.
856
qq|//-->\n</script>\n|;
857
}
858
}
859
860
$temphtml='';
861
# show quotahit del warning
862
if ($quotahit_deltype ne '') {
863
my $msg=qq|<font size="-1" color="#cc0000">$lang_err{$quotahit_deltype}</font>|;
864
$msg=~s/\@\@\@QUOTALIMIT\@\@\@/$config{'quota_limit'}$lang_sizes{'kb'}/;
865
$msg =~ s!\\!\\\\!g; $msg =~ s!'!\\'!g; # escape ' for javascript
866
$temphtml.=qq|<script language="JavaScript">\n<!--\n|.
867
qq|showmsg('$readcharset', '$lang_text{"quotahit"}', '$msg', '$lang_text{"close"}', '_quotahit_del', 400, 100, 60);\n|.
868
qq|//-->\n</script>\n|;
869
}
870
# show quotahit alert
871
if ($quotalimit>0 && $quotausage>=$quotalimit) {
872
my $msg=qq|<font size="-1" color="#cc0000">$lang_err{'quotahit_alert'}</font>|;
873
$msg =~ s!\\!\\\\!g; $msg =~ s!'!\\'!g; # escape ' for javascript
874
$temphtml.=qq|<script language="JavaScript">\n<!--\n|.
875
qq|showmsg('$readcharset', '$lang_text{"quotahit"}', '$msg', '$lang_text{"close"}', '_quotahit_alert', 400, 100, 60);\n|.
876
qq|//-->\n</script>\n|;
877
# show spool overlimit alert
878
} elsif ($config{'spool_limit'}>0 && $inboxsize_k>$config{'spool_limit'}) {
879
my $msg=qq|<font size="-1" color="#cc0000">$lang_err{'spool_overlimit'}</font>|;
880
$msg=~s/\@\@\@SPOOLLIMIT\@\@\@/$config{'spool_limit'}$lang_sizes{'kb'}/;
881
$msg =~ s!\\!\\\\!g; $msg =~ s!'!\\'!g; # escape ' for javascript
882
$temphtml.=qq|<script language="JavaScript">\n<!--\n|.
883
qq|showmsg('$readcharset', '$lang_text{"quotahit"}', '$msg', '$lang_text{"close"}', '_spool_overlimit', 400, 100, 60);\n|.
884
qq|//-->\n</script>\n|;
885
}
886
# popup stat of incoming msgs
887
if ($prefs{'newmailwindowtime'}>0) {
888
my ($totalfiltered, %filtered)=read_filterfolderdb(1);
889
if ($totalfiltered>0) {
890
my $msg;
891
my $line=0;
892
foreach my $f (get_defaultfolders(), 'DELETE') {
893
if ($filtered{$f}>0) {
894
$msg .= qq|$lang_folders{$f} &nbsp; $filtered{$f}<br>|;
895
$line++;
896
}
897
}
898
foreach my $f (sort keys %filtered) {
899
next if (is_defaultfolder($f));
900
$msg .= qq|$f &nbsp; $filtered{$f}<br>|;
901
$line++;
902
}
903
$msg = qq|<font size="-1">$msg</font>|;
904
$msg =~ s!\\!\\\\!g; $msg =~ s!'!\\'!g; # escape ' for javascript
905
$temphtml.=qq|<script language="JavaScript">\n<!--\n|.
906
qq|showmsg('$readcharset', '$lang_text{"inmessages"}', '$msg', '$lang_text{"close"}', '_incoming', 160, |.($line*16+70).qq|, $prefs{'newmailwindowtime'});\n|.
907
qq|//-->\n</script>\n|;
908
}
909
}
910
$html.=readtemplate('showmsg.js').$temphtml if ($temphtml);
911
912
my $footermode=2;
913
if ($printfriendly eq "yes") {
914
$html.=qq|<script language="JavaScript">\n<!--\n|.
915
qq|setTimeout("window.print()", 1*1000);\n|.
916
qq|//-->\n</script>\n|;
917
$footermode=0;
918
}
919
920
@tmp=();
921
if ($readcharset ne $prefs{'charset'}) {
922
@tmp=($prefs{'language'}, $prefs{'charset'});
923
($prefs{'language'}, $prefs{'charset'})=('en', $readcharset);
924
}
925
httpprint([], [htmlheader(), $html, htmlfooter($footermode)]);
926
if ($#tmp>=1) {
927
($prefs{'language'}, $prefs{'charset'})=@tmp;
928
}
929
930
# fork a child to do the status update and folderdb update
931
# thus the result of readmessage can be returned as soon as possible
932
if ($message{status} !~ /R/i) { # msg file doesn't has R flag
933
local $SIG{CHLD} = 'IGNORE'; # handle zombie
934
local $|=1; # flush all output
935
if ( fork() == 0 ) { # child
936
close(STDIN); close(STDOUT); close(STDERR);
937
938
my ($folderfile, $folderdb)=get_folderpath_folderdb($user, $folder);
939
ow::filelock::lock($folderfile, LOCK_EX) or openwebmail_exit(1);
940
941
# since status in folderdb may have flags not found in msg header
942
# we must read the status from folderdb and then update it back
943
my @attr=get_message_attributes($messageid, $folderdb);
944
update_message_status($messageid, $attr[$_STATUS]."R", $folderdb, $folderfile) if ($#attr>0);
945
946
ow::filelock::lock($folderfile, LOCK_UN);
947
openwebmail_exit(0);
948
}
949
} elsif (param('db_chkstatus')) { # check and set msg status R flag
950
my ($folderfile, $folderdb)=get_folderpath_folderdb($user, $folder);
951
my (%FDB, @attr);
952
ow::dbm::open(\%FDB, $folderdb, LOCK_EX) or
953
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_lock'} db $folderdb");
954
@attr=string2msgattr($FDB{$messageid});
955
if ($attr[$_STATUS] !~ /R/i) {
956
$attr[$_STATUS].="R";
957
$FDB{$messageid}=msgattr2string(@attr);
958
}
959
ow::dbm::close(\%FDB, $folderdb);
960
}
961
return;
962
}
963
964
965
sub html_att2table {
966
my ($r_attachments, $attnumber, $attcharset, $readcharset, $escapedmessageid, $showhtmlastext)=@_;
967
968
my $r_attachment=${$r_attachments}[$attnumber];
969
my $temphtml;
970
971
if (${$r_attachment}{'content-transfer-encoding'} =~ /^quoted-printable/i) {
972
$temphtml = decode_qp(${${$r_attachment}{r_content}});
973
} elsif (${$r_attachment}{'content-transfer-encoding'} =~ /^base64/i) {
974
$temphtml = decode_base64(${${$r_attachment}{r_content}});
975
} elsif (${$r_attachment}{'content-transfer-encoding'} =~ /^x-uuencode/i) {
976
$temphtml = ow::mime::uudecode(${${$r_attachment}{r_content}});
977
} else {
978
$temphtml = ${${$r_attachment}{r_content}};
979
}
980
981
if ($showhtmlastext) { # html -> text -> html
982
$temphtml = ow::htmltext::html2text($temphtml);
983
$temphtml = ow::htmltext::text2html($temphtml);
984
# change color for quoted lines
985
$temphtml =~ s!^(&gt;.*<br>)$!<font color=#009900>$1</font>!img;
986
$temphtml =~ s/<a href=/<a class=msgbody href=/ig;
987
} else { # html rendering
988
$temphtml = ow::htmlrender::html4nobase($temphtml);
989
$temphtml = ow::htmlrender::html4noframe($temphtml);
990
$temphtml = ow::htmlrender::html4link($temphtml);
991
$temphtml = ow::htmlrender::html4disablejs($temphtml) if ($prefs{'disablejs'});
992
$temphtml = ow::htmlrender::html4disableembcode($temphtml) if ($prefs{'disableembcode'});
993
$temphtml = ow::htmlrender::html4disableemblink($temphtml, $prefs{'disableemblink'}, "$config{'ow_htmlurl'}/images/backgrounds/Transparent.gif") if ($prefs{'disableemblink'} ne 'none');
994
$temphtml = ow::htmlrender::html4attachments($temphtml, $r_attachments, "$config{'ow_cgiurl'}/openwebmail-viewatt.pl", "action=viewattachment&amp;sessionid=$thissession&amp;message_id=$escapedmessageid&amp;folder=$escapedfolder");
995
$temphtml = ow::htmlrender::html4mailto($temphtml, "$config{'ow_cgiurl'}/openwebmail-send.pl",
996
"sessionid=$thissession&amp;folder=$escapedfolder&amp;page=$page&amp;".
997
"sort=$sort&amp;keyword=$escapedkeyword&amp;searchtype=$searchtype&amp;".
998
"action=composemessage&amp;message_id=$escapedmessageid&amp;compose_caller=read");
999
}
1000
$temphtml = ow::htmlrender::html2table($temphtml);
1001
if (is_convertable($attcharset, $readcharset)) {
1002
($temphtml)=iconv($attcharset, $readcharset, $temphtml);
1003
}
1004
return($temphtml);
1005
}
1006
1007
sub enriched_att2table {
1008
my ($r_attachments, $attnumber, $attcharset, $readcharset, $showhtmlastext)=@_;
1009
1010
my $r_attachment=${$r_attachments}[$attnumber];
1011
my $temphtml;
1012
1013
if (${$r_attachment}{'content-transfer-encoding'} =~ /^quoted-printable/i) {
1014
$temphtml = decode_qp(${${$r_attachment}{r_content}});
1015
} elsif (${$r_attachment}{'content-transfer-encoding'} =~ /^base64/i) {
1016
$temphtml = decode_base64(${${$r_attachment}{r_content}});
1017
} elsif (${$r_attachment}{'content-transfer-encoding'} =~ /^x-uuencode/i) {
1018
$temphtml = ow::mime::uudecode(${${$r_attachment}{r_content}});
1019
} else {
1020
$temphtml = ${${$r_attachment}{r_content}};
1021
}
1022
$temphtml = ow::enriched::enriched2html($temphtml);
1023
if ($showhtmlastext) { # html -> text -> html
1024
$temphtml = ow::htmltext::html2text($temphtml);
1025
$temphtml = ow::htmltext::text2html($temphtml);
1026
# change color for quoted lines
1027
$temphtml =~ s!^(&gt;.*<br>)$!<font color=#009900>$1</font>!img;
1028
$temphtml =~ s/<a href=/<a class=msgbody href=/ig;
1029
}
1030
$temphtml = ow::htmlrender::html2table($temphtml);
1031
if (is_convertable($attcharset, $readcharset)) {
1032
($temphtml)=iconv($attcharset, $readcharset, $temphtml);
1033
}
1034
return($temphtml);
1035
}
1036
1037
sub text_att2table {
1038
my ($r_attachments, $attnumber, $attcharset, $readcharset)=@_;
1039
1040
my $r_attachment=${$r_attachments}[$attnumber];
1041
my $temptext;
1042
1043
if (${$r_attachment}{'content-transfer-encoding'} =~ /^quoted-printable/i) {
1044
$temptext = decode_qp(${${$r_attachment}{r_content}});
1045
} elsif (${$r_attachment}{'content-transfer-encoding'} =~ /^base64/i) {
1046
$temptext = decode_base64(${${$r_attachment}{r_content}});
1047
} elsif (${$r_attachment}{'content-transfer-encoding'} =~ /^x-uuencode/i) {
1048
$temptext = ow::mime::uudecode(${${$r_attachment}{r_content}});
1049
} else {
1050
$temptext = ${${$r_attachment}{r_content}};
1051
}
1052
1053
# remove odds space or blank lines
1054
$temptext =~ s/(\r?\n){2,}/\n\n/g;
1055
$temptext =~ s/^\s+//;
1056
$temptext =~ s/\n\s*$/\n/;
1057
if ($prefs{'usesmileicon'}) {
1058
$temptext =~ s/(^|\D)(>?)([:;8])[-^]?([\(\)\>\<\|PpDdOoX\\\/])([\s\<])/$1 SMILY_$smilies{"$2$3$4"}\.png $5/g;
1059
$temptext = ow::htmltext::text2html($temptext);
1060
$temptext =~ s/SMILY_(.+?\.png)/<img border="0" width="12" height="12" src="$config{'ow_htmlurl'}\/images\/smilies\/$1">/g;
1061
} else {
1062
$temptext = ow::htmltext::text2html($temptext);
1063
}
1064
$temptext =~ s/<a href=/<a class=msgbody href=/ig;
1065
if (is_convertable($attcharset, $readcharset)) {
1066
($temptext)=iconv($attcharset, $readcharset, $temptext);
1067
}
1068
return($temptext. "<BR>");
1069
}
1070
1071
sub message_att2table {
1072
my ($r_attachments, $attnumber, $attcharset, $readcharset, $headercolor)=@_;
1073
$headercolor='#dddddd' if ($headercolor eq '');
1074
1075
my $r_attachment=${$r_attachments}[$attnumber];
1076
my $temptext;
1077
1078
if (${$r_attachment}{'content-transfer-encoding'} =~ /^quoted-printable/i) {
1079
$temptext = decode_qp(${${$r_attachment}{r_content}});
1080
} elsif (${$r_attachment}{'content-transfer-encoding'} =~ /^base64/i) {
1081
$temptext = decode_base64(${${$r_attachment}{r_content}});
1082
} elsif (${$r_attachment}{'content-transfer-encoding'} =~ /^x-uuencode/i) {
1083
$temptext = ow::mime::uudecode(${${$r_attachment}{r_content}});
1084
} else {
1085
$temptext = ${${$r_attachment}{r_content}};
1086
}
1087
1088
my ($header, $body)=split(/\n\r*\n/, $temptext, 2);
1089
my %msg;
1090
$msg{'content-type'}='N/A'; # assume msg is simple text
1091
ow::mailparse::parse_header(\$header, \%msg);
1092
1093
$header=simpleheader($header);
1094
$header=ow::htmltext::text2html($header);
1095
1096
if ($msg{'content-type'} =~ /^text/i) {
1097
if ($msg{'content-transfer-encoding'} =~ /^quoted-printable/i) {
1098
$body = decode_qp($body);
1099
} elsif ($msg{'content-transfer-encoding'} =~ /^base64/i) {
1100
$body = decode_base64($body);
1101
} elsif ($msg{'content-transfer-encoding'} =~ /^x-uuencode/i) {
1102
$body = ow::mime::uudecode($body);
1103
}
1104
}
1105
if ($msg{'content-type'} =~ m#^text/html#i) { # convert into html table
1106
$body = ow::htmlrender::html4nobase($body);
1107
$body = ow::htmlrender::html4disablejs($body) if ($prefs{'disablejs'});
1108
$body = ow::htmlrender::html4disableembcode($body) if ($prefs{'disableembcode'});
1109
$body = ow::htmlrender::html4disableemblink($body, $prefs{'disableemblink'}, "$config{'ow_htmlurl'}/images/backgrounds/Transparent.gif") if ($prefs{'disableemblink'} ne 'none');
1110
$body = ow::htmlrender::html2table($body);
1111
} else {
1112
$body = ow::htmltext::text2html($body);
1113
$body =~ s/<a href=/<a class=msgbody href=/ig;
1114
}
1115
1116
if (is_convertable($attcharset, $readcharset)) {
1117
($header, $body)=iconv($attcharset, $readcharset, $header, $body);
1118
}
1119
1120
# header lang_text replacement should be done after iconv
1121
$header=~s!Date: !<B>$lang_text{'date'}:</B> !i;
1122
$header=~s!From: !<B>$lang_text{'from'}:</B> !i;
1123
$header=~s!Reply-To: !<B>$lang_text{'replyto'}:</B> !i;
1124
$header=~s!To: !<B>$lang_text{'to'}:</B> !i;
1125
$header=~s!Cc: !<B>$lang_text{'cc'}:</B> !i;
1126
$header=~s!Subject: !<B>$lang_text{'subject'}:</B> !i;
1127
1128
# be aware the message header are keep untouched here
1129
# in order to make it easy for further parsing
1130
my $temphtml=qq|<table width="100%" border=0 cellpadding=2 cellspacing=0>\n|.
1131
qq|<tr bgcolor=$headercolor><td class="msgbody">\n|.
1132
qq|$header\n|.
1133
qq|</td></tr>\n|.
1134
qq|\n\n|.
1135
qq|<tr><td class="msgbody">\n|.
1136
qq|$body\n|.
1137
qq|</td></tr></table>|;
1138
return($temphtml);
1139
}
1140
1141
sub image_att2table {
1142
my ($r_attachments, $attnumber, $attcharset, $readcharset, $escapedmessageid, $extraparm)=@_;
1143
1144
my $r_attachment=${$r_attachments}[$attnumber];
1145
my $filename=${$r_attachment}{filename};
1146
my $description=${$r_attachment}{'content-description'};
1147
1148
if (is_convertable($attcharset, $readcharset)) {
1149
($filename, $description)=iconv($attcharset, $readcharset, $filename, $description);
1150
}
1151
1152
my $attlen=lenstr(${$r_attachment}{'content-length'},1);
1153
my $nodeid=${$r_attachment}{nodeid};
1154
my $disposition=substr(${$r_attachment}{'content-disposition'},0,1);
1155
my $escapedfilename = ow::tool::escapeURL($filename);
1156
1157
my $temphtml .= qq|<table border="0" align="center" cellpadding="2">|.
1158
qq|<tr><td bgcolor=$style{"attachment_dark"} align="center">|.
1159
qq|$lang_text{'attachment'} $attnumber: |.ow::htmltext::str2html($filename).qq| &nbsp;($attlen)&nbsp;&nbsp;|;
1160
if ($config{'enable_webdisk'} && !$config{'webdisk_readonly'}) {
1161
$temphtml .= qq|<a href=#here title="$lang_text{'saveatt_towd'}" onClick="window.open('$config{'ow_cgiurl'}/openwebmail-webdisk.pl?action=sel_saveattachment&amp;sessionid=$thissession&amp;message_id=$escapedmessageid&amp;folder=$escapedfolder&amp;attachment_nodeid=$nodeid$extraparm&amp;attname=$escapedfilename|.
1162
qq|', '_blank','width=500,height=330,scrollbars=yes,resizable=yes,location=no');">$lang_text{'webdisk'}</a>|.
1163
qq|&nbsp;\n|;
1164
}
1165
$temphtml .= qq|<font color=$style{"attachment_dark"} class="smalltext">$nodeid $disposition</font>|.
1166
qq|</td></tr>|.
1167
qq|<tr><td bgcolor=$style{"attachment_light"} align="center">|.
1168
qq|<a href="$config{'ow_cgiurl'}/openwebmail-viewatt.pl/$escapedfilename?action=viewattachment&amp;sessionid=$thissession&amp;message_id=$escapedmessageid&amp;folder=$escapedfolder&amp;attachment_nodeid=$nodeid$extraparm" title="$lang_text{'download'}">|.
1169
qq|<img border="0" |;
1170
$temphtml .= qq|alt="$description" | if ($description ne "");
1171
$temphtml .= qq|SRC="$config{'ow_cgiurl'}/openwebmail-viewatt.pl/$escapedfilename?action=viewattachment&amp;sessionid=$thissession&amp;message_id=$escapedmessageid&amp;folder=$escapedfolder&amp;attachment_nodeid=$nodeid$extraparm">|.
1172
qq|</a>|.
1173
qq|</td></tr></table>|;
1174
return($temphtml);
1175
}
1176
1177
sub misc_att2table {
1178
my ($r_attachments, $attnumber, $attcharset, $readcharset, $escapedmessageid, $extraparm, $checktnef)[email protected]_;
1179
my $r_attachment=${$r_attachments}[$attnumber];
1180
my $filename=${$r_attachment}{filename};
1181
my $contenttype=${$r_attachment}{'content-type'}; $contenttype =~ s/^(.+?);.*/$1/g;
1182
my $description=${$r_attachment}{'content-description'};
1183
1184
if ($checktnef && $contenttype=~/^application\/ms\-tnef/i) {
1185
my ($arcname, @filelist)=tnef_att2namelist($filename, ${$r_attachment}{'content-transfer-encoding'}, ${$r_attachment}{'r_content'});
1186
if ($arcname ne '') {
1187
$filename=$arcname;
1188
$contenttype=ow::tool::ext2contenttype($filename);
1189
$description='encapsulated as ms-tnef';
1190
$description=ow::htmltext::str2html(join(', ', @filelist)).' '.$description if ($#filelist>0);
1191
} else {
1192
$description='unrecognized ms-tnef ?';
1193
}
1194
if (${$r_attachment}{'content-description'} ne '') {
1195
$description.= ", ${$r_attachment}{'content-description'}";
1196
}
1197
}
1198
1199
if (is_convertable($attcharset, $readcharset)) {
1200
($filename, $description)=iconv($attcharset, $readcharset, $filename, $description);
1201
}
1202
1203
my $escapedfilename = ow::tool::escapeURL($filename);
1204
my $attlen=lenstr(${$r_attachment}{'content-length'},1);
1205
my $nodeid=${$r_attachment}{nodeid};
1206
my $disposition=substr(${$r_attachment}{'content-disposition'},0,1);
1207
my $attlink="$config{'ow_cgiurl'}/openwebmail-viewatt.pl/$escapedfilename?action=viewattachment&amp;sessionid=$thissession&amp;message_id=$escapedmessageid&amp;folder=$escapedfolder&amp;attachment_nodeid=$nodeid$extraparm";
1208
1209
my $temphtml .= qq|<table border="0" width="40%" align="center" cellpadding="2">|.
1210
qq|<tr><td nowrap colspan="2" bgcolor=$style{"attachment_dark"} align="center">|.
1211
qq|$lang_text{'attachment'} $attnumber: |.ow::htmltext::str2html($filename). qq|&nbsp;($attlen)&nbsp;&nbsp;\n|;
1212
if ($filename=~/\.(?:doc|dot)$/ ) {
1213
$temphtml .= qq|<a href="$attlink&amp;wordpreview=1" target="_blank">$lang_wdbutton{'preview'}</a>|.
1214
qq|&nbsp;\n|;
1215
}
1216
if ($config{'enable_webdisk'} && !$config{'webdisk_readonly'}) {
1217
$temphtml .= qq|<a href=#here title="$lang_text{'saveatt_towd'}" onClick="window.open('$config{'ow_cgiurl'}/openwebmail-webdisk.pl?action=sel_saveattachment&amp;sessionid=$thissession&amp;message_id=$escapedmessageid&amp;folder=$escapedfolder&amp;attachment_nodeid=$nodeid$extraparm&amp;attname=$escapedfilename|.
1218
qq|', '_blank','width=500,height=330,scrollbars=yes,resizable=yes,location=no');">$lang_text{'webdisk'}</a>|.
1219
qq|&nbsp;\n|;
1220
}
1221
$temphtml .= qq|<font color=$style{"attachment_dark"} class="smalltext">$nodeid $disposition|.
1222
qq|</td></tr>|.
1223
qq|<tr><td nowrap bgcolor= $style{"attachment_light"} align="center">|.
1224
qq|$lang_text{'type'}: |.ow::htmltext::str2html($contenttype).qq|<br>|.
1225
qq|$lang_text{'encoding'}: |.ow::htmltext::str2html(${$r_attachment}{'content-transfer-encoding'});
1226
if ($description ne "") {
1227
$temphtml .= qq|<br>$lang_text{'description'}: |.ow::htmltext::str2html($description);
1228
}
1229
my $blank="";
1230
if ($contenttype=~/^text/ || $filename=~/\.(?:jpg|jpeg|gif|png|bmp)$/i) {
1231
$blank="target=_blank";
1232
}
1233
$temphtml .= qq|</td><td nowrap width="10%" bgcolor= $style{"attachment_light"} align="center">|.
1234
qq|<a href="$attlink" $blank>$lang_text{'download'}</a>|.
1235
qq|</td></tr></table>|;
1236
return($temphtml);
1237
}
1238
1239
sub tnef_att2namelist {
1240
my ($attfilename, $attencoding, $r_content)[email protected]_;
1241
my $tnefbin=ow::tool::findbin('tnef'); return '' if ($tnefbin eq '');
1242
my @filelist;
1243
if ($attencoding =~ /^quoted-printable/i) {
1244
my $tnefdata = decode_qp(${$r_content});
1245
@filelist=ow::tnef::get_tnef_filelist($tnefbin, \$tnefdata);
1246
} elsif ($attencoding =~ /^base64/i) {
1247
my $tnefdata = decode_base64(${$r_content});
1248
@filelist=ow::tnef::get_tnef_filelist($tnefbin, \$tnefdata);
1249
} else {
1250
@filelist=ow::tnef::get_tnef_filelist($tnefbin, $r_content);
1251
}
1252
if ($#filelist==0) {
1253
return($filelist[0], @filelist);
1254
} elsif ($#filelist>0) {
1255
my $arcbasename = $attfilename; $arcbasename=~s/\.[\w\d]{0,4}$//;
1256
if (ow::tool::findbin('zip') ne '') {
1257
return($arcbasename.'.zip', @filelist);
1258
} elsif (ow::tool::findbin('tar') ne '') {
1259
if (ow::tool::findbin('gzip') ne '') {
1260
return($arcbasename.'.tgz', @filelist);
1261
} else {
1262
return($arcbasename.'.tar', @filelist);
1263
}
1264
}
1265
}
1266
return '';
1267
}
1268
########## END READMESSAGE #######################################
1269
1270
########## REBUILDMESSAGE ########################################
1271
sub rebuildmessage {
1272
my $partialid = $_[0];
1273
my ($folderfile, $folderdb)=get_folderpath_folderdb($user, $folder);
1274
1275
ow::filelock::lock($folderfile, LOCK_EX) or
1276
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_lock'} $folderfile!");
1277
1278
my ($errorcode, $rebuildmsgid, @partialmsgids)=
1279
rebuild_message_with_partialid($folderfile, $folderdb, $partialid);
1280
1281
ow::filelock::lock($folderfile, LOCK_UN);
1282
1283
if ($errorcode==0) {
1284
# move partial msgs to trash folder
1285
my ($trashfile, $trashdb)=get_folderpath_folderdb($user, "mail-trash");
1286
if ($folderfile ne $trashfile) {
1287
ow::filelock::lock($trashfile, LOCK_EX) or
1288
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_lock'} $trashfile");
1289
my $moved=operate_message_with_ids("move", \@partialmsgids,
1290
$folderfile, $folderdb, $trashfile, $trashdb);
1291
folder_zapmessages($folderfile, $folderdb) if ($moved>0);
1292
ow::filelock::lock($trashfile, LOCK_UN);
1293
}
1294
1295
readmessage($rebuildmsgid);
1296
writelog("rebuild message - rebuild $rebuildmsgid in $folder");
1297
writehistory("rebuild message - rebuild $rebuildmsgid from $folder");
1298
} else {
1299
my ($html, $temphtml);
1300
$html = applystyle(readtemplate("rebuildfailed.template"));
1301
1302
my $errormsg;
1303
if ($errorcode==-1) {
1304
$errormsg=$lang_err{'no_endpart'};
1305
} elsif ($errorcode==-2) {
1306
$errormsg=$lang_err{'part_missing'};
1307
} elsif ($errorcode==-3) {
1308
$errormsg=$lang_err{'rebuild_fmterr'};
1309
} elsif ($errorcode==-4) {
1310
$errormsg=$lang_err{'rebuild_sizeerr'};
1311
}
1312
$html =~ s/\@\@\@ERRORMSG\@\@\@/$errormsg/;
1313
1314
$temphtml = start_form(-action=>"$config{'ow_cgiurl'}/openwebmail-read.pl").
1315
ow::tool::hiddens(action=>'readmessage',
1316
page=>$page,
1317
sort=>$sort,
1318
keyword=>$keyword,
1319
searchtype=>$searchtype,
1320
folder=>$folder,
1321
headers=>param('headers') ||$prefs{'headers'} || 'simple',
1322
attmode=>param('attmode') || 'simple',
1323
sessionid=>$thissession,
1324
message_id=>param('message_id')||'').
1325
submit("$lang_text{'continue'}").
1326
end_form();
1327
$html =~ s/\@\@\@CONTINUEBUTTON\@\@\@/$temphtml/;
1328
1329
httpprint([], [htmlheader(), $html, htmlfooter(2)]);
1330
}
1331
}
1332
########## END REBUILDMESSGAE ####################################
1333