]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/API2/Postfix.pm
1 package PMG
::API2
::Postfix
;
8 use PVE
::Tools
qw(extract_param);
9 use PVE
::JSONSchema
qw(get_standard_option);
15 use base
qw(PVE::RESTHandler);
17 my $postfix_queues = ['deferred', 'active', 'incoming', 'hold'];
19 my $queue_name_option = {
20 description
=> "Postfix queue name.",
22 enum
=> $postfix_queues,
25 my $queue_id_option = {
26 description
=> "The Message queue ID.",
28 pattern
=> '[a-zA-Z0-9]+',
33 __PACKAGE__-
>register_method ({
37 permissions
=> { user
=> 'all' },
38 description
=> "Directory index.",
40 additionalProperties
=> 0,
42 node
=> get_standard_option
('pve-node'),
51 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
59 { name
=> 'flush_queues' },
60 { name
=> 'discard_verify_cache' },
66 __PACKAGE__-
>register_method ({
70 permissions
=> { check
=> [ 'admin', 'audit' ] },
73 description
=> "Print Postfix queue domain and age distribution.",
75 additionalProperties
=> 0,
77 node
=> get_standard_option
('pve-node'),
79 description
=> $queue_name_option->{description
},
81 enum
=> $postfix_queues,
82 default => 'deferred',
97 my $queue = $param->{queue
} || 'deferred';
99 my $res = PMG
::Postfix
::qshape
($queue);
105 __PACKAGE__-
>register_method ({
106 name
=> 'queue_index',
109 permissions
=> { user
=> 'all' },
110 description
=> "Directory index.",
112 additionalProperties
=> 0,
114 node
=> get_standard_option
('pve-node'),
123 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
129 foreach my $queue (@$postfix_queues) {
130 push @$res, { name
=> $queue };
135 __PACKAGE__-
>register_method ({
137 path
=> 'queue/{queue}',
139 permissions
=> { check
=> [ 'admin', 'audit' ] },
142 description
=> "List the mail queue for a specific domain.",
144 additionalProperties
=> 0,
146 node
=> get_standard_option
('pve-node'),
147 queue
=> $queue_name_option,
159 description
=> "Filter string.",
165 description
=> "Sort field.",
168 enum
=> ['arrival_time', 'message_size', 'sender', 'receiver', 'reason'],
171 description
=> "Sort direction.",
174 enum
=> ['ASC', 'DESC'],
175 requires
=> 'sortfield',
185 links
=> [ { rel
=> 'child', href
=> "{queue_id}" } ],
190 my $restenv = PMG
::RESTEnvironment-
>get();
192 my ($count, $res) = PMG
::Postfix
::mailq
(
193 $param->{queue
}, $param->{filter
}, $param->{start
}, $param->{limit
});
195 $restenv->set_result_attrib('total', $count);
197 my $sortfield = $param->{sortfield
};
198 if (defined($sortfield)) {
199 my $sort_func = sub {
200 my ($c, $d) = ($param->{sortdir
} eq 'DESC') ?
($b, $a) : ($a, $b);
201 if ($sortfield eq 'message_size' || $sortfield eq 'arrival_time') {
202 return $c->{$sortfield} <=> $d->{$sortfield};
204 return $c->{$sortfield} cmp $d->{$sortfield};
208 $res = [ sort $sort_func @$res ] ;
216 __PACKAGE__-
>register_method ({
217 name
=> 'read_queued_mail',
218 path
=> 'queue/{queue}/{queue_id}',
220 permissions
=> { check
=> [ 'admin' ] },
223 description
=> "Get the contents of a queued mail.",
225 additionalProperties
=> 0,
227 node
=> get_standard_option
('pve-node'),
228 queue
=> $queue_name_option,
229 queue_id
=> $queue_id_option,
231 description
=> "Show message header content.",
237 description
=> "Include body content.",
244 returns
=> { type
=> 'string' },
248 $param->{header
} //= 1;
250 return PMG
::Postfix
::postcat
($param->{queue_id
}, $param->{header
}, $param->{body
});
253 __PACKAGE__-
>register_method ({
254 name
=> 'flush_queued_mail',
255 path
=> 'queue/{queue}/{queue_id}',
257 permissions
=> { check
=> [ 'admin' ] },
260 description
=> "Schedule immediate delivery of deferred mail with the specified queue ID.",
262 additionalProperties
=> 0,
264 node
=> get_standard_option
('pve-node'),
265 queue
=> $queue_name_option,
266 queue_id
=> $queue_id_option,
269 returns
=> { type
=> 'null' },
273 PMG
::Postfix
::flush_queued_mail
($param->{queue_id
});
278 __PACKAGE__-
>register_method ({
279 name
=> 'delete_queued_mail',
280 path
=> 'queue/{queue}/{queue_id}',
282 permissions
=> { check
=> [ 'admin' ] },
285 description
=> "Delete one message with the named queue ID.",
287 additionalProperties
=> 0,
289 node
=> get_standard_option
('pve-node'),
290 queue
=> $queue_name_option,
291 queue_id
=> $queue_id_option,
294 returns
=> { type
=> 'null' },
298 PMG
::Postfix
::delete_queued_mail
($param->{queue
}, $param->{queue_id
});
304 __PACKAGE__-
>register_method ({
305 name
=> 'delete_all_queues',
308 description
=> "Delete all mails in all posfix queues.",
310 permissions
=> { check
=> [ 'admin' ] },
313 additionalProperties
=> 0,
315 node
=> get_standard_option
('pve-node'),
318 returns
=> { type
=> 'null' },
322 PMG
::Postfix
::delete_queue
();
327 __PACKAGE__-
>register_method ({
328 name
=> 'delete_queue',
329 path
=> 'queue/{queue}',
331 description
=> "Delete all mails in the queue.",
333 permissions
=> { check
=> [ 'admin' ] },
336 additionalProperties
=> 0,
338 node
=> get_standard_option
('pve-node'),
339 queue
=> $queue_name_option,
342 returns
=> { type
=> 'null' },
346 PMG
::Postfix
::delete_queue
($param->{queue
});
352 __PACKAGE__-
>register_method ({
353 name
=> 'flush_queues',
354 path
=> 'flush_queues',
356 description
=> "Flush the queue: attempt to deliver all queued mail.",
358 permissions
=> { check
=> [ 'admin' ] },
361 additionalProperties
=> 0,
363 node
=> get_standard_option
('pve-node'),
366 returns
=> { type
=> 'null' },
370 PMG
::Postfix
::flush_queues
();
376 __PACKAGE__-
>register_method ({
377 name
=> 'discard_verify_cache',
378 path
=> 'discard_verify_cache',
380 description
=> "Discards the address verification cache.",
382 permissions
=> { check
=> [ 'admin' ] },
385 additionalProperties
=> 0,
387 node
=> get_standard_option
('pve-node'),
390 returns
=> { type
=> 'null' },
394 PMG
::Postfix
::discard_verify_cache
();