From 9124c5b63bbe6e224fae5031b8cb1bc9c02b0784 Mon Sep 17 00:00:00 2001 From: Cambell Date: Tue, 20 Jul 2021 18:03:21 +0700 Subject: [PATCH] Fix Handler.pm deleteMail - Add $CWD in deleteMail - Check that folders exist before attempting to delete them. Failing to do this causes iMSCP::Dir to error. --- src/Handler.pm | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Handler.pm b/src/Handler.pm index 6611fb0..b2685ad 100755 --- a/src/Handler.pm +++ b/src/Handler.pm @@ -219,6 +219,8 @@ sub deleteMail $data->{'MAIL_ADDR'} ); + local $CWD = $::imscpConfig{'GUI_ROOT_DIR'}; + # Remove unwanted characters from the email (Mimic RainLoop behavior) ( my $email = $data->{'MAIL_ADDR'} ) =~ s/[^a-z0-9\-\.@]+/_/i; my $storageRootDir = "$CWD/data/persistent/rainloop/imscp/storage"; @@ -229,14 +231,17 @@ sub deleteMail # (Mimic RainLoop behavior) my $storageSubDir = substr( $email, 0, 2 ) =~ s/\@$//r; $storageSubDir .= ( '_' x ( 2-length( $storageSubDir ) ) ); - my $storagePath = $storageRootDir . '/' . $storageType . '/' - . $storageSubDir . '/' . $email . '/'; - - iMSCP::Dir->new( dirname => $storagePath )->remove(); - my $dir = iMSCP::Dir->new( dirname => $storageRootDir . '/' - . $storageType . '/' . $storageSubDir ); - next unless $dir->isEmpty(); - $dir->remove(); + my $storageSubPath = $storageRootDir . '/' . $storageType . '.' + . $storageSubDir; + my $storagePath = $storageSubPath . '/' . $email . '/'; + if (-d $storagePath) { + iMSCP::Dir->new( dirname => $storagePath )->remove(); + } + my $dir = iMSCP::Dir->new( dirname => $storageSubPath ); + next unless (-d $storageSubPath && $dir->isEmpty()); + if (-d $storageSubPath) { + $dir->remove(); + } } }; if ( $@ ) {