From 685ff6cecd3b2bc4f73cdc5cca3b3429b344c82d Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 30 Jun 2016 15:19:58 +0200 Subject: [PATCH] Startup fixes - correctly test for "smtpdeliver" variable without crashing - new method for safely getting values from config even if the option may be missing --- src/bitmessagemain.py | 2 +- src/class_smtpDeliver.py | 4 ++-- src/class_sqlThread.py | 2 ++ src/shared.py | 6 ++++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index f67f6619..4818f97b 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -187,7 +187,7 @@ class Main: sqlLookup.start() # SMTP delivery thread - if daemon and shared.config.get("bitmessagesettings", "smtpdeliver", None): + if daemon and shared.safeConfigGet("bitmessagesettings", "smtpdeliver", '') != '': smtpDeliveryThread = smtpDeliver() smtpDeliveryThread.start() diff --git a/src/class_smtpDeliver.py b/src/class_smtpDeliver.py index 477ca8fe..2c63d830 100644 --- a/src/class_smtpDeliver.py +++ b/src/class_smtpDeliver.py @@ -46,8 +46,8 @@ class smtpDeliver(threading.Thread, StoppableThread): pass elif command == 'displayNewInboxMessage': inventoryHash, toAddress, fromAddress, subject, body = data - dest = shared.config.get("bitmessagesettings", "smtpdeliver", None) - if not dest: + dest = shared.safeConfigGet("bitmessagesettings", "smtpdeliver", '') + if dest == '': continue try: u = urlparse.urlparse(dest) diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py index b8fd12c2..016386ab 100644 --- a/src/class_sqlThread.py +++ b/src/class_sqlThread.py @@ -425,6 +425,8 @@ class sqlThread(threading.Thread): shared.config.set('bitmessagesettings', 'onionport', '8444') if not shared.config.has_option('bitmessagesettings', 'onionbindip'): shared.config.set('bitmessagesettings', 'onionbindip', '127.0.0.1') + if not shared.config.has_option('bitmessagesettings', 'smtpdeliver'): + shared.config.set('bitmessagesettings', 'smtpdeliver', '') shared.writeKeysFile() # Are you hoping to add a new option to the keys.dat file of existing diff --git a/src/shared.py b/src/shared.py index 87d8d2b5..ca9200e5 100644 --- a/src/shared.py +++ b/src/shared.py @@ -401,6 +401,12 @@ def safeConfigGetBoolean(section,field): except Exception, err: return False +def safeConfigGet(section, option, default = None): + if config.has_option (section, option): + return config.get(section, option) + else: + return default + def decodeWalletImportFormat(WIFstring): fullString = arithmetic.changebase(WIFstring,58,256) privkey = fullString[:-4]