| 1707 | | |
| 1708 | | # We don't trust libotr, that's why we only pass the message |
| 1709 | | # to it if necessary. otrl_proto_message_type does this check. |
| 1710 | | if gajim.otr_module and not xep_200_encrypted \ |
| 1711 | | and isinstance(msgtxt, unicode) and \ |
| 1712 | | gajim.otr_module.otrl_proto_message_type(msgtxt.encode()) != \ |
| 1713 | | gajim.otr_module.OTRL_MSGTYPE_NOTOTR: |
| 1714 | | # set to encrypted if it's really encrypted. |
| 1715 | | if gajim.otr_module.otrl_proto_message_type( |
| 1716 | | msgtxt.encode()) != \ |
| 1717 | | gajim.otr_module.OTRL_MSGTYPE_TAGGEDPLAINTEXT: |
| 1718 | | encrypted = True |
| 1719 | | |
| 1720 | | # TODO: Do we really need .encode()? |
| 1721 | | # yes we do. OTR can't handle unicode. |
| 1722 | | otr_msg_tuple = \ |
| 1723 | | gajim.otr_module.otrl_message_receiving( |
| 1724 | | self.otr_userstates, |
| 1725 | | (gajim.otr_ui_ops, {'account': self.name}), |
| 1726 | | gajim.get_jid_from_account(self.name).encode(), |
| 1727 | | gajim.OTR_PROTO, |
| 1728 | | frm.encode(), |
| 1729 | | msgtxt.encode(), |
| 1730 | | (gajim.otr_add_appdata, self.name)) |
| 1731 | | msgtxt = unicode(otr_msg_tuple[1]) |
| 1732 | | |
| 1733 | | html_node = msg.getTag('html') |
| 1734 | | if html_node: |
| 1735 | | msg.delChild(html_node) |
| 1736 | | msg.setBody(msgtxt) |
| 1737 | | |
| 1738 | | if gajim.otr_module.otrl_tlv_find( |
| 1739 | | otr_msg_tuple[2], |
| 1740 | | gajim.otr_module.OTRL_TLV_DISCONNECTED) != None: |
| 1741 | | gajim.otr_ui_ops.gajim_log(_('%s ' \ |
| 1742 | | 'has ended his/her private ' \ |
| 1743 | | 'conversation with you. You should ' \ |
| 1744 | | 'do the same.') % frm, |
| 1745 | | self.name, |
| 1746 | | frm.encode()) |
| 1747 | | |
| 1748 | | ctrls = gajim.interface.msg_win_mgr.get_chat_controls(jid, self.name) |
| 1749 | | for ctrl in ctrls: |
| 1750 | | ctrl.update_otr() |
| 1751 | | |
| 1752 | | ctx = gajim.otr_module. \ |
| 1753 | | otrl_context_find( |
| 1754 | | self.otr_userstates, |
| 1755 | | frm.encode(), |
| 1756 | | gajim.get_jid_from_account( |
| 1757 | | self.name).encode(), |
| 1758 | | gajim.OTR_PROTO, 1, |
| 1759 | | (gajim.otr_add_appdata, |
| 1760 | | self.name))[0] |
| 1761 | | tlvs = otr_msg_tuple[2] |
| 1762 | | ctx.app_data.handle_tlv(tlvs) |
| 1763 | | |
| 1764 | | if msgtxt == '': |
| 1765 | | return |
| 1766 | | elif msgtxt != None and msgtxt != '': |
| 1767 | | gajim.otr_dont_append_tag[frm] = True |
| 1768 | | |
| 1769 | | # We're also here if we just don't |
| 1770 | | # support OTR. Thus, we should strip |
| 1771 | | # the tags from plaintext messages |
| 1772 | | # since they look ugly. |
| 1773 | | msgtxt = msgtxt.replace('\x20\x09\x20' \ |
| 1774 | | '\x20\x09\x09\x09\x09\x20\x09' \ |
| 1775 | | '\x20\x09\x20\x09\x20\x20', '') |
| 1776 | | msgtxt = msgtxt.replace('\x20\x09\x20' \ |
| 1777 | | '\x09\x20\x20\x09\x20', '') |
| 1778 | | msgtxt = msgtxt.replace('\x20\x20\x09' \ |
| 1779 | | '\x09\x20\x20\x09\x20', '') |