OpenSMTPD queue Support
This commit is contained in:
1 parent
243c04c51b
commit
f0949ce60c
3 files changed
+172
-51
No files matched your search
+46
-22
@@ -26,7 +26,7 @@ from pymailq import CONFIG, debug
|
||||
|
||||
class QueueControl(object):
|
||||
"""
|
||||
Postfix queue control using postsuper command.
|
||||
Postfix/openSMTPD queue control using postsuper/smtpctl command.
|
||||
|
||||
The :class:`~control.QueueControl` instance defines the following
|
||||
attributes:
|
||||
@@ -109,31 +109,55 @@ class QueueControl(object):
|
||||
# It should not be possible to inject commands, but who knows...
|
||||
# https://www.kevinlondon.com/2015/07/26/dangerous-python-functions.html
|
||||
# And consider the use of sh module: https://amoffat.github.io/sh/
|
||||
operation_cmd = self.get_operation_cmd(operation) + ['-']
|
||||
try:
|
||||
child = subprocess.Popen(operation_cmd,
|
||||
stdin=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
except EnvironmentError as exc:
|
||||
command_str = " ".join(operation_cmd)
|
||||
error_msg = "Unable to call '%s': %s" % (command_str, str(exc))
|
||||
raise RuntimeError(error_msg)
|
||||
if 'postfix' in CONFIG['core']['smtpd_type']:
|
||||
operation_cmd = self.get_operation_cmd(operation) + ['-']
|
||||
try:
|
||||
child = subprocess.Popen(operation_cmd,
|
||||
stdin=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
except EnvironmentError as exc:
|
||||
command_str = " ".join(operation_cmd)
|
||||
error_msg = "Unable to call '%s': %s" % (command_str, str(exc))
|
||||
raise RuntimeError(error_msg)
|
||||
|
||||
# If permissions error, the postsuper process takes ~1s to teardown.
|
||||
# Wait this delay and raise error message if process has stopped.
|
||||
time.sleep(1.1)
|
||||
child.poll()
|
||||
if child.returncode:
|
||||
raise RuntimeError(child.communicate()[1].strip().decode())
|
||||
# If permissions error, the postsuper process takes ~1s to teardown.
|
||||
# Wait this delay and raise error message if process has stopped.
|
||||
time.sleep(1.1)
|
||||
child.poll()
|
||||
if child.returncode:
|
||||
raise RuntimeError(child.communicate()[1].strip().decode())
|
||||
|
||||
try:
|
||||
try:
|
||||
for msg in messages:
|
||||
child.stdin.write((msg.qid+'\n').encode())
|
||||
stderr = child.communicate()[1].strip()
|
||||
except BrokenPipeError:
|
||||
raise RuntimeError("Unexpected error: child process has crashed")
|
||||
|
||||
return [line.strip() for line in stderr.decode().split('\n')]
|
||||
|
||||
# smtpctl do not use stdin, have to call the binary for each message :-(
|
||||
else:
|
||||
result = []
|
||||
for msg in messages:
|
||||
child.stdin.write((msg.qid+'\n').encode())
|
||||
stderr = child.communicate()[1].strip()
|
||||
except BrokenPipeError:
|
||||
raise RuntimeError("Unexpected error: child process has crashed")
|
||||
operation_cmd = self.get_operation_cmd(operation) + [msg.qid]
|
||||
try:
|
||||
child = subprocess.Popen(operation_cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
except EnvironmentError as exc:
|
||||
command_str = " ".join(operation_cmd)
|
||||
error_msg = "Unable to call '%s': %s" % (command_str, str(exc))
|
||||
raise RuntimeError(error_msg)
|
||||
|
||||
stdout, stderr = child.communicate()
|
||||
if not len(stdout):
|
||||
return [line.strip() for line in stderr.decode().split('\n')]
|
||||
|
||||
result.append(stdout.decode())
|
||||
|
||||
return result
|
||||
|
||||
return [line.strip() for line in stderr.decode().split('\n')]
|
||||
|
||||
def delete_messages(self, messages):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user