From 779e712a5d81f1c2023c0b89c6f0beef50c9d74c Mon Sep 17 00:00:00 2001 From: uragit Date: Thu, 21 Nov 2013 21:59:20 -0800 Subject: [PATCH] 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 e3489ed..e870fc8 100644 --- a/GnuPG/__init__.py +++ b/GnuPG/__init__.py @@ -30,7 +30,7 @@ def update(self, message): 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", "--armor", "--encrypt"] diff --git a/gpg-mailgate.py b/gpg-mailgate.py index 1fcf6cd..b787fc2 100755 --- a/gpg-mailgate.py +++ b/gpg-mailgate.py @@ -60,7 +60,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