Browse Source

fix email_requests plugin

3.1
SomberNight 7 years ago
parent
commit
2f4ee16fd4
  1. 13
      gui/qt/util.py
  2. 41
      plugins/email_requests/qt.py

13
gui/qt/util.py

@ -738,6 +738,19 @@ def export_meta_gui(electrum_window, title, exporter):
.format(title, str(filename))) .format(title, str(filename)))
def get_parent_main_window(widget):
"""Returns a reference to the ElectrumWindow this widget belongs to."""
from .main_window import ElectrumWindow
for _ in range(100):
if widget is None:
return None
if not isinstance(widget, ElectrumWindow):
widget = widget.parentWidget()
else:
return widget
return None
if __name__ == "__main__": if __name__ == "__main__":
app = QApplication([]) app = QApplication([])
t = WaitingDialog(None, 'testing ...', lambda: [time.sleep(1)], lambda x: QMessageBox.information(None, 'done', "done")) t = WaitingDialog(None, 'testing ...', lambda: [time.sleep(1)], lambda x: QMessageBox.information(None, 'done', "done"))

41
plugins/email_requests/qt.py

@ -27,6 +27,8 @@ import time
import threading import threading
import base64 import base64
from functools import partial from functools import partial
import traceback
import sys
import smtplib import smtplib
import imaplib import imaplib
@ -37,14 +39,14 @@ from email.encoders import encode_base64
from PyQt5.QtGui import * from PyQt5.QtGui import *
from PyQt5.QtCore import * from PyQt5.QtCore import *
import PyQt5.QtGui as QtGui from PyQt5.QtWidgets import (QVBoxLayout, QLabel, QGridLayout, QLineEdit,
from PyQt5.QtWidgets import (QVBoxLayout, QLabel, QGridLayout, QLineEdit) QInputDialog)
from electrum.plugins import BasePlugin, hook from electrum.plugins import BasePlugin, hook
from electrum.paymentrequest import PaymentRequest from electrum.paymentrequest import PaymentRequest
from electrum.i18n import _ from electrum.i18n import _
from electrum_gui.qt.util import EnterButton, Buttons, CloseButton from electrum_gui.qt.util import (EnterButton, Buttons, CloseButton, OkButton,
from electrum_gui.qt.util import OkButton, WindowModalDialog WindowModalDialog, get_parent_main_window)
class Processor(threading.Thread): class Processor(threading.Thread):
@ -64,9 +66,9 @@ class Processor(threading.Thread):
except: except:
return return
typ, data = self.M.search(None, 'ALL') typ, data = self.M.search(None, 'ALL')
for num in data[0].split(): for num in str(data[0], 'utf8').split():
typ, msg_data = self.M.fetch(num, '(RFC822)') typ, msg_data = self.M.fetch(num, '(RFC822)')
msg = email.message_from_string(msg_data[0][1]) msg = email.message_from_string(str(msg_data[0][1], 'utf8'))
p = msg.get_payload() p = msg.get_payload()
if not msg.is_multipart(): if not msg.is_multipart():
p = [p] p = [p]
@ -127,19 +129,29 @@ class Plugin(BasePlugin):
self.processor.start() self.processor.start()
self.obj = QEmailSignalObject() self.obj = QEmailSignalObject()
self.obj.email_new_invoice_signal.connect(self.new_invoice) self.obj.email_new_invoice_signal.connect(self.new_invoice)
self.wallets = set()
def on_receive(self, pr_str): def on_receive(self, pr_str):
self.print_error('received payment request') self.print_error('received payment request')
self.pr = PaymentRequest(pr_str) self.pr = PaymentRequest(pr_str)
self.obj.email_new_invoice_signal.emit() self.obj.email_new_invoice_signal.emit()
@hook
def load_wallet(self, wallet, main_window):
self.wallets |= {wallet}
@hook
def close_wallet(self, wallet):
self.wallets -= {wallet}
def new_invoice(self): def new_invoice(self):
self.parent.invoices.add(self.pr) for wallet in self.wallets:
#window.update_invoices_list() wallet.invoices.add(self.pr)
#main_window.invoice_list.update()
@hook @hook
def receive_list_menu(self, menu, addr): def receive_list_menu(self, menu, addr):
window = menu.parentWidget() window = get_parent_main_window(menu)
menu.addAction(_("Send via e-mail"), lambda: self.send(window, addr)) menu.addAction(_("Send via e-mail"), lambda: self.send(window, addr))
def send(self, window, addr): def send(self, window, addr):
@ -152,21 +164,21 @@ class Plugin(BasePlugin):
pr = paymentrequest.make_request(self.config, r) pr = paymentrequest.make_request(self.config, r)
if not pr: if not pr:
return return
recipient, ok = QtGui.QInputDialog.getText(window, 'Send request', 'Email invoice to:') recipient, ok = QInputDialog.getText(window, 'Send request', 'Email invoice to:')
if not ok: if not ok:
return return
recipient = str(recipient) recipient = str(recipient)
payload = pr.SerializeToString() payload = pr.SerializeToString()
self.print_error('sending mail to', recipient) self.print_error('sending mail to', recipient)
try: try:
# FIXME this runs in the GUI thread and blocks it...
self.processor.send(recipient, message, payload) self.processor.send(recipient, message, payload)
except BaseException as e: except BaseException as e:
traceback.print_exc(file=sys.stderr)
window.show_message(str(e)) window.show_message(str(e))
return else:
window.show_message(_('Request sent.')) window.show_message(_('Request sent.'))
def requires_settings(self): def requires_settings(self):
return True return True
@ -204,9 +216,12 @@ class Plugin(BasePlugin):
server = str(server_e.text()) server = str(server_e.text())
self.config.set_key('email_server', server) self.config.set_key('email_server', server)
self.imap_server = server
username = str(username_e.text()) username = str(username_e.text())
self.config.set_key('email_username', username) self.config.set_key('email_username', username)
self.username = username
password = str(password_e.text()) password = str(password_e.text())
self.config.set_key('email_password', password) self.config.set_key('email_password', password)
self.password = password

Loading…
Cancel
Save