perl<<'EOF'
use lib qw( /usr/local/cpanel /usr/local/cpanel/3rdparty/perl/514/lib64/perl5/cpanel_lib );
use strict;
use cPanel::PublicAPI;

my $accesshash = get_accesshash();

my $cp = cPanel::PublicAPI->new( 'user' => 'root', 'accesshash' => $accesshash );

my $domain = 'domain_placeholder';
my $user = check_user($domain);

my $output = $cp->cpanel_api2_request(
         'whostmgr',
        {
                'module' => 'Email',
                'func' => 'listforwards',
                'user' => $user
        }
);
if ( $output->{'cpanelresult'}->{'event'}->{'result'} == 1 ) {
	print "[*] Forwarders for $user - \n";
	foreach my $fwders ($output->{'cpanelresult'}->{data}) {
	        foreach my $fwder(@$fwders) {
	                print "\t" . $fwder->{'html_dest'} . " ->  " . $fwder->{'html_forward'} . "\n";
	        }
	}
} else { 
	print "[!] Err, User not found \n"; 
}


sub get_accesshash {
        my $accesshash;
        if ( ! -f '/root/.accesshash' ) {
                $ENV{REMOTE_USER} = 'root';
                system('/usr/local/cpanel/bin/realmkaccesshash');
        }
        if ( -f '/root/.accesshash' ) {
                open my $hash, "<", "/root/.accesshash";
                my @accesshash = <$hash>;
                close $hash;
                foreach(@accesshash){
                        $accesshash .= $_
                }
                return $accesshash;
        }
}

sub check_user {
        my $domain = shift;
        my $user;
        open(my $DAT, "<", "/etc/trueuserdomains");
                while(<$DAT>) {
                        if ( /^$domain:\s([a-zA-Z0-9]+)$/ ) {
                                $user = $1;
                                last;
                        }
                }
        close($DAT);
        my $file = "/var/cpanel/users/$user";
        unless ( -f $file ) {
                       die "[!] Invalid user: $user does not exist.\n";
        }
        return($user);
}
EOF
