Add a decode_entities option to the OTR plugin

This commit is contained in:
mathieui 2014-12-08 20:06:11 +01:00
parent b852f7279b
commit ad20d6dbc2
No known key found for this signature in database
GPG key ID: C59F84CEEFD616E3

View file

@ -128,6 +128,13 @@ Configuration
Decode embedded XHTML.
decode_entities
**Default:** ``false``
Decode XML and HTML entities (like ``&``) even when the
document isn't valid (if it is valid, it will be decoded even
without this option).
keys_dir
**Default:** ``$XDG_DATA_HOME/poezio/otr``
@ -155,7 +162,7 @@ Configuration
Log conversations (OTR start/end marker, and messages).
The :term:`allow_v1`, :term:`allow_v2`, :term:`decode_xhtml`
The :term:`allow_v1`, :term:`allow_v2`, :term:`decode_xhtml`, :term:`decode_entities`
and :term:`log` configuration parameters are tab-specific.
Important details
@ -177,6 +184,7 @@ import logging
log = logging.getLogger(__name__)
import os
import html
import curses
from potr.context import NotEncryptedError, UnencryptedMessage, ErrorReceived, NotOTRMessage,\
@ -544,11 +552,17 @@ class Plugin(BasePlugin):
nick_color = get_theme().COLOR_REMOTE_USER
body = txt.decode()
decode_entities = self.config.get_by_tabname('decode_entities',
msg['from'].bare,
default=False)
if self.config.get_by_tabname('decode_xhtml', msg['from'].bare, default=True):
try:
body = xhtml.xhtml_to_poezio_colors(body, force=True)
except:
pass
if decode_entities:
body = html.unescape(body)
elif decode_entities:
body = html.unescape(body)
tab.add_message(body, nickname=tab.nick, jid=msg['from'],
forced_user=user, typ=ctx.log,
nick_color=nick_color)