fix using GPG with non-utf8 OS. Fixes #7227

This commit is contained in:
Yann Leboulanger 2013-06-20 20:48:34 +02:00
parent 03b06bd72b
commit 084681cb7f
3 changed files with 5 additions and 3 deletions

View File

@ -294,7 +294,8 @@ class CommonConnection:
else: else:
def encrypt_thread(msg, keyID, always_trust=False): def encrypt_thread(msg, keyID, always_trust=False):
# encrypt message. This function returns (msgenc, error) # encrypt message. This function returns (msgenc, error)
return self.gpg.encrypt(msg, [keyID], always_trust) return self.gpg.encrypt(msg.encode('utf-8'), [keyID],
always_trust)
def _on_encrypted(output): def _on_encrypted(output):
msgenc, error = output msgenc, error = output
if error == 'NOT_TRUSTED': if error == 'NOT_TRUSTED':

View File

@ -34,6 +34,7 @@ import sys
import operator import operator
import hashlib import hashlib
import gobject import gobject
import locale
from time import (altzone, daylight, gmtime, localtime, mktime, strftime, from time import (altzone, daylight, gmtime, localtime, mktime, strftime,
time as time_time, timezone, tzname) time as time_time, timezone, tzname)
@ -1157,7 +1158,8 @@ class ConnectionHandlersBase:
decmsg = self.gpg.decrypt(encmsg, keyID) decmsg = self.gpg.decrypt(encmsg, keyID)
decmsg = self.connection.Dispatcher.replace_non_character(decmsg) decmsg = self.connection.Dispatcher.replace_non_character(decmsg)
# \x00 chars are not allowed in C (so in GTK) # \x00 chars are not allowed in C (so in GTK)
obj.msgtxt = helpers.decode_string(decmsg.replace('\x00', '')) obj.msgtxt = decmsg.replace('\x00', '').encode(
locale.getpreferredencoding()).decode('utf-8')
obj.encrypted = 'xep27' obj.encrypted = 'xep27'
self.gpg_messages_to_decrypt.remove([encmsg, keyID, obj]) self.gpg_messages_to_decrypt.remove([encmsg, keyID, obj])

View File

@ -31,7 +31,6 @@ if HAVE_GPG:
class GnuPG(gnupg.GPG): class GnuPG(gnupg.GPG):
def __init__(self, use_agent=False): def __init__(self, use_agent=False):
gnupg.GPG.__init__(self) gnupg.GPG.__init__(self)
gnupg.GPG.decode_errors = 'replace'
self.passphrase = None self.passphrase = None
self.use_agent = use_agent self.use_agent = use_agent
self.always_trust = False self.always_trust = False