Work on function to uncompress mail folders

This commit is contained in:
Jamie Cameron
2023-08-27 21:54:18 -07:00
parent 0dd94f5957
commit 54ad4f7f74
2 changed files with 55 additions and 0 deletions

View File

@@ -3006,6 +3006,40 @@ if ($switched) {
return $rv;
}
# is_gzipped_file(file)
# Returns 1 if a file is gzip compressed
sub is_gzipped_file
{
my ($file) = @_;
my $fh;
my $rv = open($fh, "<", $file);
return 0 if (!$rv);
my $two;
read($fh, $two, 2);
close($fh);
return $two eq "\037\213" ? 1 : 0;
}
# gunzip_mail_file(file)
# Uncompress a mail file in place
sub gunzip_mail_file
{
my ($file) = @_;
my $switched = &switch_to_mail_user();
my $outfile = $file.".$$.uncompressed";
my $ex = system("gunzip -c ".quotemeta($file)."> ".quotemeta($outfile)." 2>/dev/null");
if ($ex) {
unlink($outfile);
}
else {
rename($outfile, $file);
}
if ($switched) {
$) = 0;
$> = 0;
}
}
# create_as_mail_user(fh, file)
# Creates a new file, but ensures that it does not yet exist first, and then
# sets the ownership to the mail user

View File

@@ -1543,6 +1543,27 @@ if ($src->{'sortable'}) {
}
}
# mailbox_uncompress_folder(&folder)
# If a folder or it's files are gzipped, uncompress them in place
sub mailbox_uncompress_folder
{
my ($folder) = @_;
if ($folder->{'type'} == 1 || $folder->{'type'} == 3) {
my @files = $src->{'type'} == 1 ? &get_maildir_files($folder->{'file'})
: &get_mhdir_files($folder->{'file'});
foreach my $f (@files) {
if (&is_gzipped_file($f)) {
&gunzip_mail_file($f);
}
}
}
elsif ($folder->{'type'} == 0) {
if (&is_gzipped_file($folder->{'file'})) {
&gunzip_mail_file($folder->{'file'});
}
}
}
# mailbox_copy_mail(&source, &dest, mail, ...)
# Copy mail from one folder to another
sub mailbox_copy_mail