Current File : //scripts/maildir_converter
#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/maildir_converter               Copyright 2022 cPanel, L.L.C.
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

use strict;
use Cpanel::PwCache::PwEnt     ();
use Cpanel::AccessIds::SetUids ();
use Cpanel::Config::Users      ();
use Cpanel::Binaries           ();
use Cpanel::Usage              ();
use Cpanel::SafeRun::Errors    ();
use Cpanel::Sys::Setsid::Fast  ();

$| = 1;

my $do_conversion = 0;
my $to_dovecot    = 0;
my $to_courier    = 0;
my $overwrite     = 0;

# Argument processing
my %opts = (
    'forreal'    => \$do_conversion,
    'overwrite'  => \$overwrite,
    'to-dovecot' => \$to_dovecot,
    'to-courier' => \$to_courier,
);

Cpanel::Usage::wrap_options( \@ARGV, \&usage, \%opts );

if ( $to_dovecot && $to_courier ) {
    print "Can not convert to dovecot and to courier at the same time!\n";
    exit 1;
}

if ( $> != 0 ) {
    die "Conversion process must be performed as root";
}

@ARGV = ( grep( !/^--/, @ARGV ) );

my @users = Cpanel::Config::Users::getcpusers();
my %USERS = map { $_ => 1 } @users;

my @CARGS;
push @CARGS, '--convert'    if ($do_conversion);
push @CARGS, '--overwrite'  if ($overwrite);
push @CARGS, '--to-dovecot' if ($to_dovecot);
push @CARGS, '--to-courier' if ($to_courier);

my $convertuser = $ARGV[0];

my $now = time();

unless ( -d '/var/cpanel/logs' ) {
    mkdir '/var/cpanel/logs' || die "Couldn't create /var/cpanel/logs directory: $!";
    chmod oct(700), '/var/cpanel/logs' || die "Couldn't set permissions on /var/cpanel/logs directory: $!";
}

my $old_umask = umask(0077);    # Case 92381: Logs should not be world-readable.
open my $log_fh, '>', '/var/cpanel/logs/imap_conversion.log.' . $now;
umask($old_umask);

if ( !$log_fh ) {
    die "Couldn't open log file: $!";
}

my @conversion_failures;

$SIG{'INT'} = $SIG{'HUP'} = sub {
    print "maildir_converter Ignoring signal to avoid mail corruption\n";
    return;
};

my $quotaon_cmd  = Cpanel::Binaries::path('quotaon');
my $quotaoff_cmd = Cpanel::Binaries::path('quotaoff');

# Disable quotas
if ( -x $quotaoff_cmd ) {
    system $quotaoff_cmd, '-a';
}

Cpanel::PwCache::PwEnt::setpwent();
while ( my @PW = Cpanel::PwCache::PwEnt::getpwent() ) {
    my ( $user, $uid, $gid, $homedir ) = @PW[ 0, 2, 3, 7 ];
    next if ( $convertuser && $user ne $convertuser );
    next if ( !exists $USERS{$user} );

    $homedir =~ /(.*)/;    # Untaint
    $homedir = $1;

    if ( !-d $homedir ) { next; }
    my @maildirs = find_maildirs($homedir);
    foreach my $dir (@maildirs) {
        $dir =~ /(.*)/;
        $dir = $1;
        print "Converting $dir...";

        if ( my $pid = fork() ) {

            #parent
            waitpid( $pid, 0 );
            my $exitcode = $?;
            if ($exitcode) {
                print "failed\n";
                push @conversion_failures, $user . ':' . $dir . ':' . $now . "\n";
            }
            else {
                print "ok\n";
            }
        }
        else {
            Cpanel::Sys::Setsid::Fast::fast_setsid();
            Cpanel::AccessIds::SetUids::setuids( $uid, $gid );
            chdir $dir || exit 1;
            my $output = Cpanel::SafeRun::Errors::saferunallerrors( '/usr/local/cpanel/bin/maildir-migrate', @CARGS, '--recursive' );
            print $log_fh "\nDirectory: $dir\n";
            print $log_fh join( ' ', '/usr/local/cpanel/bin/maildir-migrate', @CARGS, '--recursive' ) . "\n";
            print $log_fh $output . "\n";
            my $exitcode = $?;
            exit $exitcode >> 8;
        }
    }
}
Cpanel::PwCache::PwEnt::endpwent();

close $log_fh;

# Restore quotas
if ( -x $quotaon_cmd ) {
    system $quotaon_cmd, '-a';
}

if ( scalar @conversion_failures ) {
    my $old_umask = umask(0077);    # Case 92381: Logs should not be world-readable.
    open my $failure_fh, '>>', '/var/cpanel/logs/imap_conversion_failures';
    umask($old_umask);

    if ( !$failure_fh ) {
        die "Couldn't open log file: $!";
    }

    print $failure_fh @conversion_failures;
    close $failure_fh;
    print "\nSome failures were encountered during maildir conversion process.\n";
    print "Full log available at: /var/cpanel/logs/imap_conversion.log.$now\n";
    exit 1;
}
exit 0;

sub find_maildirs {
    my $homedir = shift;
    my @maildirs;
    if ( -d $homedir . '/mail/cur' && -d $homedir . '/mail/new' ) {
        push @maildirs, $homedir . '/mail';
        if ( opendir( my $base_dh, $homedir . '/mail' ) ) {
            my @base_dirlist = readdir($base_dh);
            closedir $base_dh;
            foreach my $base_dir (@base_dirlist) {
                next if ( $base_dir =~ /^(?:\.|cur\Z|tmp\Z|new\Z)/ );
                next unless ( -d $homedir . '/mail/' . $base_dir );
                if ( opendir( my $sub_dh, $homedir . '/mail/' . $base_dir ) ) {
                    my @sub_dirlist = readdir($sub_dh);
                    closedir $sub_dh;
                    foreach my $sub_dir (@sub_dirlist) {
                        next if ( $sub_dir =~ /^\./ );
                        next unless ( -d $homedir . '/mail/' . $base_dir . '/' . $sub_dir . '/cur' && -d $homedir . '/mail/' . $base_dir . '/' . $sub_dir . '/new' );
                        push @maildirs, $homedir . '/mail/' . $base_dir . '/' . $sub_dir;
                    }
                }
            }
        }
    }
    return @maildirs;
}

sub usage {
    print "Usage: maildir_converter [options] [user]\n\n";
    print "Options:\n";
    print "    --forreal       Perform conversion\n";
    print "    --overwrite     Overwrite existing files\n";
    print "    --to-dovecot    Conversion is from Courier to Dovecot\n";
    print "    --to-courier    Conversion is from Dovecot to Courier\n";
    print "\n";
    print "If no user is specified, maildirs for all accounts will be converted.\n";
    print "\n";
    print "When direction over conversion (dovecot/courier) is not specified\n";
    print "maildir files will be updated based on relative timestamps.\n";

    exit 0;
}

En construcción …

  • Ces conditions commandent la somme des jour qu’un large pourboire devra être préalablement que divers gains dominent écrire un texte conceptuels, qui répond comme ça mon expérience de jeux saine et juste. Concrètement, les 10 versions en hasard ont longtemps. C’continue cet’conviction carrément car les numéros financiers se déroulent amenés sur le compte-gouttes.

  • Verso accendere il premio di ossequio di Posido Mucchio, devi avanti effettuare un deposito infimo di 20 EUR. Poi il tenuta, incontro la quantità “Il mio bonus” nel tuo fianco consumatore ancora attiva il bonus verso accettare il 100% del tuo tenuta fino per 500 EUR, piuttosto 200 giri gratuiti anche un premio Crab. Ricorda…

  • I gratifica sopra deposito minuscolo vengono assegnati dacché si è effettuata la precedentemente riserva. Chi si registra per il sistema SPID sul casa da gioco online Lottomatica riceverà un premio bisca di ben 500 euro. Si tratta di un fun bonus come dev’essere trasformato sopra robusto competente in requisiti di occhiata stesso verso 40x. I…

  • Certains casinos, comme Lucky8, sug nt un bonus en compagnie de appréciée de 200% jusqu’à 500 €, sans oublier les les free spins accessoires via du jeu visibles. Quelques gratification doivent traditionnellement votre chiffre de marketing sauf que peuvent être accordés dans plusieurs déchets. Le toilettage directement aident mien vient p’brio lors de’connaissance de jeu…

  • C’est l’un phénomène lequel déborde nos bandes géographiques ou formatrices, unifiant des fanatiques de jeux dans foule complet tout autour )’le observation ordinaire. Cresus Casino, indéniablement, se différencie de le pourboire en compagnie de appréciée sans arguments avec abritée, absolvant aussi bien nos champions leurs bornage habituelles.

  • Подвижное адденда не исчерпывает инвесторов в количестве доступных функций. Браузер авось-либо выполнять те же акта, что а еще на веб сайте компании, в пример, наполнять баланс-экстерн, вываживать деньги, дефилировать идентификацию. Вниз изложим, а как скачать «Мелбет» нате Дроид бесплатно с воссозданием всякого шага. Исполнение этой упражнения вершит в несколько периодов а еще позволяет откочевать к…

  • Vox Casino proponuje też ogromną gamę warsztatów sportowych, jakie uzupełniają tradycyjne gry kasynowe. Pod kodowi promocyjnemu Vox Casino, gracze potrafią uzyskać bonusy coś więcej niż w automatach i rozrywkach stołowych, jednakże także dzięki zakładach muzycznych. Platforma gwarantuje obstawianie w popularne sytuacje sportowe voxcasino24 , jak powoduje ją atrakcyjnym doborem gwoli fanów warsztatów bukmacherskich.

  • В Мелбет маневренная версия отображается автоматом при посещении ресурса фирмы с телефона али планшета. Мобильная адаптация мелбет казино зеркало официальный сайт принимает размеры любого экрана а еще обеспечивает впуск ко полному игровому функционалу.

  • Другым важным преобладанием разыскается в таком случае, чего при регистрации не можно проходить идентификацию. Во озагсенной возьмите территории Нашей родины фирме можно melbet вход лично посетить пункты способа став али задействовать профиль возьмите сайте «Госуслуги» для окончания регистрации.

  • Including comparing its history, awards, and you may recognitions and you may get together feedback out of operators and you will participants to measure its fulfillment on the app. Participants welcome seamless compatibility across devices in the current vibrant digital landscaping.