diff --git a/cron.php b/cron.php index 30fb564..7a369a5 100644 --- a/cron.php +++ b/cron.php @@ -32,6 +32,10 @@ while ( $tmp = $stmt->fetch( PDO::FETCH_ASSOC ) ) { if ( file_exists( $mail_files ) ) { exec( 'rm -r ' . escapeshellarg( $mail_files ) ); } + $snapmail_files = '/var/local/snappymail/_data_/_default_/storage/' . $domain_basename . '/' . $local_basename; + if ( file_exists( $snapmail_files ) ) { + exec( 'rm -r ' . escapeshellarg( $snapmail_files ) ); + } $files = glob( '/var/local/squirrelmail/data/' . $local_basename . '@' . $domain_basename . '.{pref,abook,sig}', GLOB_BRACE ); if ( $tmp[ 'domain' ] === 'danwin1210.de' ) { $files = array_merge( $files, glob( '/var/local/squirrelmail/data/' . $local_basename . '{@danielas3rtn54uwmofdo3x2bsdifr47huasnmbgqzfrec5ubupvtpid.onion,}.{pref,abook,sig}', GLOB_BRACE ) ); @@ -66,6 +70,10 @@ while ( $tmp = $stmt->fetch( PDO::FETCH_ASSOC ) ) { if ( file_exists( $mail_files ) ) { exec( 'rm -r ' . escapeshellarg( $mail_files ) ); } + $snapmail_files = '/var/local/snappymail/_data_/_default_/storage/' . $domain_basename . '/'; + if ( file_exists( $snapmail_files ) ) { + exec( 'rm -r ' . escapeshellarg( $snapmail_files ) ); + } if ( is_array( $files ) ) { foreach ( $files as $file ) { @unlink( $file ); diff --git a/tools/delete_leftover_files.php b/tools/delete_leftover_files.php index 43047bf..3c880ff 100644 --- a/tools/delete_leftover_files.php +++ b/tools/delete_leftover_files.php @@ -25,3 +25,36 @@ foreach ( $domains as $domain ) { } } } +$domains = array_diff( scandir( '/var/local/snappymail/_data_/_default_/storage/' ), array( '..', '.', '__nobody__' ) ); +$dirs = []; +foreach ( $domains as $domain ) { + if ( is_dir( '/var/local/snappymail/_data_/_default_/storage/' . basename( $domain ) ) ) { + if ( ! isset( $mailboxes[ $domain ] ) ) { + echo sprintf(_('%s does not seem to have any accounts, but has a snappymail directory. Consider deleting it.'), $domain).PHP_EOL; + } else { + $accounts = array_diff( scandir( '/var/local/snappymail/_data_/_default_/storage/' . basename( $domain ) ), array( '..', '.' ) ); + foreach ( $accounts as $account ) { + if ( ! isset( $mailboxes[ $domain ][ $account ] ) && is_dir( '/var/local/snappymail/_data_/_default_/storage/' . basename( $domain ) . '/' . basename( $account ) ) ) { + exec( 'rm -r ' . escapeshellarg('/var/local/snappymail/_data_/_default_/storage/' . basename( $domain ) . '/' . basename( $account ))); + echo sprintf(_('Deleted: %s'), '/var/local/snappymail/_data_/_default_/storage/' . basename( $domain ) . '/' . basename( $account )) . PHP_EOL; + } elseif( is_file('/var/local/snappymail/_data_/_default_/storage/' . basename( $domain ) . '/' . basename( $account ))){ + echo sprintf(_('File found in mail directory location: "%s". Consider deleting it.'), '/var/local/snappymail/_data_/_default_/storage/'. basename( $domain ) . '/' . basename( $account ) ) . PHP_EOL; + } + } + } + } +} +$accout_files = array_diff( scandir( '/var/local/squirrelmail/data/' ), array( '..', '.' ) ); +foreach( $accout_files as $file ){ + if(preg_match( '/^(.+?)(@(.+))?\.(pref|abook|sig)$/', $file, $matches )){ + $domain = $matches[ 3 ]; + if(in_array($domain, ['', 'danielas3rtn54uwmofdo3x2bsdifr47huasnmbgqzfrec5ubupvtpid.onion'], true)){ + $domain = 'danwin1210.de'; + } + $account = $matches[ 1 ]; + if ( ! isset( $mailboxes[ $domain ][ $account ] )){ + unlink('/var/local/squirrelmail/data/' . $file); + echo sprintf(_('Deleted: %s'), '/var/local/squirrelmail/data/' . $file) . PHP_EOL; + } + } +}