perl <<'EOF'
use Cpanel::PublicAPI;

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 is_remote {
    my $domain = shift;
    open my $fh, '<', "/etc/remotedomains";
    while ( <$fh> ) {
        if ( $_ =~ /^$domain$/ ) {
            return 1;
        }
    }
    return 0;
}

my $accesshash = get_accesshash();
my $cp = Cpanel::PublicAPI->new( 'user' => 'root', 'accesshash' => $accesshash );
my $domain = 'domain_placeholder';
my $user;
open(my $DAT, '<', '/etc/userdomains');
	while(<$DAT>) {
		if ( /^$domain:\s([a-zA-Z0-9]+)$/ ) {
			$user = $1;
			last;
		}
	}
close($DAT);
if ( ! $user ) {
	die "[!] Could not determine owner for $domain.\n";
}
unless ( -f "/var/cpanel/users/$user" ) {
        die "[!] $user does not exist.\n";
}
my $listmail = $cp->cpanel_api2_request('whostmgr', { 'module' => 'Email', 'func' => 'listpopswithdisk' },
        {   
            'user' => $user,
	}
);
my @mailinfo = @{$listmail->{cpanelresult}{data}};
my $count = @mailinfo;
if ( $count ) {
	printf "%-8s %-52s %30s %30s %30s \n", '', 'Login', 'Disk Used', 'Disk Quota', 'Remote';
	foreach(@mailinfo){
		my ( undef, $domain ) = split('@', $_->{login});
		printf "%-10s %-50s %30s %30s %30s \n", '', $_->{login}, $_->{diskused}, $_->{diskquota}, is_remote($domain);
	}
} else {
	print "[!] No e-mail accounts found for $user.\n";
}
EOF
