diff --git a/src/common/connection.py b/src/common/connection.py index c6daf899e..781c9dd57 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -167,7 +167,8 @@ class Connection(ConnectionHandlers): self.private_storage_supported = True if gajim.otr_module: - self.otr_userstates = gajim.otr_module.otrl_userstate_create() + self.otr_userstates = \ + gajim.otr_module.otrl_userstate_create() # END __init__ def put_event(self, ev): diff --git a/src/message_control.py b/src/message_control.py index d12f4ef4d..9b63aa60c 100644 --- a/src/message_control.py +++ b/src/message_control.py @@ -139,37 +139,47 @@ class MessageControl: def send_message(self, message, keyID = '', type = 'chat', chatstate = None, msg_id = None, composing_xep = None, resource = None, user_nick = None): - '''Send the given message to the active tab. Doesn't return None if error - ''' + # Send the given message to the active tab. + # Doesn't return None if error jid = self.contact.jid original_message = message - if gajim.otr_module: + if gajim.otr_module and self.session.append_otr_tag: if type == 'chat' and isinstance(message, unicode): - d = {'kwargs':{'keyID':keyID, 'type':type, - 'chatstate':chatstate, 'msg_id':msg_id, - 'composing_xep':composing_xep, 'resource':self.resource, - 'user_nick':user_nick, 'session':self.session, - 'original_message':original_message}, 'account':self.account} + d = {'kwargs': {'keyID': keyID, 'type': type, + 'chatstate': chatstate, + 'msg_id': msg_id, + 'composing_xep': composing_xep, + 'resource': self.resource, + 'user_nick': user_nick, + 'session': self.session, + 'original_message': original_message}, + 'account': self.account} new_msg = gajim.otr_module.otrl_message_sending( - gajim.connections[self.account].otr_userstates, + self.session.conn.otr_userstates, (gajim.otr_ui_ops, d), - gajim.get_jid_from_account(self.account).encode(), - gajim.OTR_PROTO, self.contact.get_full_jid().encode(), - message.encode(), None, (gajim.otr_add_appdata, self.account)) + gajim.get_jid_from_account( + self.account).encode(), + gajim.OTR_PROTO, + self.contact.get_full_jid().encode(), + message.encode(), None, + (gajim.otr_add_appdata, self.account)) - context = gajim.otr_module.otrl_context_find( - gajim.connections[self.account].otr_userstates, - self.contact.get_full_jid().encode(), - gajim.get_jid_from_account(self.account).encode(), - gajim.OTR_PROTO, 1, (gajim.otr_add_appdata, - self.account))[0] + ctx = gajim.otr_module.otrl_context_find( + self.session.conn.otr_userstates, + self.contact.get_full_jid().encode(), + gajim.get_jid_from_account( + self.account).encode(), + gajim.OTR_PROTO, 1, + (gajim.otr_add_appdata, + self.account))[0] - # we send all because inject_message can filter on HTML stuff then + # we send all because inject_message can filter + # on HTML stuff then gajim.otr_module.otrl_message_fragment_and_send( - (gajim.otr_ui_ops, d), - context, new_msg, gajim.otr_module.OTRL_FRAGMENT_SEND_ALL) + (gajim.otr_ui_ops, d), ctx, new_msg, + gajim.otr_module.OTRL_FRAGMENT_SEND_ALL) return # Send and update history diff --git a/src/session.py b/src/session.py index f7ce5d090..90afc5276 100644 --- a/src/session.py +++ b/src/session.py @@ -18,6 +18,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): stanza_session.EncryptedStanzaSession.__init__(self, conn, jid, thread_id, type = 'chat') self.control = None + self.append_otr_tag = True def acknowledge_termination(self): # the other party terminated the session. we'll keep the control around, though. @@ -151,6 +152,19 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): if msgtxt == '': return + else: + self.append_otr_tag = False + + # We're also here if we just don't support OTR. + # Thus, we should strip the tags from plaintext + # messages since they look ugly. + msgtxt = msgtxt.replace('\x20\x09\x20\x20\x09' \ + '\x09\x09\x09\x20\x09\x20\x09\x20\x09' \ + '\x20\x20', '') + msgtxt = msgtxt.replace('\x20\x09\x20\x09\x20' \ + '\x20\x09\x20', '') + msgtxt = msgtxt.replace('\x20\x20\x09\x09\x20' \ + '\x20\x09\x20', '') else: log_type = 'single_msg_recv'