package Cpanel::Easy::PHP5::Imap;

# cpanel - Cpanel/Easy/PHP5/Imap.pm               Copyright(c) 2011 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

our $easyconfig = {
    'name'      => 'Imap',
    'url'       => 'http://www.php.net/manual/en/ref.imap.php',
    'ensurepkg' => ['e2fsprogs-devel'],
    'dryrun'    => {
        '0' => {
            'name'    => 'Get OpenSSL path for PHP 5 Imap',
            'command' => sub {
                my ($self) = @_;
                $self->{'__'}{'OpenSSLPath'} = $self->get_openssl_prefix( { 'skip_mach' => 1 } );
                return ( 1, 'Ok' );
            },
        },
        '1' => {
            'name'    => 'Get Imap path for PHP 5',
            'command' => sub {
                my ($self) = @_;

                if ( -e '/var/cpanel/use_this_imap_path' ) {
                    my $path = $self->slurp_file_chomped('/var/cpanel/use_this_imap_path');
                    if ( -d $path ) {
                        $self->{'__'}{'ImapPath'} = $path;
                        return 1, 'Ok';
                    }
                }

                my ( $path, @text ) = $self->get_path_installed('Cpanel::Easy::OptLib::imap');

                if ($path) {
                    if ( $self->slurp_file_chomped( $path . '/version' ) !~ /keepmine/i && !-e '/var/cpanel/ea3_skip_imap_cleanup' && !$self->imap_rpm_cleanup() ) {
                        $self->{'_'}{'hide_imap_libraries'} = 1;
                    }

                    $self->{'__'}{'ImapPath'} = $path;
                    return ( 1, 'Ok' );
                }
                else {
                    return $path, @text;
                }
            },
        },
        '2' => {
            'name'    => 'Find Kerberos for PHP 5 Imap',
            'command' => sub {
                my ($self) = @_;
                $self->{'__'}{'Krb5Opt'} =
                    ( -e '/etc/krb5.conf' )
                  ? [ '--with-kerberos' => '' ]
                  : [];
                return ( 1, 'Ok' );
            },
        },
    },
    'step' => {
        '0' => {
            'name'    => 'to config options',
            'command' => sub {
                my ($self) = @_;
                $self->add_to_configure(
                    {
                        '--with-imap' => $self->{'__'}{'ImapPath'},
                        @{ $self->{'__'}{'Krb5Opt'} },
                        '--with-imap-ssl' => $self->{'__'}{'OpenSSLPath'},
                    }
                );
                return ( 1, 'Ok' );
            },
        },
    },
};

1;

# see ea r270 to see why --with-imap=$cclient is not used
