2018-05-15 17:15:44 +02:00
|
|
|
#!/usr/bin/python2.7
|
2017-12-26 14:17:37 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-05-15 17:15:44 +02:00
|
|
|
# pylint: disable=too-many-lines,global-statement,too-many-branches,too-many-statements,inconsistent-return-statements
|
|
|
|
# pylint: disable=too-many-nested-blocks,too-many-locals,protected-access,too-many-arguments,too-many-function-args
|
|
|
|
# pylint: disable=no-member
|
|
|
|
"""
|
|
|
|
Created by Adam Melton (.dok) referenceing https://bitmessage.org/wiki/API_Reference for API documentation
|
|
|
|
Distributed under the MIT/X11 software license. See http://www.opensource.org/licenses/mit-license.php.
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
This is an example of a daemon client for PyBitmessage 0.6.2, by .dok (Version 0.3.1) , modified
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
TODO: fix the following (currently ignored) violations:
|
|
|
|
|
|
|
|
"""
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
import datetime
|
|
|
|
import imghdr
|
|
|
|
import json
|
2020-01-24 15:03:13 +01:00
|
|
|
import ntpath
|
|
|
|
import os
|
2017-08-22 13:23:03 +02:00
|
|
|
import socket
|
2015-01-19 18:53:07 +01:00
|
|
|
import sys
|
2020-01-24 15:03:13 +01:00
|
|
|
import time
|
|
|
|
import xmlrpclib
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2017-02-22 09:34:54 +01:00
|
|
|
from bmconfigparser import BMConfigParser
|
2016-12-06 10:47:39 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
api = ''
|
|
|
|
keysName = 'keys.dat'
|
|
|
|
keysPath = 'keys.dat'
|
2018-05-15 17:15:44 +02:00
|
|
|
usrPrompt = 0 # 0 = First Start, 1 = prompt, 2 = no prompt if the program is starting up
|
2015-01-19 18:53:07 +01:00
|
|
|
knownAddresses = dict()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
def userInput(message):
|
|
|
|
"""Checks input for exit or quit. Also formats for input, etc"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n' + message)
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = raw_input('> ')
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if uInput.lower() == 'exit': # Returns the user to the main menu
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
elif uInput.lower() == 'quit': # Quits the program
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Bye\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
sys.exit(0)
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
return uInput
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
def restartBmNotify():
|
|
|
|
"""Prompt the user to restart Bitmessage"""
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n *******************************************************************')
|
|
|
|
print(' WARNING: If Bitmessage is running locally, you must restart it now.')
|
|
|
|
print(' *******************************************************************\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
# Begin keys.dat interactions
|
|
|
|
|
|
|
|
|
|
|
|
def lookupAppdataFolder():
|
|
|
|
"""gets the appropriate folders for the .dat files depending on the OS. Taken from bitmessagemain.py"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
APPNAME = "PyBitmessage"
|
|
|
|
if sys.platform == 'darwin':
|
2018-05-15 17:15:44 +02:00
|
|
|
if "HOME" in os.environ:
|
|
|
|
dataFolder = os.path.join(os.environ["HOME"], "Library/Application support/", APPNAME) + '/'
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
2018-05-15 17:15:44 +02:00
|
|
|
print(
|
|
|
|
' Could not find home folder, please report '
|
|
|
|
'this message and your OS X version to the Daemon Github.')
|
|
|
|
sys.exit(1)
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
elif 'win32' in sys.platform or 'win64' in sys.platform:
|
2018-05-15 17:15:44 +02:00
|
|
|
dataFolder = os.path.join(os.environ['APPDATA'], APPNAME) + '\\'
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
2018-05-15 17:15:44 +02:00
|
|
|
dataFolder = os.path.expanduser(os.path.join("~", ".config/" + APPNAME + "/"))
|
2015-01-19 18:53:07 +01:00
|
|
|
return dataFolder
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def configInit():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Initialised the configuration"""
|
|
|
|
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().add_section('bitmessagesettings')
|
2018-05-15 17:15:44 +02:00
|
|
|
# Sets the bitmessage port to stop the warning about the api not properly
|
|
|
|
# being setup. This is in the event that the keys.dat is in a different
|
|
|
|
# directory or is created locally to connect to a machine remotely.
|
|
|
|
BMConfigParser().set('bitmessagesettings', 'port', '8444')
|
|
|
|
BMConfigParser().set('bitmessagesettings', 'apienabled', 'true') # Sets apienabled to true in keys.dat
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
with open(keysName, 'wb') as configfile:
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().write(configfile)
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n ' + str(keysName) + ' Initalized in the same directory as daemon.py')
|
|
|
|
print(' You will now need to configure the ' + str(keysName) + ' file.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def apiInit(apiEnabled):
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Initialise the API"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().read(keysPath)
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if apiEnabled is False: # API information there but the api is disabled.
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("The API is not enabled. Would you like to do that now, (Y)es or (N)o?").lower()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if uInput == "y":
|
|
|
|
BMConfigParser().set('bitmessagesettings', 'apienabled', 'true') # Sets apienabled to true in keys.dat
|
2015-01-19 18:53:07 +01:00
|
|
|
with open(keysPath, 'wb') as configfile:
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().write(configfile)
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('Done')
|
2015-01-19 18:53:07 +01:00
|
|
|
restartBmNotify()
|
|
|
|
return True
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "n":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' \n************************************************************')
|
|
|
|
print(' Daemon will not work when the API is disabled. ')
|
|
|
|
print(' Please refer to the Bitmessage Wiki on how to setup the API.')
|
|
|
|
print(' ************************************************************\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Entry\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
elif apiEnabled: # API correctly setup
|
|
|
|
# Everything is as it should be
|
2015-01-19 18:53:07 +01:00
|
|
|
return True
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
else: # API information was not present.
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n ' + str(keysPath) + ' not properly configured!\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Would you like to do this now, (Y)es or (N)o?").lower()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if uInput == "y": # User said yes, initalize the api by writing these values to the keys.dat file
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
apiUsr = userInput("API Username")
|
|
|
|
apiPwd = userInput("API Password")
|
|
|
|
apiPort = userInput("API Port")
|
|
|
|
apiEnabled = userInput("API Enabled? (True) or (False)").lower()
|
|
|
|
daemon = userInput("Daemon mode Enabled? (True) or (False)").lower()
|
|
|
|
|
|
|
|
if (daemon != 'true' and daemon != 'false'):
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Entry for Daemon.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = 1
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' -----------------------------------\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
# sets the bitmessage port to stop the warning about the api not properly
|
|
|
|
# being setup. This is in the event that the keys.dat is in a different
|
|
|
|
# directory or is created locally to connect to a machine remotely.
|
|
|
|
BMConfigParser().set('bitmessagesettings', 'port', '8444')
|
|
|
|
BMConfigParser().set('bitmessagesettings', 'apienabled', 'true')
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'apiport', apiPort)
|
|
|
|
BMConfigParser().set('bitmessagesettings', 'apiinterface', '127.0.0.1')
|
|
|
|
BMConfigParser().set('bitmessagesettings', 'apiusername', apiUsr)
|
|
|
|
BMConfigParser().set('bitmessagesettings', 'apipassword', apiPwd)
|
|
|
|
BMConfigParser().set('bitmessagesettings', 'daemon', daemon)
|
2015-01-19 18:53:07 +01:00
|
|
|
with open(keysPath, 'wb') as configfile:
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().write(configfile)
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Finished configuring the keys.dat file with API information.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
restartBmNotify()
|
|
|
|
return True
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "n":
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n ***********************************************************')
|
|
|
|
print(' Please refer to the Bitmessage Wiki on how to setup the API.')
|
|
|
|
print(' ***********************************************************\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' \nInvalid entry\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
|
|
|
def apiData():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""TBC"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global keysName
|
|
|
|
global keysPath
|
|
|
|
global usrPrompt
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
BMConfigParser().read(keysPath) # First try to load the config file (the keys.dat file) from the program directory
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
try:
|
2018-05-15 17:15:44 +02:00
|
|
|
BMConfigParser().get('bitmessagesettings', 'port')
|
2015-01-19 18:53:07 +01:00
|
|
|
appDataFolder = ''
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2018-05-15 17:15:44 +02:00
|
|
|
# Could not load the keys.dat file in the program directory. Perhaps it is in the appdata directory.
|
2015-01-19 18:53:07 +01:00
|
|
|
appDataFolder = lookupAppdataFolder()
|
|
|
|
keysPath = appDataFolder + keysPath
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().read(keysPath)
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
try:
|
2018-05-15 17:15:44 +02:00
|
|
|
BMConfigParser().get('bitmessagesettings', 'port')
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2018-05-15 17:15:44 +02:00
|
|
|
# keys.dat was not there either, something is wrong.
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n ******************************************************************')
|
|
|
|
print(' There was a problem trying to access the Bitmessage keys.dat file')
|
|
|
|
print(' or keys.dat is not set up correctly')
|
|
|
|
print(' Make sure that daemon is in the same directory as Bitmessage. ')
|
|
|
|
print(' ******************************************************************\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
uInput = userInput("Would you like to create a keys.dat in the local directory, (Y)es or (N)o?").lower()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput in ("y", "yes"):
|
2015-01-19 18:53:07 +01:00
|
|
|
configInit()
|
|
|
|
keysPath = keysName
|
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
2021-08-11 18:50:56 +02:00
|
|
|
elif uInput in ("n", "no"):
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Trying Again.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Input.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
try: # checks to make sure that everyting is configured correctly. Excluding apiEnabled, it is checked after
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().get('bitmessagesettings', 'apiport')
|
|
|
|
BMConfigParser().get('bitmessagesettings', 'apiinterface')
|
|
|
|
BMConfigParser().get('bitmessagesettings', 'apiusername')
|
|
|
|
BMConfigParser().get('bitmessagesettings', 'apipassword')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2018-05-15 17:15:44 +02:00
|
|
|
apiInit("") # Initalize the keys.dat file with API information
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
# keys.dat file was found or appropriately configured, allow information retrieval
|
|
|
|
# apiEnabled =
|
|
|
|
# apiInit(BMConfigParser().safeGetBoolean('bitmessagesettings','apienabled'))
|
|
|
|
# #if false it will prompt the user, if true it will return true
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
BMConfigParser().read(keysPath) # read again since changes have been made
|
2017-01-11 14:27:19 +01:00
|
|
|
apiPort = int(BMConfigParser().get('bitmessagesettings', 'apiport'))
|
|
|
|
apiInterface = BMConfigParser().get('bitmessagesettings', 'apiinterface')
|
|
|
|
apiUsername = BMConfigParser().get('bitmessagesettings', 'apiusername')
|
|
|
|
apiPassword = BMConfigParser().get('bitmessagesettings', 'apipassword')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n API data successfully imported.\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
# Build the api credentials
|
|
|
|
return "http://" + apiUsername + ":" + apiPassword + "@" + apiInterface + ":" + str(apiPort) + "/"
|
|
|
|
|
|
|
|
|
|
|
|
# End keys.dat interactions
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
def apiTest():
|
|
|
|
"""Tests the API connection to bitmessage. Returns true if it is connected."""
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
try:
|
2018-05-15 17:15:44 +02:00
|
|
|
result = api.add(2, 3)
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2015-01-19 18:53:07 +01:00
|
|
|
return False
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
return result == 5
|
|
|
|
|
|
|
|
|
|
|
|
def bmSettings():
|
|
|
|
"""Allows the viewing and modification of keys.dat settings."""
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
global keysPath
|
|
|
|
global usrPrompt
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
keysPath = 'keys.dat'
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
BMConfigParser().read(keysPath) # Read the keys.dat
|
2015-01-19 18:53:07 +01:00
|
|
|
try:
|
2017-01-11 14:27:19 +01:00
|
|
|
port = BMConfigParser().get('bitmessagesettings', 'port')
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n File not found.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2017-01-11 14:27:19 +01:00
|
|
|
startonlogon = BMConfigParser().safeGetBoolean('bitmessagesettings', 'startonlogon')
|
|
|
|
minimizetotray = BMConfigParser().safeGetBoolean('bitmessagesettings', 'minimizetotray')
|
|
|
|
showtraynotifications = BMConfigParser().safeGetBoolean('bitmessagesettings', 'showtraynotifications')
|
|
|
|
startintray = BMConfigParser().safeGetBoolean('bitmessagesettings', 'startintray')
|
|
|
|
defaultnoncetrialsperbyte = BMConfigParser().get('bitmessagesettings', 'defaultnoncetrialsperbyte')
|
|
|
|
defaultpayloadlengthextrabytes = BMConfigParser().get('bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
|
|
|
daemon = BMConfigParser().safeGetBoolean('bitmessagesettings', 'daemon')
|
|
|
|
|
|
|
|
socksproxytype = BMConfigParser().get('bitmessagesettings', 'socksproxytype')
|
|
|
|
sockshostname = BMConfigParser().get('bitmessagesettings', 'sockshostname')
|
|
|
|
socksport = BMConfigParser().get('bitmessagesettings', 'socksport')
|
|
|
|
socksauthentication = BMConfigParser().safeGetBoolean('bitmessagesettings', 'socksauthentication')
|
|
|
|
socksusername = BMConfigParser().get('bitmessagesettings', 'socksusername')
|
|
|
|
sockspassword = BMConfigParser().get('bitmessagesettings', 'sockspassword')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n -----------------------------------')
|
|
|
|
print(' | Current Bitmessage Settings |')
|
|
|
|
print(' -----------------------------------')
|
|
|
|
print(' port = ' + port)
|
|
|
|
print(' startonlogon = ' + str(startonlogon))
|
|
|
|
print(' minimizetotray = ' + str(minimizetotray))
|
|
|
|
print(' showtraynotifications = ' + str(showtraynotifications))
|
|
|
|
print(' startintray = ' + str(startintray))
|
|
|
|
print(' defaultnoncetrialsperbyte = ' + defaultnoncetrialsperbyte)
|
|
|
|
print(' defaultpayloadlengthextrabytes = ' + defaultpayloadlengthextrabytes)
|
|
|
|
print(' daemon = ' + str(daemon))
|
|
|
|
print('\n ------------------------------------')
|
|
|
|
print(' | Current Connection Settings |')
|
|
|
|
print(' -----------------------------------')
|
|
|
|
print(' socksproxytype = ' + socksproxytype)
|
|
|
|
print(' sockshostname = ' + sockshostname)
|
|
|
|
print(' socksport = ' + socksport)
|
|
|
|
print(' socksauthentication = ' + str(socksauthentication))
|
|
|
|
print(' socksusername = ' + socksusername)
|
|
|
|
print(' sockspassword = ' + sockspassword)
|
|
|
|
print(' ')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
uInput = userInput("Would you like to modify any of these settings, (Y)es or (N)o?").lower()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
if uInput == "y":
|
2018-05-15 17:15:44 +02:00
|
|
|
while True: # loops if they mistype the setting name, they can exit the loop with 'exit'
|
2015-01-19 18:53:07 +01:00
|
|
|
invalidInput = False
|
|
|
|
uInput = userInput("What setting would you like to modify?").lower()
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
if uInput == "port":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current port number: ' + port)
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new port number.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'port', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "startonlogon":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current status: ' + str(startonlogon))
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new status.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'startonlogon', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "minimizetotray":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current status: ' + str(minimizetotray))
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new status.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'minimizetotray', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "showtraynotifications":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current status: ' + str(showtraynotifications))
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new status.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'showtraynotifications', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "startintray":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current status: ' + str(startintray))
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new status.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'startintray', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "defaultnoncetrialsperbyte":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current default nonce trials per byte: ' + defaultnoncetrialsperbyte)
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new defaultnoncetrialsperbyte.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'defaultnoncetrialsperbyte', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "defaultpayloadlengthextrabytes":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current default payload length extra bytes: ' + defaultpayloadlengthextrabytes)
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new defaultpayloadlengthextrabytes.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'defaultpayloadlengthextrabytes', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "daemon":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current status: ' + str(daemon))
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new status.").lower()
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'daemon', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "socksproxytype":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current socks proxy type: ' + socksproxytype)
|
|
|
|
print("Possibilities: 'none', 'SOCKS4a', 'SOCKS5'.")
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new socksproxytype.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'socksproxytype', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "sockshostname":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current socks host name: ' + sockshostname)
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new sockshostname.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'sockshostname', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "socksport":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current socks port number: ' + socksport)
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new socksport.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'socksport', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "socksauthentication":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current status: ' + str(socksauthentication))
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new status.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'socksauthentication', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "socksusername":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current socks username: ' + socksusername)
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new socksusername.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'socksusername', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "sockspassword":
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Current socks password: ' + sockspassword)
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Enter the new password.")
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set('bitmessagesettings', 'sockspassword', str(uInput))
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print("\n Invalid input. Please try again.\n")
|
2015-01-19 18:53:07 +01:00
|
|
|
invalidInput = True
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if invalidInput is not True: # don't prompt if they made a mistake.
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Would you like to change another setting, (Y)es or (N)o?").lower()
|
|
|
|
|
|
|
|
if uInput != "y":
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Changes Made.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
with open(keysPath, 'wb') as configfile:
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().write(configfile)
|
2015-01-19 18:53:07 +01:00
|
|
|
restartBmNotify()
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
elif uInput == "n":
|
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print("Invalid input.")
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def validAddress(address):
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Predicate to test address validity"""
|
2018-02-18 20:14:21 +01:00
|
|
|
address_information = json.loads(api.decodeAddress(address))
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
return 'success' in str(address_information['status']).lower()
|
|
|
|
|
|
|
|
|
|
|
|
def getAddress(passphrase, vNumber, sNumber):
|
|
|
|
"""Get a deterministic address"""
|
|
|
|
passphrase = passphrase.encode('base64') # passphrase must be encoded
|
|
|
|
|
|
|
|
return api.getDeterministicAddress(passphrase, vNumber, sNumber)
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
def subscribe():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Subscribe to an address"""
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
|
|
|
|
|
|
|
while True:
|
|
|
|
address = userInput("What address would you like to subscribe to?")
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if address == "c":
|
|
|
|
usrPrompt = 1
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2018-05-15 17:15:44 +02:00
|
|
|
main()
|
|
|
|
elif validAddress(address) is False:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid. "c" to cancel. Please try again.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
label = userInput("Enter a label for this address.")
|
|
|
|
label = label.encode('base64')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
api.addSubscription(address, label)
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n You are now subscribed to: ' + address + '\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
def unsubscribe():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Unsusbcribe from an address"""
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
while True:
|
|
|
|
address = userInput("What address would you like to unsubscribe from?")
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if address == "c":
|
|
|
|
usrPrompt = 1
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2018-05-15 17:15:44 +02:00
|
|
|
main()
|
|
|
|
elif validAddress(address) is False:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid. "c" to cancel. Please try again.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
userInput("Are you sure, (Y)es or (N)o?").lower() # uInput =
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
api.deleteSubscription(address)
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n You are now unsubscribed from: ' + address + '\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
def listSubscriptions():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""List subscriptions"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\nLabel, Address, Enabled\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
try:
|
2021-08-10 16:19:29 +02:00
|
|
|
print(api.listSubscriptions())
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def createChan():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Create a channel"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
|
|
|
password = userInput("Enter channel name")
|
|
|
|
password = password.encode('base64')
|
|
|
|
try:
|
2021-08-10 16:19:29 +02:00
|
|
|
print(api.createChan(password))
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
|
|
|
def joinChan():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Join a channel"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
|
|
|
while True:
|
|
|
|
address = userInput("Enter channel address")
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if address == "c":
|
|
|
|
usrPrompt = 1
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2018-05-15 17:15:44 +02:00
|
|
|
main()
|
|
|
|
elif validAddress(address) is False:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid. "c" to cancel. Please try again.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
password = userInput("Enter channel name")
|
|
|
|
password = password.encode('base64')
|
|
|
|
try:
|
2021-08-10 16:19:29 +02:00
|
|
|
print(api.joinChan(password, address))
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def leaveChan():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Leave a channel"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
|
|
|
while True:
|
|
|
|
address = userInput("Enter channel address")
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if address == "c":
|
|
|
|
usrPrompt = 1
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2018-05-15 17:15:44 +02:00
|
|
|
main()
|
|
|
|
elif validAddress(address) is False:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid. "c" to cancel. Please try again.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
try:
|
2021-08-10 16:19:29 +02:00
|
|
|
print(api.leaveChan(address))
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
def listAdd():
|
|
|
|
"""List all of the addresses and their info"""
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
|
|
|
try:
|
|
|
|
jsonAddresses = json.loads(api.listAddresses())
|
2018-05-15 17:15:44 +02:00
|
|
|
numAddresses = len(jsonAddresses['addresses']) # Number of addresses
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
# print('\nAddress Number,Label,Address,Stream,Enabled\n')
|
|
|
|
print('\n --------------------------------------------------------------------------')
|
|
|
|
print(' | # | Label | Address |S#|Enabled|')
|
|
|
|
print(' |---|-------------------|-------------------------------------|--|-------|')
|
2018-05-15 17:15:44 +02:00
|
|
|
for addNum in range(0, numAddresses): # processes all of the addresses and lists them out
|
|
|
|
label = (jsonAddresses['addresses'][addNum]['label']).encode(
|
2021-08-10 16:19:29 +02:00
|
|
|
'utf') # may still misdiplay in some consoles
|
2015-01-19 18:53:07 +01:00
|
|
|
address = str(jsonAddresses['addresses'][addNum]['address'])
|
2018-05-15 17:15:44 +02:00
|
|
|
stream = str(jsonAddresses['addresses'][addNum]['stream'])
|
2015-01-19 18:53:07 +01:00
|
|
|
enabled = str(jsonAddresses['addresses'][addNum]['enabled'])
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if len(label) > 19:
|
2015-01-19 18:53:07 +01:00
|
|
|
label = label[:16] + '...'
|
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print(''.join([
|
2018-05-15 17:15:44 +02:00
|
|
|
' |',
|
|
|
|
str(addNum).ljust(3),
|
|
|
|
'|',
|
|
|
|
label.ljust(19),
|
|
|
|
'|',
|
|
|
|
address.ljust(37),
|
|
|
|
'|',
|
|
|
|
stream.ljust(1),
|
|
|
|
'|',
|
|
|
|
enabled.ljust(7),
|
|
|
|
'|',
|
2021-03-04 15:15:41 +01:00
|
|
|
]))
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print(''.join([
|
2018-05-15 17:15:44 +02:00
|
|
|
' ',
|
|
|
|
74 * '-',
|
|
|
|
'\n',
|
2021-03-04 15:15:41 +01:00
|
|
|
]))
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
def genAdd(lbl, deterministic, passphrase, numOfAdd, addVNum, streamNum, ripe):
|
|
|
|
"""Generate address"""
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
global usrPrompt
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if deterministic is False: # Generates a new address with the user defined label. non-deterministic
|
2015-01-19 18:53:07 +01:00
|
|
|
addressLabel = lbl.encode('base64')
|
|
|
|
try:
|
|
|
|
generatedAddress = api.createRandomAddress(addressLabel)
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
return generatedAddress
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
elif deterministic: # Generates a new deterministic address with the user inputs.
|
2015-01-19 18:53:07 +01:00
|
|
|
passphrase = passphrase.encode('base64')
|
|
|
|
try:
|
|
|
|
generatedAddress = api.createDeterministicAddresses(passphrase, numOfAdd, addVNum, streamNum, ripe)
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
return generatedAddress
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
return 'Entry Error'
|
2015-06-20 09:54:15 +02:00
|
|
|
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
def saveFile(fileName, fileData):
|
|
|
|
"""Allows attachments and messages/broadcats to be saved"""
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
# This section finds all invalid characters and replaces them with ~
|
2015-01-19 18:53:07 +01:00
|
|
|
fileName = fileName.replace(" ", "")
|
|
|
|
fileName = fileName.replace("/", "~")
|
2018-05-15 17:15:44 +02:00
|
|
|
# fileName = fileName.replace("\\", "~") How do I get this to work...?
|
2015-01-19 18:53:07 +01:00
|
|
|
fileName = fileName.replace(":", "~")
|
|
|
|
fileName = fileName.replace("*", "~")
|
|
|
|
fileName = fileName.replace("?", "~")
|
|
|
|
fileName = fileName.replace('"', "~")
|
|
|
|
fileName = fileName.replace("<", "~")
|
|
|
|
fileName = fileName.replace(">", "~")
|
|
|
|
fileName = fileName.replace("|", "~")
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
directory = os.path.abspath('attachments')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
if not os.path.exists(directory):
|
|
|
|
os.makedirs(directory)
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
filePath = os.path.join(directory, fileName)
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
with open(filePath, 'wb+') as path_to_file:
|
|
|
|
path_to_file.write(fileData.decode("base64"))
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Successfully saved ' + filePath + '\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
def attachment():
|
|
|
|
"""Allows users to attach a file to their message or broadcast"""
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
theAttachmentS = ''
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
while True:
|
|
|
|
|
|
|
|
isImage = False
|
|
|
|
theAttachment = ''
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
while True: # loops until valid path is entered
|
|
|
|
filePath = userInput(
|
|
|
|
'\nPlease enter the path to the attachment or just the attachment name if in this folder.')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
try:
|
2018-05-15 17:15:44 +02:00
|
|
|
with open(filePath):
|
|
|
|
break
|
2015-01-19 18:53:07 +01:00
|
|
|
except IOError:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n %s was not found on your filesystem or can not be opened.\n' % filePath)
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
# print(filesize, and encoding estimate with confirmation if file is over X size(1mb?))
|
2015-01-19 18:53:07 +01:00
|
|
|
invSize = os.path.getsize(filePath)
|
2018-05-15 17:15:44 +02:00
|
|
|
invSize = (invSize / 1024) # Converts to kilobytes
|
|
|
|
round(invSize, 2) # Rounds to two decimal places
|
|
|
|
|
|
|
|
if invSize > 500.0: # If over 500KB
|
2021-08-10 16:19:29 +02:00
|
|
|
print(''.join([
|
2018-05-15 17:15:44 +02:00
|
|
|
'\n WARNING:The file that you are trying to attach is ',
|
|
|
|
invSize,
|
|
|
|
'KB and will take considerable time to send.\n'
|
2021-03-04 15:15:41 +01:00
|
|
|
]))
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput('Are you sure you still want to attach it, (Y)es or (N)o?').lower()
|
|
|
|
|
|
|
|
if uInput != "y":
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Attachment discarded.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
return ''
|
2018-05-15 17:15:44 +02:00
|
|
|
elif invSize > 184320.0: # If larger than 180MB, discard.
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Attachment too big, maximum allowed size:180MB\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
pathLen = len(str(ntpath.basename(filePath))) # Gets the length of the filepath excluding the filename
|
|
|
|
fileName = filePath[(len(str(filePath)) - pathLen):] # reads the filename
|
|
|
|
|
|
|
|
filetype = imghdr.what(filePath) # Tests if it is an image file
|
2015-01-19 18:53:07 +01:00
|
|
|
if filetype is not None:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n ---------------------------------------------------')
|
|
|
|
print(' Attachment detected as an Image.')
|
|
|
|
print(' <img> tags will automatically be included,')
|
|
|
|
print(' allowing the recipient to view the image')
|
|
|
|
print(' using the "View HTML code..." option in Bitmessage.')
|
|
|
|
print(' ---------------------------------------------------\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
isImage = True
|
|
|
|
time.sleep(2)
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
# Alert the user that the encoding process may take some time.
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Encoding Attachment, Please Wait ...\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
with open(filePath, 'rb') as f: # Begin the actual encoding
|
|
|
|
data = f.read(188743680) # Reads files up to 180MB, the maximum size for Bitmessage.
|
2015-01-19 18:53:07 +01:00
|
|
|
data = data.encode("base64")
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if isImage: # If it is an image, include image tags in the message
|
2015-01-19 18:53:07 +01:00
|
|
|
theAttachment = """
|
|
|
|
<!-- Note: Image attachment below. Please use the right click "View HTML code ..." option to view it. -->
|
|
|
|
<!-- Sent using Bitmessage Daemon. https://github.com/Dokument/PyBitmessage-Daemon -->
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
Filename:%s
|
|
|
|
Filesize:%sKB
|
|
|
|
Encoding:base64
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
<center>
|
|
|
|
<div id="image">
|
|
|
|
<img alt = "%s" src='data:image/%s;base64, %s' />
|
|
|
|
</div>
|
2018-05-15 17:15:44 +02:00
|
|
|
</center>""" % (fileName, invSize, fileName, filetype, data)
|
|
|
|
else: # Else it is not an image so do not include the embedded image code.
|
2015-01-19 18:53:07 +01:00
|
|
|
theAttachment = """
|
|
|
|
<!-- Note: File attachment below. Please use a base64 decoder, or Daemon, to save it. -->
|
|
|
|
<!-- Sent using Bitmessage Daemon. https://github.com/Dokument/PyBitmessage-Daemon -->
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
Filename:%s
|
|
|
|
Filesize:%sKB
|
|
|
|
Encoding:base64
|
|
|
|
|
|
|
|
<attachment alt = "%s" src='data:file/%s;base64, %s' />""" % (fileName, invSize, fileName, fileName, data)
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
uInput = userInput('Would you like to add another attachment, (Y)es or (N)o?').lower()
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput in ('y', 'yes'): # Allows multiple attachments to be added to one message
|
2018-05-15 17:15:44 +02:00
|
|
|
theAttachmentS = str(theAttachmentS) + str(theAttachment) + '\n\n'
|
2021-08-11 18:50:56 +02:00
|
|
|
elif uInput in ('n', 'no'):
|
2015-01-19 18:53:07 +01:00
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
theAttachmentS = theAttachmentS + theAttachment
|
|
|
|
return theAttachmentS
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
def sendMsg(toAddress, fromAddress, subject, message):
|
|
|
|
"""
|
|
|
|
With no arguments sent, sendMsg fills in the blanks.
|
|
|
|
subject and message must be encoded before they are passed.
|
|
|
|
"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
2018-05-15 17:15:44 +02:00
|
|
|
if validAddress(toAddress) is False:
|
2015-01-19 18:53:07 +01:00
|
|
|
while True:
|
|
|
|
toAddress = userInput("What is the To Address?")
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if toAddress == "c":
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
elif validAddress(toAddress) is False:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Address. "c" to cancel. Please try again.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if validAddress(fromAddress) is False:
|
|
|
|
try:
|
2015-01-19 18:53:07 +01:00
|
|
|
jsonAddresses = json.loads(api.listAddresses())
|
2018-05-15 17:15:44 +02:00
|
|
|
numAddresses = len(jsonAddresses['addresses']) # Number of addresses
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if numAddresses > 1: # Ask what address to send from if multiple addresses
|
2015-01-19 18:53:07 +01:00
|
|
|
found = False
|
|
|
|
while True:
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2015-01-19 18:53:07 +01:00
|
|
|
fromAddress = userInput("Enter an Address or Address Label to send from.")
|
|
|
|
|
|
|
|
if fromAddress == "exit":
|
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
for addNum in range(0, numAddresses): # processes all of the addresses
|
2015-01-19 18:53:07 +01:00
|
|
|
label = jsonAddresses['addresses'][addNum]['label']
|
|
|
|
address = jsonAddresses['addresses'][addNum]['address']
|
2018-05-15 17:15:44 +02:00
|
|
|
if fromAddress == label: # address entered was a label and is found
|
2015-01-19 18:53:07 +01:00
|
|
|
fromAddress = address
|
|
|
|
found = True
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if found is False:
|
|
|
|
if validAddress(fromAddress) is False:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Address. Please try again.\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
2018-05-15 17:15:44 +02:00
|
|
|
for addNum in range(0, numAddresses): # processes all of the addresses
|
2015-01-19 18:53:07 +01:00
|
|
|
address = jsonAddresses['addresses'][addNum]['address']
|
2018-05-15 17:15:44 +02:00
|
|
|
if fromAddress == address: # address entered was a found in our addressbook.
|
2015-01-19 18:53:07 +01:00
|
|
|
found = True
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if found is False:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n The address entered is not one of yours. Please try again.\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if found:
|
|
|
|
break # Address was found
|
|
|
|
|
|
|
|
else: # Only one address in address book
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Using the only address in the addressbook to send from.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
fromAddress = jsonAddresses['addresses'][0]['address']
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if not subject:
|
2015-01-19 18:53:07 +01:00
|
|
|
subject = userInput("Enter your Subject.")
|
|
|
|
subject = subject.encode('base64')
|
2021-08-11 18:50:56 +02:00
|
|
|
if not message:
|
2015-01-19 18:53:07 +01:00
|
|
|
message = userInput("Enter your Message.")
|
|
|
|
|
|
|
|
uInput = userInput('Would you like to add an attachment, (Y)es or (N)o?').lower()
|
|
|
|
if uInput == "y":
|
|
|
|
message = message + '\n\n' + attachment()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
message = message.encode('base64')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
try:
|
|
|
|
ackData = api.sendMessage(toAddress, fromAddress, subject, message)
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Message Status:', api.getStatus(ackData), '\n')
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
def sendBrd(fromAddress, subject, message):
|
|
|
|
"""Send a broadcast"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
2021-08-11 18:50:56 +02:00
|
|
|
if not fromAddress:
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
jsonAddresses = json.loads(api.listAddresses())
|
2018-05-15 17:15:44 +02:00
|
|
|
numAddresses = len(jsonAddresses['addresses']) # Number of addresses
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if numAddresses > 1: # Ask what address to send from if multiple addresses
|
2015-01-19 18:53:07 +01:00
|
|
|
found = False
|
|
|
|
while True:
|
|
|
|
fromAddress = userInput("\nEnter an Address or Address Label to send from.")
|
|
|
|
|
|
|
|
if fromAddress == "exit":
|
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
for addNum in range(0, numAddresses): # processes all of the addresses
|
2015-01-19 18:53:07 +01:00
|
|
|
label = jsonAddresses['addresses'][addNum]['label']
|
|
|
|
address = jsonAddresses['addresses'][addNum]['address']
|
2018-05-15 17:15:44 +02:00
|
|
|
if fromAddress == label: # address entered was a label and is found
|
2015-01-19 18:53:07 +01:00
|
|
|
fromAddress = address
|
|
|
|
found = True
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if found is False:
|
|
|
|
if validAddress(fromAddress) is False:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Address. Please try again.\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
2018-05-15 17:15:44 +02:00
|
|
|
for addNum in range(0, numAddresses): # processes all of the addresses
|
2015-01-19 18:53:07 +01:00
|
|
|
address = jsonAddresses['addresses'][addNum]['address']
|
2018-05-15 17:15:44 +02:00
|
|
|
if fromAddress == address: # address entered was a found in our addressbook.
|
2015-01-19 18:53:07 +01:00
|
|
|
found = True
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if found is False:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n The address entered is not one of yours. Please try again.\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if found:
|
|
|
|
break # Address was found
|
|
|
|
|
|
|
|
else: # Only one address in address book
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Using the only address in the addressbook to send from.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
fromAddress = jsonAddresses['addresses'][0]['address']
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if not subject:
|
2018-05-15 17:15:44 +02:00
|
|
|
subject = userInput("Enter your Subject.")
|
|
|
|
subject = subject.encode('base64')
|
2021-08-11 18:50:56 +02:00
|
|
|
if not message:
|
2018-05-15 17:15:44 +02:00
|
|
|
message = userInput("Enter your Message.")
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
uInput = userInput('Would you like to add an attachment, (Y)es or (N)o?').lower()
|
|
|
|
if uInput == "y":
|
|
|
|
message = message + '\n\n' + attachment()
|
|
|
|
|
|
|
|
message = message.encode('base64')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
ackData = api.sendBroadcast(fromAddress, subject, message)
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Message Status:', api.getStatus(ackData), '\n')
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
def inbox(unreadOnly=False):
|
|
|
|
"""Lists the messages by: Message Number, To Address Label, From Address Label, Subject, Received Time)"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
|
|
|
try:
|
|
|
|
inboxMessages = json.loads(api.getAllInboxMessages())
|
|
|
|
numMessages = len(inboxMessages['inboxMessages'])
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
|
|
|
messagesPrinted = 0
|
|
|
|
messagesUnread = 0
|
2018-05-15 17:15:44 +02:00
|
|
|
for msgNum in range(0, numMessages): # processes all of the messages in the inbox
|
2015-01-19 18:53:07 +01:00
|
|
|
message = inboxMessages['inboxMessages'][msgNum]
|
|
|
|
# if we are displaying all messages or if this message is unread then display it
|
|
|
|
if not unreadOnly or not message['read']:
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' -----------------------------------\n')
|
|
|
|
print(' Message Number:', msgNum) # Message Number)
|
|
|
|
print(' To:', getLabelForAddress(message['toAddress'])) # Get the to address)
|
|
|
|
print(' From:', getLabelForAddress(message['fromAddress'])) # Get the from address)
|
|
|
|
print(' Subject:', message['subject'].decode('base64')) # Get the subject)
|
|
|
|
print(''.join([
|
2018-05-15 17:15:44 +02:00
|
|
|
' Received:',
|
|
|
|
datetime.datetime.fromtimestamp(
|
|
|
|
float(message['receivedTime'])).strftime('%Y-%m-%d %H:%M:%S'),
|
2021-03-04 15:15:41 +01:00
|
|
|
]))
|
2015-01-19 18:53:07 +01:00
|
|
|
messagesPrinted += 1
|
2018-05-15 17:15:44 +02:00
|
|
|
if not message['read']:
|
|
|
|
messagesUnread += 1
|
|
|
|
|
|
|
|
if messagesPrinted % 20 == 0 and messagesPrinted != 0:
|
|
|
|
userInput('(Press Enter to continue or type (Exit) to return to the main menu.)').lower() # uInput =
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n -----------------------------------')
|
|
|
|
print(' There are %d unread messages of %d messages in the inbox.' % (messagesUnread, numMessages))
|
|
|
|
print(' -----------------------------------\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def outbox():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""TBC"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
|
|
|
try:
|
|
|
|
outboxMessages = json.loads(api.getAllSentMessages())
|
|
|
|
numMessages = len(outboxMessages['sentMessages'])
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
for msgNum in range(0, numMessages): # processes all of the messages in the outbox
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n -----------------------------------\n')
|
|
|
|
print(' Message Number:', msgNum) # Message Number)
|
|
|
|
# print(' Message ID:', outboxMessages['sentMessages'][msgNum]['msgid'])
|
|
|
|
print(' To:', getLabelForAddress(
|
|
|
|
outboxMessages['sentMessages'][msgNum]['toAddress']
|
|
|
|
)) # Get the to address)
|
2018-05-15 17:15:44 +02:00
|
|
|
# Get the from address
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' From:', getLabelForAddress(outboxMessages['sentMessages'][msgNum]['fromAddress']))
|
|
|
|
print(' Subject:', outboxMessages['sentMessages'][msgNum]['subject'].decode('base64')) # Get the subject)
|
|
|
|
print(' Status:', outboxMessages['sentMessages'][msgNum]['status']) # Get the subject)
|
2021-03-04 15:15:41 +01:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
# print(''.join([
|
2021-03-04 15:15:41 +01:00
|
|
|
# ' Last Action Time:',
|
|
|
|
# datetime.datetime.fromtimestamp(
|
|
|
|
# float(outboxMessages['sentMessages'][msgNum]['lastActionTime'])).strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
|
# ]))
|
2021-08-10 16:19:29 +02:00
|
|
|
print(''.join([
|
2018-05-15 17:15:44 +02:00
|
|
|
' Last Action Time:',
|
|
|
|
datetime.datetime.fromtimestamp(
|
|
|
|
float(outboxMessages['sentMessages'][msgNum]['lastActionTime'])).strftime('%Y-%m-%d %H:%M:%S'),
|
2021-03-04 15:15:41 +01:00
|
|
|
]))
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if msgNum % 20 == 0 and msgNum != 0:
|
|
|
|
userInput('(Press Enter to continue or type (Exit) to return to the main menu.)').lower() # uInput =
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n -----------------------------------')
|
|
|
|
print(' There are ', numMessages, ' messages in the outbox.')
|
|
|
|
print(' -----------------------------------\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
def readSentMsg(msgNum):
|
|
|
|
"""Opens a sent message for reading"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
|
|
|
try:
|
|
|
|
outboxMessages = json.loads(api.getAllSentMessages())
|
|
|
|
numMessages = len(outboxMessages['sentMessages'])
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if msgNum >= numMessages:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Message Number.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
# Begin attachment detection
|
2015-01-19 18:53:07 +01:00
|
|
|
message = outboxMessages['sentMessages'][msgNum]['message'].decode('base64')
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
while True: # Allows multiple messages to be downloaded/saved
|
|
|
|
if ';base64,' in message: # Found this text in the message, there is probably an attachment.
|
|
|
|
attPos = message.index(";base64,") # Finds the attachment position
|
|
|
|
attEndPos = message.index("' />") # Finds the end of the attachment
|
|
|
|
# attLen = attEndPos - attPos #Finds the length of the message
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if 'alt = "' in message: # We can get the filename too
|
|
|
|
fnPos = message.index('alt = "') # Finds position of the filename
|
|
|
|
fnEndPos = message.index('" src=') # Finds the end position
|
|
|
|
# fnLen = fnEndPos - fnPos #Finds the length of the filename
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
fileName = message[fnPos + 7:fnEndPos]
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
fnPos = attPos
|
|
|
|
fileName = 'Attachment'
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
uInput = userInput(
|
|
|
|
'\n Attachment Detected. Would you like to save the attachment, (Y)es or (N)o?').lower()
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput in ("y", 'yes'):
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
this_attachment = message[attPos + 9:attEndPos]
|
|
|
|
saveFile(fileName, this_attachment)
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
message = message[:fnPos] + '~<Attachment data removed for easier viewing>~' + message[(attEndPos + 4):]
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
else:
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
# End attachment Detection
|
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n To:', getLabelForAddress(outboxMessages['sentMessages'][msgNum]['toAddress'])) # Get the to address)
|
2018-05-15 17:15:44 +02:00
|
|
|
# Get the from address
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' From:', getLabelForAddress(outboxMessages['sentMessages'][msgNum]['fromAddress']))
|
|
|
|
print(' Subject:', outboxMessages['sentMessages'][msgNum]['subject'].decode('base64')) # Get the subject)
|
|
|
|
print(' Status:', outboxMessages['sentMessages'][msgNum]['status']) # Get the subject)
|
|
|
|
print(''.join([
|
2018-05-15 17:15:44 +02:00
|
|
|
' Last Action Time:',
|
|
|
|
datetime.datetime.fromtimestamp(
|
|
|
|
float(outboxMessages['sentMessages'][msgNum]['lastActionTime'])).strftime('%Y-%m-%d %H:%M:%S'),
|
2021-03-04 15:15:41 +01:00
|
|
|
]))
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Message:\n')
|
|
|
|
print(message) # inboxMessages['inboxMessages'][msgNum]['message'].decode('base64'))
|
|
|
|
print(' ')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
def readMsg(msgNum):
|
|
|
|
"""Open a message for reading"""
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
|
|
|
try:
|
|
|
|
inboxMessages = json.loads(api.getAllInboxMessages())
|
|
|
|
numMessages = len(inboxMessages['inboxMessages'])
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if msgNum >= numMessages:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Message Number.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
# Begin attachment detection
|
2015-01-19 18:53:07 +01:00
|
|
|
message = inboxMessages['inboxMessages'][msgNum]['message'].decode('base64')
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
while True: # Allows multiple messages to be downloaded/saved
|
|
|
|
if ';base64,' in message: # Found this text in the message, there is probably an attachment.
|
|
|
|
attPos = message.index(";base64,") # Finds the attachment position
|
|
|
|
attEndPos = message.index("' />") # Finds the end of the attachment
|
|
|
|
# attLen = attEndPos - attPos #Finds the length of the message
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if 'alt = "' in message: # We can get the filename too
|
|
|
|
fnPos = message.index('alt = "') # Finds position of the filename
|
|
|
|
fnEndPos = message.index('" src=') # Finds the end position
|
|
|
|
# fnLen = fnEndPos - fnPos #Finds the length of the filename
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
fileName = message[fnPos + 7:fnEndPos]
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
fnPos = attPos
|
|
|
|
fileName = 'Attachment'
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
uInput = userInput(
|
|
|
|
'\n Attachment Detected. Would you like to save the attachment, (Y)es or (N)o?').lower()
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput in ("y", 'yes'):
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
this_attachment = message[attPos + 9:attEndPos]
|
|
|
|
saveFile(fileName, this_attachment)
|
|
|
|
|
|
|
|
message = message[:fnPos] + '~<Attachment data removed for easier viewing>~' + message[attEndPos + 4:]
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
else:
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
# End attachment Detection
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n To:', getLabelForAddress(inboxMessages['inboxMessages'][msgNum]['toAddress'])) # Get the to address)
|
2018-05-15 17:15:44 +02:00
|
|
|
# Get the from address
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' From:', getLabelForAddress(inboxMessages['inboxMessages'][msgNum]['fromAddress']))
|
|
|
|
print(' Subject:', inboxMessages['inboxMessages'][msgNum]['subject'].decode('base64')) # Get the subject)
|
|
|
|
print(''.join([
|
2018-05-15 17:15:44 +02:00
|
|
|
' Received:', datetime.datetime.fromtimestamp(
|
|
|
|
float(inboxMessages['inboxMessages'][msgNum]['receivedTime'])).strftime('%Y-%m-%d %H:%M:%S'),
|
2021-03-04 15:15:41 +01:00
|
|
|
]))
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Message:\n')
|
|
|
|
print(message) # inboxMessages['inboxMessages'][msgNum]['message'].decode('base64'))
|
|
|
|
print(' ')
|
2015-01-19 18:53:07 +01:00
|
|
|
return inboxMessages['inboxMessages'][msgNum]['msgid']
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
def replyMsg(msgNum, forwardORreply):
|
|
|
|
"""Allows you to reply to the message you are currently on. Saves typing in the addresses and subject."""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
2018-05-15 17:15:44 +02:00
|
|
|
forwardORreply = forwardORreply.lower() # makes it lowercase
|
2015-01-19 18:53:07 +01:00
|
|
|
try:
|
|
|
|
inboxMessages = json.loads(api.getAllInboxMessages())
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
fromAdd = inboxMessages['inboxMessages'][msgNum]['toAddress'] # Address it was sent To, now the From address
|
|
|
|
message = inboxMessages['inboxMessages'][msgNum]['message'].decode('base64') # Message that you are replying too.
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
subject = inboxMessages['inboxMessages'][msgNum]['subject']
|
|
|
|
subject = subject.decode('base64')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if forwardORreply == 'reply':
|
|
|
|
toAdd = inboxMessages['inboxMessages'][msgNum]['fromAddress'] # Address it was From, now the To address
|
2015-01-19 18:53:07 +01:00
|
|
|
subject = "Re: " + subject
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
elif forwardORreply == 'forward':
|
2015-01-19 18:53:07 +01:00
|
|
|
subject = "Fwd: " + subject
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
while True:
|
|
|
|
toAdd = userInput("What is the To Address?")
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if toAdd == "c":
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
elif validAddress(toAdd) is False:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Address. "c" to cancel. Please try again.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
break
|
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Selection. Reply or Forward only')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
subject = subject.encode('base64')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
newMessage = userInput("Enter your Message.")
|
|
|
|
|
|
|
|
uInput = userInput('Would you like to add an attachment, (Y)es or (N)o?').lower()
|
|
|
|
if uInput == "y":
|
|
|
|
newMessage = newMessage + '\n\n' + attachment()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
newMessage = newMessage + '\n\n------------------------------------------------------\n'
|
|
|
|
newMessage = newMessage + message
|
|
|
|
newMessage = newMessage.encode('base64')
|
|
|
|
|
|
|
|
sendMsg(toAdd, fromAdd, subject, newMessage)
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
def delMsg(msgNum):
|
|
|
|
"""Deletes a specified message from the inbox"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
|
|
|
try:
|
|
|
|
inboxMessages = json.loads(api.getAllInboxMessages())
|
2018-05-15 17:15:44 +02:00
|
|
|
# gets the message ID via the message index number
|
|
|
|
msgId = inboxMessages['inboxMessages'][int(msgNum)]['msgid']
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
msgAck = api.trashMessage(msgId)
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
return msgAck
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
def delSentMsg(msgNum):
|
|
|
|
"""Deletes a specified message from the outbox"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
|
|
|
try:
|
|
|
|
outboxMessages = json.loads(api.getAllSentMessages())
|
2018-05-15 17:15:44 +02:00
|
|
|
# gets the message ID via the message index number
|
|
|
|
msgId = outboxMessages['sentMessages'][int(msgNum)]['msgid']
|
2015-01-19 18:53:07 +01:00
|
|
|
msgAck = api.trashSentMessage(msgId)
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
return msgAck
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def getLabelForAddress(address):
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Get label for an address"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
if address in knownAddresses:
|
|
|
|
return knownAddresses[address]
|
|
|
|
else:
|
|
|
|
buildKnownAddresses()
|
|
|
|
if address in knownAddresses:
|
|
|
|
return knownAddresses[address]
|
|
|
|
|
|
|
|
return address
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def buildKnownAddresses():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Build known addresses"""
|
|
|
|
|
|
|
|
global usrPrompt
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
# add from address book
|
|
|
|
try:
|
|
|
|
response = api.listAddressBookEntries()
|
|
|
|
# if api is too old then fail
|
2018-05-15 17:15:44 +02:00
|
|
|
if "API Error 0020" in response:
|
|
|
|
return
|
2015-01-19 18:53:07 +01:00
|
|
|
addressBook = json.loads(response)
|
|
|
|
for entry in addressBook['addresses']:
|
|
|
|
if entry['address'] not in knownAddresses:
|
|
|
|
knownAddresses[entry['address']] = "%s (%s)" % (entry['label'].decode('base64'), entry['address'])
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
|
|
|
# add from my addresses
|
|
|
|
try:
|
|
|
|
response = api.listAddresses2()
|
|
|
|
# if api is too old just return then fail
|
2018-05-15 17:15:44 +02:00
|
|
|
if "API Error 0020" in response:
|
|
|
|
return
|
2015-01-19 18:53:07 +01:00
|
|
|
addresses = json.loads(response)
|
|
|
|
for entry in addresses['addresses']:
|
|
|
|
if entry['address'] not in knownAddresses:
|
|
|
|
knownAddresses[entry['address']] = "%s (%s)" % (entry['label'].decode('base64'), entry['address'])
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def listAddressBookEntries():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""List addressbook entries"""
|
|
|
|
|
|
|
|
global usrPrompt
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
try:
|
|
|
|
response = api.listAddressBookEntries()
|
|
|
|
if "API Error" in response:
|
|
|
|
return getAPIErrorCode(response)
|
|
|
|
addressBook = json.loads(response)
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' --------------------------------------------------------------')
|
|
|
|
print(' | Label | Address |')
|
|
|
|
print(' |--------------------|---------------------------------------|')
|
2015-01-19 18:53:07 +01:00
|
|
|
for entry in addressBook['addresses']:
|
|
|
|
label = entry['label'].decode('base64')
|
|
|
|
address = entry['address']
|
2018-05-15 17:15:44 +02:00
|
|
|
if len(label) > 19:
|
|
|
|
label = label[:16] + '...'
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' | ' + label.ljust(19) + '| ' + address.ljust(37) + ' |')
|
|
|
|
print(' --------------------------------------------------------------')
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def addAddressToAddressBook(address, label):
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Add an address to an addressbook"""
|
|
|
|
|
|
|
|
global usrPrompt
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
try:
|
|
|
|
response = api.addAddressBookEntry(address, label.encode('base64'))
|
|
|
|
if "API Error" in response:
|
|
|
|
return getAPIErrorCode(response)
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def deleteAddressFromAddressBook(address):
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Delete an address from an addressbook"""
|
|
|
|
|
|
|
|
global usrPrompt
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
try:
|
|
|
|
response = api.deleteAddressBookEntry(address)
|
|
|
|
if "API Error" in response:
|
|
|
|
return getAPIErrorCode(response)
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def getAPIErrorCode(response):
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Get API error code"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
if "API Error" in response:
|
|
|
|
# if we got an API error return the number by getting the number
|
|
|
|
# after the second space and removing the trailing colon
|
|
|
|
return int(response.split()[2][:-1])
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def markMessageRead(messageID):
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Mark a message as read"""
|
|
|
|
|
|
|
|
global usrPrompt
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
try:
|
|
|
|
response = api.getInboxMessageByID(messageID, True)
|
|
|
|
if "API Error" in response:
|
|
|
|
return getAPIErrorCode(response)
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def markMessageUnread(messageID):
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Mark a mesasge as unread"""
|
|
|
|
|
|
|
|
global usrPrompt
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
try:
|
|
|
|
response = api.getInboxMessageByID(messageID, False)
|
|
|
|
if "API Error" in response:
|
|
|
|
return getAPIErrorCode(response)
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def markAllMessagesRead():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Mark all messages as read"""
|
|
|
|
|
|
|
|
global usrPrompt
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
try:
|
|
|
|
inboxMessages = json.loads(api.getAllInboxMessages())['inboxMessages']
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
for message in inboxMessages:
|
|
|
|
if not message['read']:
|
|
|
|
markMessageRead(message['msgid'])
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def markAllMessagesUnread():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Mark all messages as unread"""
|
|
|
|
|
|
|
|
global usrPrompt
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
try:
|
|
|
|
inboxMessages = json.loads(api.getAllInboxMessages())['inboxMessages']
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
|
|
|
for message in inboxMessages:
|
|
|
|
if message['read']:
|
|
|
|
markMessageUnread(message['msgid'])
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-06-20 09:54:15 +02:00
|
|
|
def clientStatus():
|
2021-03-04 15:15:41 +01:00
|
|
|
"""Print (the client status"""
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
global usrPrompt
|
|
|
|
|
2015-06-20 09:54:15 +02:00
|
|
|
try:
|
2018-05-15 17:15:44 +02:00
|
|
|
client_status = json.loads(api.clientStatus())
|
2021-08-11 17:47:06 +02:00
|
|
|
except: # noqa:E722
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Connection Error\n')
|
2015-06-20 09:54:15 +02:00
|
|
|
usrPrompt = 0
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print("\nnetworkStatus: " + client_status['networkStatus'] + "\n")
|
|
|
|
print("\nnetworkConnections: " + str(client_status['networkConnections']) + "\n")
|
|
|
|
print("\nnumberOfPubkeysProcessed: " + str(client_status['numberOfPubkeysProcessed']) + "\n")
|
|
|
|
print("\nnumberOfMessagesProcessed: " + str(client_status['numberOfMessagesProcessed']) + "\n")
|
|
|
|
print("\nnumberOfBroadcastsProcessed: " + str(client_status['numberOfBroadcastsProcessed']) + "\n")
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-06-20 09:54:15 +02:00
|
|
|
|
2017-08-22 13:23:03 +02:00
|
|
|
def shutdown():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Shutdown the API"""
|
|
|
|
|
2017-08-22 13:23:03 +02:00
|
|
|
try:
|
|
|
|
api.shutdown()
|
|
|
|
except socket.error:
|
|
|
|
pass
|
2021-08-10 16:19:29 +02:00
|
|
|
print("\nShutdown command relayed\n")
|
2017-08-22 13:23:03 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
def UI(usrInput):
|
|
|
|
"""Main user menu"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global usrPrompt
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if usrInput in ("help", "h", "?"):
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
|
|
|
print(' -------------------------------------------------------------------------')
|
|
|
|
print(' | https://github.com/Dokument/PyBitmessage-Daemon |')
|
|
|
|
print(' |-----------------------------------------------------------------------|')
|
|
|
|
print(' | Command | Description |')
|
|
|
|
print(' |------------------------|----------------------------------------------|')
|
|
|
|
print(' | help | This help file. |')
|
|
|
|
print(' | apiTest | Tests the API |')
|
|
|
|
print(' | addInfo | Returns address information (If valid) |')
|
|
|
|
print(' | bmSettings | BitMessage settings |')
|
|
|
|
print(' | exit | Use anytime to return to main menu |')
|
|
|
|
print(' | quit | Quits the program |')
|
|
|
|
print(' |------------------------|----------------------------------------------|')
|
|
|
|
print(' | listAddresses | Lists all of the users addresses |')
|
|
|
|
print(' | generateAddress | Generates a new address |')
|
|
|
|
print(' | getAddress | Get determinist address from passphrase |')
|
|
|
|
print(' |------------------------|----------------------------------------------|')
|
|
|
|
print(' | listAddressBookEntries | Lists entries from the Address Book |')
|
|
|
|
print(' | addAddressBookEntry | Add address to the Address Book |')
|
|
|
|
print(' | deleteAddressBookEntry | Deletes address from the Address Book |')
|
|
|
|
print(' |------------------------|----------------------------------------------|')
|
|
|
|
print(' | subscribe | Subscribes to an address |')
|
|
|
|
print(' | unsubscribe | Unsubscribes from an address |')
|
|
|
|
print(' |------------------------|----------------------------------------------|')
|
|
|
|
print(' | create | Creates a channel |')
|
|
|
|
print(' | join | Joins a channel |')
|
|
|
|
print(' | leave | Leaves a channel |')
|
|
|
|
print(' |------------------------|----------------------------------------------|')
|
|
|
|
print(' | inbox | Lists the message information for the inbox |')
|
|
|
|
print(' | outbox | Lists the message information for the outbox |')
|
|
|
|
print(' | send | Send a new message or broadcast |')
|
|
|
|
print(' | unread | Lists all unread inbox messages |')
|
|
|
|
print(' | read | Reads a message from the inbox or outbox |')
|
|
|
|
print(' | save | Saves message to text file |')
|
|
|
|
print(' | delete | Deletes a message or all messages |')
|
|
|
|
print(' -------------------------------------------------------------------------')
|
|
|
|
print(' ')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
elif usrInput == "apitest": # tests the API Connection.
|
|
|
|
if apiTest():
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n API connection test has: PASSED\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n API connection test has: FAILED\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
|
|
|
|
elif usrInput == "addinfo":
|
|
|
|
tmp_address = userInput('\nEnter the Bitmessage Address.')
|
2018-02-18 20:14:21 +01:00
|
|
|
address_information = json.loads(api.decodeAddress(tmp_address))
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n------------------------------')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2018-02-18 20:14:21 +01:00
|
|
|
if 'success' in str(address_information['status']).lower():
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Valid Address')
|
|
|
|
print(' Address Version: %s' % str(address_information['addressVersion']))
|
|
|
|
print(' Stream Number: %s' % str(address_information['streamNumber']))
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Invalid Address !')
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('------------------------------\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
elif usrInput == "bmsettings": # tests the API Connection.
|
2015-01-19 18:53:07 +01:00
|
|
|
bmSettings()
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
elif usrInput == "quit": # Quits the application
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Bye\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
elif usrInput == "listaddresses": # Lists all of the identities in the addressbook
|
2015-01-19 18:53:07 +01:00
|
|
|
listAdd()
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
elif usrInput == "generateaddress": # Generates a new address
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput('\nWould you like to create a (D)eterministic or (R)andom address?').lower()
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput in ("d", "deterministic"): # Creates a deterministic address
|
2015-01-19 18:53:07 +01:00
|
|
|
deterministic = True
|
|
|
|
|
|
|
|
lbl = ''
|
2018-05-15 17:15:44 +02:00
|
|
|
passphrase = userInput('Enter the Passphrase.') # .encode('base64')
|
2015-01-19 18:53:07 +01:00
|
|
|
numOfAdd = int(userInput('How many addresses would you like to generate?'))
|
|
|
|
addVNum = 3
|
|
|
|
streamNum = 1
|
|
|
|
isRipe = userInput('Shorten the address, (Y)es or (N)o?').lower()
|
|
|
|
|
|
|
|
if isRipe == "y":
|
|
|
|
ripe = True
|
2021-08-10 16:19:29 +02:00
|
|
|
print(genAdd(lbl, deterministic, passphrase, numOfAdd, addVNum, streamNum, ripe))
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
elif isRipe == "n":
|
|
|
|
ripe = False
|
2021-08-10 16:19:29 +02:00
|
|
|
print(genAdd(lbl, deterministic, passphrase, numOfAdd, addVNum, streamNum, ripe))
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
elif isRipe == "exit":
|
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid input\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
elif uInput == "r" or uInput == "random": # Creates a random address with user-defined label
|
2015-01-19 18:53:07 +01:00
|
|
|
deterministic = False
|
|
|
|
null = ''
|
|
|
|
lbl = userInput('Enter the label for the new address.')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print(genAdd(lbl, deterministic, null, null, null, null, null))
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid input\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
elif usrInput == "getaddress": # Gets the address for/from a passphrase
|
2015-01-19 18:53:07 +01:00
|
|
|
phrase = userInput("Enter the address passphrase.")
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Working...\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
address = getAddress(phrase, 4, 1) # ,vNumber,sNumber)
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Address: ' + address + '\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
elif usrInput == "subscribe": # Subsribe to an address
|
2015-01-19 18:53:07 +01:00
|
|
|
subscribe()
|
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
elif usrInput == "unsubscribe": # Unsubscribe from an address
|
2015-01-19 18:53:07 +01:00
|
|
|
unsubscribe()
|
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
elif usrInput == "listsubscriptions": # Unsubscribe from an address
|
2015-01-19 18:53:07 +01:00
|
|
|
listSubscriptions()
|
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
|
|
|
elif usrInput == "create":
|
|
|
|
createChan()
|
2017-12-26 14:17:37 +01:00
|
|
|
usrPrompt = 1
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
|
|
|
|
elif usrInput == "join":
|
|
|
|
joinChan()
|
2017-12-26 14:17:37 +01:00
|
|
|
usrPrompt = 1
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
elif usrInput == "leave":
|
|
|
|
leaveChan()
|
2017-12-26 14:17:37 +01:00
|
|
|
usrPrompt = 1
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
elif usrInput == "inbox":
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Loading...\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
inbox()
|
|
|
|
main()
|
|
|
|
|
|
|
|
elif usrInput == "unread":
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Loading...\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
inbox(True)
|
|
|
|
main()
|
|
|
|
|
|
|
|
elif usrInput == "outbox":
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Loading...\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
outbox()
|
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
elif usrInput == 'send': # Sends a message or broadcast
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput('Would you like to send a (M)essage or (B)roadcast?').lower()
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput in ('m', 'message'):
|
2015-01-19 18:53:07 +01:00
|
|
|
null = ''
|
2018-05-15 17:15:44 +02:00
|
|
|
sendMsg(null, null, null, null)
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
2021-08-11 18:50:56 +02:00
|
|
|
elif uInput in ('b', 'broadcast'):
|
2015-01-19 18:53:07 +01:00
|
|
|
null = ''
|
2018-05-15 17:15:44 +02:00
|
|
|
sendBrd(null, null, null)
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
elif usrInput == "read": # Opens a message from the inbox for viewing.
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
uInput = userInput("Would you like to read a message from the (I)nbox or (O)utbox?").lower()
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput not in ('i', 'inbox', 'o', 'outbox'):
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Input.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
|
|
|
msgNum = int(userInput("What is the number of the message you wish to open?"))
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput in ('i', 'inbox'):
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Loading...\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
messageID = readMsg(msgNum)
|
|
|
|
|
|
|
|
uInput = userInput("\nWould you like to keep this message unread, (Y)es or (N)o?").lower()
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput not in ('y', 'yes'):
|
2015-01-19 18:53:07 +01:00
|
|
|
markMessageRead(messageID)
|
|
|
|
usrPrompt = 1
|
|
|
|
|
|
|
|
uInput = userInput("\nWould you like to (D)elete, (F)orward, (R)eply to, or (Exit) this message?").lower()
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput in ('r', 'reply'):
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Loading...\n')
|
|
|
|
print(' ')
|
2018-05-15 17:15:44 +02:00
|
|
|
replyMsg(msgNum, 'reply')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
elif uInput in ('f', 'forward'):
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Loading...\n')
|
|
|
|
print(' ')
|
2018-05-15 17:15:44 +02:00
|
|
|
replyMsg(msgNum, 'forward')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
elif uInput in ("d", 'delete'):
|
2018-05-15 17:15:44 +02:00
|
|
|
uInput = userInput("Are you sure, (Y)es or (N)o?").lower() # Prevent accidental deletion
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
if uInput == "y":
|
|
|
|
delMsg(msgNum)
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Message Deleted.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
else:
|
|
|
|
usrPrompt = 1
|
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid entry\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
elif uInput in ('o', 'outbox'):
|
2015-01-19 18:53:07 +01:00
|
|
|
readSentMsg(msgNum)
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
# Gives the user the option to delete the message
|
|
|
|
uInput = userInput("Would you like to (D)elete, or (Exit) this message?").lower()
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput in ("d", 'delete'):
|
2018-05-15 17:15:44 +02:00
|
|
|
uInput = userInput('Are you sure, (Y)es or (N)o?').lower() # Prevent accidental deletion
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
if uInput == "y":
|
|
|
|
delSentMsg(msgNum)
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Message Deleted.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
else:
|
|
|
|
usrPrompt = 1
|
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Entry\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
elif usrInput == "save":
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Would you like to save a message from the (I)nbox or (O)utbox?").lower()
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput not in ('i', 'inbox', 'o', 'outbox'):
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Input.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput in ('i', 'inbox'):
|
2015-01-19 18:53:07 +01:00
|
|
|
inboxMessages = json.loads(api.getAllInboxMessages())
|
|
|
|
numMessages = len(inboxMessages['inboxMessages'])
|
|
|
|
|
|
|
|
while True:
|
|
|
|
msgNum = int(userInput("What is the number of the message you wish to save?"))
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if msgNum >= numMessages:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Message Number.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
subject = inboxMessages['inboxMessages'][msgNum]['subject'].decode('base64')
|
|
|
|
# Don't decode since it is done in the saveFile function
|
|
|
|
message = inboxMessages['inboxMessages'][msgNum]['message']
|
|
|
|
|
|
|
|
elif uInput == 'o' or uInput == 'outbox':
|
2015-01-19 18:53:07 +01:00
|
|
|
outboxMessages = json.loads(api.getAllSentMessages())
|
|
|
|
numMessages = len(outboxMessages['sentMessages'])
|
|
|
|
|
|
|
|
while True:
|
|
|
|
msgNum = int(userInput("What is the number of the message you wish to save?"))
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if msgNum >= numMessages:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Message Number.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
subject = outboxMessages['sentMessages'][msgNum]['subject'].decode('base64')
|
|
|
|
# Don't decode since it is done in the saveFile function
|
|
|
|
message = outboxMessages['sentMessages'][msgNum]['message']
|
|
|
|
|
|
|
|
subject = subject + '.txt'
|
|
|
|
saveFile(subject, message)
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
elif usrInput == "delete": # will delete a message from the system, not reflected on the UI.
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
uInput = userInput("Would you like to delete a message from the (I)nbox or (O)utbox?").lower()
|
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if uInput in ('i', 'inbox'):
|
2015-01-19 18:53:07 +01:00
|
|
|
inboxMessages = json.loads(api.getAllInboxMessages())
|
|
|
|
numMessages = len(inboxMessages['inboxMessages'])
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
while True:
|
|
|
|
msgNum = userInput(
|
|
|
|
'Enter the number of the message you wish to delete or (A)ll to empty the inbox.').lower()
|
|
|
|
|
|
|
|
if msgNum == 'a' or msgNum == 'all':
|
2015-01-19 18:53:07 +01:00
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
elif int(msgNum) >= numMessages:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Message Number.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
uInput = userInput("Are you sure, (Y)es or (N)o?").lower() # Prevent accidental deletion
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
if uInput == "y":
|
2021-08-11 18:50:56 +02:00
|
|
|
if msgNum in ('a', 'all'):
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2018-05-15 17:15:44 +02:00
|
|
|
for msgNum in range(0, numMessages): # processes all of the messages in the inbox
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Deleting message ', msgNum + 1, ' of ', numMessages)
|
2015-01-19 18:53:07 +01:00
|
|
|
delMsg(0)
|
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Inbox is empty.')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
else:
|
|
|
|
delMsg(int(msgNum))
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Notice: Message numbers may have changed.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
else:
|
|
|
|
usrPrompt = 1
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
elif uInput in ('o', 'outbox'):
|
2015-01-19 18:53:07 +01:00
|
|
|
outboxMessages = json.loads(api.getAllSentMessages())
|
|
|
|
numMessages = len(outboxMessages['sentMessages'])
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
while True:
|
2018-05-15 17:15:44 +02:00
|
|
|
msgNum = userInput(
|
|
|
|
'Enter the number of the message you wish to delete or (A)ll to empty the inbox.').lower()
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2021-08-11 18:50:56 +02:00
|
|
|
if msgNum in ('a', 'all'):
|
2015-01-19 18:53:07 +01:00
|
|
|
break
|
2018-05-15 17:15:44 +02:00
|
|
|
elif int(msgNum) >= numMessages:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Message Number.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
uInput = userInput("Are you sure, (Y)es or (N)o?").lower() # Prevent accidental deletion
|
2015-01-19 18:53:07 +01:00
|
|
|
|
|
|
|
if uInput == "y":
|
2021-08-11 18:50:56 +02:00
|
|
|
if msgNum in ('a', 'all'):
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' ')
|
2018-05-15 17:15:44 +02:00
|
|
|
for msgNum in range(0, numMessages): # processes all of the messages in the outbox
|
2021-08-10 16:19:29 +02:00
|
|
|
print(' Deleting message ', msgNum + 1, ' of ', numMessages)
|
2015-01-19 18:53:07 +01:00
|
|
|
delSentMsg(0)
|
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Outbox is empty.')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
else:
|
|
|
|
delSentMsg(int(msgNum))
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Notice: Message numbers may have changed.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
else:
|
|
|
|
usrPrompt = 1
|
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Invalid Entry.\n')
|
2017-12-26 14:17:37 +01:00
|
|
|
usrPrompt = 1
|
2015-01-19 18:53:07 +01:00
|
|
|
main()
|
|
|
|
|
|
|
|
elif usrInput == "exit":
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n You are already at the main menu. Use "quit" to quit.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
|
|
|
elif usrInput == "listaddressbookentries":
|
|
|
|
res = listAddressBookEntries()
|
2018-05-15 17:15:44 +02:00
|
|
|
if res == 20:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Error: API function not supported.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
|
|
|
elif usrInput == "addaddressbookentry":
|
|
|
|
address = userInput('Enter address')
|
|
|
|
label = userInput('Enter label')
|
|
|
|
res = addAddressToAddressBook(address, label)
|
2018-05-15 17:15:44 +02:00
|
|
|
if res == 16:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Error: Address already exists in Address Book.\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
if res == 20:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Error: API function not supported.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
|
|
|
elif usrInput == "deleteaddressbookentry":
|
|
|
|
address = userInput('Enter address')
|
|
|
|
res = deleteAddressFromAddressBook(address)
|
2018-05-15 17:15:44 +02:00
|
|
|
if res == 20:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n Error: API function not supported.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
|
|
|
elif usrInput == "markallmessagesread":
|
|
|
|
markAllMessagesRead()
|
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
|
|
|
elif usrInput == "markallmessagesunread":
|
|
|
|
markAllMessagesUnread()
|
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
2015-06-20 09:54:15 +02:00
|
|
|
|
|
|
|
elif usrInput == "status":
|
|
|
|
clientStatus()
|
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
2017-08-22 13:23:03 +02:00
|
|
|
elif usrInput == "shutdown":
|
|
|
|
shutdown()
|
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
else:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n "', usrInput, '" is not a command.\n')
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 1
|
|
|
|
main()
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
def main():
|
2018-05-15 17:15:44 +02:00
|
|
|
"""Entrypoint for the CLI app"""
|
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
global api
|
|
|
|
global usrPrompt
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
if usrPrompt == 0:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n ------------------------------')
|
|
|
|
print(' | Bitmessage Daemon by .dok |')
|
|
|
|
print(' | Version 0.3.1 for BM 0.6.2 |')
|
|
|
|
print(' ------------------------------')
|
2018-05-15 17:15:44 +02:00
|
|
|
api = xmlrpclib.ServerProxy(apiData()) # Connect to BitMessage using these api credentials
|
2015-01-19 18:53:07 +01:00
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
if apiTest() is False:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\n ****************************************************************')
|
|
|
|
print(' WARNING: You are not connected to the Bitmessage client.')
|
|
|
|
print(' Either Bitmessage is not running or your settings are incorrect.')
|
|
|
|
print(' Use the command "apiTest" or "bmSettings" to resolve this issue.')
|
|
|
|
print(' ****************************************************************\n')
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2021-08-10 16:19:29 +02:00
|
|
|
print('Type (H)elp for a list of commands.') # Startup message)
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 2
|
2018-05-15 17:15:44 +02:00
|
|
|
|
|
|
|
elif usrPrompt == 1:
|
2021-08-10 16:19:29 +02:00
|
|
|
print('\nType (H)elp for a list of commands.') # Startup message)
|
2015-01-19 18:53:07 +01:00
|
|
|
usrPrompt = 2
|
|
|
|
|
|
|
|
try:
|
|
|
|
UI((raw_input('>').lower()).replace(" ", ""))
|
|
|
|
except EOFError:
|
|
|
|
UI("quit")
|
|
|
|
|
2018-05-15 17:15:44 +02:00
|
|
|
|
2015-01-19 18:53:07 +01:00
|
|
|
if __name__ == "__main__":
|
2018-05-15 17:15:44 +02:00
|
|
|
main()
|