#!/usr/bin/perl

use POSIX;

my $system = ( POSIX::uname() )[0];

exit if ( $system ne 'FreeBSD' );

my $imap_config = '/usr/local/etc/courier-imap/imapd';

exit if !-e $imap_config;

if ( open my $imap_fh, '<', $imap_config ) {
    my $has_maxperip = 0;
    while ( my $line = readline($imap_fh) ) {
        if ( $line =~ m/^\s*MAXPERIP=\d+/ ) {
            $has_maxperip = 1;
            last;
        }
    }
    close $imap_fh;

    if ( !$has_maxperip ) {
        system '/scripts/courierup', '--reconfig';
        system '/scripts/restartsrv_imap';
    }
}

print "Done\n";
