From 63435c72c5bd59c9497f878ba244423a03df2f13 Mon Sep 17 00:00:00 2001 From: fkrone Date: Sat, 14 Feb 2015 15:22:29 +0100 Subject: [PATCH] Merged change: https://github.com/uragit/gpg-mailgate/commit/779e712a5d81f1c2023c0b89c6f0beef50c9d74c ( Changed GPGEncryptor.encrypt() to also give PGP return code. Write rc to logfile in encrypt_payload(). ) --- GnuPG/__init__.py | 2 +- gpg-mailgate.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/GnuPG/__init__.py b/GnuPG/__init__.py index efdb9ea..e34d22e 100644 --- a/GnuPG/__init__.py +++ b/GnuPG/__init__.py @@ -100,7 +100,7 @@ class GPGEncryptor: def encrypt(self): p = subprocess.Popen( self._command(), stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE ) encdata = p.communicate(input=self._message)[0] - return encdata + return (encdata, p.returncode) def _command(self): cmd = ["/usr/bin/gpg", "--trust-model", "always", "--homedir", self._keyhome, "--batch", "--yes", "--pgp7", "--no-secmem-warning", "-a", "-e"] diff --git a/gpg-mailgate.py b/gpg-mailgate.py index 8879a60..035695e 100755 --- a/gpg-mailgate.py +++ b/gpg-mailgate.py @@ -82,7 +82,10 @@ def encrypt_payload( payload, gpg_to_cmdline ): return payload gpg = GnuPG.GPGEncryptor( cfg['gpg']['keyhome'], gpg_to_cmdline, payload.get_content_charset() ) gpg.update( raw_payload ) - payload.set_payload( gpg.encrypt() ) + encrypted_data, returncode = gpg.encrypt() + if verbose: + log("Return code from encryption=%d (0 indicates success)." % returncode) + payload.set_payload( encrypted_data ) isAttachment = payload.get_param( 'attachment', None, 'Content-Disposition' ) is not None if isAttachment: filename = payload.get_filename()