package Cpanel::Easy::PHP5::MailHeaders;

# cpanel - Cpanel/Easy/PHP5/MailHeaders.pm        Copyright(c) 2012 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' => 'MailHeaders',
    'url'  => 'http://choon.net/php-mail-header.php',
    'step' => {
        '0' => {
            'name'    => 'Apply mail headers patch for PHP5',
            'command' => sub {
                my ($self) = @_;

                # For security reasons, do not include the mail header for internal PHP
                # (Case 61937)
                if ( $self->get_param('makecpphp') ) {
                    $self->print_alert_color( 'blue', 'You have enabled cpphp compatibility: the MailHeaders option will not be used.' );
                    return ( 1, 'Ok' );
                }

                my $php_version = '';
                my $pns         = "Cpanel::Easy::PHP5";
                if ( $self->{'working_profile'}{$pns} ) {
                    for my $spec ( $pns->versions() ) {
                        if ( $self->{'working_profile'}{ $pns . '::' . $spec } ) {
                            $php_version = $pns . '::' . $spec;
                            next;
                        }
                    }
                }
                return ( 0, 'Could not determine PHP version' ) unless ($php_version);

                my $pp_ec = $self->get_easyconfig_hr_from_ns_variations($php_version);
                return ( 0, 'Could not find parent PHP path info' )
                  if ref $pp_ec ne 'HASH' || !exists $pp_ec->{'src_cd2'};

                require File::Spec;    # Already brought in, but just in case...
                my $path = File::Spec->catdir( $self->{'opt_mod_src_dir'}, $pp_ec->{'src_cd2'} );
                return $self->apply_patch( '../cppatch/php5-mail-header.patch', $path );
            },
        },
    },
};

1;
