From 96a17264266d84a4d15b22796fb8ba7458b0a6c5 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Mon, 29 Feb 2016 07:47:07 +0800 Subject: [PATCH] Clickable email and http links in plain text Email addresses and URIs are now clickable when viewing a message in plain text mode. Clicking an email address moves to the Send tab, while clicking an URI has the same result as clicking an URI in html mode, it will ask for confirmation before opening it in external handler. --- src/bitmessageqt/messageview.py | 11 +++++++++++ src/bitmessageqt/safehtmlparser.py | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/bitmessageqt/messageview.py b/src/bitmessageqt/messageview.py index a579dd13..66aac2cb 100644 --- a/src/bitmessageqt/messageview.py +++ b/src/bitmessageqt/messageview.py @@ -1,5 +1,6 @@ from PyQt4 import QtCore, QtGui +from urlparse import urlparse from safehtmlparser import * class MessageView(QtGui.QTextBrowser): @@ -42,6 +43,16 @@ class MessageView(QtGui.QTextBrowser): QtGui.QApplication.activeWindow().statusBar().showMessage(QtGui.QApplication.translate("MainWindow", "Zoom level %1%").arg(str(zoom))) def confirmURL(self, link): + if link.scheme() == "mailto": + QtGui.QApplication.activeWindow().ui.lineEditTo.setText(link.path()) + if link.hasQueryItem("subject"): + QtGui.QApplication.activeWindow().ui.lineEditSubject.setText(link.queryItemValue("subject")) + if link.hasQueryItem("body"): + QtGui.QApplication.activeWindow().ui.textEditMessage.setText(link.queryItemValue("body")) + QtGui.QApplication.activeWindow().ui.tabWidgetSend.setCurrentIndex(0) + QtGui.QApplication.activeWindow().ui.tabWidget.setCurrentIndex(1) + QtGui.QApplication.activeWindow().ui.textEditMessage.setFocus() + return reply = QtGui.QMessageBox.warning(self, QtGui.QApplication.translate(type(self).__name__, MessageView.CONFIRM_TITLE), QtGui.QApplication.translate(type(self).__name__, MessageView.CONFIRM_TEXT).arg(str(link.toString())), diff --git a/src/bitmessageqt/safehtmlparser.py b/src/bitmessageqt/safehtmlparser.py index 79ad0f73..78f89888 100644 --- a/src/bitmessageqt/safehtmlparser.py +++ b/src/bitmessageqt/safehtmlparser.py @@ -1,5 +1,6 @@ from HTMLParser import HTMLParser import inspect +import re from urllib import quote, quote_plus from urlparse import urlparse @@ -20,6 +21,9 @@ class SafeHTMLParser(HTMLParser): 'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var', 'video'] replaces = [["&", "&"], ["\"", """], ["<", "<"], [">", ">"], ["\n", "
"], ["\t", "    "], [" ", "  "], [" ", "  "], ["
", "
 "]] src_schemes = [ "data" ] + uriregex1 = re.compile(r'(\b(?:https?|telnet|gopher|file|wais|ftp):[\w/#~:.?+=&%@!\-.:;?\\-]+?(?=[.:?\-]*(?:[^\w/#~:;.?+=&%@!\-.:?\-]|$)))') + uriregex2 = re.compile(r'\1', + unicode(tmp, 'utf-8', 'replace')) + tmp = SafeHTMLParser.uriregex2.sub(r'\1', tmp) + self.raw += tmp def is_html(self, text = None, allow_picture = False): if text: