def __init__(self, pa, parent): QDialog.__init__(self, parent) TE_Dialog.__init__(self) self.setupUi(self) opts = smtp_prefs().parse() self.test_func = parent.test_email_settings self.test_button.clicked.connect(self.test) self.from_.setText(unicode(self.from_.text())%opts.from_) if pa: self.to.setText(pa) if opts.relay_host: tmp_password='' if opts.relay_prompt: header=opts.relay_username+'@'+opts.relay_host tmp_password, ok = QInputDialog.getText(self, header, _('Password:'******'' else: conf = smtp_prefs() conf.set('relay_password', hexlify(str(tmp_password).encode('utf-8'))) tmp_password='******' else: tmp_password=unhexlify(opts.relay_password).decode('utf-8') self.label.setText(_('Using: %(un)s:%(pw)s@%(host)s:%(port)s and %(enc)s encryption')% dict(un=opts.relay_username, pw=tmp_password, host=opts.relay_host, port=opts.relay_port, enc=opts.encryption))
def test_email(self, *args): pa = self.preferred_to_address() to_set = pa is not None opts = smtp_prefs().parse() if self.set_email_settings(to_set): if opts.relay_prompt or not opts.relay_password or question_dialog(self, _('OK to proceed?'), _('This will display your email password on the screen' '. Is it OK to proceed?'), show_copy_button=False): TestEmail(pa, self).exec_() if opts.relay_prompt: conf = smtp_prefs() conf.set('relay_password', '')
def test_email(self, *args): pa = self.preferred_to_address() to_set = pa is not None opts = smtp_prefs().parse() if self.set_email_settings(to_set): if opts.relay_prompt or not opts.relay_password or question_dialog( self, _('OK to proceed?'), _('This will display your email password on the screen' '. Is it OK to proceed?'), show_copy_button=False): TestEmail(pa, self).exec_() if opts.relay_prompt: conf = smtp_prefs() conf.set('relay_password', '')
def test_email_settings(self, to): opts = smtp_prefs().parse() from calibre.utils.smtp import sendmail, create_mail buf = cStringIO.StringIO() oout, oerr = sys.stdout, sys.stderr sys.stdout = sys.stderr = buf tb = None try: msg = create_mail(opts.from_, to, "Test mail from calibre", "Test mail from calibre") sendmail( msg, from_=opts.from_, to=[to], verbose=3, timeout=30, relay=opts.relay_host, username=opts.relay_username, password=unhexlify(opts.relay_password).decode("utf-8"), encryption=opts.encryption, port=opts.relay_port, ) except: import traceback tb = traceback.format_exc() tb += "\n\nLog:\n" + buf.getvalue() finally: sys.stdout, sys.stderr = oout, oerr return tb
def set_email_settings(self, to_set): from_ = unicode(self.email_from.text()).strip() if to_set and not from_: error_dialog(self, _('Bad configuration'), _('You must set the From email address')).exec_() return False username = unicode(self.relay_username.text()).strip() password = unicode(self.relay_password.text()).strip() host = unicode(self.relay_host.text()).strip() enc_method = ('TLS' if self.relay_tls.isChecked() else 'SSL' if self.relay_ssl.isChecked() else 'NONE') if host: # Validate input if ((username and not password) or (not username and password)): error_dialog( self, _('Bad configuration'), _('You must either set both the username <b>and</b> password for ' 'the mail server or no username and no password at all.') ).exec_() return False if not (username and password) and not question_dialog( self, _('Are you sure?'), _('No username and password set for mailserver. Most ' ' mailservers need a username and password. Are you sure?' )): return False conf = smtp_prefs() conf.set('from_', from_) conf.set('relay_host', host if host else None) conf.set('relay_port', self.relay_port.value()) conf.set('relay_username', username if username else None) conf.set('relay_password', hexlify(password.encode('utf-8'))) conf.set('encryption', enc_method) return True
def test_email_settings(self, to): opts = smtp_prefs().parse() from calibre.utils.smtp import sendmail, create_mail buf = cStringIO.StringIO() debug_out = partial(prints, file=buf) oout, oerr = sys.stdout, sys.stderr sys.stdout = sys.stderr = buf tb = None try: msg = create_mail(opts.from_, to, 'Test mail from calibre', 'Test mail from calibre') sendmail(msg, from_=opts.from_, to=[to], verbose=3, timeout=30, relay=opts.relay_host, username=opts.relay_username, debug_output=debug_out, password=unhexlify(opts.relay_password).decode('utf-8'), encryption=opts.encryption, port=opts.relay_port) except: import traceback tb = traceback.format_exc() tb += '\n\nLog:\n' + buf.getvalue() finally: sys.stdout, sys.stderr = oout, oerr return tb
def __init__(self, pa, parent): QDialog.__init__(self, parent) self.test_func = parent.test_email_settings self.setWindowTitle(_("Test email settings")) self.setWindowIcon(QIcon(I('config.ui'))) l = QVBoxLayout(self) opts = smtp_prefs().parse() self.from_ = la = QLabel(_("Send test mail from %s to:") % opts.from_) l.addWidget(la) self.to = le = QLineEdit(self) if pa: self.to.setText(pa) self.test_button = b = QPushButton(_('&Test'), self) b.clicked.connect(self.start_test) self.test_done.connect(self.on_test_done, type=Qt.QueuedConnection) self.h = h = QHBoxLayout() h.addWidget(le), h.addWidget(b) l.addLayout(h) if opts.relay_host: self.la = la = QLabel( _('Using: %(un)s:%(pw)s@%(host)s:%(port)s and %(enc)s encryption' ) % dict(un=opts.relay_username, pw=unhexlify(opts.relay_password).decode('utf-8'), host=opts.relay_host, port=opts.relay_port, enc=opts.encryption)) l.addWidget(la) self.log = QPlainTextEdit(self) l.addWidget(self.log) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Close) bb.rejected.connect(self.reject), bb.accepted.connect(self.accept) l.addWidget(bb)
def __init__(self, pa, parent): QDialog.__init__(self, parent) self.test_func = parent.test_email_settings self.setWindowTitle(_("Test email settings")) self.setWindowIcon(QIcon(I('config.ui'))) l = QVBoxLayout(self) opts = smtp_prefs().parse() self.from_ = la = QLabel(_("Send test mail from %s to:")%opts.from_) l.addWidget(la) self.to = le = QLineEdit(self) if pa: self.to.setText(pa) self.test_button = b = QPushButton(_('&Test'), self) b.clicked.connect(self.start_test) self.test_done.connect(self.on_test_done, type=Qt.QueuedConnection) self.h = h = QHBoxLayout() h.addWidget(le), h.addWidget(b) l.addLayout(h) if opts.relay_host: self.la = la = QLabel(_('Using: %(un)s:%(pw)s@%(host)s:%(port)s and %(enc)s encryption')% dict(un=opts.relay_username, pw=unhexlify(opts.relay_password).decode('utf-8'), host=opts.relay_host, port=opts.relay_port, enc=opts.encryption)) l.addWidget(la) self.log = QPlainTextEdit(self) l.addWidget(self.log) self.bb = bb = QDialogButtonBox(QDialogButtonBox.Close) bb.rejected.connect(self.reject), bb.accepted.connect(self.accept) l.addWidget(bb)
def initialize(self, preferred_to_address): self.preferred_to_address = preferred_to_address opts = smtp_prefs().parse() self.smtp_opts = opts if opts.from_: self.email_from.setText(opts.from_) self.email_from.textChanged.connect(self.changed) if opts.relay_host: self.relay_host.setText(opts.relay_host) self.relay_host.textChanged.connect(self.changed) self.relay_port.setValue(opts.relay_port) self.relay_port.valueChanged.connect(self.changed) if opts.relay_username: self.relay_username.setText(opts.relay_username) self.relay_username.textChanged.connect(self.changed) if opts.relay_password: self.relay_password.setText( unhexlify(opts.relay_password).decode('utf-8')) self.relay_password.textChanged.connect(self.changed) getattr(self, 'relay_' + opts.encryption.lower()).setChecked(True) self.relay_tls.toggled.connect(self.changed) for x in ('gmx', 'hotmail'): button = getattr(self, 'relay_use_' + x) button.clicked.connect(partial(self.create_service_relay, x)) self.relay_show_password.stateChanged.connect( lambda state: self.relay_password.setEchoMode( self.relay_password.Password if state == 0 else self.relay_password.Normal)) self.test_email_button.clicked.connect(self.test_email)
def initialize(self, preferred_to_address): self.preferred_to_address = preferred_to_address opts = smtp_prefs().parse() self.smtp_opts = opts if opts.from_: self.email_from.setText(opts.from_) self.email_from.textChanged.connect(self.changed) if opts.relay_host: self.relay_host.setText(opts.relay_host) self.relay_host.textChanged.connect(self.changed) self.relay_port.setValue(opts.relay_port) self.relay_port.valueChanged.connect(self.changed) if opts.relay_username: self.relay_username.setText(opts.relay_username) self.relay_username.textChanged.connect(self.changed) if opts.relay_password: self.relay_password.setText(unhexlify(opts.relay_password).decode('utf-8')) self.relay_password.textChanged.connect(self.changed) getattr(self, 'relay_'+opts.encryption.lower()).setChecked(True) self.relay_tls.toggled.connect(self.changed) for x in ('gmail', 'hotmail'): button = getattr(self, 'relay_use_'+x) button.clicked.connect(partial(self.create_service_relay, x)) self.relay_show_password.stateChanged.connect( lambda state : self.relay_password.setEchoMode( self.relay_password.Password if state == 0 else self.relay_password.Normal)) self.test_email_button.clicked.connect(self.test_email)
def set_email_settings(self, to_set): from_ = unicode(self.email_from.text()).strip() if to_set and not from_: error_dialog(self, _('Bad configuration'), _('You must set the From email address')).exec_() return False username = unicode(self.relay_username.text()).strip() password = unicode(self.relay_password.text()).strip() host = unicode(self.relay_host.text()).strip() enc_method = ('TLS' if self.relay_tls.isChecked() else 'SSL' if self.relay_ssl.isChecked() else 'NONE') if host: # Validate input if ((username and not password) or (not username and password)): error_dialog(self, _('Bad configuration'), _('You must either set both the username <b>and</b> password for ' 'the mail server or no username and no password at all.')).exec_() return False if not (username and password) and not question_dialog(self, _('Are you sure?'), _('No username and password set for mailserver. Most ' ' mailservers need a username and password. Are you sure?')): return False conf = smtp_prefs() conf.set('from_', from_) conf.set('relay_host', host if host else None) conf.set('relay_port', self.relay_port.value()) conf.set('relay_username', username if username else None) conf.set('relay_password', hexlify(password.encode('utf-8'))) conf.set('encryption', enc_method) return True
def test_email(self, *args): pa = self.preferred_to_address() to_set = pa is not None if self.set_email_settings(to_set): opts = smtp_prefs().parse() if not opts.relay_password or question_dialog( self, _("OK to proceed?"), _("This will display your email password on the screen" ". Is it OK to proceed?"), show_copy_button=False, ): TestEmail(pa, self).exec_()
def __init__(self, pa, parent): QDialog.__init__(self, parent) TE_Dialog.__init__(self) self.setupUi(self) opts = smtp_prefs().parse() self.test_func = parent.test_email_settings self.test_button.clicked.connect(self.test) self.from_.setText(unicode(self.from_.text())%opts.from_) if pa: self.to.setText(pa) if opts.relay_host: self.label.setText(_('Using: %(un)s:%(pw)s@%(host)s:%(port)s and %(enc)s encryption')% dict(un=opts.relay_username, pw=unhexlify(opts.relay_password), host=opts.relay_host, port=opts.relay_port, enc=opts.encryption))
def __init__(self, pa, parent): QDialog.__init__(self, parent) TE_Dialog.__init__(self) self.setupUi(self) opts = smtp_prefs().parse() self.test_func = parent.test_email_settings self.test_button.clicked.connect(self.test) self.from_.setText(unicode(self.from_.text())%opts.from_) if pa: self.to.setText(pa) if opts.relay_host: self.label.setText(_('Using: %(un)s:%(pw)s@%(host)s:%(port)s and %(enc)s encryption')% dict(un=opts.relay_username, pw=unhexlify(opts.relay_password).decode('utf-8'), host=opts.relay_host, port=opts.relay_port, enc=opts.encryption))
def genesis(self, gui): self.gui = gui self.proxy = ConfigProxy(smtp_prefs()) self.send_email_widget.initialize(self.preferred_to_address) self.send_email_widget.changed_signal.connect(self.changed_signal.emit) opts = self.send_email_widget.smtp_opts self._email_accounts = EmailAccounts(opts.accounts, opts.subjects) self._email_accounts.dataChanged.connect(lambda x, y: self.changed_signal.emit()) self.email_view.setModel(self._email_accounts) self.email_add.clicked.connect(self.add_email_account) self.email_make_default.clicked.connect(self.make_default) self.email_view.resizeColumnsToContents() self.email_remove.clicked.connect(self.remove_email_account)
def __init__(self, pa, parent): QDialog.__init__(self, parent) TE_Dialog.__init__(self) self.setupUi(self) opts = smtp_prefs().parse() self.test_func = parent.test_email_settings self.test_button.clicked.connect(self.test) self.from_.setText(unicode(self.from_.text()) % opts.from_) if pa: self.to.setText(pa) if opts.relay_host: tmp_password = '' if opts.relay_prompt: header = opts.relay_username + '@' + opts.relay_host tmp_password, ok = QInputDialog.getText( self, header, _('Password:'******'' else: conf = smtp_prefs() conf.set('relay_password', hexlify(str(tmp_password).encode('utf-8'))) tmp_password = '******' else: tmp_password = unhexlify(opts.relay_password).decode('utf-8') self.label.setText( _('Using: %(un)s:%(pw)s@%(host)s:%(port)s and %(enc)s encryption' ) % dict(un=opts.relay_username, pw=tmp_password, host=opts.relay_host, port=opts.relay_port, enc=opts.encryption))
def genesis(self, gui): self.gui = gui self.proxy = ConfigProxy(smtp_prefs()) self.send_email_widget.initialize(self.preferred_to_address) self.send_email_widget.changed_signal.connect(self.changed_signal.emit) opts = self.send_email_widget.smtp_opts self._email_accounts = EmailAccounts(opts.accounts, opts.subjects) self._email_accounts.dataChanged.connect( lambda x, y: self.changed_signal.emit()) self.email_view.setModel(self._email_accounts) self.email_add.clicked.connect(self.add_email_account) self.email_make_default.clicked.connect(self.make_default) self.email_view.resizeColumnsToContents() self.email_remove.clicked.connect(self.remove_email_account)
def set_email_settings(self, to_set): from_ = unicode(self.email_from.text()).strip() if to_set and not from_: error_dialog(self, _("Bad configuration"), _("You must set the From email address")).exec_() return False username = unicode(self.relay_username.text()).strip() password = unicode(self.relay_password.text()).strip() host = unicode(self.relay_host.text()).strip() enc_method = "TLS" if self.relay_tls.isChecked() else "SSL" if self.relay_ssl.isChecked() else "NONE" if host: # Validate input if (username and not password) or (not username and password): error_dialog( self, _("Bad configuration"), _( "You must either set both the username <b>and</b> password for " "the mail server or no username and no password at all." ), ).exec_() return False if not username and not password and enc_method != "NONE": error_dialog( self, _("Bad configuration"), _("Please enter a username and password or set" " encryption to None "), ).exec_() return False if not (username and password) and not question_dialog( self, _("Are you sure?"), _( "No username and password set for mailserver. Most " " mailservers need a username and password. Are you sure?" ), ): return False conf = smtp_prefs() conf.set("from_", from_) conf.set("relay_host", host if host else None) conf.set("relay_port", self.relay_port.value()) conf.set("relay_username", username if username else None) conf.set("relay_password", hexlify(password.encode("utf-8"))) conf.set("encryption", enc_method) return True
def genesis(self, gui): self.gui = gui self.proxy = ConfigProxy(smtp_prefs()) r = self.register r('add_comments_to_email', gprefs) self.send_email_widget.initialize(self.preferred_to_address) self.send_email_widget.changed_signal.connect(self.changed_signal.emit) opts = self.send_email_widget.smtp_opts self._email_accounts = EmailAccounts(opts.accounts, opts.subjects, opts.aliases, opts.tags) connect_lambda(self._email_accounts.dataChanged, self, lambda self: self.changed_signal.emit()) self.email_view.setModel(self._email_accounts) self.email_view.sortByColumn(0, Qt.SortOrder.AscendingOrder) self.email_view.setSortingEnabled(True) self.email_add.clicked.connect(self.add_email_account) self.email_make_default.clicked.connect(self.make_default) self.email_view.resizeColumnsToContents() self.email_remove.clicked.connect(self.remove_email_account)
def genesis(self, gui): self.gui = gui self.proxy = ConfigProxy(smtp_prefs()) r = self.register r('add_comments_to_email', gprefs) self.send_email_widget.initialize(self.preferred_to_address) self.send_email_widget.changed_signal.connect(self.changed_signal.emit) opts = self.send_email_widget.smtp_opts self._email_accounts = EmailAccounts(opts.accounts, opts.subjects, opts.aliases, opts.tags) connect_lambda(self._email_accounts.dataChanged, self, lambda self: self.changed_signal.emit()) self.email_view.setModel(self._email_accounts) self.email_view.sortByColumn(0, Qt.AscendingOrder) self.email_view.setSortingEnabled(True) self.email_add.clicked.connect(self.add_email_account) self.email_make_default.clicked.connect(self.make_default) self.email_view.resizeColumnsToContents() self.email_remove.clicked.connect(self.remove_email_account)
def test_email_settings(self, to): opts = smtp_prefs().parse() from calibre.utils.smtp import sendmail, create_mail buf = PolyglotBytesIO() debug_out = partial(prints, file=buf) oout, oerr = sys.stdout, sys.stderr sys.stdout = sys.stderr = buf tb = None try: msg = create_mail(opts.from_, to, 'Test mail from calibre', 'Test mail from calibre') sendmail(msg, from_=opts.from_, to=[to], verbose=3, timeout=30, relay=opts.relay_host, username=opts.relay_username, debug_output=debug_out, password=from_hex_unicode(opts.relay_password), encryption=opts.encryption, port=opts.relay_port) except: import traceback tb = traceback.format_exc() tb += '\n\nLog:\n' + buf.getvalue().decode('utf-8', 'replace') finally: sys.stdout, sys.stderr = oout, oerr return tb