Sharedwww / cgi-bin / openwebmail / openwebmail-folder.plOpen in CoCalc
Author: William A. Stein
1
#!/usr/bin/perl
2
#
3
# openwebmail-folder.pl - mail folder management 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
22
require "modules/dbm.pl";
23
require "modules/suid.pl";
24
require "modules/filelock.pl";
25
require "modules/tool.pl";
26
require "modules/datetime.pl";
27
require "modules/lang.pl";
28
require "modules/mime.pl";
29
require "modules/mailparse.pl";
30
require "modules/htmltext.pl";
31
require "auth/auth.pl";
32
require "quota/quota.pl";
33
require "shares/ow-shared.pl";
34
require "shares/maildb.pl";
35
36
# common globals
37
use vars qw(%config %config_raw);
38
use vars qw($thissession);
39
use vars qw($domain $user $userrealname $uuid $ugid $homedir);
40
use vars qw(%prefs %style %icontext);
41
use vars qw($quotausage $quotalimit);
42
43
# extern vars
44
use vars qw(%lang_folders %lang_text %lang_err); # defined in lang/xy
45
use vars qw($_OFFSET $_STATUS %is_internal_dbkey); # defined in maildb.pl
46
47
# local globals
48
use vars qw($folder);
49
use vars qw($sort $page);
50
use vars qw($escapedfolder);
51
52
########## MAIN ##################################################
53
openwebmail_requestbegin();
54
$SIG{PIPE}=\&openwebmail_exit; # for user stop
55
$SIG{TERM}=\&openwebmail_exit; # for user stop
56
57
userenv_init();
58
59
if (!$config{'enable_webmail'}) {
60
openwebmailerror(__FILE__, __LINE__, "$lang_text{'webmail'} $lang_err{'access_denied'}");
61
}
62
63
$folder = param('folder') || 'INBOX';
64
$page = param('page') || 1;
65
$sort = param('sort') || $prefs{'sort'} || 'date';
66
67
$escapedfolder=ow::tool::escapeURL($folder);
68
69
my $action = param('action')||'';
70
if ($action eq "editfolders") {
71
editfolders();
72
} elsif ($action eq "refreshfolders") {
73
refreshfolders();
74
} elsif ($action eq "markreadfolder") {
75
markreadfolder();
76
} elsif ($action eq "chkindexfolder") {
77
reindexfolder(0);
78
} elsif ($action eq "reindexfolder") {
79
reindexfolder(1);
80
} elsif ($action eq "addfolder") {
81
addfolder();
82
} elsif ($action eq "deletefolder") {
83
deletefolder();
84
} elsif ($action eq "renamefolder") {
85
renamefolder();
86
} elsif ($action eq "downloadfolder") {
87
downloadfolder();
88
} else {
89
openwebmailerror(__FILE__, __LINE__, "Action $lang_err{'has_illegal_chars'}");
90
}
91
92
openwebmail_requestend();
93
########## END MAIN ##############################################
94
95
########## EDITFOLDERS ###########################################
96
sub editfolders {
97
my (@userfolders, @validfolders, $inboxusage, $folderusage);
98
99
getfolders(\@validfolders, \$inboxusage, \$folderusage);
100
foreach (@validfolders) {
101
push (@userfolders, $_) if (!is_defaultfolder($_));
102
}
103
104
my $total_newmessages=0;
105
my $total_allmessages=0;
106
my $total_foldersize=0;
107
108
my ($html, $temphtml);
109
$html = applystyle(readtemplate("editfolders.template"));
110
111
$html =~ s/\@\@\@FOLDERNAME_MAXLEN\@\@\@/$config{'foldername_maxlen'}/g;
112
113
$temphtml = iconlink("backtofolder.gif", "$lang_text{'backto'} ".( $lang_folders{$folder}||$folder), qq|accesskey="B" href="$config{'ow_cgiurl'}/openwebmail-main.pl?action=listmessages&amp;sessionid=$thissession&amp;sort=$sort&amp;page=$page&amp;folder=$escapedfolder"|). qq|&nbsp; \n|;
114
$temphtml .= iconlink("refresh.gif", $lang_text{'refresh'}, qq|accesskey="R" href="$config{'ow_cgiurl'}/openwebmail-folder.pl?action=refreshfolders&amp;sessionid=$thissession&amp;sort=$sort&amp;folder=$escapedfolder&amp;page=$page"|). qq| \n|;
115
116
$html =~ s/\@\@\@MENUBARLINKS\@\@\@/$temphtml/g;
117
118
$temphtml = start_form(-action=>"$config{'ow_cgiurl'}/openwebmail-folder.pl").
119
ow::tool::hiddens(action=>'addfolder',
120
sessionid=>$thissession,
121
sort=>$sort,
122
page=>$page,
123
folder=>$folder);
124
$html =~ s/\@\@\@STARTFOLDERFORM\@\@\@/$temphtml/;
125
126
$temphtml = textfield(-name=>'foldername',
127
-default=>'',
128
-size=> 24,
129
-maxlength=>$config{'foldername_maxlen'},
130
-override=>'1');
131
# -accesskey=>'I',
132
$html =~ s/\@\@\@FOLDERNAMEFIELD\@\@\@/$temphtml/;
133
134
$temphtml = submit(-name=>$lang_text{'add'},
135
-accesskey=>'A',
136
-class=>"medtext");
137
$html =~ s/\@\@\@ADDBUTTON\@\@\@/$temphtml/;
138
139
$temphtml = end_form();
140
$html =~ s/\@\@\@ENDFORM\@\@\@/$temphtml/;
141
142
my $bgcolor = $style{"tablerow_dark"};
143
my $currfolder;
144
my $form_i=0;
145
$temphtml='';
146
foreach $currfolder (@userfolders) {
147
$temphtml .= _folderline($currfolder, $form_i, $bgcolor,
148
\$total_newmessages, \$total_allmessages, \$total_foldersize);
149
if ($bgcolor eq $style{"tablerow_dark"}) {
150
$bgcolor = $style{"tablerow_light"};
151
} else {
152
$bgcolor = $style{"tablerow_dark"};
153
}
154
$form_i++;
155
}
156
$html =~ s/\@\@\@FOLDERS\@\@\@/$temphtml/;
157
158
$bgcolor = $style{"tablerow_dark"};
159
$temphtml='';
160
foreach $currfolder (get_defaultfolders()) {
161
$temphtml .= _folderline($currfolder, $form_i, $bgcolor,
162
\$total_newmessages, \$total_allmessages, \$total_foldersize);
163
if ($bgcolor eq $style{"tablerow_dark"}) {
164
$bgcolor = $style{"tablerow_light"};
165
} else {
166
$bgcolor = $style{"tablerow_dark"};
167
}
168
$form_i++;
169
}
170
$html =~ s/\@\@\@DEFAULTFOLDERS\@\@\@/$temphtml/;
171
172
my $usagestr;
173
if ($config{'quota_module'} ne "none") {
174
my $percent=0;
175
$usagestr="$lang_text{'quotausage'}: ".lenstr($quotausage*1024,1);
176
if ($quotalimit>0) {
177
$percent=int($quotausage*1000/$quotalimit)/10;
178
$usagestr.=" ($percent%) &nbsp;";
179
$usagestr.="$lang_text{'quotalimit'}: ".lenstr($quotalimit*1024,1);
180
}
181
if ($percent>=90) {
182
$usagestr="<B><font color='#cc0000'>$usagestr</font></B>";
183
} else {
184
$usagestr="<B>$usagestr</B>";
185
}
186
} else {
187
$usagestr="&nbsp;";
188
}
189
$total_foldersize=lenstr($total_foldersize,0);
190
191
$temphtml = qq|<tr>|.
192
qq|<td align="center" bgcolor=$bgcolor><B>$lang_text{'total'}</B></td>|.
193
qq|<td align="center" bgcolor=$bgcolor><B>$total_newmessages</B></td>|.
194
qq|<td align="center" bgcolor=$bgcolor><B>&nbsp;$total_allmessages</B></td>|.
195
qq|<td align="center" bgcolor=$bgcolor><B>&nbsp;$total_foldersize</B></td>|.
196
qq|<td bgcolor=$bgcolor align="center">$usagestr</td>|.
197
qq|</tr>|;
198
$html =~ s/\@\@\@TOTAL\@\@\@/$temphtml/;
199
200
httpprint([], [htmlheader(), $html, htmlfooter(1)]);
201
}
202
203
# this is inline function used by sub editfolders(), it changes
204
# $total_newmessages, $total_allmessages and $total_size in editfolders()
205
sub _folderline {
206
my ($currfolder, $i, $bgcolor,
207
$r_total_newmessages, $r_total_allmessages, $r_total_foldersize)=@_;
208
my $temphtml='';
209
my (%FDB, $newmessages, $allmessages, $foldersize);
210
my ($folderfile,$folderdb)=get_folderpath_folderdb($user, $currfolder);
211
212
if (ow::dbm::exist("$folderdb")) {
213
ow::dbm::open(\%FDB, $folderdb, LOCK_SH) or
214
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_locksh'} db $folderdb");
215
if ( defined($FDB{'ALLMESSAGES'}) ) {
216
$allmessages=$FDB{'ALLMESSAGES'};
217
${$r_total_allmessages}+=$allmessages;
218
} else {
219
$allmessages='&nbsp;';
220
}
221
if ( defined($FDB{'NEWMESSAGES'}) ) {
222
$newmessages=$FDB{'NEWMESSAGES'};
223
${$r_total_newmessages}+=$newmessages;
224
} else {
225
$newmessages='&nbsp;';
226
}
227
ow::dbm::close(\%FDB, $folderdb);
228
} else {
229
$allmessages='&nbsp;';
230
$newmessages='&nbsp;';
231
}
232
233
# we count size for both folder file and related dbm
234
$foldersize = (-s "$folderfile");
235
236
${$r_total_foldersize}+=$foldersize;
237
$foldersize=lenstr($foldersize,0);
238
239
my $escapedcurrfolder = ow::tool::escapeURL($currfolder);
240
my $url = "$config{'ow_cgiurl'}/openwebmail-folder.pl?sessionid=$thissession&amp;folder=$escapedcurrfolder&amp;action=downloadfolder";
241
my $folderstr=$lang_folders{$currfolder}||$currfolder;
242
243
my $accesskeystr=$i%10+1;
244
if ($accesskeystr == 10) {
245
$accesskeystr=qq|accesskey="0"|;
246
} elsif ($accesskeystr < 10) {
247
$accesskeystr=qq|accesskey="$accesskeystr"|;
248
}
249
250
$temphtml .= qq|<tr>|.
251
qq|<td align="center" bgcolor=$bgcolor>|.
252
qq|<a href="$config{'ow_cgiurl'}/openwebmail-main.pl?action=listmessages&amp;sessionid=$thissession&amp;sort=$sort&amp;page=$page&amp;folder=$escapedcurrfolder">|.
253
ow::htmltext::str2html($folderstr).qq| </a>&nbsp;\n|.
254
iconlink("download.gif", "$lang_text{'download'} $folderstr ", qq|$accesskeystr href="$url"|).
255
qq|</td>\n|.
256
qq|<td align="center" bgcolor=$bgcolor>$newmessages</td>|.
257
qq|<td align="center" bgcolor=$bgcolor>&nbsp;$allmessages</td>|.
258
qq|<td align="center" bgcolor=$bgcolor>&nbsp;$foldersize</td>\n|;
259
260
$temphtml .= qq|<td bgcolor=$bgcolor align="center">\n|;
261
262
$temphtml .= start_form(-action=>"$config{'ow_cgiurl'}/openwebmail-folder.pl",
263
-name=>"folderform$i").
264
ow::tool::hiddens(action=>'chkindexfolder',
265
sessionid=>$thissession,
266
sort=>$sort,
267
page=>$page,
268
folder=>$folder,
269
foldername=>$currfolder,
270
foldernewname=>$currfolder)."\n";
271
272
my $jsfolderstr=$lang_folders{$currfolder}||$currfolder;
273
$jsfolderstr=~ s/'/\\'/g; # escaep ' with \'
274
$temphtml .= submit(-name=>$lang_text{'markread'},
275
-class=>"medtext",
276
-onClick=>"return OpConfirm('folderform$i', 'markreadfolder', $lang_text{'foldermarkreadconf'}+' ( $jsfolderstr )')");
277
$temphtml .= submit(-name=>$lang_text{'chkindex'},
278
-class=>"medtext",
279
-onClick=>"return OpConfirm('folderform$i', 'chkindexfolder', $lang_text{'folderchkindexconf'}+' ( $jsfolderstr )')");
280
$temphtml .= submit(-name=>$lang_text{'reindex'},
281
-class=>"medtext",
282
-onClick=>"return OpConfirm('folderform$i', 'reindexfolder', $lang_text{'folderreindexconf'}+' ( $jsfolderstr )')");
283
if ($currfolder ne "INBOX") {
284
$temphtml .= submit(-name=>$lang_text{'rename'},
285
-class=>"medtext",
286
-onClick=>"return OpConfirm('folderform$i', 'renamefolder', $lang_text{'folderrenprop'}+' ( $jsfolderstr )')");
287
}
288
$temphtml .= submit(-name=>$lang_text{'delete'},
289
-class=>"medtext",
290
-onClick=>"return OpConfirm('folderform$i', 'deletefolder', $lang_text{'folderdelconf'}+' ( $jsfolderstr )')");
291
292
$temphtml .= "</td></tr>".end_form()."\n";
293
294
return($temphtml);
295
}
296
########## END EDITFOLDERS #######################################
297
298
########## REFRESHFOLDERS ########################################
299
sub refreshfolders {
300
my $errcount=0;
301
302
my (@validfolders, $inboxusage, $folderusage);
303
getfolders(\@validfolders, \$inboxusage, \$folderusage);
304
305
foreach my $currfolder (@validfolders) {
306
my ($folderfile,$folderdb)=get_folderpath_folderdb($user, $currfolder);
307
308
ow::filelock::lock($folderfile, LOCK_EX) or
309
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_lock'} $folderfile!");
310
if (update_folderindex($folderfile, $folderdb)<0) {
311
$errcount++;
312
writelog("db error - Couldn't update db $folderdb");
313
writehistory("db error - Couldn't update db $folderdb");
314
}
315
ow::filelock::lock($folderfile, LOCK_UN);
316
}
317
318
writelog("folder - refresh, $errcount errors");
319
writehistory("folder - refresh, $errcount errors");
320
321
if ($config{'quota_module'} ne 'none') {
322
$quotausage=(ow::quota::get_usage_limit(\%config, $user, $homedir, 1))[2];
323
}
324
editfolders();
325
}
326
########## END REFRESHFOLDERS ####################################
327
328
########## MARKREADFOLDER ########################################
329
sub markreadfolder {
330
my $foldertomark = ow::tool::untaint(safefoldername(param('foldername'))) || '';
331
my ($folderfile, $folderdb)=get_folderpath_folderdb($user, $foldertomark);
332
333
my $ioerr=0;
334
335
ow::filelock::lock($folderfile, LOCK_EX) or
336
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_lock'} $folderfile!");
337
338
if (update_folderindex($folderfile, $folderdb)<0) {
339
ow::filelock::lock($folderfile, LOCK_UN);
340
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_updatedb'} db $folderdb");
341
}
342
343
my (%FDB, %offset, %status);
344
ow::dbm::open(\%FDB, $folderdb, LOCK_SH) or
345
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_locksh'} db $folderdb");
346
foreach my $messageid (keys %FDB) {
347
next if ($is_internal_dbkey{$messageid});
348
my @attr=string2msgattr($FDB{$messageid});
349
if ($attr[$_STATUS] !~ /R/i) {
350
$offset{$messageid}=$attr[$_OFFSET];
351
$status{$messageid}=$attr[$_STATUS];
352
}
353
}
354
ow::dbm::close(\%FDB, $folderdb);
355
my @unreadmsgids=(sort { $offset{$a}<=>$offset{$b} } keys %offset);
356
357
my $tmpfile=ow::tool::untaint("/tmp/.markread.tmpfile.$$");
358
my $tmpdb=ow::tool::untaint("/tmp/.markread.tmpdb.$$");
359
360
while (!$ioerr && $#unreadmsgids>=0) {
361
my @markids=();
362
363
open(F, ">$tmpfile"); close(F);
364
ow::filelock::lock($tmpfile, LOCK_EX) or
365
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_lock'} $tmpfile");
366
367
if (update_folderindex($tmpfile, $tmpdb)<0) {
368
ow::filelock::lock($tmpfile, LOCK_UN);
369
ow::dbm::unlink($tmpdb);
370
unlink($tmpfile);
371
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_updatedb'} db $tmpdb");
372
}
373
374
while (!$ioerr && $#unreadmsgids>=0) {
375
my $messageid=shift(@unreadmsgids);
376
377
my $copied=operate_message_with_ids("copy", [$messageid], $folderfile, $folderdb, $tmpfile, $tmpdb);
378
if ($copied>0) {
379
if (update_message_status($messageid, $status{$messageid}."R", $tmpdb, $tmpfile)==0) {
380
push(@markids, $messageid);
381
} else {
382
$ioerr++;
383
}
384
} elsif ($copied<0) {
385
$ioerr++;
386
}
387
388
my $tmpsize=(stat($tmpfile))[7];
389
if ( (!$ioerr && ($tmpsize>10*1024*1024||$#markids>=999)) || # tmpfolder size>10MB or marked==1000
390
($ioerr && $tmpsize>0) || # any io error
391
$#unreadmsgids<0 ) { # no more unread msg
392
# copy read msg back from tmp folder
393
if ($#markids>=0) {
394
$ioerr++ if (operate_message_with_ids("delete", \@markids, $folderfile, $folderdb)<0);
395
$ioerr++ if (folder_zapmessages($folderfile, $folderdb)<0);
396
$ioerr++ if (operate_message_with_ids("move", \@markids,
397
$tmpfile, $tmpdb, $folderfile, $folderdb)<0);
398
}
399
last; # renew tmp folder and @markids
400
}
401
}
402
403
ow::dbm::unlink($tmpdb);
404
ow::filelock::lock("$tmpfile", LOCK_UN);
405
unlink($tmpfile);
406
}
407
408
ow::filelock::lock($folderfile, LOCK_UN);
409
410
writelog("markread folder - $foldertomark");
411
writehistory("markread folder - $foldertomark");
412
413
editfolders();
414
}
415
########## END MARKREADFOLDER ####################################
416
417
########## REINDEXFOLDER #########################################
418
sub reindexfolder {
419
my $recreate=$_[0];
420
my $foldertoindex = ow::tool::untaint(safefoldername(param('foldername'))) || '';
421
my ($folderfile, $folderdb)=get_folderpath_folderdb($user, $foldertoindex);
422
423
ow::filelock::lock($folderfile, LOCK_SH|LOCK_NB) or
424
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_locksh'} $folderfile");
425
426
if ($recreate) {
427
ow::dbm::unlink($folderdb);
428
}
429
if (ow::dbm::exist($folderdb) ) {
430
my %FDB;
431
if (!ow::dbm::open(\%FDB, $folderdb, LOCK_SH)) {
432
ow::filelock::lock($folderfile, LOCK_UN);
433
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_locksh'} db $folderdb");
434
}
435
@FDB{'METAINFO', 'LSTMTIME'}=('RENEW', -1);
436
ow::dbm::close(\%FDB, $folderdb);
437
}
438
if (update_folderindex($folderfile, $folderdb)<0) {
439
ow::filelock::lock($folderfile, LOCK_UN);
440
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_updatedb'} db $folderdb");
441
}
442
443
if ($recreate) {
444
folder_zapmessages($folderfile, $folderdb);
445
446
writelog("reindex folder - $foldertoindex");
447
writehistory("reindex folder - $foldertoindex");
448
} else {
449
writelog("chkindex folder - $foldertoindex");
450
writehistory("chkindex folder - $foldertoindex");
451
}
452
453
ow::filelock::lock($folderfile, LOCK_UN);
454
455
editfolders();
456
}
457
########## END REINDEXFOLDER #####################################
458
459
########## ADDFOLDER #############################################
460
sub addfolder {
461
if ($quotalimit>0 && $quotausage>$quotalimit) {
462
$quotausage=(ow::quota::get_usage_limit(\%config, $user, $homedir, 1))[2]; # get uptodate quotausage
463
if ($quotausage>$quotalimit) {
464
openwebmailerror(__FILE__, __LINE__, $lang_err{'quotahit_alert'});
465
}
466
}
467
468
my $foldertoadd = ow::tool::untaint(safefoldername(param('foldername'))) || '';
469
return editfolders() if ($foldertoadd eq '');
470
471
if (length($foldertoadd) > $config{'foldername_maxlen'}) {
472
openwebmailerror(__FILE__, __LINE__, "$lang_err{'foldername_long'}");
473
}
474
if ( is_defaultfolder($foldertoadd) || is_lang_defaultfolder($foldertoadd) ||
475
$foldertoadd eq "$user" || $foldertoadd eq "" ) {
476
openwebmailerror(__FILE__, __LINE__, "$lang_err{'cant_create_folder'}");
477
}
478
479
my ($folderfile, $folderdb)=get_folderpath_folderdb($user, $foldertoadd);
480
if ( -f $folderfile ) {
481
openwebmailerror(__FILE__, __LINE__, "$lang_err{'folder_with_name'} $foldertoadd $lang_err{'already_exists'}");
482
}
483
484
open (FOLDERTOADD, ">$folderfile") or
485
openwebmailerror(__FILE__, __LINE__, "$lang_err{'cant_create_folder'} $foldertoadd! ($!)");
486
close (FOLDERTOADD) or openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_close'} $foldertoadd! ($!)");
487
488
# create empty index dbm with mode 0600
489
my %FDB;
490
ow::dbm::open(\%FDB, $folderdb, LOCK_EX) or
491
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_lock'} $folderdb");
492
ow::dbm::close(\%FDB, $folderdb);
493
494
writelog("create folder - $foldertoadd");
495
writehistory("create folder - $foldertoadd");
496
497
editfolders();
498
}
499
500
sub is_lang_defaultfolder {
501
foreach (keys %lang_folders) { # defaultfolder locallized name check
502
return 1 if ($_[0] eq $lang_folders{$_} && is_defaultfolder($_));
503
}
504
return 0;
505
}
506
########## END ADDFOLDER #########################################
507
508
########## DELETEFOLDER ##########################################
509
sub deletefolder {
510
my $foldertodel = safefoldername(param('foldername')) || '';
511
512
my ($folderfile, $folderdb)=get_folderpath_folderdb($user, $foldertodel);
513
if ( -f $folderfile) {
514
unlink ($folderfile,
515
"$folderfile.lock",
516
"$folderfile.lock.lock",
517
"$folderdb.cache");
518
ow::dbm::unlink($folderdb);
519
520
writelog("delete folder - $foldertodel");
521
writehistory("delete folder - $foldertodel");
522
}
523
524
if ($quotalimit>0 && $quotausage>$quotalimit) {
525
$quotausage=(ow::quota::get_usage_limit(\%config, $user, $homedir, 1))[2];
526
}
527
editfolders();
528
}
529
########## END DELETEFOLDER ######################################
530
531
########## RENAMEFOLDER ##########################################
532
sub renamefolder {
533
my $oldname = ow::tool::untaint(safefoldername(param('foldername'))) || '';
534
if ($oldname eq 'INBOX') {
535
editfolders();
536
return;
537
}
538
539
my $newname = ow::tool::untaint(safefoldername(param('foldernewname')))||'';
540
if (length($newname) > $config{'foldername_maxlen'}) {
541
openwebmailerror(__FILE__, __LINE__, "$lang_err{'foldername_long'}");
542
}
543
if ( is_defaultfolder($newname) || is_lang_defaultfolder($newname) ||
544
$newname eq "$user" || $newname eq "" ) {
545
openwebmailerror(__FILE__, __LINE__, "$lang_err{'cant_create_folder'}");
546
}
547
548
my ($oldfolderfile, $olddb)=get_folderpath_folderdb($user, $oldname);
549
my ($newfolderfile, $newdb)=get_folderpath_folderdb($user, $newname);
550
551
if ( -f $newfolderfile ) {
552
openwebmailerror(__FILE__, __LINE__, "$lang_err{'folder_with_name'} $newname $lang_err{'already_exists'}");
553
}
554
555
if ( -f $oldfolderfile ) {
556
unlink("$oldfolderfile.lock", "$oldfolderfile.lock.lock");
557
rename($oldfolderfile, $newfolderfile);
558
rename("$olddb.cache", "$newdb.cache");
559
ow::dbm::rename($olddb, $newdb);
560
561
writelog("rename folder - $oldname to $newname");
562
writehistory("rename folder - $oldname to $newname");
563
}
564
565
editfolders();
566
}
567
########## END RENAMEFOLDER ######################################
568
569
########## DOWNLOAD FOLDER #######################################
570
sub downloadfolder {
571
my ($folderfile, $folderdb)=get_folderpath_folderdb($user, $folder);
572
my ($cmd, $contenttype, $filename);
573
my $buff;
574
575
if ( ($cmd=ow::tool::findbin("zip")) ne "" ) {
576
$cmd.=" -jrq - $folderfile |";
577
$contenttype='application/x-zip-compressed';
578
$filename="$folder.zip";
579
580
} elsif ( ($cmd=ow::tool::findbin("gzip")) ne "" ) {
581
$cmd.=" -c $folderfile |";
582
$contenttype='application/x-gzip-compressed';
583
$filename="$folder.gz";
584
585
} else {
586
$cmd="$folderfile";
587
$contenttype='text/plain';
588
$filename="$folder";
589
}
590
591
$filename=~s/\s+/_/g;
592
593
ow::filelock::lock($folderfile, LOCK_EX) or
594
openwebmailerror(__FILE__, __LINE__, "$lang_err{'couldnt_lock'} $folderfile");
595
596
# disposition:attachment default to save
597
print qq|Connection: close\n|,
598
qq|Content-Type: $contenttype; name="$filename"\n|;
599
if ( $ENV{'HTTP_USER_AGENT'}=~/MSIE 5.5/ ) { # ie5.5 is broken with content-disposition: attachment
600
print qq|Content-Disposition: filename="$filename"\n|;
601
} else {
602
print qq|Content-Disposition: attachment; filename="$filename"\n|;
603
}
604
print qq|\n|;
605
606
$cmd=ow::tool::untaint($cmd);
607
open (T, $cmd);
608
while ( read(T, $buff,32768) ) {
609
print $buff;
610
}
611
close(T);
612
613
ow::filelock::lock($folderfile, LOCK_UN);
614
615
writelog("download folder - $folder");
616
writehistory("download folder - $folder");
617
618
return;
619
}
620
########## END DOWNLOADFOLDER ####################################
621