Beispiel #1
0
 def smtp_AUTH(self, arg):
     if not arg or arg[0:5] not in ["PLAIN"]:
         self.push('501 Syntax: AUTH PLAIN')
         return
     authstring = arg[6:]
     try:
         decoded = base64.b64decode(authstring)
         correctauth = "\x00" + shared.safeConfigGet("bitmessagesettings", "smtpdusername", "") + \
                 "\x00" + shared.safeConfigGet("bitmessagesettings", "smtpdpassword", "")
         logger.debug("authstring: %s / %s", correctauth, decoded)
         if correctauth == decoded:
             self.auth = True
             self.push('235 2.7.0 Authentication successful')
         else:
             raise Error("Auth fail")
     except:
         self.push('501 Authentication fail')
 def run(self):
     while shared.shutdown == 0:
         command, data = shared.UISignalQueue.get()
         if command == 'writeNewAddressToTable':
             label, address, streamNumber = data
             pass
         elif command == 'updateStatusBar':
             pass
         elif command == 'updateSentItemStatusByToAddress':
             toAddress, message = data
             pass
         elif command == 'updateSentItemStatusByAckdata':
             ackData, message = data
             pass
         elif command == 'displayNewInboxMessage':
             inventoryHash, toAddress, fromAddress, subject, body = data
             dest = shared.safeConfigGet("bitmessagesettings", "smtpdeliver", '')
             if dest == '':
                 continue
             try:
                 u = urlparse.urlparse(dest)
                 to = urlparse.parse_qs(u.query)['to']
                 client = smtplib.SMTP(u.hostname, u.port)
                 msg = MIMEText(body, 'plain', 'utf-8')
                 msg['Subject'] = Header(subject, 'utf-8')
                 msg['From'] = fromAddress + '@' + SMTPDOMAIN
                 toLabel = map (lambda y: shared.safeConfigGet(y, "label"), filter(lambda x: x == toAddress, shared.config.sections()))
                 if len(toLabel) > 0:
                     msg['To'] = "\"%s\" <%s>" % (Header(toLabel[0], 'utf-8'), toAddress + '@' + SMTPDOMAIN)
                 else:
                     msg['To'] = toAddress + '@' + SMTPDOMAIN
                 client.ehlo()
                 client.starttls()
                 client.ehlo()
                 client.sendmail(msg['From'], [to], msg.as_string())
                 logger.info("Delivered via SMTP to %s through %s:%i ...", to, u.hostname, u.port)
                 client.quit()
             except:
                 logger.error("smtp delivery error", exc_info=True)
         elif command == 'displayNewSentMessage':
             toAddress, fromLabel, fromAddress, subject, message, ackdata = data
             pass
         elif command == 'updateNetworkStatusTab':
             pass
         elif command == 'updateNumberOfMessagesProcessed':
             pass
         elif command == 'updateNumberOfPubkeysProcessed':
             pass
         elif command == 'updateNumberOfBroadcastsProcessed':
             pass
         elif command == 'setStatusIcon':
             pass
         elif command == 'changedInboxUnread':
             pass
         elif command == 'rerenderMessagelistFromLabels':
             pass
         elif command == 'rerenderMessagelistToLabels':
             pass
         elif command == 'rerenderAddressBook':
             pass
         elif command == 'rerenderSubscriptions':
             pass
         elif command == 'rerenderBlackWhiteList':
             pass
         elif command == 'removeInboxRowByMsgid':
             pass
         elif command == 'newVersionAvailable':
             pass
         elif command == 'alert':
             title, text, exitAfterUserClicksOk = data
             pass
         elif command == 'stopThread':
             break
         else:
             sys.stderr.write(
                 'Command sent to smtpDeliver not recognized: %s\n' % command)
Beispiel #3
0
    def start(self, daemon=False):
        _fixWinsock()

        shared.daemon = daemon

        # get curses flag
        shared.curses = False
        if '-c' in sys.argv:
            shared.curses = True

        # is the application already running?  If yes then exit.
        shared.thisapp = singleton.singleinstance("", daemon)

        if daemon:
            with shared.printLock:
                print('Running as a daemon. Send TERM signal to end.')
            self.daemonize()

        self.setSignalHandler()

        helper_bootstrap.knownNodes()
        # Start the address generation thread
        addressGeneratorThread = addressGenerator()
        addressGeneratorThread.daemon = True  # close the main program even if there are threads left
        addressGeneratorThread.start()

        # Start the thread that calculates POWs
        singleWorkerThread = singleWorker()
        singleWorkerThread.daemon = True  # close the main program even if there are threads left
        singleWorkerThread.start()

        # Start the SQL thread
        sqlLookup = sqlThread()
        sqlLookup.daemon = False  # DON'T close the main program even if there are threads left. The closeEvent should command this thread to exit gracefully.
        sqlLookup.start()

        # SMTP delivery thread
        if daemon and shared.safeConfigGet("bitmessagesettings", "smtpdeliver", '') != '':
            smtpDeliveryThread = smtpDeliver()
            smtpDeliveryThread.start()

        # SMTP daemon thread
        if daemon and shared.safeConfigGetBoolean("bitmessagesettings", "smtpd"):
            smtpServerThread = smtpServer()
            smtpServerThread.start()

        # Start the thread that calculates POWs
        objectProcessorThread = objectProcessor()
        objectProcessorThread.daemon = False  # DON'T close the main program even the thread remains. This thread checks the shutdown variable after processing each object.
        objectProcessorThread.start()

        # Start the cleanerThread
        singleCleanerThread = singleCleaner()
        singleCleanerThread.daemon = True  # close the main program even if there are threads left
        singleCleanerThread.start()

        shared.reloadMyAddressHashes()
        shared.reloadBroadcastSendersForWhichImWatching()

        if shared.safeConfigGetBoolean('bitmessagesettings', 'apienabled'):
            try:
                apiNotifyPath = shared.config.get(
                    'bitmessagesettings', 'apinotifypath')
            except:
                apiNotifyPath = ''
            if apiNotifyPath != '':
                with shared.printLock:
                    print('Trying to call', apiNotifyPath)

                call([apiNotifyPath, "startingUp"])
            singleAPIThread = singleAPI()
            singleAPIThread.daemon = True  # close the main program even if there are threads left
            singleAPIThread.start()

        connectToStream(1)

        singleListenerThread = singleListener()
        singleListenerThread.setup(selfInitiatedConnections)
        singleListenerThread.daemon = True  # close the main program even if there are threads left
        singleListenerThread.start()
        
        if shared.safeConfigGetBoolean('bitmessagesettings','upnp'):
            import upnp
            upnpThread = upnp.uPnPThread()
            upnpThread.start()

        if daemon == False and shared.safeConfigGetBoolean('bitmessagesettings', 'daemon') == False:
            if shared.curses == False:
                if not depends.check_pyqt():
                    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('You can also run PyBitmessage with the new curses interface by providing \'-c\' as a commandline argument.')
                    sys.exit()

                import bitmessageqt
                bitmessageqt.run()
            else:
                if True:
#                if depends.check_curses():
                    print('Running with curses')
                    import bitmessagecurses
                    bitmessagecurses.runwrapper()
        else:
            shared.config.remove_option('bitmessagesettings', 'dontconnect')

            while True:
                time.sleep(20)
Beispiel #4
0
 def run(self):
     while shared.shutdown == 0:
         command, data = shared.UISignalQueue.get()
         if command == 'writeNewAddressToTable':
             label, address, streamNumber = data
             pass
         elif command == 'updateStatusBar':
             pass
         elif command == 'updateSentItemStatusByToAddress':
             toAddress, message = data
             pass
         elif command == 'updateSentItemStatusByAckdata':
             ackData, message = data
             pass
         elif command == 'displayNewInboxMessage':
             inventoryHash, toAddress, fromAddress, subject, body = data
             dest = shared.safeConfigGet("bitmessagesettings",
                                         "smtpdeliver", '')
             if dest == '':
                 continue
             try:
                 u = urlparse.urlparse(dest)
                 to = urlparse.parse_qs(u.query)['to']
                 client = smtplib.SMTP(u.hostname, u.port)
                 msg = MIMEText(body, 'plain', 'utf-8')
                 msg['Subject'] = Header(subject, 'utf-8')
                 msg['From'] = fromAddress + '@' + SMTPDOMAIN
                 toLabel = map(
                     lambda y: shared.safeConfigGet(y, "label"),
                     filter(lambda x: x == toAddress,
                            shared.config.sections()))
                 if len(toLabel) > 0:
                     msg['To'] = "\"%s\" <%s>" % (Header(
                         toLabel[0], 'utf-8'), toAddress + '@' + SMTPDOMAIN)
                 else:
                     msg['To'] = toAddress + '@' + SMTPDOMAIN
                 client.ehlo()
                 client.starttls()
                 client.ehlo()
                 client.sendmail(msg['From'], [to], msg.as_string())
                 logger.info("Delivered via SMTP to %s through %s:%i ...",
                             to, u.hostname, u.port)
                 client.quit()
             except:
                 logger.error("smtp delivery error", exc_info=True)
         elif command == 'displayNewSentMessage':
             toAddress, fromLabel, fromAddress, subject, message, ackdata = data
             pass
         elif command == 'updateNetworkStatusTab':
             pass
         elif command == 'updateNumberOfMessagesProcessed':
             pass
         elif command == 'updateNumberOfPubkeysProcessed':
             pass
         elif command == 'updateNumberOfBroadcastsProcessed':
             pass
         elif command == 'setStatusIcon':
             pass
         elif command == 'changedInboxUnread':
             pass
         elif command == 'rerenderMessagelistFromLabels':
             pass
         elif command == 'rerenderMessagelistToLabels':
             pass
         elif command == 'rerenderAddressBook':
             pass
         elif command == 'rerenderSubscriptions':
             pass
         elif command == 'rerenderBlackWhiteList':
             pass
         elif command == 'removeInboxRowByMsgid':
             pass
         elif command == 'newVersionAvailable':
             pass
         elif command == 'alert':
             title, text, exitAfterUserClicksOk = data
             pass
         elif command == 'stopThread':
             break
         else:
             sys.stderr.write(
                 'Command sent to smtpDeliver not recognized: %s\n' %
                 command)