additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
+ start => {
+ type => 'integer',
+ minimum => 0,
+ optional => 1,
+ },
+ limit => {
+ type => 'integer',
+ minimum => 0,
+ optional => 1,
+ },
filter => {
description => "Filter string.",
type => 'string',
code => sub {
my ($param) = @_;
- my $res = PMG::Postfix::mailq($param->{filter});
+ my $restenv = PVE::RESTEnvironment::get();
+
+ my ($count, $res) = PMG::Postfix::mailq(
+ $param->{filter}, $param->{start}, $param->{limit});
+
+ $restenv->set_result_attrib('total', $count);
return $res;
}});
}
sub mailq {
- my ($filter, $limit) = @_;
+ my ($filter, $start, $limit) = @_;
open(my $fh, '-|', '/usr/sbin/postqueue', '-j') || die "ERROR: unable to run postqueue - $!\n";
my $count = 0;
+
+ $start = 0 if !$start;
+ $limit = 50 if !$limit;
+
my $res = [];
my $line;
while (defined($line = <$fh>)) {
foreach my $entry (@$recipients) {
if (!$filter || $entry->{address} =~ m/$filter/i ||
$rec->{sender} =~ m/$filter/i) {
+ next if $count++ < $start;
+ next if $limit-- <= 0;
+
my $data = {};
foreach my $k (qw(queue_name queue_id arrival_time message_size sender)) {
$data->{$k} = $rec->{$k};
$data->{receiver} = $entry->{address};
$data->{reason} = $entry->{delay_reason};
push @$res, $data;
- last if $limit && (++$count >= $limit);
}
}
}
close (CMD);
- return $res;
+ return ($count, $res);
}
1;