Fix bug causing messages to have extra characters or failing to encode properly.

This commit is contained in:
perennate 2013-08-11 20:35:48 +08:00 committed by Igor Rzegocki
parent 72395a7e9f
commit c04db9c35f
2 changed files with 16 additions and 4 deletions

View file

@ -16,10 +16,11 @@ def public_keys( keyhome ):
return keys
class GPGEncryptor:
def __init__(self, keyhome, recipients = None):
def __init__(self, keyhome, recipients = None, charset = None):
self._keyhome = keyhome
self._message = ''
self._recipients = list()
self._charset = charset
if recipients != None:
self._recipients.extend(recipients)
@ -32,5 +33,16 @@ class GPGEncryptor:
return encdata
def _command(self):
cmd = "/usr/bin/gpg --trust-model always --homedir %s --batch --yes --pgp7 --no-secmem-warning -a -e -r %s" % (self._keyhome, ' -r '.join(self._recipients))
return cmd.split()
cmd = ["/usr/bin/gpg", "--trust-model", "always", "--homedir", self._keyhome, "--batch", "--yes", "--pgp7", "--no-secmem-warning", "-a", "-e"]
# add recipients
for recipient in self._recipients:
cmd.append("-r")
cmd.append(recipient)
# add on the charset, if set
if self._charset:
cmd.append("--comment")
cmd.append('Charset: ' + self._charset)
return cmd

View file

@ -44,7 +44,7 @@ def encrypt_payload( payload, gpg_to_cmdline ):
raw_payload = payload.get_payload(decode=True)
if "-----BEGIN PGP MESSAGE-----" in raw_payload and "-----END PGP MESSAGE-----" in raw_payload:
return payload
gpg = GnuPG.GPGEncryptor( cfg['gpg']['keyhome'], gpg_to_cmdline )
gpg = GnuPG.GPGEncryptor( cfg['gpg']['keyhome'], gpg_to_cmdline, payload.get_content_charset() )
gpg.update( raw_payload )
payload.set_payload( gpg.encrypt() )
if payload['Content-Disposition']: