summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-10-16 18:49:32 +0200
committermathieui <mathieui@mathieui.net>2014-10-16 18:56:12 +0200
commita9f642f7438fe4489cdb9cc5ac59c929054656c8 (patch)
tree5ce6cba2105f178f92235fa325725941a5c9924c /src/core
parentd4590949f7b691e3e1d6eff8fa339e62a44bae51 (diff)
downloadpoezio-a9f642f7438fe4489cdb9cc5ac59c929054656c8.tar.gz
poezio-a9f642f7438fe4489cdb9cc5ac59c929054656c8.tar.bz2
poezio-a9f642f7438fe4489cdb9cc5ac59c929054656c8.tar.xz
poezio-a9f642f7438fe4489cdb9cc5ac59c929054656c8.zip
Extract XHTML-IM inline imags by default
- Add two new options: tmp_image_dir and extract_inline_images - tmp_image_dir is $XDG_CACHE_HOME(usually ~/.cache)/poezio/images if unset - Name the images from a SHA-1 of their data and their mimetype - Output file:// links inside the message
Diffstat (limited to 'src/core')
-rw-r--r--src/core/handlers.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/core/handlers.py b/src/core/handlers.py
index 75c372bb..87aaecd5 100644
--- a/src/core/handlers.py
+++ b/src/core/handlers.py
@@ -10,6 +10,7 @@ import ssl
import time
from hashlib import sha1, sha512
from gettext import gettext as _
+from os import path
from sleekxmpp import InvalidJID
from sleekxmpp.stanza import Message
@@ -24,7 +25,7 @@ import windows
import xhtml
import multiuserchat as muc
from common import safeJID
-from config import config
+from config import config, CACHE_DIR
from contact import Resource
from logger import logger
from roster import roster
@@ -178,7 +179,11 @@ def on_normal_message(self, message):
return self.information('%s says: %s' % (message['from'], message['body']), 'Headline')
use_xhtml = config.get('enable_xhtml_im', True)
- body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml)
+ tmp_dir = config.get('tmp_image_dir', '') or path.join(CACHE_DIR, 'images')
+ extract_images = config.get('extract_inline_images', True)
+ body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml,
+ tmp_dir=tmp_dir,
+ extract_images=extract_images)
if not body:
return
@@ -223,7 +228,9 @@ def on_normal_message(self, message):
self.events.trigger('conversation_msg', message, conversation)
if not message['body']:
return
- body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml)
+ body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml,
+ tmp_dir=tmp_dir,
+ extract_images=extract_images)
delayed, date = common.find_delayed_tag(message)
def try_modify():
@@ -441,7 +448,11 @@ def on_groupchat_message(self, message):
self.events.trigger('muc_msg', message, tab)
use_xhtml = config.get('enable_xhtml_im', True)
- body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml)
+ tmp_dir = config.get('tmp_image_dir', '') or path.join(CACHE_DIR, 'images')
+ extract_images = config.get('extract_inline_images', True)
+ body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml,
+ tmp_dir=tmp_dir,
+ extract_images=extract_images)
if not body:
return
@@ -498,7 +509,11 @@ def on_groupchat_private_message(self, message):
room_from = jid.bare
use_xhtml = config.get('enable_xhtml_im', True)
- body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml)
+ tmp_dir = config.get('tmp_image_dir', '') or path.join(CACHE_DIR, 'images')
+ extract_images = config.get('extract_inline_images', True)
+ body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml,
+ tmp_dir=tmp_dir,
+ extract_images=extract_images)
tab = self.get_tab_by_name(jid.full, tabs.PrivateTab) # get the tab with the private conversation
ignore = config.get_by_tabname('ignore_private', False, room_from)
if not tab: # It's the first message we receive: create the tab
@@ -511,7 +526,9 @@ def on_groupchat_private_message(self, message):
self.xmpp.send_message(mto=jid.full, mbody=msg, mtype='chat')
return
self.events.trigger('private_msg', message, tab)
- body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml)
+ body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml,
+ tmp_dir=tmp_dir,
+ extract_images=extract_images)
if not body or not tab:
return
replaced_id = message['replace']['id']