gotr: enable html messages
This commit is contained in:
@@ -54,11 +54,12 @@ ended_tip = 'The private chat session to this contact has <i>ended</i>'
|
||||
inactive_tip = 'Communication to this contact is currently ' \
|
||||
'<i>unencrypted</i>'
|
||||
|
||||
import cgi
|
||||
import logging
|
||||
import os
|
||||
import pickle
|
||||
import time
|
||||
import sys
|
||||
import logging
|
||||
|
||||
import common.xmpp
|
||||
from common import gajim
|
||||
@@ -69,6 +70,9 @@ from message_control import TYPE_CHAT, MessageControl
|
||||
from plugins.helpers import log_calls, log
|
||||
from plugins.plugin import GajimPluginException
|
||||
|
||||
from HTMLParser import HTMLParser
|
||||
from htmlentitydefs import name2codepoint
|
||||
|
||||
import ui
|
||||
|
||||
sys.path.insert(0, os.path.dirname(ui.__file__))
|
||||
@@ -570,14 +574,11 @@ class OtrPlugin(GajimPlugin):
|
||||
if ctx is not None:
|
||||
ctx.smpWindow.handle_tlv(tlvs)
|
||||
|
||||
event.msgtxt = unicode(msgtxt or '')
|
||||
stripper = HTMLStripper()
|
||||
stripper.feed(unicode(msgtxt or ''))
|
||||
event.msgtxt = stripper.stripped_data
|
||||
event.stanza.setBody(event.msgtxt)
|
||||
|
||||
# every message that went through OTR (ie. was OTR-related) gets
|
||||
# stripped from html. I don't like html.
|
||||
html_node = event.stanza.getTag('html')
|
||||
if html_node:
|
||||
event.stanza.delChild(html_node)
|
||||
event.stanza.setXHTML(msgtxt)
|
||||
|
||||
return PASS
|
||||
|
||||
@@ -596,9 +597,11 @@ class OtrPlugin(GajimPlugin):
|
||||
if event.resource:
|
||||
fjid += '/' + event.resource
|
||||
|
||||
message = event.xhtml or cgi.escape(event.message)
|
||||
|
||||
try:
|
||||
newmsg = self.us[event.account].getContext(fjid).sendMessage(
|
||||
potr.context.FRAGMENT_SEND_ALL_BUT_LAST, event.message,
|
||||
potr.context.FRAGMENT_SEND_ALL_BUT_LAST, message,
|
||||
appdata={'session':event.session})
|
||||
except potr.context.NotEncryptedError, e:
|
||||
if e.args[0] == potr.context.EXC_FINISHED:
|
||||
@@ -608,9 +611,36 @@ class OtrPlugin(GajimPlugin):
|
||||
return IGNORE
|
||||
else:
|
||||
raise e
|
||||
event.message = newmsg
|
||||
|
||||
if event.xhtml: # if we had html before, replace with new content
|
||||
event.xhtml = newmsg
|
||||
|
||||
stripper = HTMLStripper()
|
||||
stripper.feed(unicode(newmsg or ''))
|
||||
event.message = stripper.stripped_data
|
||||
|
||||
return PASS
|
||||
|
||||
|
||||
class HTMLStripper(HTMLParser):
|
||||
def reset(self):
|
||||
self.stripped_data = ''
|
||||
HTMLParser.reset(self)
|
||||
|
||||
def handle_data(self, data):
|
||||
self.stripped_data += data
|
||||
def handle_entityref(self, name):
|
||||
c = unichr(name2codepoint[name])
|
||||
self.stripped_data += c
|
||||
def handle_charref(self, name):
|
||||
if name.startswith('x'):
|
||||
c = unichr(int(name[1:], 16))
|
||||
else:
|
||||
c = unichr(int(name))
|
||||
self.stripped_data += c
|
||||
def unknown_decl(self, data):
|
||||
if data.startswith('CDATA['):
|
||||
self.data += data[6:]
|
||||
|
||||
## TODO:
|
||||
## - disconnect ctxs on disconnect
|
||||
|
||||
Reference in New Issue
Block a user