mirror of
https://github.com/DanWin/mail-hosting.git
synced 2024-11-25 00:50:32 +00:00
27 lines
1.4 KiB
PHP
27 lines
1.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../common_config.php';
|
|
$db = get_db_instance();
|
|
$stmt = $db->query( "select local_part, domain from mailbox;" );
|
|
$mailboxes = [];
|
|
while ( $mailbox = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
|
|
$mailboxes[ $mailbox[ 'domain' ] ][ $mailbox[ 'local_part' ] ] = true;
|
|
}
|
|
$domains = array_diff( scandir( '/var/mail/vmail/' ), array( '..', '.' ) );
|
|
$dirs = [];
|
|
foreach ( $domains as $domain ) {
|
|
if ( is_dir( '/var/mail/vmail/' . basename( $domain ) ) ) {
|
|
if ( ! isset( $mailboxes[ $domain ] ) ) {
|
|
echo sprintf(_('%s does not seem to have any accounts, but has a directory. Consider deleting it.'), $domain).PHP_EOL;
|
|
} else {
|
|
$accounts = array_diff( scandir( '/var/mail/vmail/' . basename( $domain ) ), array( '..', '.' ) );
|
|
foreach ( $accounts as $account ) {
|
|
if ( ! isset( $mailboxes[ $domain ][ $account ] ) && is_dir( '/var/mail/vmail/' . basename( $domain ) . '/' . basename( $account ) ) ) {
|
|
exec( 'rm -r ' . escapeshellarg('/var/mail/vmail/' . basename( $domain ) . '/' . basename( $account )));
|
|
echo sprintf(_('Deleted: %s'), '/var/mail/vmail/' . basename( $domain ) . '/' . basename( $account )) . PHP_EOL;
|
|
} elseif( is_file('/var/mail/vmail/' . basename( $domain ) . '/' . basename( $account ))){
|
|
echo sprintf(_('File found in mail directory location: "%s". Consider deleting it.'), '/var/mail/vmail/'. basename( $domain ) . '/' . basename( $account ) ) . PHP_EOL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|