Gajim 1.9 support
This commit is contained in:
parent
12659472b0
commit
7f72c4bc60
36
otr.py
36
otr.py
|
@ -21,10 +21,11 @@ import random
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
from gajim.common import const, app, helpers, configpaths
|
from gajim.common import const, app, helpers, configpaths
|
||||||
from gajim.common.const import EncryptionData
|
from gajim.common.const import Trust
|
||||||
from gajim.common.structs import OutgoingMessage
|
from gajim.common.structs import OutgoingMessage
|
||||||
from nbxmpp.protocol import Message, JID
|
from nbxmpp.protocol import Message, JID
|
||||||
from nbxmpp.simplexml import Node
|
from nbxmpp.simplexml import Node
|
||||||
|
from nbxmpp.structs import EncryptionData
|
||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
import sys
|
import sys
|
||||||
|
@ -110,14 +111,9 @@ class OTR(context.Account):
|
||||||
# factory for Gajim 1.4+
|
# factory for Gajim 1.4+
|
||||||
def makeOutgoingMessage(self,message,control,peer):
|
def makeOutgoingMessage(self,message,control,peer):
|
||||||
contact = control.client.get_module('Contacts').get_contact(peer, groupchat=False)
|
contact = control.client.get_module('Contacts').get_contact(peer, groupchat=False)
|
||||||
chatstate = control.client.get_module('Chatstate').get_active_chatstate(contact)
|
|
||||||
return OutgoingMessage(account=self.account,
|
return OutgoingMessage(account=self.account,
|
||||||
contact=contact,
|
contact=contact,
|
||||||
message=message,
|
text=message)
|
||||||
type_='chat',
|
|
||||||
chatstate=chatstate,
|
|
||||||
label=None,
|
|
||||||
correct_id=None)
|
|
||||||
|
|
||||||
# load my private key
|
# load my private key
|
||||||
def loadPrivkey(self):
|
def loadPrivkey(self):
|
||||||
|
@ -152,30 +148,36 @@ class OTR(context.Account):
|
||||||
else:
|
else:
|
||||||
channel.resource = sFrom.resource
|
channel.resource = sFrom.resource
|
||||||
stanza.setBody(text and text.decode() or "")
|
stanza.setBody(text and text.decode() or "")
|
||||||
properties.encrypted = EncryptionData({'name': OTR.ENCRYPTION_NAME})
|
properties.encrypted = EncryptionData(protocol=OTR.ENCRYPTION_NAME, key='Unknown', trust=Trust.UNDECIDED)
|
||||||
finally:
|
finally:
|
||||||
if channel.mayRetransmit and channel.state and ctl: channel.mayRetransmit = ctl.client.send_message(self.makeOutgoingMessage(channel.lastMessage.decode(), ctl, peer))
|
if channel.mayRetransmit and channel.state and ctl: channel.mayRetransmit = ctl.client.send_message(self.makeOutgoingMessage(channel.lastMessage.decode(), ctl, peer))
|
||||||
|
|
||||||
# encrypt message
|
# encrypt message
|
||||||
def encrypt(self,event,callback):
|
def encrypt(self,event,callback):
|
||||||
peer = event.msg_iq.getTo().new_as_bare()
|
peer = event.contact.jid
|
||||||
channel, ctl = self.getContext(peer), self.getControl(peer)
|
channel, ctl = self.getContext(peer), self.getControl(peer)
|
||||||
|
stanza = event.get_stanza()
|
||||||
if not hasattr(channel, 'resource'):
|
if not hasattr(channel, 'resource'):
|
||||||
channel.resource = ""
|
channel.resource = ""
|
||||||
if channel.resource:
|
if channel.resource:
|
||||||
peer = peer.new_with(resource=channel.resource)
|
peer = peer.new_with(resource=channel.resource)
|
||||||
if event.xhtml: return ctl.client.send_message(self.makeOutgoingMessage(event.message, ctl, peer)) # skip xhtml messages
|
|
||||||
try:
|
try:
|
||||||
encrypted = channel.sendMessage(context.FRAGMENT_SEND_ALL_BUT_LAST,event.message.encode(),appdata=event.msg_iq.getThread()) or b''
|
encrypted = channel.sendMessage(context.FRAGMENT_SEND_ALL_BUT_LAST,event.get_text().encode(),appdata=stanza.getThread()) or b''
|
||||||
message = (encrypted != self.getDefaultQueryMessage(OTR.DEFAULT_POLICY.get)) and event.message or ""
|
message = (encrypted != self.getDefaultQueryMessage(OTR.DEFAULT_POLICY.get)) and event.get_text() or ""
|
||||||
except context.NotEncryptedError as e:
|
except context.NotEncryptedError as e:
|
||||||
self.log.error("** got exception while encrypting message: %s" % e)
|
self.log.error("** got exception while encrypting message: %s" % e)
|
||||||
channel.printl(peer,OTR.STATUS[e.__class__])
|
channel.printl(peer,OTR.STATUS[e.__class__])
|
||||||
else:
|
else:
|
||||||
event.msg_iq.setBody(encrypted.decode()) # encrypted data goes here
|
stanza.setBody(encrypted.decode()) # encrypted data goes here
|
||||||
event.message = message # message that will be displayed in our chat goes here
|
event._text = message # message that will be displayed in our chat goes here
|
||||||
event.encrypted, event.additional_data["encrypted"] = OTR.ENCRYPTION_NAME, {"name":OTR.ENCRYPTION_NAME} # some mandatory encryption flags
|
event.set_encryption(
|
||||||
|
EncryptionData(
|
||||||
|
protocol=OTR.ENCRYPTION_NAME,
|
||||||
|
key='Unknown',
|
||||||
|
trust=Trust.UNDECIDED,
|
||||||
|
)
|
||||||
|
) # some mandatory encryption flags
|
||||||
if channel.resource:
|
if channel.resource:
|
||||||
event.stanza.addChild('no-copy', namespace='urn:xmpp:hints') # don't send carbons
|
stanza.addChild('no-copy', namespace='urn:xmpp:hints') # don't send carbons
|
||||||
event.stanza.addChild('no-store', namespace='urn:xmpp:hints') # don't store in MAM
|
stanza.addChild('no-store', namespace='urn:xmpp:hints') # don't store in MAM
|
||||||
callback(event)
|
callback(event)
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
"win32"
|
"win32"
|
||||||
],
|
],
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"gajim>=1.6,<1.9"
|
"gajim>=1.9,<1.10"
|
||||||
],
|
],
|
||||||
"short_name": "otrplugin",
|
"short_name": "otrplugin",
|
||||||
"version": "0.5.3"
|
"version": "0.6"
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ ERROR = None
|
||||||
import logging
|
import logging
|
||||||
from gajim.plugins import GajimPlugin
|
from gajim.plugins import GajimPlugin
|
||||||
from gajim.common import app
|
from gajim.common import app
|
||||||
|
from gajim.common.storage.archive.const import MessageType
|
||||||
from gajim.gtk.util import make_menu_item
|
from gajim.gtk.util import make_menu_item
|
||||||
from gi.repository import Gtk, Gio
|
from gi.repository import Gtk, Gio
|
||||||
|
|
||||||
|
@ -93,7 +94,7 @@ class OTRPlugin(GajimPlugin):
|
||||||
|
|
||||||
# encrypt message #
|
# encrypt message #
|
||||||
def _encrypt_message(self,con,event,callback):
|
def _encrypt_message(self,con,event,callback):
|
||||||
if not event.message or event.type_ != 'chat': return # drop empty and non-chat messages
|
if not event.has_text() or event.type != MessageType.CHAT: return # drop empty and non-chat messages
|
||||||
otr = self.get_otr(event.account)
|
otr = self.get_otr(event.account)
|
||||||
otr.otr.encrypt(event,callback)
|
otr.otr.encrypt(event,callback)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue