diff options
Diffstat (limited to 'src/jwebmail/model')
-rw-r--r-- | src/jwebmail/model/read_mails.py | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/src/jwebmail/model/read_mails.py b/src/jwebmail/model/read_mails.py index 43f13ca..d3887ca 100644 --- a/src/jwebmail/model/read_mails.py +++ b/src/jwebmail/model/read_mails.py @@ -1,4 +1,3 @@ -import shlex import os from subprocess import PIPE, Popen, TimeoutExpired from subprocess import run as subprocess_run @@ -202,43 +201,42 @@ class QMailAuthuser: idx = user_mail_addr.find("@") user_name = user_mail_addr[:idx] - cmdline = " ".join( - shlex.quote(str(x)) - for x in ( - self._authenticator, - self._prog, - self._mailbox_path, - self._virtual_user, - user_name, - mode, - ) - ) - - if rp != 3: - cmdline += f" 3<&{rp} {rp}<&-" + cmdline = [ + "moveto3.py", + "-a", + self._authenticator, + str(rp), + self._prog, + self._mailbox_path, + self._virtual_user, + user_name, + mode, + ] return cmdline def _read_qmauth(self, cmd, args, rp, wp): - popen = Popen(cmd, stdin=PIPE, stdout=PIPE, pass_fds=[rp], shell=True, bufsize=0) + with Popen(cmd, stdin=PIPE, stdout=PIPE, pass_fds=[rp], bufsize=0) as popen: + os.close(rp) + os.write(wp, f"{self._username}\0{self._password}\0\0".encode()) + os.close(wp) + r = popen.stdout.read(10) + if popen.poll(): + raise QMAuthError( + "qmail-authuser unexpectedly exited", popen.returncode, r + ) + assert r == b"OPEN\n" + popen.stdin.write(args) + popen.stdin.close() + inp = popen.stdout.readall() - os.close(rp) - os.write(wp, f"{self._username}\0{self._password}\0\0".encode()) - os.close(wp) - r = popen.stdout.read(10) - if popen.poll(): - raise QMAuthError("qmail-authuser unexpectedly exited", popen.returncode, r) - assert r == b"OPEN\n" - popen.stdin.write(args) - popen.stdin.close() - inp = popen.stdout.readall() + if popen.poll() is None: + popen.kill() + popen.poll() - if popen.poll() is None: - popen.kill() - popen.poll() + rc = popen.returncode - rc = popen.returncode if rc == 0: return inp elif rc == 3: |