]>
git.proxmox.com Git - pmg-api.git/blob - 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.",
172 links
=> [ { rel
=> 'child', href
=> "{queue_id}" } ],
177 my $restenv = PMG
::RESTEnvironment-
>get();
179 my ($count, $res) = PMG
::Postfix
::mailq
(
180 $param->{queue
}, $param->{filter
}, $param->{start
}, $param->{limit
});
182 $restenv->set_result_attrib('total', $count);
188 __PACKAGE__-
>register_method ({
189 name
=> 'read_queued_mail',
190 path
=> 'queue/{queue}/{queue_id}',
192 permissions
=> { check
=> [ 'admin' ] },
195 description
=> "Get the contents of a queued mail.",
197 additionalProperties
=> 0,
199 node
=> get_standard_option
('pve-node'),
200 queue
=> $queue_name_option,
201 queue_id
=> $queue_id_option,
203 description
=> "Show message header content.",
209 description
=> "Include body content.",
216 returns
=> { type
=> 'string' },
220 $param->{header
} //= 1;
222 return PMG
::Postfix
::postcat
($param->{queue_id
}, $param->{header
}, $param->{body
});
225 __PACKAGE__-
>register_method ({
226 name
=> 'flush_queued_mail',
227 path
=> 'queue/{queue}/{queue_id}',
229 permissions
=> { check
=> [ 'admin' ] },
232 description
=> "Schedule immediate delivery of deferred mail with the specified queue ID.",
234 additionalProperties
=> 0,
236 node
=> get_standard_option
('pve-node'),
237 queue
=> $queue_name_option,
238 queue_id
=> $queue_id_option,
241 returns
=> { type
=> 'null' },
245 PMG
::Postfix
::flush_queued_mail
($param->{queue_id
});
250 __PACKAGE__-
>register_method ({
251 name
=> 'delete_queued_mail',
252 path
=> 'queue/{queue}/{queue_id}',
254 permissions
=> { check
=> [ 'admin' ] },
257 description
=> "Delete one message with the named queue ID.",
259 additionalProperties
=> 0,
261 node
=> get_standard_option
('pve-node'),
262 queue
=> $queue_name_option,
263 queue_id
=> $queue_id_option,
266 returns
=> { type
=> 'null' },
270 PMG
::Postfix
::delete_queued_mail
($param->{queue
}, $param->{queue_id
});
276 __PACKAGE__-
>register_method ({
277 name
=> 'delete_all_queues',
280 description
=> "Delete all mails in all posfix queues.",
282 permissions
=> { check
=> [ 'admin' ] },
285 additionalProperties
=> 0,
287 node
=> get_standard_option
('pve-node'),
290 returns
=> { type
=> 'null' },
294 PMG
::Postfix
::delete_queue
();
299 __PACKAGE__-
>register_method ({
300 name
=> 'delete_queue',
301 path
=> 'queue/{queue}',
303 description
=> "Delete all mails in the queue.",
305 permissions
=> { check
=> [ 'admin' ] },
308 additionalProperties
=> 0,
310 node
=> get_standard_option
('pve-node'),
311 queue
=> $queue_name_option,
314 returns
=> { type
=> 'null' },
318 PMG
::Postfix
::delete_queue
($param->{queue
});
324 __PACKAGE__-
>register_method ({
325 name
=> 'flush_queues',
326 path
=> 'flush_queues',
328 description
=> "Flush the queue: attempt to deliver all queued mail.",
330 permissions
=> { check
=> [ 'admin' ] },
333 additionalProperties
=> 0,
335 node
=> get_standard_option
('pve-node'),
338 returns
=> { type
=> 'null' },
342 PMG
::Postfix
::flush_queues
();
348 __PACKAGE__-
>register_method ({
349 name
=> 'discard_verify_cache',
350 path
=> 'discard_verify_cache',
352 description
=> "Discards the address verification cache.",
354 permissions
=> { check
=> [ 'admin' ] },
357 additionalProperties
=> 0,
359 node
=> get_standard_option
('pve-node'),
362 returns
=> { type
=> 'null' },
366 PMG
::Postfix
::discard_verify_cache
();