diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index db30dbe9..83e729c5 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -9,6 +9,26 @@ # The software version variable is now held in shared.py + +import sys +#Version check +#Older versions of Python don't support the print function while Python 3 doesn't +#like the print statement, so we use sys.stdout for the version check. After this +#check we can then use the print function in the remainder of this file. Currently +#in order to use logging, a lot of unnecessary code needs to be executed which could +#potentially render this version check useless. So logging won't be used here until +#there is a more efficient way to configure logging +if sys.hexversion >= 0x3000000: + msg = "PyBitmessage does not support Python 3. Python 2.7.5 or later is required. Your version: %s" % sys.version + #logger.critical(msg) + sys.stdout.write(msg) + sys.exit(0) +if sys.hexversion < 0x20705F0: + msg = "You should use Python 2.7.5 or greater (but not Python 3). Your version: %s" % sys.version + #logger.critical(msg) + sys.stdout.write(msg) + sys.exit(0) + import signal # Used to capture a Ctrl-C keypress so that Bitmessage can shutdown gracefully. # The next 3 are used for the API import singleton @@ -45,15 +65,7 @@ import helper_generic from subprocess import call import time - -# OSX python version check -import sys -if 'win' in sys.platform: - if float("{1}.{2}".format(*sys.version_info)) < 7.5: - msg = "You should use python 2.7.5 or greater. Your version: %s", "{0}.{1}.{2}".format(*sys.version_info) - logger.critical(msg) - print msg - sys.exit(0) + def connectToStream(streamNumber): shared.streamsInWhichIAmParticipating[streamNumber] = 'no data' @@ -199,7 +211,7 @@ class Main: apiNotifyPath = '' if apiNotifyPath != '': with shared.printLock: - print 'Trying to call', apiNotifyPath + print('Trying to call', apiNotifyPath) call([apiNotifyPath, "startingUp"]) singleAPIThread = singleAPI() @@ -218,15 +230,15 @@ class Main: try: from PyQt4 import QtCore, QtGui except Exception as err: - print 'PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\'. If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon' - print 'Error message:', err - print 'You can also run PyBitmessage with the new curses interface by providing \'-c\' as a commandline argument.' + print('PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\'. If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon') + print('Error message:', err) + print('You can also run PyBitmessage with the new curses interface by providing \'-c\' as a commandline argument.') os._exit(0) import bitmessageqt bitmessageqt.run() else: - print 'Running with curses' + print('Running with curses') import bitmessagecurses bitmessagecurses.runwrapper() else: @@ -234,16 +246,16 @@ class Main: if daemon: with shared.printLock: - print 'Running as a daemon. The main program should exit this thread.' + print('Running as a daemon. The main program should exit this thread.') else: with shared.printLock: - print 'Running as a daemon. You can use Ctrl+C to exit.' + print('Running as a daemon. You can use Ctrl+C to exit.') while True: time.sleep(20) def stop(self): with shared.printLock: - print 'Stopping Bitmessage Deamon.' + print('Stopping Bitmessage Deamon.') shared.doCleanShutdown() diff --git a/src/class_objectProcessor.py b/src/class_objectProcessor.py index b8a3c949..ce3f8b63 100644 --- a/src/class_objectProcessor.py +++ b/src/class_objectProcessor.py @@ -595,29 +595,22 @@ class objectProcessor(threading.Thread): if queryreturn == []: logger.info('Message ignored because address not in whitelist.') blockMessage = True - - toLabel = shared.config.get(toAddress, 'label') - if toLabel == '': - toLabel = toAddress - - if messageEncodingType == 2: - subject, body = self.decodeType2Message(message) - logger.info('Message subject (first 100 characters): %s' % repr(subject)[:100]) - elif messageEncodingType == 1: - body = message - subject = '' - elif messageEncodingType == 0: - logger.info('messageEncodingType == 0. Doing nothing with the message. They probably just sent it so that we would store their public key or send their ack data for them.') - subject = '' - body = '' - else: - body = 'Unknown encoding type.\n\n' + repr(message) - subject = '' - # Let us make sure that we haven't already received this message - if helper_inbox.isMessageAlreadyInInbox(toAddress, fromAddress, subject, body, messageEncodingType): - logger.info('This msg is already in our inbox. Ignoring it.') - blockMessage = True if not blockMessage: + toLabel = shared.config.get(toAddress, 'label') + if toLabel == '': + toLabel = toAddress + + if messageEncodingType == 2: + subject, body = self.decodeType2Message(message) + logger.info('Message subject (first 100 characters): %s' % repr(subject)[:100]) + elif messageEncodingType == 1: + body = message + subject = '' + elif messageEncodingType == 0: + logger.info('messageEncodingType == 0. Doing nothing with the message. They probably just sent it so that we would store their public key or send their ack data for them.') + else: + body = 'Unknown encoding type.\n\n' + repr(message) + subject = '' if messageEncodingType != 0: t = (inventoryHash, toAddress, fromAddress, subject, int( time.time()), body, 'inbox', messageEncodingType, 0) @@ -815,28 +808,25 @@ class objectProcessor(threading.Thread): toAddress = '[Broadcast subscribers]' if messageEncodingType != 0: - # Let us make sure that we haven't already received this message - if helper_inbox.isMessageAlreadyInInbox(toAddress, fromAddress, subject, body, messageEncodingType): - logger.info('This broadcast is already in our inbox. Ignoring it.') - else: - t = (inventoryHash, toAddress, fromAddress, subject, int( - time.time()), body, 'inbox', messageEncodingType, 0) - helper_inbox.insert(t) - - shared.UISignalQueue.put(('displayNewInboxMessage', ( - inventoryHash, toAddress, fromAddress, subject, body))) - - # If we are behaving as an API then we might need to run an - # outside command to let some program know that a new - # message has arrived. - if shared.safeConfigGetBoolean('bitmessagesettings', 'apienabled'): - try: - apiNotifyPath = shared.config.get( - 'bitmessagesettings', 'apinotifypath') - except: - apiNotifyPath = '' - if apiNotifyPath != '': - call([apiNotifyPath, "newBroadcast"]) + + t = (inventoryHash, toAddress, fromAddress, subject, int( + time.time()), body, 'inbox', messageEncodingType, 0) + helper_inbox.insert(t) + + shared.UISignalQueue.put(('displayNewInboxMessage', ( + inventoryHash, toAddress, fromAddress, subject, body))) + + # If we are behaving as an API then we might need to run an + # outside command to let some program know that a new + # message has arrived. + if shared.safeConfigGetBoolean('bitmessagesettings', 'apienabled'): + try: + apiNotifyPath = shared.config.get( + 'bitmessagesettings', 'apinotifypath') + except: + apiNotifyPath = '' + if apiNotifyPath != '': + call([apiNotifyPath, "newBroadcast"]) # Display timing data logger.debug('Time spent processing this interesting broadcast: %s' % (time.time() - messageProcessingStartTime,)) @@ -963,27 +953,25 @@ class objectProcessor(threading.Thread): toAddress = '[Broadcast subscribers]' if messageEncodingType != 0: - if helper_inbox.isMessageAlreadyInInbox(toAddress, fromAddress, subject, body, messageEncodingType): - logger.info('This broadcast is already in our inbox. Ignoring it.') - else: - t = (inventoryHash, toAddress, fromAddress, subject, int( - time.time()), body, 'inbox', messageEncodingType, 0) - helper_inbox.insert(t) - - shared.UISignalQueue.put(('displayNewInboxMessage', ( - inventoryHash, toAddress, fromAddress, subject, body))) - - # If we are behaving as an API then we might need to run an - # outside command to let some program know that a new message - # has arrived. - if shared.safeConfigGetBoolean('bitmessagesettings', 'apienabled'): - try: - apiNotifyPath = shared.config.get( - 'bitmessagesettings', 'apinotifypath') - except: - apiNotifyPath = '' - if apiNotifyPath != '': - call([apiNotifyPath, "newBroadcast"]) + + t = (inventoryHash, toAddress, fromAddress, subject, int( + time.time()), body, 'inbox', messageEncodingType, 0) + helper_inbox.insert(t) + + shared.UISignalQueue.put(('displayNewInboxMessage', ( + inventoryHash, toAddress, fromAddress, subject, body))) + + # If we are behaving as an API then we might need to run an + # outside command to let some program know that a new message + # has arrived. + if shared.safeConfigGetBoolean('bitmessagesettings', 'apienabled'): + try: + apiNotifyPath = shared.config.get( + 'bitmessagesettings', 'apinotifypath') + except: + apiNotifyPath = '' + if apiNotifyPath != '': + call([apiNotifyPath, "newBroadcast"]) # Display timing data logger.info('Time spent processing this interesting broadcast: %s' % (time.time() - messageProcessingStartTime,)) @@ -1108,27 +1096,25 @@ class objectProcessor(threading.Thread): toAddress = '[Broadcast subscribers]' if messageEncodingType != 0: - if helper_inbox.isMessageAlreadyInInbox(toAddress, fromAddress, subject, body, messageEncodingType): - logger.info('This broadcast is already in our inbox. Ignoring it.') - else: - t = (inventoryHash, toAddress, fromAddress, subject, int( - time.time()), body, 'inbox', messageEncodingType, 0) - helper_inbox.insert(t) - - shared.UISignalQueue.put(('displayNewInboxMessage', ( - inventoryHash, toAddress, fromAddress, subject, body))) - - # If we are behaving as an API then we might need to run an - # outside command to let some program know that a new message - # has arrived. - if shared.safeConfigGetBoolean('bitmessagesettings', 'apienabled'): - try: - apiNotifyPath = shared.config.get( - 'bitmessagesettings', 'apinotifypath') - except: - apiNotifyPath = '' - if apiNotifyPath != '': - call([apiNotifyPath, "newBroadcast"]) + + t = (inventoryHash, toAddress, fromAddress, subject, int( + time.time()), body, 'inbox', messageEncodingType, 0) + helper_inbox.insert(t) + + shared.UISignalQueue.put(('displayNewInboxMessage', ( + inventoryHash, toAddress, fromAddress, subject, body))) + + # If we are behaving as an API then we might need to run an + # outside command to let some program know that a new message + # has arrived. + if shared.safeConfigGetBoolean('bitmessagesettings', 'apienabled'): + try: + apiNotifyPath = shared.config.get( + 'bitmessagesettings', 'apinotifypath') + except: + apiNotifyPath = '' + if apiNotifyPath != '': + call([apiNotifyPath, "newBroadcast"]) # Display timing data logger.debug('Time spent processing this interesting broadcast: %s' % (time.time() - messageProcessingStartTime,)) diff --git a/src/helper_inbox.py b/src/helper_inbox.py index 04ca1d0c..1ba0e34b 100644 --- a/src/helper_inbox.py +++ b/src/helper_inbox.py @@ -9,7 +9,3 @@ def trash(msgid): sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', msgid) shared.UISignalQueue.put(('removeInboxRowByMsgid',msgid)) -def isMessageAlreadyInInbox(toAddress, fromAddress, subject, body, encodingType): - queryReturn = sqlQuery( - '''SELECT COUNT(*) FROM inbox WHERE toaddress=? AND fromaddress=? AND subject=? AND message=? AND encodingtype=? ''', toAddress, fromAddress, subject, body, encodingType) - return queryReturn[0][0] != 0 \ No newline at end of file