From e704037a34b1db4ec76c136514346ea5a9a0f80a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 26 Mar 2009 19:16:37 -0700 Subject: [PATCH] Fix nasty bug that was preventing the use of a mail server to send email --- src/calibre/gui2/device.py | 3 ++- src/calibre/gui2/dialogs/config.py | 4 +++- src/calibre/gui2/main.py | 23 ++++++++++++++--------- src/calibre/utils/smtp.py | 7 +++---- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 782a705ee9..de11366b3b 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -5,6 +5,7 @@ import os, traceback, Queue, time, socket from threading import Thread, RLock from itertools import repeat from functools import partial +from binascii import unhexlify from PyQt4.Qt import QMenu, QAction, QActionGroup, QIcon, SIGNAL, QPixmap, \ Qt @@ -385,7 +386,7 @@ class Emailer(Thread): verbose=opts.verbose, timeout=self.timeout, relay=opts.relay_host, username=opts.relay_username, - password=opts.relay_password, port=opts.relay_port, + password=unhexlify(opts.relay_password), port=opts.relay_port, encryption=opts.encryption) results.append([jobname, None, None]) except Exception, e: diff --git a/src/calibre/gui2/dialogs/config.py b/src/calibre/gui2/dialogs/config.py index 8e7898cc21..209212a6be 100644 --- a/src/calibre/gui2/dialogs/config.py +++ b/src/calibre/gui2/dialogs/config.py @@ -387,7 +387,9 @@ class ConfigDialog(QDialog, Ui_Dialog): self.connect(self.relay_use_gmail, SIGNAL('clicked(bool)'), self.create_gmail_relay) self.connect(self.relay_show_password, SIGNAL('stateChanged(int)'), - lambda state:self.relay_password.setEchoMode(self.relay_password.Password)) + lambda + state:self.relay_password.setEchoMode(self.relay_password.Password if + state == 0 else self.relay_password.Normal)) self.connect(self.email_add, SIGNAL('clicked(bool)'), self.add_email_account) self.connect(self.email_make_default, SIGNAL('clicked(bool)'), diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 57d199a64e..ee97f16568 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -118,12 +118,12 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): self.system_tray_icon.setContextMenu(self.system_tray_menu) self.connect(self.quit_action, SIGNAL('triggered(bool)'), self.quit) self.connect(self.donate_action, SIGNAL('triggered(bool)'), self.donate) - self.connect(self.restore_action, SIGNAL('triggered(bool)'), - lambda c : self.show()) + self.connect(self.restore_action, SIGNAL('triggered()'), + self.show) self.connect(self.action_show_book_details, SIGNAL('triggered(bool)'), self.show_book_info) - self.connect(self.action_restart, SIGNAL('triggered(bool)'), - lambda c : self.quit(None, restart=True)) + self.connect(self.action_restart, SIGNAL('triggered()'), + self.restart) self.connect(self.system_tray_icon, SIGNAL('activated(QSystemTrayIcon::ActivationReason)'), self.system_tray_icon_activated) @@ -290,7 +290,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): self.connect(self.action_books_in_this_series, SIGNAL('triggered()'), lambda : self.show_similar_books('series')) self.connect(self.action_books_with_the_same_tags, - SIGNAL('triggered()'), + SIGNAL('triggered()'), lambda : self.show_similar_books('tag')) self.connect(self.action_books_by_this_publisher, SIGNAL('triggered()'), lambda : self.show_similar_books('publisher')) @@ -490,6 +490,9 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): + def uncheck_cover_button(self, *args): + self.status_bar.cover_flow_button.setChecked(False) + def toggle_cover_flow(self, show): if config['separate_cover_flow']: if show: @@ -505,8 +508,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): self.library_view.scrollTo(self.library_view.currentIndex()) d.show() self.connect(d, SIGNAL('finished(int)'), - lambda x: self.status_bar.\ - cover_flow_button.setChecked(False)) + self.uncheck_cover_button) self.cf_dialog = d else: cfd = getattr(self, 'cf_dialog', None) @@ -1395,7 +1397,10 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): if self.device_connected: self.memory_view.write_settings() - def quit(self, checked, restart=False): + def restart(self): + self.quit(restart=True) + + def quit(self, checked=True, restart=False): if not self.confirm_quit(): return try: @@ -1596,5 +1601,5 @@ if __name__ == '__main__': if os.path.exists(logfile): log = open(logfile).read().decode('utf-8', 'ignore') d = QErrorMessage(('Error:%s
Traceback:
' - '%sLog:
')%(unicode(err), unicode(tb), log)) + '%sLog:
%s')%(unicode(err), unicode(tb), log)) d.exec_() diff --git a/src/calibre/utils/smtp.py b/src/calibre/utils/smtp.py index 63629c8394..79e46c03c3 100644 --- a/src/calibre/utils/smtp.py +++ b/src/calibre/utils/smtp.py @@ -54,8 +54,7 @@ def get_mx(host): def sendmail_direct(from_, to, msg, timeout, localhost, verbose): import smtplib hosts = get_mx(to.split('@')[-1].strip()) - if 'darwin' in sys.platform: - timeout=None # Non blocking sockets dont work on OS X + timeout=None # Non blocking sockets sometimes don't work s = smtplib.SMTP(timeout=timeout, local_hostname=localhost) s.set_debuglevel(verbose) if not hosts: @@ -81,8 +80,8 @@ def sendmail(msg, from_, to, localhost=None, verbose=0, timeout=30, return sendmail_direct(from_, x, msg, timeout, localhost, verbose) import smtplib cls = smtplib.SMTP if encryption == 'TLS' else smtplib.SMTP_SSL - if 'darwin' in sys.platform: - timeout = None # Non-blocking sockets in OS X don't work + timeout = None # Non-blocking sockets sometimes don't work + port = int(port) s = cls(timeout=timeout, local_hostname=localhost) s.set_debuglevel(verbose) if port < 0: