2019-09-23 11:42:40 +02:00
|
|
|
"""
|
2019-12-27 15:12:57 +01:00
|
|
|
Bitmessage commandline interface
|
2019-09-23 11:42:40 +02:00
|
|
|
"""
|
2014-04-18 07:48:42 +02:00
|
|
|
# Copyright (c) 2014 Luke Montalvo <lukemontalvo@gmail.com>
|
2014-04-29 07:10:33 +02:00
|
|
|
# This file adds a alternative commandline interface, feel free to critique and fork
|
2019-09-23 11:42:40 +02:00
|
|
|
#
|
2014-05-01 02:29:04 +02:00
|
|
|
# This has only been tested on Arch Linux and Linux Mint
|
2014-04-19 20:45:37 +02:00
|
|
|
# Dependencies:
|
|
|
|
# * from python2-pip
|
|
|
|
# * python2-pythondialog
|
|
|
|
# * dialog
|
2014-04-18 07:48:42 +02:00
|
|
|
|
2019-09-23 11:42:40 +02:00
|
|
|
import ConfigParser
|
|
|
|
import curses
|
2014-04-18 07:48:42 +02:00
|
|
|
import os
|
|
|
|
import sys
|
2014-04-19 20:45:37 +02:00
|
|
|
import time
|
2019-09-23 11:42:40 +02:00
|
|
|
from textwrap import fill
|
2014-04-19 20:45:37 +02:00
|
|
|
from threading import Timer
|
|
|
|
|
|
|
|
from dialog import Dialog
|
2020-09-15 13:18:24 +02:00
|
|
|
import helper_sent
|
2017-02-08 13:41:56 +01:00
|
|
|
import l10n
|
2019-09-23 11:42:40 +02:00
|
|
|
import network.stats
|
2017-02-08 13:41:56 +01:00
|
|
|
import queues
|
|
|
|
import shared
|
|
|
|
import shutdown
|
2019-11-05 17:54:04 +01:00
|
|
|
import state
|
2018-11-01 15:28:42 +01:00
|
|
|
|
2019-12-27 15:12:57 +01:00
|
|
|
from addresses import addBMIfNotPresent, decodeAddress
|
|
|
|
from bmconfigparser import BMConfigParser
|
|
|
|
from helper_ackPayload import genAckPayload
|
|
|
|
from helper_sql import sqlExecute, sqlQuery
|
|
|
|
from inventory import Inventory
|
2020-09-14 20:35:55 +02:00
|
|
|
|
2019-12-27 15:12:57 +01:00
|
|
|
# pylint: disable=global-statement
|
|
|
|
|
2014-04-18 07:48:42 +02:00
|
|
|
|
2019-12-27 15:12:57 +01:00
|
|
|
quit_ = False
|
2014-04-18 07:48:42 +02:00
|
|
|
menutab = 1
|
|
|
|
menu = ["Inbox", "Send", "Sent", "Your Identities", "Subscriptions", "Address Book", "Blacklist", "Network Status"]
|
2014-04-19 20:57:08 +02:00
|
|
|
naptime = 100
|
2014-04-18 07:48:42 +02:00
|
|
|
log = ""
|
2014-04-19 20:45:37 +02:00
|
|
|
logpad = None
|
|
|
|
inventorydata = 0
|
|
|
|
startuptime = time.time()
|
2014-04-29 07:10:33 +02:00
|
|
|
|
|
|
|
inbox = []
|
|
|
|
inboxcur = 0
|
2014-04-30 04:45:41 +02:00
|
|
|
sentbox = []
|
2014-04-29 07:10:33 +02:00
|
|
|
sentcur = 0
|
2014-04-18 07:48:42 +02:00
|
|
|
addresses = []
|
|
|
|
addrcur = 0
|
2014-04-19 20:45:37 +02:00
|
|
|
addrcopy = 0
|
2014-04-29 07:10:33 +02:00
|
|
|
subscriptions = []
|
|
|
|
subcur = 0
|
|
|
|
addrbook = []
|
|
|
|
abookcur = 0
|
|
|
|
blacklist = []
|
|
|
|
blackcur = 0
|
2014-04-30 04:45:41 +02:00
|
|
|
bwtype = "black"
|
2014-04-29 07:10:33 +02:00
|
|
|
|
|
|
|
BROADCAST_STR = "[Broadcast subscribers]"
|
2014-04-18 07:48:42 +02:00
|
|
|
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2019-12-27 15:12:57 +01:00
|
|
|
class printLog(object):
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Printing logs"""
|
2019-12-27 15:12:57 +01:00
|
|
|
# pylint: disable=no-self-use
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-18 07:48:42 +02:00
|
|
|
def write(self, output):
|
2019-12-27 15:12:57 +01:00
|
|
|
"""Write logs"""
|
2014-04-18 07:48:42 +02:00
|
|
|
global log
|
|
|
|
log += output
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-19 20:45:37 +02:00
|
|
|
def flush(self):
|
2019-12-27 15:12:57 +01:00
|
|
|
"""Flush logs"""
|
2014-04-19 20:45:37 +02:00
|
|
|
pass
|
2019-09-23 11:42:40 +02:00
|
|
|
|
|
|
|
|
2019-12-27 15:12:57 +01:00
|
|
|
class errLog(object):
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Error logs"""
|
2019-12-27 15:12:57 +01:00
|
|
|
# pylint: disable=no-self-use
|
|
|
|
|
2014-04-19 20:45:37 +02:00
|
|
|
def write(self, output):
|
2019-12-27 15:12:57 +01:00
|
|
|
"""Write error logs"""
|
2014-04-19 20:45:37 +02:00
|
|
|
global log
|
2019-09-23 11:42:40 +02:00
|
|
|
log += "!" + output
|
|
|
|
|
2014-04-19 20:45:37 +02:00
|
|
|
def flush(self):
|
2019-12-27 15:12:57 +01:00
|
|
|
"""Flush error logs"""
|
2014-04-19 20:45:37 +02:00
|
|
|
pass
|
2019-09-23 11:42:40 +02:00
|
|
|
|
|
|
|
|
2014-04-18 07:48:42 +02:00
|
|
|
printlog = printLog()
|
2014-04-19 20:45:37 +02:00
|
|
|
errlog = errLog()
|
|
|
|
|
2014-04-18 07:48:42 +02:00
|
|
|
|
|
|
|
def cpair(a):
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Color pairs"""
|
2014-04-18 07:48:42 +02:00
|
|
|
r = curses.color_pair(a)
|
2019-09-23 11:42:40 +02:00
|
|
|
if r not in range(1, curses.COLOR_PAIRS - 1):
|
2014-04-18 07:48:42 +02:00
|
|
|
r = curses.color_pair(0)
|
|
|
|
return r
|
2019-09-23 11:42:40 +02:00
|
|
|
|
|
|
|
|
2014-04-29 07:10:33 +02:00
|
|
|
def ascii(s):
|
2019-09-23 11:42:40 +02:00
|
|
|
"""ASCII values"""
|
2014-04-29 07:10:33 +02:00
|
|
|
r = ""
|
|
|
|
for c in s:
|
|
|
|
if ord(c) in range(128):
|
|
|
|
r += c
|
|
|
|
return r
|
2014-04-18 07:48:42 +02:00
|
|
|
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-18 07:48:42 +02:00
|
|
|
def drawmenu(stdscr):
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Creating menu's"""
|
2014-04-18 07:48:42 +02:00
|
|
|
menustr = " "
|
2019-09-23 11:42:40 +02:00
|
|
|
for i, _ in enumerate(menu):
|
|
|
|
if menutab == i + 1:
|
2014-04-18 07:48:42 +02:00
|
|
|
menustr = menustr[:-1]
|
|
|
|
menustr += "["
|
2019-09-23 11:42:40 +02:00
|
|
|
menustr += str(i + 1) + menu[i]
|
|
|
|
if menutab == i + 1:
|
2014-04-18 07:48:42 +02:00
|
|
|
menustr += "] "
|
2019-09-23 11:42:40 +02:00
|
|
|
elif i != len(menu) - 1:
|
2014-04-18 07:48:42 +02:00
|
|
|
menustr += " "
|
|
|
|
stdscr.addstr(2, 5, menustr, curses.A_UNDERLINE)
|
|
|
|
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2016-06-30 12:28:17 +02:00
|
|
|
def set_background_title(d, title):
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Setting background title"""
|
2016-06-30 12:28:17 +02:00
|
|
|
try:
|
|
|
|
d.set_background_title(title)
|
|
|
|
except:
|
|
|
|
d.add_persistent_args(("--backtitle", title))
|
|
|
|
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2016-06-30 12:28:17 +02:00
|
|
|
def scrollbox(d, text, height=None, width=None):
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Setting scroll box"""
|
2016-06-30 12:28:17 +02:00
|
|
|
try:
|
2019-09-23 11:42:40 +02:00
|
|
|
d.scrollbox(text, height, width, exit_label="Continue")
|
2016-06-30 12:28:17 +02:00
|
|
|
except:
|
2019-09-23 11:42:40 +02:00
|
|
|
d.msgbox(text, height or 0, width or 0, ok_label="Continue")
|
|
|
|
|
2016-06-30 12:28:17 +02:00
|
|
|
|
2014-04-19 20:45:37 +02:00
|
|
|
def resetlookups():
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Reset the Inventory Lookups"""
|
2019-12-27 15:12:57 +01:00
|
|
|
global inventorydata
|
2017-01-10 21:15:35 +01:00
|
|
|
inventorydata = Inventory().numberOfInventoryLookupsPerformed
|
|
|
|
Inventory().numberOfInventoryLookupsPerformed = 0
|
2014-04-29 07:10:33 +02:00
|
|
|
Timer(1, resetlookups, ()).start()
|
2019-09-23 11:42:40 +02:00
|
|
|
|
|
|
|
|
2019-12-27 15:12:57 +01:00
|
|
|
def drawtab(stdscr):
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Method for drawing different tabs"""
|
2019-12-27 15:12:57 +01:00
|
|
|
# pylint: disable=too-many-branches, too-many-statements
|
2019-09-23 11:42:40 +02:00
|
|
|
if menutab in range(1, len(menu) + 1):
|
|
|
|
if menutab == 1: # Inbox
|
2014-04-29 07:10:33 +02:00
|
|
|
stdscr.addstr(3, 5, "To", curses.A_BOLD)
|
2014-04-30 04:45:41 +02:00
|
|
|
stdscr.addstr(3, 40, "From", curses.A_BOLD)
|
|
|
|
stdscr.addstr(3, 80, "Subject", curses.A_BOLD)
|
|
|
|
stdscr.addstr(3, 120, "Time Received", curses.A_BOLD)
|
|
|
|
stdscr.hline(4, 5, '-', 121)
|
2019-09-23 11:42:40 +02:00
|
|
|
for i, item in enumerate(inbox[max(min(len(inbox) - curses.LINES + 6, inboxcur - 5), 0):]):
|
|
|
|
if 6 + i < curses.LINES:
|
2014-04-29 07:10:33 +02:00
|
|
|
a = 0
|
2019-09-23 11:42:40 +02:00
|
|
|
if i == inboxcur - max(min(len(inbox) - curses.LINES + 6, inboxcur - 5), 0):
|
|
|
|
# Highlight current address
|
2014-04-29 07:10:33 +02:00
|
|
|
a = a | curses.A_REVERSE
|
2019-09-23 11:42:40 +02:00
|
|
|
if item[7] is False: # If not read, highlight
|
2014-04-29 07:10:33 +02:00
|
|
|
a = a | curses.A_BOLD
|
2019-09-23 11:42:40 +02:00
|
|
|
stdscr.addstr(5 + i, 5, item[1][:34], a)
|
|
|
|
stdscr.addstr(5 + i, 40, item[3][:39], a)
|
|
|
|
stdscr.addstr(5 + i, 80, item[5][:39], a)
|
|
|
|
stdscr.addstr(5 + i, 120, item[6][:39], a)
|
|
|
|
elif menutab == 3: # Sent
|
2014-04-30 04:45:41 +02:00
|
|
|
stdscr.addstr(3, 5, "To", curses.A_BOLD)
|
|
|
|
stdscr.addstr(3, 40, "From", curses.A_BOLD)
|
|
|
|
stdscr.addstr(3, 80, "Subject", curses.A_BOLD)
|
|
|
|
stdscr.addstr(3, 120, "Status", curses.A_BOLD)
|
|
|
|
stdscr.hline(4, 5, '-', 121)
|
2019-09-23 11:42:40 +02:00
|
|
|
for i, item in enumerate(sentbox[max(min(len(sentbox) - curses.LINES + 6, sentcur - 5), 0):]):
|
|
|
|
if 6 + i < curses.LINES:
|
2014-04-30 04:45:41 +02:00
|
|
|
a = 0
|
2019-09-23 11:42:40 +02:00
|
|
|
if i == sentcur - max(min(len(sentbox) - curses.LINES + 6, sentcur - 5), 0):
|
|
|
|
# Highlight current address
|
2014-04-30 04:45:41 +02:00
|
|
|
a = a | curses.A_REVERSE
|
2019-09-23 11:42:40 +02:00
|
|
|
stdscr.addstr(5 + i, 5, item[0][:34], a)
|
|
|
|
stdscr.addstr(5 + i, 40, item[2][:39], a)
|
|
|
|
stdscr.addstr(5 + i, 80, item[4][:39], a)
|
|
|
|
stdscr.addstr(5 + i, 120, item[5][:39], a)
|
|
|
|
elif menutab == 2 or menutab == 4: # Send or Identities
|
2014-04-19 20:45:37 +02:00
|
|
|
stdscr.addstr(3, 5, "Label", curses.A_BOLD)
|
2014-04-30 04:45:41 +02:00
|
|
|
stdscr.addstr(3, 40, "Address", curses.A_BOLD)
|
|
|
|
stdscr.addstr(3, 80, "Stream", curses.A_BOLD)
|
|
|
|
stdscr.hline(4, 5, '-', 81)
|
2019-09-23 11:42:40 +02:00
|
|
|
for i, item in enumerate(addresses[max(min(len(addresses) - curses.LINES + 6, addrcur - 5), 0):]):
|
|
|
|
if 6 + i < curses.LINES:
|
2014-04-30 04:45:41 +02:00
|
|
|
a = 0
|
2019-09-23 11:42:40 +02:00
|
|
|
if i == addrcur - max(min(len(addresses) - curses.LINES + 6, addrcur - 5), 0):
|
|
|
|
# Highlight current address
|
2014-04-30 04:45:41 +02:00
|
|
|
a = a | curses.A_REVERSE
|
2019-09-23 11:42:40 +02:00
|
|
|
if item[1] and item[3] not in [8, 9]: # Embolden enabled, non-special addresses
|
2014-04-30 04:45:41 +02:00
|
|
|
a = a | curses.A_BOLD
|
2019-09-23 11:42:40 +02:00
|
|
|
stdscr.addstr(5 + i, 5, item[0][:34], a)
|
|
|
|
stdscr.addstr(5 + i, 40, item[2][:39], cpair(item[3]) | a)
|
|
|
|
stdscr.addstr(5 + i, 80, str(1)[:39], a)
|
|
|
|
elif menutab == 5: # Subscriptions
|
2014-04-30 04:45:41 +02:00
|
|
|
stdscr.addstr(3, 5, "Label", curses.A_BOLD)
|
|
|
|
stdscr.addstr(3, 80, "Address", curses.A_BOLD)
|
|
|
|
stdscr.addstr(3, 120, "Enabled", curses.A_BOLD)
|
|
|
|
stdscr.hline(4, 5, '-', 121)
|
2019-09-23 11:42:40 +02:00
|
|
|
for i, item in enumerate(subscriptions[max(min(len(subscriptions) - curses.LINES + 6, subcur - 5), 0):]):
|
|
|
|
if 6 + i < curses.LINES:
|
2014-04-30 04:45:41 +02:00
|
|
|
a = 0
|
2019-09-23 11:42:40 +02:00
|
|
|
if i == subcur - max(min(len(subscriptions) - curses.LINES + 6, subcur - 5), 0):
|
|
|
|
# Highlight current address
|
2014-04-30 04:45:41 +02:00
|
|
|
a = a | curses.A_REVERSE
|
2019-09-23 11:42:40 +02:00
|
|
|
if item[2]: # Embolden enabled subscriptions
|
2014-04-30 04:45:41 +02:00
|
|
|
a = a | curses.A_BOLD
|
2019-09-23 11:42:40 +02:00
|
|
|
stdscr.addstr(5 + i, 5, item[0][:74], a)
|
|
|
|
stdscr.addstr(5 + i, 80, item[1][:39], a)
|
|
|
|
stdscr.addstr(5 + i, 120, str(item[2]), a)
|
|
|
|
elif menutab == 6: # Address book
|
2014-04-29 07:10:33 +02:00
|
|
|
stdscr.addstr(3, 5, "Label", curses.A_BOLD)
|
2014-04-30 04:45:41 +02:00
|
|
|
stdscr.addstr(3, 40, "Address", curses.A_BOLD)
|
|
|
|
stdscr.hline(4, 5, '-', 41)
|
2019-09-23 11:42:40 +02:00
|
|
|
for i, item in enumerate(addrbook[max(min(len(addrbook) - curses.LINES + 6, abookcur - 5), 0):]):
|
|
|
|
if 6 + i < curses.LINES:
|
2014-04-30 04:45:41 +02:00
|
|
|
a = 0
|
2019-09-23 11:42:40 +02:00
|
|
|
if i == abookcur - max(min(len(addrbook) - curses.LINES + 6, abookcur - 5), 0):
|
|
|
|
# Highlight current address
|
2014-04-30 04:45:41 +02:00
|
|
|
a = a | curses.A_REVERSE
|
2019-09-23 11:42:40 +02:00
|
|
|
stdscr.addstr(5 + i, 5, item[0][:34], a)
|
|
|
|
stdscr.addstr(5 + i, 40, item[1][:39], a)
|
|
|
|
elif menutab == 7: # Blacklist
|
|
|
|
stdscr.addstr(3, 5, "Type: " + bwtype)
|
2014-04-30 04:45:41 +02:00
|
|
|
stdscr.addstr(4, 5, "Label", curses.A_BOLD)
|
|
|
|
stdscr.addstr(4, 80, "Address", curses.A_BOLD)
|
|
|
|
stdscr.addstr(4, 120, "Enabled", curses.A_BOLD)
|
|
|
|
stdscr.hline(5, 5, '-', 121)
|
2019-09-23 11:42:40 +02:00
|
|
|
for i, item in enumerate(blacklist[max(min(len(blacklist) - curses.LINES + 6, blackcur - 5), 0):]):
|
|
|
|
if 7 + i < curses.LINES:
|
2014-04-30 04:45:41 +02:00
|
|
|
a = 0
|
2019-09-23 11:42:40 +02:00
|
|
|
if i == blackcur - max(min(len(blacklist) - curses.LINES + 6, blackcur - 5), 0):
|
|
|
|
# Highlight current address
|
2014-04-30 04:45:41 +02:00
|
|
|
a = a | curses.A_REVERSE
|
2019-09-23 11:42:40 +02:00
|
|
|
if item[2]: # Embolden enabled subscriptions
|
2014-04-30 04:45:41 +02:00
|
|
|
a = a | curses.A_BOLD
|
2019-09-23 11:42:40 +02:00
|
|
|
stdscr.addstr(6 + i, 5, item[0][:74], a)
|
|
|
|
stdscr.addstr(6 + i, 80, item[1][:39], a)
|
|
|
|
stdscr.addstr(6 + i, 120, str(item[2]), a)
|
|
|
|
elif menutab == 8: # Network status
|
2014-04-19 20:45:37 +02:00
|
|
|
# Connection data
|
2018-11-01 15:28:42 +01:00
|
|
|
connected_hosts = network.stats.connectedHostsList()
|
|
|
|
stdscr.addstr(
|
|
|
|
4, 5, "Total Connections: " +
|
|
|
|
str(len(connected_hosts)).ljust(2)
|
|
|
|
)
|
2014-04-19 20:45:37 +02:00
|
|
|
stdscr.addstr(6, 6, "Stream #", curses.A_BOLD)
|
2014-04-19 20:57:08 +02:00
|
|
|
stdscr.addstr(6, 18, "Connections", curses.A_BOLD)
|
|
|
|
stdscr.hline(7, 6, '-', 23)
|
2014-04-19 20:45:37 +02:00
|
|
|
streamcount = []
|
2018-11-01 15:28:42 +01:00
|
|
|
for host, stream in connected_hosts:
|
2014-04-19 20:45:37 +02:00
|
|
|
if stream >= len(streamcount):
|
|
|
|
streamcount.append(1)
|
|
|
|
else:
|
|
|
|
streamcount[stream] += 1
|
|
|
|
for i, item in enumerate(streamcount):
|
2014-04-19 20:57:08 +02:00
|
|
|
if i < 4:
|
2014-04-19 20:45:37 +02:00
|
|
|
if i == 0:
|
2019-09-23 11:42:40 +02:00
|
|
|
stdscr.addstr(8 + i, 6, "?")
|
2014-04-19 20:45:37 +02:00
|
|
|
else:
|
2019-09-23 11:42:40 +02:00
|
|
|
stdscr.addstr(8 + i, 6, str(i))
|
|
|
|
stdscr.addstr(8 + i, 18, str(item).ljust(2))
|
|
|
|
|
2014-04-19 20:45:37 +02:00
|
|
|
# Uptime and processing data
|
2019-09-23 11:42:40 +02:00
|
|
|
stdscr.addstr(6, 35, "Since startup on " + l10n.formatTimestamp(startuptime, False))
|
|
|
|
stdscr.addstr(7, 40, "Processed " + str(
|
2019-11-05 17:54:04 +01:00
|
|
|
state.numberOfMessagesProcessed).ljust(4) + " person-to-person messages.")
|
2019-09-23 11:42:40 +02:00
|
|
|
stdscr.addstr(8, 40, "Processed " + str(
|
2019-11-05 17:54:04 +01:00
|
|
|
state.numberOfBroadcastsProcessed).ljust(4) + " broadcast messages.")
|
2019-09-23 11:42:40 +02:00
|
|
|
stdscr.addstr(9, 40, "Processed " + str(
|
2019-11-05 17:54:04 +01:00
|
|
|
state.numberOfPubkeysProcessed).ljust(4) + " public keys.")
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-19 20:45:37 +02:00
|
|
|
# Inventory data
|
2019-09-23 11:42:40 +02:00
|
|
|
stdscr.addstr(11, 35, "Inventory lookups per second: " + str(inventorydata).ljust(3))
|
|
|
|
|
2014-04-19 20:45:37 +02:00
|
|
|
# Log
|
|
|
|
stdscr.addstr(13, 6, "Log", curses.A_BOLD)
|
|
|
|
n = log.count('\n')
|
|
|
|
if n > 0:
|
2019-12-27 15:12:57 +01:00
|
|
|
lg = log.split('\n')
|
2014-04-19 20:45:37 +02:00
|
|
|
if n > 512:
|
2019-12-27 15:12:57 +01:00
|
|
|
del lg[:(n - 256)]
|
2014-04-19 20:45:37 +02:00
|
|
|
logpad.erase()
|
2019-12-27 15:12:57 +01:00
|
|
|
n = len(lg)
|
|
|
|
for i, item in enumerate(lg):
|
2014-04-19 20:45:37 +02:00
|
|
|
a = 0
|
2019-09-23 11:42:40 +02:00
|
|
|
if item and item[0] == '!':
|
2014-04-19 20:45:37 +02:00
|
|
|
a = curses.color_pair(1)
|
|
|
|
item = item[1:]
|
|
|
|
logpad.addstr(i, 0, item, a)
|
2019-09-23 11:42:40 +02:00
|
|
|
logpad.refresh(n - curses.LINES + 2, 0, 14, 6, curses.LINES - 2, curses.COLS - 7)
|
2014-04-18 07:48:42 +02:00
|
|
|
stdscr.refresh()
|
|
|
|
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-18 07:48:42 +02:00
|
|
|
def redraw(stdscr):
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Redraw menu"""
|
2014-04-18 07:48:42 +02:00
|
|
|
stdscr.erase()
|
|
|
|
stdscr.border()
|
|
|
|
drawmenu(stdscr)
|
|
|
|
stdscr.refresh()
|
2019-09-23 11:42:40 +02:00
|
|
|
|
|
|
|
|
2014-04-19 20:45:37 +02:00
|
|
|
def dialogreset(stdscr):
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Resetting dialogue"""
|
2014-04-19 20:45:37 +02:00
|
|
|
stdscr.clear()
|
|
|
|
stdscr.keypad(1)
|
|
|
|
curses.curs_set(0)
|
2019-09-23 11:42:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=too-many-branches, too-many-statements
|
2014-04-18 07:48:42 +02:00
|
|
|
def handlech(c, stdscr):
|
2019-12-27 15:12:57 +01:00
|
|
|
"""Handle character given on the command-line interface"""
|
|
|
|
# pylint: disable=redefined-outer-name, too-many-nested-blocks, too-many-locals
|
2014-04-18 07:48:42 +02:00
|
|
|
if c != curses.ERR:
|
2014-05-01 02:03:12 +02:00
|
|
|
global inboxcur, addrcur, sentcur, subcur, abookcur, blackcur
|
2019-09-23 11:42:40 +02:00
|
|
|
if c in range(256):
|
2014-04-18 07:48:42 +02:00
|
|
|
if chr(c) in '12345678':
|
2014-04-29 07:10:33 +02:00
|
|
|
global menutab
|
2014-04-18 07:48:42 +02:00
|
|
|
menutab = int(chr(c))
|
|
|
|
elif chr(c) == 'q':
|
2019-12-27 15:12:57 +01:00
|
|
|
global quit_
|
|
|
|
quit_ = True
|
2014-04-19 20:45:37 +02:00
|
|
|
elif chr(c) == '\n':
|
2014-04-30 04:45:41 +02:00
|
|
|
curses.curs_set(1)
|
|
|
|
d = Dialog(dialog="dialog")
|
2014-04-29 07:10:33 +02:00
|
|
|
if menutab == 1:
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Inbox Message Dialog Box")
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.menu(
|
|
|
|
"Do what with \"" + inbox[inboxcur][5] + "\" from \"" + inbox[inboxcur][3] + "\"?",
|
|
|
|
choices=[
|
|
|
|
("1", "View message"),
|
2014-04-29 07:10:33 +02:00
|
|
|
("2", "Mark message as unread"),
|
|
|
|
("3", "Reply"),
|
|
|
|
("4", "Add sender to Address Book"),
|
|
|
|
("5", "Save message as text file"),
|
|
|
|
("6", "Move to trash")])
|
|
|
|
if r == d.DIALOG_OK:
|
2019-09-23 11:42:40 +02:00
|
|
|
if t == "1": # View
|
|
|
|
set_background_title(
|
|
|
|
d,
|
|
|
|
"\"" +
|
|
|
|
inbox[inboxcur][5] +
|
|
|
|
"\" from \"" +
|
|
|
|
inbox[inboxcur][3] +
|
|
|
|
"\" to \"" +
|
|
|
|
inbox[inboxcur][1] +
|
|
|
|
"\"")
|
|
|
|
data = "" # pyint: disable=redefined-outer-name
|
2014-04-29 07:10:33 +02:00
|
|
|
ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", inbox[inboxcur][0])
|
|
|
|
if ret != []:
|
|
|
|
for row in ret:
|
2014-05-01 02:03:12 +02:00
|
|
|
data, = row
|
|
|
|
data = shared.fixPotentiallyInvalidUTF8Data(data)
|
|
|
|
msg = ""
|
|
|
|
for i, item in enumerate(data.split("\n")):
|
2019-09-23 11:42:40 +02:00
|
|
|
msg += fill(item, replace_whitespace=False) + "\n"
|
2016-06-30 12:28:17 +02:00
|
|
|
scrollbox(d, unicode(ascii(msg)), 30, 80)
|
2014-04-29 07:10:33 +02:00
|
|
|
sqlExecute("UPDATE inbox SET read=1 WHERE msgid=?", inbox[inboxcur][0])
|
|
|
|
inbox[inboxcur][7] = 1
|
|
|
|
else:
|
2016-06-30 12:28:17 +02:00
|
|
|
scrollbox(d, unicode("Could not fetch message."))
|
2019-12-27 15:12:57 +01:00
|
|
|
elif t == "2": # Mark unread
|
2014-04-29 07:10:33 +02:00
|
|
|
sqlExecute("UPDATE inbox SET read=0 WHERE msgid=?", inbox[inboxcur][0])
|
|
|
|
inbox[inboxcur][7] = 0
|
2019-12-27 15:12:57 +01:00
|
|
|
elif t == "3": # Reply
|
2014-04-29 07:10:33 +02:00
|
|
|
curses.curs_set(1)
|
|
|
|
m = inbox[inboxcur]
|
|
|
|
fromaddr = m[4]
|
|
|
|
ischan = False
|
|
|
|
for i, item in enumerate(addresses):
|
|
|
|
if fromaddr == item[2] and item[3] != 0:
|
|
|
|
ischan = True
|
|
|
|
break
|
2019-12-27 15:12:57 +01:00
|
|
|
if not addresses[i][1]: # pylint: disable=undefined-loop-variable
|
2019-09-23 11:42:40 +02:00
|
|
|
scrollbox(d, unicode(
|
|
|
|
"Sending address disabled, please either enable it"
|
|
|
|
"or choose a different address."))
|
2014-04-29 07:10:33 +02:00
|
|
|
return
|
|
|
|
toaddr = m[2]
|
|
|
|
if ischan:
|
|
|
|
toaddr = fromaddr
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-29 07:10:33 +02:00
|
|
|
subject = m[5]
|
|
|
|
if not m[5][:4] == "Re: ":
|
2019-09-23 11:42:40 +02:00
|
|
|
subject = "Re: " + m[5]
|
2014-04-29 07:10:33 +02:00
|
|
|
body = ""
|
|
|
|
ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", m[0])
|
|
|
|
if ret != []:
|
|
|
|
body = "\n\n------------------------------------------------------\n"
|
|
|
|
for row in ret:
|
|
|
|
body, = row
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-30 04:45:41 +02:00
|
|
|
sendMessage(fromaddr, toaddr, ischan, subject, body, True)
|
2014-04-29 07:10:33 +02:00
|
|
|
dialogreset(stdscr)
|
2019-12-27 15:12:57 +01:00
|
|
|
elif t == "4": # Add to Address Book
|
2014-04-29 07:10:33 +02:00
|
|
|
addr = inbox[inboxcur][4]
|
2019-09-23 11:42:40 +02:00
|
|
|
if addr not in [item[1] for i, item in enumerate(addrbook)]:
|
|
|
|
r, t = d.inputbox("Label for address \"" + addr + "\"")
|
2014-04-29 07:10:33 +02:00
|
|
|
if r == d.DIALOG_OK:
|
2014-05-01 02:03:12 +02:00
|
|
|
label = t
|
|
|
|
sqlExecute("INSERT INTO addressbook VALUES (?,?)", label, addr)
|
|
|
|
# Prepend entry
|
|
|
|
addrbook.reverse()
|
|
|
|
addrbook.append([label, addr])
|
|
|
|
addrbook.reverse()
|
2014-04-29 07:10:33 +02:00
|
|
|
else:
|
2016-06-30 12:28:17 +02:00
|
|
|
scrollbox(d, unicode("The selected address is already in the Address Book."))
|
2019-12-27 15:12:57 +01:00
|
|
|
elif t == "5": # Save message
|
2019-09-23 11:42:40 +02:00
|
|
|
set_background_title(d, "Save \"" + inbox[inboxcur][5] + "\" as text file")
|
|
|
|
r, t = d.inputbox("Filename", init=inbox[inboxcur][5] + ".txt")
|
2014-04-29 07:10:33 +02:00
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
msg = ""
|
|
|
|
ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", inbox[inboxcur][0])
|
|
|
|
if ret != []:
|
|
|
|
for row in ret:
|
|
|
|
msg, = row
|
2019-12-27 15:12:57 +01:00
|
|
|
fh = open(t, "a") # Open in append mode just in case
|
2014-04-29 07:10:33 +02:00
|
|
|
fh.write(msg)
|
|
|
|
fh.close()
|
|
|
|
else:
|
2016-06-30 12:28:17 +02:00
|
|
|
scrollbox(d, unicode("Could not fetch message."))
|
2019-12-27 15:12:57 +01:00
|
|
|
elif t == "6": # Move to trash
|
2014-04-29 07:10:33 +02:00
|
|
|
sqlExecute("UPDATE inbox SET folder='trash' WHERE msgid=?", inbox[inboxcur][0])
|
|
|
|
del inbox[inboxcur]
|
2019-09-23 11:42:40 +02:00
|
|
|
scrollbox(d, unicode(
|
|
|
|
"Message moved to trash. There is no interface to view your trash,"
|
|
|
|
" \nbut the message is still on disk if you are desperate to recover it."))
|
2014-04-29 07:10:33 +02:00
|
|
|
elif menutab == 2:
|
2014-05-01 02:29:04 +02:00
|
|
|
a = ""
|
2019-12-27 15:12:57 +01:00
|
|
|
if addresses[addrcur][3] != 0: # if current address is a chan
|
2014-05-01 02:29:04 +02:00
|
|
|
a = addresses[addrcur][2]
|
|
|
|
sendMessage(addresses[addrcur][2], a)
|
2014-04-30 04:45:41 +02:00
|
|
|
elif menutab == 3:
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Sent Messages Dialog Box")
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.menu(
|
|
|
|
"Do what with \"" + sentbox[sentcur][4] + "\" to \"" + sentbox[sentcur][0] + "\"?",
|
|
|
|
choices=[
|
|
|
|
("1", "View message"),
|
2014-04-30 04:45:41 +02:00
|
|
|
("2", "Move to trash")])
|
|
|
|
if r == d.DIALOG_OK:
|
2019-09-23 11:42:40 +02:00
|
|
|
if t == "1": # View
|
|
|
|
set_background_title(
|
|
|
|
d,
|
|
|
|
"\"" +
|
|
|
|
sentbox[sentcur][4] +
|
|
|
|
"\" from \"" +
|
|
|
|
sentbox[sentcur][3] +
|
|
|
|
"\" to \"" +
|
|
|
|
sentbox[sentcur][1] +
|
|
|
|
"\"")
|
2014-05-01 02:03:12 +02:00
|
|
|
data = ""
|
2019-09-23 11:42:40 +02:00
|
|
|
ret = sqlQuery(
|
|
|
|
"SELECT message FROM sent WHERE subject=? AND ackdata=?",
|
|
|
|
sentbox[sentcur][4],
|
|
|
|
sentbox[sentcur][6])
|
2014-04-30 04:45:41 +02:00
|
|
|
if ret != []:
|
|
|
|
for row in ret:
|
2014-05-01 02:03:12 +02:00
|
|
|
data, = row
|
|
|
|
data = shared.fixPotentiallyInvalidUTF8Data(data)
|
|
|
|
msg = ""
|
|
|
|
for i, item in enumerate(data.split("\n")):
|
2019-09-23 11:42:40 +02:00
|
|
|
msg += fill(item, replace_whitespace=False) + "\n"
|
2016-06-30 12:28:17 +02:00
|
|
|
scrollbox(d, unicode(ascii(msg)), 30, 80)
|
2014-04-30 04:45:41 +02:00
|
|
|
else:
|
2016-06-30 12:28:17 +02:00
|
|
|
scrollbox(d, unicode("Could not fetch message."))
|
2019-12-27 15:12:57 +01:00
|
|
|
elif t == "2": # Move to trash
|
2019-09-23 11:42:40 +02:00
|
|
|
sqlExecute(
|
|
|
|
"UPDATE sent SET folder='trash' WHERE subject=? AND ackdata=?",
|
|
|
|
sentbox[sentcur][4],
|
|
|
|
sentbox[sentcur][6])
|
2014-04-30 04:45:41 +02:00
|
|
|
del sentbox[sentcur]
|
2019-09-23 11:42:40 +02:00
|
|
|
scrollbox(d, unicode(
|
|
|
|
"Message moved to trash. There is no interface to view your trash"
|
|
|
|
" \nbut the message is still on disk if you are desperate to recover it."))
|
2014-04-29 07:10:33 +02:00
|
|
|
elif menutab == 4:
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Your Identities Dialog Box")
|
|
|
|
if len(addresses) <= addrcur:
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.menu(
|
|
|
|
"Do what with addresses?",
|
|
|
|
choices=[
|
|
|
|
("1", "Create new address")])
|
2016-06-30 12:28:17 +02:00
|
|
|
else:
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.menu(
|
|
|
|
"Do what with \"" + addresses[addrcur][0] + "\" : \"" + addresses[addrcur][2] + "\"?",
|
|
|
|
choices=[
|
|
|
|
("1", "Create new address"),
|
2016-06-30 12:28:17 +02:00
|
|
|
("2", "Send a message from this address"),
|
|
|
|
("3", "Rename"),
|
|
|
|
("4", "Enable"),
|
|
|
|
("5", "Disable"),
|
|
|
|
("6", "Delete"),
|
|
|
|
("7", "Special address behavior")])
|
2014-04-19 20:45:37 +02:00
|
|
|
if r == d.DIALOG_OK:
|
2019-12-27 15:12:57 +01:00
|
|
|
if t == "1": # Create new address
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Create new address")
|
2019-09-23 11:42:40 +02:00
|
|
|
scrollbox(
|
|
|
|
d, unicode(
|
|
|
|
"Here you may generate as many addresses as you like.\n"
|
|
|
|
"Indeed, creating and abandoning addresses is encouraged.\n"
|
|
|
|
"Deterministic addresses have several pros and cons:\n"
|
|
|
|
"\nPros:\n"
|
|
|
|
" * You can recreate your addresses on any computer from memory\n"
|
|
|
|
" * You need not worry about backing up your keys.dat file as long as you"
|
|
|
|
" \n can remember your passphrase\n"
|
|
|
|
"Cons:\n"
|
|
|
|
" * You must remember (or write down) your passphrase in order to recreate"
|
|
|
|
" \n your keys if they are lost\n"
|
|
|
|
" * You must also remember the address version and stream numbers\n"
|
|
|
|
" * If you choose a weak passphrase someone may be able to brute-force it"
|
|
|
|
" \n and then send and receive messages as you"))
|
|
|
|
r, t = d.menu(
|
|
|
|
"Choose an address generation technique",
|
|
|
|
choices=[
|
|
|
|
("1", "Use a random number generator"),
|
2014-04-19 20:45:37 +02:00
|
|
|
("2", "Use a passphrase")])
|
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
if t == "1":
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Randomly generate address")
|
2014-04-19 20:45:37 +02:00
|
|
|
r, t = d.inputbox("Label (not shown to anyone except you)")
|
|
|
|
label = ""
|
2019-09-23 11:42:40 +02:00
|
|
|
if r == d.DIALOG_OK and t:
|
2014-04-19 20:45:37 +02:00
|
|
|
label = t
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.menu(
|
|
|
|
"Choose a stream",
|
|
|
|
choices=[("1", "Use the most available stream"),
|
|
|
|
("", "(Best if this is the first of many addresses you will create)"),
|
|
|
|
("2", "Use the same stream as an existing address"),
|
|
|
|
("", "(Saves you some bandwidth and processing power)")])
|
2014-04-19 20:45:37 +02:00
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
if t == "1":
|
|
|
|
stream = 1
|
|
|
|
elif t == "2":
|
|
|
|
addrs = []
|
|
|
|
for i, item in enumerate(addresses):
|
|
|
|
addrs.append([str(i), item[2]])
|
|
|
|
r, t = d.menu("Choose an existing address's stream", choices=addrs)
|
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
stream = decodeAddress(addrs[int(t)][1])[2]
|
|
|
|
shorten = False
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.checklist(
|
|
|
|
"Miscellaneous options",
|
|
|
|
choices=[(
|
|
|
|
"1",
|
|
|
|
"Spend time shortening the address",
|
|
|
|
1 if shorten else 0)])
|
2014-04-19 20:45:37 +02:00
|
|
|
if r == d.DIALOG_OK and "1" in t:
|
|
|
|
shorten = True
|
2019-09-23 11:42:40 +02:00
|
|
|
queues.addressGeneratorQueue.put((
|
|
|
|
"createRandomAddress",
|
|
|
|
4,
|
|
|
|
stream,
|
|
|
|
label,
|
|
|
|
1,
|
|
|
|
"",
|
|
|
|
shorten))
|
2014-04-19 20:45:37 +02:00
|
|
|
elif t == "2":
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Make deterministic addresses")
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.passwordform(
|
|
|
|
"Enter passphrase",
|
|
|
|
[
|
|
|
|
("Passphrase", 1, 1, "", 2, 1, 64, 128),
|
|
|
|
("Confirm passphrase", 3, 1, "", 4, 1, 64, 128)],
|
2014-04-19 20:45:37 +02:00
|
|
|
form_height=4, insecure=True)
|
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
if t[0] == t[1]:
|
|
|
|
passphrase = t[0]
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.rangebox(
|
|
|
|
"Number of addresses to generate",
|
|
|
|
width=48,
|
|
|
|
min=1,
|
|
|
|
max=99,
|
|
|
|
init=8)
|
2014-04-19 20:45:37 +02:00
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
number = t
|
|
|
|
stream = 1
|
|
|
|
shorten = False
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.checklist(
|
|
|
|
"Miscellaneous options",
|
|
|
|
choices=[(
|
|
|
|
"1",
|
|
|
|
"Spend time shortening the address",
|
|
|
|
1 if shorten else 0)])
|
2014-04-19 20:45:37 +02:00
|
|
|
if r == d.DIALOG_OK and "1" in t:
|
|
|
|
shorten = True
|
2019-09-23 11:42:40 +02:00
|
|
|
scrollbox(
|
|
|
|
d, unicode(
|
|
|
|
"In addition to your passphrase, be sure to remember the"
|
|
|
|
" following numbers:\n"
|
|
|
|
"\n * Address version number: " + str(4) + "\n"
|
|
|
|
" * Stream number: " + str(stream)))
|
|
|
|
queues.addressGeneratorQueue.put(
|
|
|
|
('createDeterministicAddresses', 4, stream,
|
|
|
|
"unused deterministic address", number,
|
|
|
|
str(passphrase), shorten))
|
2014-04-19 20:45:37 +02:00
|
|
|
else:
|
2016-06-30 12:28:17 +02:00
|
|
|
scrollbox(d, unicode("Passphrases do not match"))
|
2019-12-27 15:12:57 +01:00
|
|
|
elif t == "2": # Send a message
|
2014-05-01 02:29:04 +02:00
|
|
|
a = ""
|
2019-12-27 15:12:57 +01:00
|
|
|
if addresses[addrcur][3] != 0: # if current address is a chan
|
2014-05-01 02:29:04 +02:00
|
|
|
a = addresses[addrcur][2]
|
|
|
|
sendMessage(addresses[addrcur][2], a)
|
2019-12-27 15:12:57 +01:00
|
|
|
elif t == "3": # Rename address label
|
2014-04-19 20:45:37 +02:00
|
|
|
a = addresses[addrcur][2]
|
|
|
|
label = addresses[addrcur][0]
|
|
|
|
r, t = d.inputbox("New address label", init=label)
|
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
label = t
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set(a, "label", label)
|
2014-04-19 20:45:37 +02:00
|
|
|
# Write config
|
2017-01-15 10:50:02 +01:00
|
|
|
BMConfigParser().save()
|
2014-04-19 20:45:37 +02:00
|
|
|
addresses[addrcur][0] = label
|
2019-12-27 15:12:57 +01:00
|
|
|
elif t == "4": # Enable address
|
2014-04-19 20:45:37 +02:00
|
|
|
a = addresses[addrcur][2]
|
2019-12-27 15:12:57 +01:00
|
|
|
BMConfigParser().set(a, "enabled", "true") # Set config
|
2014-04-19 20:45:37 +02:00
|
|
|
# Write config
|
2017-01-15 10:50:02 +01:00
|
|
|
BMConfigParser().save()
|
2014-04-19 20:45:37 +02:00
|
|
|
# Change color
|
2017-01-11 14:27:19 +01:00
|
|
|
if BMConfigParser().safeGetBoolean(a, 'chan'):
|
2019-12-27 15:12:57 +01:00
|
|
|
addresses[addrcur][3] = 9 # orange
|
2017-01-11 14:27:19 +01:00
|
|
|
elif BMConfigParser().safeGetBoolean(a, 'mailinglist'):
|
2019-12-27 15:12:57 +01:00
|
|
|
addresses[addrcur][3] = 5 # magenta
|
2014-04-19 20:45:37 +02:00
|
|
|
else:
|
2019-12-27 15:12:57 +01:00
|
|
|
addresses[addrcur][3] = 0 # black
|
2014-04-19 20:45:37 +02:00
|
|
|
addresses[addrcur][1] = True
|
2019-12-27 15:12:57 +01:00
|
|
|
shared.reloadMyAddressHashes() # Reload address hashes
|
|
|
|
elif t == "5": # Disable address
|
2014-04-19 20:45:37 +02:00
|
|
|
a = addresses[addrcur][2]
|
2019-12-27 15:12:57 +01:00
|
|
|
BMConfigParser().set(a, "enabled", "false") # Set config
|
|
|
|
addresses[addrcur][3] = 8 # Set color to gray
|
2014-04-19 20:45:37 +02:00
|
|
|
# Write config
|
2017-01-15 10:50:02 +01:00
|
|
|
BMConfigParser().save()
|
2014-04-19 20:45:37 +02:00
|
|
|
addresses[addrcur][1] = False
|
2019-12-27 15:12:57 +01:00
|
|
|
shared.reloadMyAddressHashes() # Reload address hashes
|
|
|
|
elif t == "6": # Delete address
|
2014-04-30 04:45:41 +02:00
|
|
|
r, t = d.inputbox("Type in \"I want to delete this address\"", width=50)
|
|
|
|
if r == d.DIALOG_OK and t == "I want to delete this address":
|
2019-09-23 11:42:40 +02:00
|
|
|
BMConfigParser().remove_section(addresses[addrcur][2])
|
|
|
|
BMConfigParser().save()
|
|
|
|
del addresses[addrcur]
|
2019-12-27 15:12:57 +01:00
|
|
|
elif t == "7": # Special address behavior
|
2014-04-19 20:45:37 +02:00
|
|
|
a = addresses[addrcur][2]
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Special address behavior")
|
2017-01-11 14:27:19 +01:00
|
|
|
if BMConfigParser().safeGetBoolean(a, "chan"):
|
2019-09-23 11:42:40 +02:00
|
|
|
scrollbox(d, unicode(
|
|
|
|
"This is a chan address. You cannot use it as a pseudo-mailing list."))
|
2014-04-19 20:45:37 +02:00
|
|
|
else:
|
2017-01-11 14:27:19 +01:00
|
|
|
m = BMConfigParser().safeGetBoolean(a, "mailinglist")
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.radiolist(
|
|
|
|
"Select address behavior",
|
|
|
|
choices=[
|
|
|
|
("1", "Behave as a normal address", not m),
|
2014-04-29 07:10:33 +02:00
|
|
|
("2", "Behave as a pseudo-mailing-list address", m)])
|
2014-04-19 20:45:37 +02:00
|
|
|
if r == d.DIALOG_OK:
|
2019-09-23 11:42:40 +02:00
|
|
|
if t == "1" and m:
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set(a, "mailinglist", "false")
|
2014-04-19 20:45:37 +02:00
|
|
|
if addresses[addrcur][1]:
|
2019-12-27 15:12:57 +01:00
|
|
|
addresses[addrcur][3] = 0 # Set color to black
|
2014-04-19 20:45:37 +02:00
|
|
|
else:
|
2019-12-27 15:12:57 +01:00
|
|
|
addresses[addrcur][3] = 8 # Set color to gray
|
2019-09-23 11:42:40 +02:00
|
|
|
elif t == "2" and m is False:
|
2014-04-19 20:45:37 +02:00
|
|
|
try:
|
2017-01-11 14:27:19 +01:00
|
|
|
mn = BMConfigParser().get(a, "mailinglistname")
|
2014-04-19 20:45:37 +02:00
|
|
|
except ConfigParser.NoOptionError:
|
2019-09-23 11:42:40 +02:00
|
|
|
mn = ""
|
2014-04-19 20:45:37 +02:00
|
|
|
r, t = d.inputbox("Mailing list name", init=mn)
|
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
mn = t
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set(a, "mailinglist", "true")
|
|
|
|
BMConfigParser().set(a, "mailinglistname", mn)
|
2019-12-27 15:12:57 +01:00
|
|
|
addresses[addrcur][3] = 6 # Set color to magenta
|
2014-04-19 20:45:37 +02:00
|
|
|
# Write config
|
2017-01-15 10:50:02 +01:00
|
|
|
BMConfigParser().save()
|
2014-04-30 04:45:41 +02:00
|
|
|
elif menutab == 5:
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Subscriptions Dialog Box")
|
|
|
|
if len(subscriptions) <= subcur:
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.menu(
|
|
|
|
"Do what with subscription to \"" + subscriptions[subcur][0] + "\"?",
|
|
|
|
choices=[
|
|
|
|
("1", "Add new subscription")])
|
2016-06-30 12:28:17 +02:00
|
|
|
else:
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.menu(
|
|
|
|
"Do what with subscription to \"" + subscriptions[subcur][0] + "\"?",
|
|
|
|
choices=[
|
|
|
|
("1", "Add new subscription"),
|
2016-06-30 12:28:17 +02:00
|
|
|
("2", "Delete this subscription"),
|
|
|
|
("3", "Enable"),
|
|
|
|
("4", "Disable")])
|
2014-04-30 04:45:41 +02:00
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
if t == "1":
|
|
|
|
r, t = d.inputbox("New subscription address")
|
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
addr = addBMIfNotPresent(t)
|
|
|
|
if not shared.isAddressInMySubscriptionsList(addr):
|
|
|
|
r, t = d.inputbox("New subscription label")
|
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
label = t
|
2014-05-01 02:29:04 +02:00
|
|
|
# Prepend entry
|
|
|
|
subscriptions.reverse()
|
|
|
|
subscriptions.append([label, addr, True])
|
|
|
|
subscriptions.reverse()
|
|
|
|
|
2017-02-08 14:19:02 +01:00
|
|
|
sqlExecute("INSERT INTO subscriptions VALUES (?,?,?)", label, addr, True)
|
2014-04-30 04:45:41 +02:00
|
|
|
shared.reloadBroadcastSendersForWhichImWatching()
|
|
|
|
elif t == "2":
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.inputbox("Type in \"I want to delete this subscription\"")
|
2014-04-30 04:45:41 +02:00
|
|
|
if r == d.DIALOG_OK and t == "I want to delete this subscription":
|
2019-09-23 11:42:40 +02:00
|
|
|
sqlExecute(
|
|
|
|
"DELETE FROM subscriptions WHERE label=? AND address=?",
|
|
|
|
subscriptions[subcur][0],
|
|
|
|
subscriptions[subcur][1])
|
|
|
|
shared.reloadBroadcastSendersForWhichImWatching()
|
|
|
|
del subscriptions[subcur]
|
2014-04-30 04:45:41 +02:00
|
|
|
elif t == "3":
|
2019-09-23 11:42:40 +02:00
|
|
|
sqlExecute(
|
|
|
|
"UPDATE subscriptions SET enabled=1 WHERE label=? AND address=?",
|
|
|
|
subscriptions[subcur][0],
|
|
|
|
subscriptions[subcur][1])
|
2014-04-30 04:45:41 +02:00
|
|
|
shared.reloadBroadcastSendersForWhichImWatching()
|
|
|
|
subscriptions[subcur][2] = True
|
|
|
|
elif t == "4":
|
2019-09-23 11:42:40 +02:00
|
|
|
sqlExecute(
|
|
|
|
"UPDATE subscriptions SET enabled=0 WHERE label=? AND address=?",
|
|
|
|
subscriptions[subcur][0],
|
|
|
|
subscriptions[subcur][1])
|
2014-04-30 04:45:41 +02:00
|
|
|
shared.reloadBroadcastSendersForWhichImWatching()
|
|
|
|
subscriptions[subcur][2] = False
|
|
|
|
elif menutab == 6:
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Address Book Dialog Box")
|
|
|
|
if len(addrbook) <= abookcur:
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.menu(
|
|
|
|
"Do what with addressbook?",
|
2016-06-30 12:28:17 +02:00
|
|
|
choices=[("3", "Add new address to Address Book")])
|
|
|
|
else:
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.menu(
|
|
|
|
"Do what with \"" + addrbook[abookcur][0] + "\" : \"" + addrbook[abookcur][1] + "\"",
|
|
|
|
choices=[
|
|
|
|
("1", "Send a message to this address"),
|
2016-06-30 12:28:17 +02:00
|
|
|
("2", "Subscribe to this address"),
|
|
|
|
("3", "Add new address to Address Book"),
|
|
|
|
("4", "Delete this address")])
|
2014-04-30 04:45:41 +02:00
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
if t == "1":
|
|
|
|
sendMessage(recv=addrbook[abookcur][1])
|
|
|
|
elif t == "2":
|
|
|
|
r, t = d.inputbox("New subscription label")
|
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
label = t
|
2014-05-01 02:29:04 +02:00
|
|
|
# Prepend entry
|
|
|
|
subscriptions.reverse()
|
|
|
|
subscriptions.append([label, addr, True])
|
|
|
|
subscriptions.reverse()
|
|
|
|
|
2017-02-08 14:19:02 +01:00
|
|
|
sqlExecute("INSERT INTO subscriptions VALUES (?,?,?)", label, addr, True)
|
2014-04-30 04:45:41 +02:00
|
|
|
shared.reloadBroadcastSendersForWhichImWatching()
|
|
|
|
elif t == "3":
|
|
|
|
r, t = d.inputbox("Input new address")
|
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
addr = t
|
2019-09-23 11:42:40 +02:00
|
|
|
if addr not in [item[1] for i, item in enumerate(addrbook)]:
|
|
|
|
r, t = d.inputbox("Label for address \"" + addr + "\"")
|
2014-04-30 04:45:41 +02:00
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
sqlExecute("INSERT INTO addressbook VALUES (?,?)", t, addr)
|
2014-05-01 02:29:04 +02:00
|
|
|
# Prepend entry
|
|
|
|
addrbook.reverse()
|
|
|
|
addrbook.append([t, addr])
|
|
|
|
addrbook.reverse()
|
2014-04-30 04:45:41 +02:00
|
|
|
else:
|
2016-06-30 12:28:17 +02:00
|
|
|
scrollbox(d, unicode("The selected address is already in the Address Book."))
|
2014-04-30 04:45:41 +02:00
|
|
|
elif t == "4":
|
|
|
|
r, t = d.inputbox("Type in \"I want to delete this Address Book entry\"")
|
|
|
|
if r == d.DIALOG_OK and t == "I want to delete this Address Book entry":
|
2019-09-23 11:42:40 +02:00
|
|
|
sqlExecute(
|
|
|
|
"DELETE FROM addressbook WHERE label=? AND address=?",
|
|
|
|
addrbook[abookcur][0],
|
|
|
|
addrbook[abookcur][1])
|
2014-04-30 04:45:41 +02:00
|
|
|
del addrbook[abookcur]
|
|
|
|
elif menutab == 7:
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Blacklist Dialog Box")
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.menu(
|
|
|
|
"Do what with \"" + blacklist[blackcur][0] + "\" : \"" + blacklist[blackcur][1] + "\"?",
|
|
|
|
choices=[
|
|
|
|
("1", "Delete"),
|
2014-04-30 04:45:41 +02:00
|
|
|
("2", "Enable"),
|
|
|
|
("3", "Disable")])
|
|
|
|
if r == d.DIALOG_OK:
|
|
|
|
if t == "1":
|
|
|
|
r, t = d.inputbox("Type in \"I want to delete this Blacklist entry\"")
|
|
|
|
if r == d.DIALOG_OK and t == "I want to delete this Blacklist entry":
|
2019-09-23 11:42:40 +02:00
|
|
|
sqlExecute(
|
|
|
|
"DELETE FROM blacklist WHERE label=? AND address=?",
|
|
|
|
blacklist[blackcur][0],
|
|
|
|
blacklist[blackcur][1])
|
2014-04-30 04:45:41 +02:00
|
|
|
del blacklist[blackcur]
|
|
|
|
elif t == "2":
|
2019-09-23 11:42:40 +02:00
|
|
|
sqlExecute(
|
|
|
|
"UPDATE blacklist SET enabled=1 WHERE label=? AND address=?",
|
|
|
|
blacklist[blackcur][0],
|
|
|
|
blacklist[blackcur][1])
|
2014-04-30 04:45:41 +02:00
|
|
|
blacklist[blackcur][2] = True
|
2019-09-23 11:42:40 +02:00
|
|
|
elif t == "3":
|
|
|
|
sqlExecute(
|
|
|
|
"UPDATE blacklist SET enabled=0 WHERE label=? AND address=?",
|
|
|
|
blacklist[blackcur][0],
|
|
|
|
blacklist[blackcur][1])
|
2014-04-30 04:45:41 +02:00
|
|
|
blacklist[blackcur][2] = False
|
|
|
|
dialogreset(stdscr)
|
2014-04-18 07:48:42 +02:00
|
|
|
else:
|
|
|
|
if c == curses.KEY_UP:
|
2014-04-29 07:10:33 +02:00
|
|
|
if menutab == 1 and inboxcur > 0:
|
|
|
|
inboxcur -= 1
|
|
|
|
if (menutab == 2 or menutab == 4) and addrcur > 0:
|
2014-04-18 07:48:42 +02:00
|
|
|
addrcur -= 1
|
2014-04-30 04:45:41 +02:00
|
|
|
if menutab == 3 and sentcur > 0:
|
|
|
|
sentcur -= 1
|
|
|
|
if menutab == 5 and subcur > 0:
|
|
|
|
subcur -= 1
|
2014-04-29 07:10:33 +02:00
|
|
|
if menutab == 6 and abookcur > 0:
|
|
|
|
abookcur -= 1
|
2014-04-30 04:45:41 +02:00
|
|
|
if menutab == 7 and blackcur > 0:
|
|
|
|
blackcur -= 1
|
2014-04-18 07:48:42 +02:00
|
|
|
elif c == curses.KEY_DOWN:
|
2019-09-23 11:42:40 +02:00
|
|
|
if menutab == 1 and inboxcur < len(inbox) - 1:
|
2014-04-29 07:10:33 +02:00
|
|
|
inboxcur += 1
|
2019-09-23 11:42:40 +02:00
|
|
|
if (menutab == 2 or menutab == 4) and addrcur < len(addresses) - 1:
|
2014-04-18 07:48:42 +02:00
|
|
|
addrcur += 1
|
2019-09-23 11:42:40 +02:00
|
|
|
if menutab == 3 and sentcur < len(sentbox) - 1:
|
2014-04-30 04:45:41 +02:00
|
|
|
sentcur += 1
|
2019-09-23 11:42:40 +02:00
|
|
|
if menutab == 5 and subcur < len(subscriptions) - 1:
|
2014-04-30 04:45:41 +02:00
|
|
|
subcur += 1
|
2019-09-23 11:42:40 +02:00
|
|
|
if menutab == 6 and abookcur < len(addrbook) - 1:
|
2014-04-29 07:10:33 +02:00
|
|
|
abookcur += 1
|
2019-09-23 11:42:40 +02:00
|
|
|
if menutab == 7 and blackcur < len(blacklist) - 1:
|
2014-04-30 04:45:41 +02:00
|
|
|
blackcur += 1
|
2014-04-29 07:10:33 +02:00
|
|
|
elif c == curses.KEY_HOME:
|
|
|
|
if menutab == 1:
|
|
|
|
inboxcur = 0
|
|
|
|
if menutab == 2 or menutab == 4:
|
|
|
|
addrcur = 0
|
2014-04-30 04:45:41 +02:00
|
|
|
if menutab == 3:
|
|
|
|
sentcur = 0
|
|
|
|
if menutab == 5:
|
|
|
|
subcur = 0
|
2014-04-29 07:10:33 +02:00
|
|
|
if menutab == 6:
|
|
|
|
abookcur = 0
|
2014-04-30 04:45:41 +02:00
|
|
|
if menutab == 7:
|
|
|
|
blackcur = 0
|
2014-04-29 07:10:33 +02:00
|
|
|
elif c == curses.KEY_END:
|
|
|
|
if menutab == 1:
|
2019-09-23 11:42:40 +02:00
|
|
|
inboxcur = len(inbox) - 1
|
2014-04-29 07:10:33 +02:00
|
|
|
if menutab == 2 or menutab == 4:
|
2019-09-23 11:42:40 +02:00
|
|
|
addrcur = len(addresses) - 1
|
2014-04-30 04:45:41 +02:00
|
|
|
if menutab == 3:
|
2019-09-23 11:42:40 +02:00
|
|
|
sentcur = len(sentbox) - 1
|
2014-04-30 04:45:41 +02:00
|
|
|
if menutab == 5:
|
2019-09-23 11:42:40 +02:00
|
|
|
subcur = len(subscriptions) - 1
|
2014-04-29 07:10:33 +02:00
|
|
|
if menutab == 6:
|
2019-09-23 11:42:40 +02:00
|
|
|
abookcur = len(addrbook) - 1
|
2014-04-30 04:45:41 +02:00
|
|
|
if menutab == 7:
|
2019-09-23 11:42:40 +02:00
|
|
|
blackcur = len(blackcur) - 1
|
2014-04-18 07:48:42 +02:00
|
|
|
redraw(stdscr)
|
2019-09-23 11:42:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=too-many-locals, too-many-arguments
|
2014-04-30 04:45:41 +02:00
|
|
|
def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=False):
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Method for message sending"""
|
2014-04-29 07:10:33 +02:00
|
|
|
if sender == "":
|
|
|
|
return
|
|
|
|
d = Dialog(dialog="dialog")
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Send a message")
|
2014-04-29 07:10:33 +02:00
|
|
|
if recv == "":
|
2019-09-23 11:42:40 +02:00
|
|
|
r, t = d.inputbox(
|
|
|
|
"Recipient address (Cancel to load from the Address Book or leave blank to broadcast)",
|
|
|
|
10,
|
|
|
|
60)
|
2014-04-29 07:10:33 +02:00
|
|
|
if r != d.DIALOG_OK:
|
2019-12-27 15:12:57 +01:00
|
|
|
global menutab
|
2014-04-29 07:10:33 +02:00
|
|
|
menutab = 6
|
|
|
|
return
|
|
|
|
recv = t
|
2019-09-23 11:42:40 +02:00
|
|
|
if broadcast is None and sender != recv:
|
|
|
|
r, t = d.radiolist(
|
|
|
|
"How to send the message?",
|
|
|
|
choices=[
|
|
|
|
("1", "Send to one or more specific people", 1),
|
2016-06-30 12:28:17 +02:00
|
|
|
("2", "Broadcast to everyone who is subscribed to your address", 0)])
|
2014-04-29 07:10:33 +02:00
|
|
|
if r != d.DIALOG_OK:
|
|
|
|
return
|
|
|
|
broadcast = False
|
2019-12-27 15:12:57 +01:00
|
|
|
if t == "2": # Broadcast
|
2014-04-29 07:10:33 +02:00
|
|
|
broadcast = True
|
2014-04-30 04:45:41 +02:00
|
|
|
if subject == "" or reply:
|
|
|
|
r, t = d.inputbox("Message subject", width=60, init=subject)
|
2014-04-29 07:10:33 +02:00
|
|
|
if r != d.DIALOG_OK:
|
|
|
|
return
|
2014-05-01 02:03:12 +02:00
|
|
|
subject = t
|
2014-04-30 04:45:41 +02:00
|
|
|
if body == "" or reply:
|
|
|
|
r, t = d.inputbox("Message body", 10, 80, init=body)
|
2014-04-29 07:10:33 +02:00
|
|
|
if r != d.DIALOG_OK:
|
|
|
|
return
|
2014-05-01 02:03:12 +02:00
|
|
|
body = t
|
|
|
|
body = body.replace("\\n", "\n").replace("\\t", "\t")
|
|
|
|
|
2014-04-29 07:10:33 +02:00
|
|
|
if not broadcast:
|
|
|
|
recvlist = []
|
2019-12-27 15:12:57 +01:00
|
|
|
for _, item in enumerate(recv.replace(",", ";").split(";")):
|
2014-04-29 07:10:33 +02:00
|
|
|
recvlist.append(item.strip())
|
2019-12-27 15:12:57 +01:00
|
|
|
list(set(recvlist)) # Remove exact duplicates
|
2014-04-29 07:10:33 +02:00
|
|
|
for addr in recvlist:
|
|
|
|
if addr != "":
|
2019-09-23 11:42:40 +02:00
|
|
|
# pylint: disable=redefined-outer-name
|
2014-04-29 07:10:33 +02:00
|
|
|
status, version, stream, ripe = decodeAddress(addr)
|
|
|
|
if status != "success":
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Recipient address error")
|
2014-04-29 07:10:33 +02:00
|
|
|
err = "Could not decode" + addr + " : " + status + "\n\n"
|
|
|
|
if status == "missingbm":
|
|
|
|
err += "Bitmessage addresses should start with \"BM-\"."
|
|
|
|
elif status == "checksumfailed":
|
|
|
|
err += "The address was not typed or copied correctly."
|
|
|
|
elif status == "invalidcharacters":
|
|
|
|
err += "The address contains invalid characters."
|
|
|
|
elif status == "versiontoohigh":
|
2019-09-23 11:42:40 +02:00
|
|
|
err += ("The address version is too high. Either you need to upgrade your Bitmessage software"
|
|
|
|
" or your acquaintance is doing something clever.")
|
2014-04-29 07:10:33 +02:00
|
|
|
elif status == "ripetooshort":
|
2019-09-23 11:42:40 +02:00
|
|
|
err += ("Some data encoded in the address is too short. There might be something wrong with"
|
|
|
|
" the software of your acquaintance.")
|
2014-04-29 07:10:33 +02:00
|
|
|
elif status == "ripetoolong":
|
2019-09-23 11:42:40 +02:00
|
|
|
err += ("Some data encoded in the address is too long. There might be something wrong with"
|
|
|
|
" the software of your acquaintance.")
|
2014-08-27 09:14:32 +02:00
|
|
|
elif status == "varintmalformed":
|
2019-09-23 11:42:40 +02:00
|
|
|
err += ("Some data encoded in the address is malformed. There might be something wrong with"
|
|
|
|
" the software of your acquaintance.")
|
2014-04-29 07:10:33 +02:00
|
|
|
else:
|
|
|
|
err += "It is unknown what is wrong with the address."
|
2016-06-30 12:28:17 +02:00
|
|
|
scrollbox(d, unicode(err))
|
2014-04-29 07:10:33 +02:00
|
|
|
else:
|
|
|
|
addr = addBMIfNotPresent(addr)
|
|
|
|
if version > 4 or version <= 1:
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Recipient address error")
|
2019-09-23 11:42:40 +02:00
|
|
|
scrollbox(d, unicode(
|
|
|
|
"Could not understand version number " +
|
|
|
|
version +
|
|
|
|
"of address" +
|
|
|
|
addr +
|
|
|
|
"."))
|
2014-04-29 07:10:33 +02:00
|
|
|
continue
|
|
|
|
if stream > 1 or stream == 0:
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Recipient address error")
|
2019-09-23 11:42:40 +02:00
|
|
|
scrollbox(d, unicode(
|
|
|
|
"Bitmessage currently only supports stream numbers of 1,"
|
|
|
|
"unlike as requested for address " + addr + "."))
|
2014-04-29 07:10:33 +02:00
|
|
|
continue
|
2018-11-01 15:28:42 +01:00
|
|
|
if not network.stats.connectedHostsList():
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Not connected warning")
|
|
|
|
scrollbox(d, unicode("Because you are not currently connected to the network, "))
|
2017-09-30 11:19:44 +02:00
|
|
|
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
|
2019-09-23 11:42:40 +02:00
|
|
|
ackdata = genAckPayload(decodeAddress(addr)[2], stealthLevel)
|
2020-11-09 16:15:28 +01:00
|
|
|
helper_sent.insert(
|
2020-11-11 22:19:14 +01:00
|
|
|
msgid='', toAddress=addr, ripe=ripe, fromAddress=sender, subject=subject,
|
|
|
|
message=body, ackdata=ackdata)
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.workerQueue.put(("sendmessage", addr))
|
2019-12-27 15:12:57 +01:00
|
|
|
else: # Broadcast
|
2014-05-01 02:29:04 +02:00
|
|
|
if recv == "":
|
2016-06-30 12:28:17 +02:00
|
|
|
set_background_title(d, "Empty sender error")
|
|
|
|
scrollbox(d, unicode("You must specify an address to send the message from."))
|
2014-04-29 07:10:33 +02:00
|
|
|
else:
|
2017-09-30 11:19:44 +02:00
|
|
|
# dummy ackdata, no need for stealth
|
2019-09-23 11:42:40 +02:00
|
|
|
ackdata = genAckPayload(decodeAddress(addr)[2], 0)
|
2014-05-01 02:29:04 +02:00
|
|
|
recv = BROADCAST_STR
|
2020-11-09 16:15:28 +01:00
|
|
|
helper_sent.insert(
|
2020-11-11 22:19:14 +01:00
|
|
|
msgid='', toAddress=recv, fromAddress=sender, subject=subject,
|
|
|
|
message=body, ackdata=ackdata, status='broadcastqueued')
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.workerQueue.put(('sendbroadcast', ''))
|
2014-04-29 07:10:33 +02:00
|
|
|
|
2019-09-23 11:42:40 +02:00
|
|
|
|
|
|
|
# pylint: disable=redefined-outer-name, too-many-locals
|
2014-04-29 07:10:33 +02:00
|
|
|
def loadInbox():
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Load the list of messages"""
|
2014-04-29 07:10:33 +02:00
|
|
|
sys.stdout = sys.__stdout__
|
2019-09-23 11:42:40 +02:00
|
|
|
print "Loading inbox messages..."
|
2014-04-29 07:10:33 +02:00
|
|
|
sys.stdout = printlog
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-29 07:10:33 +02:00
|
|
|
where = "toaddress || fromaddress || subject || message"
|
|
|
|
what = "%%"
|
|
|
|
ret = sqlQuery("""SELECT msgid, toaddress, fromaddress, subject, received, read
|
|
|
|
FROM inbox WHERE folder='inbox' AND %s LIKE ?
|
|
|
|
ORDER BY received
|
|
|
|
""" % (where,), what)
|
|
|
|
for row in ret:
|
|
|
|
msgid, toaddr, fromaddr, subject, received, read = row
|
|
|
|
subject = ascii(shared.fixPotentiallyInvalidUTF8Data(subject))
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-29 07:10:33 +02:00
|
|
|
# Set label for to address
|
|
|
|
try:
|
|
|
|
if toaddr == BROADCAST_STR:
|
|
|
|
tolabel = BROADCAST_STR
|
|
|
|
else:
|
2017-01-11 14:27:19 +01:00
|
|
|
tolabel = BMConfigParser().get(toaddr, "label")
|
2014-04-29 07:10:33 +02:00
|
|
|
except:
|
|
|
|
tolabel = ""
|
|
|
|
if tolabel == "":
|
|
|
|
tolabel = toaddr
|
|
|
|
tolabel = shared.fixPotentiallyInvalidUTF8Data(tolabel)
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-29 07:10:33 +02:00
|
|
|
# Set label for from address
|
|
|
|
fromlabel = ""
|
2017-01-11 14:27:19 +01:00
|
|
|
if BMConfigParser().has_section(fromaddr):
|
|
|
|
fromlabel = BMConfigParser().get(fromaddr, "label")
|
2019-12-27 15:12:57 +01:00
|
|
|
if fromlabel == "": # Check Address Book
|
2014-04-29 07:10:33 +02:00
|
|
|
qr = sqlQuery("SELECT label FROM addressbook WHERE address=?", fromaddr)
|
|
|
|
if qr != []:
|
|
|
|
for r in qr:
|
|
|
|
fromlabel, = r
|
2019-12-27 15:12:57 +01:00
|
|
|
if fromlabel == "": # Check Subscriptions
|
2014-04-29 07:10:33 +02:00
|
|
|
qr = sqlQuery("SELECT label FROM subscriptions WHERE address=?", fromaddr)
|
|
|
|
if qr != []:
|
|
|
|
for r in qr:
|
|
|
|
fromlabel, = r
|
|
|
|
if fromlabel == "":
|
|
|
|
fromlabel = fromaddr
|
|
|
|
fromlabel = shared.fixPotentiallyInvalidUTF8Data(fromlabel)
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-29 07:10:33 +02:00
|
|
|
# Load into array
|
2019-09-23 11:42:40 +02:00
|
|
|
inbox.append([msgid, tolabel, toaddr, fromlabel, fromaddr, subject, l10n.formatTimestamp(
|
|
|
|
received, False), read])
|
2014-04-29 07:10:33 +02:00
|
|
|
inbox.reverse()
|
2019-09-23 11:42:40 +02:00
|
|
|
|
|
|
|
|
2014-04-30 04:45:41 +02:00
|
|
|
def loadSent():
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Load the messages that sent"""
|
2014-04-30 04:45:41 +02:00
|
|
|
sys.stdout = sys.__stdout__
|
2019-09-23 11:42:40 +02:00
|
|
|
print "Loading sent messages..."
|
2014-04-30 04:45:41 +02:00
|
|
|
sys.stdout = printlog
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-30 04:45:41 +02:00
|
|
|
where = "toaddress || fromaddress || subject || message"
|
|
|
|
what = "%%"
|
|
|
|
ret = sqlQuery("""SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime
|
|
|
|
FROM sent WHERE folder='sent' AND %s LIKE ?
|
|
|
|
ORDER BY lastactiontime
|
|
|
|
""" % (where,), what)
|
|
|
|
for row in ret:
|
|
|
|
toaddr, fromaddr, subject, status, ackdata, lastactiontime = row
|
|
|
|
subject = ascii(shared.fixPotentiallyInvalidUTF8Data(subject))
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-30 04:45:41 +02:00
|
|
|
# Set label for to address
|
|
|
|
tolabel = ""
|
|
|
|
qr = sqlQuery("SELECT label FROM addressbook WHERE address=?", toaddr)
|
|
|
|
if qr != []:
|
|
|
|
for r in qr:
|
|
|
|
tolabel, = r
|
|
|
|
if tolabel == "":
|
|
|
|
qr = sqlQuery("SELECT label FROM subscriptions WHERE address=?", toaddr)
|
|
|
|
if qr != []:
|
|
|
|
for r in qr:
|
|
|
|
tolabel, = r
|
|
|
|
if tolabel == "":
|
2017-01-11 14:27:19 +01:00
|
|
|
if BMConfigParser().has_section(toaddr):
|
|
|
|
tolabel = BMConfigParser().get(toaddr, "label")
|
2014-04-30 04:45:41 +02:00
|
|
|
if tolabel == "":
|
|
|
|
tolabel = toaddr
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-30 04:45:41 +02:00
|
|
|
# Set label for from address
|
|
|
|
fromlabel = ""
|
2017-01-11 14:27:19 +01:00
|
|
|
if BMConfigParser().has_section(fromaddr):
|
|
|
|
fromlabel = BMConfigParser().get(fromaddr, "label")
|
2014-04-30 04:45:41 +02:00
|
|
|
if fromlabel == "":
|
|
|
|
fromlabel = fromaddr
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-30 04:45:41 +02:00
|
|
|
# Set status string
|
|
|
|
if status == "awaitingpubkey":
|
|
|
|
statstr = "Waiting for their public key. Will request it again soon"
|
|
|
|
elif status == "doingpowforpubkey":
|
|
|
|
statstr = "Encryption key request queued"
|
|
|
|
elif status == "msgqueued":
|
|
|
|
statstr = "Message queued"
|
|
|
|
elif status == "msgsent":
|
2014-08-06 04:01:01 +02:00
|
|
|
t = l10n.formatTimestamp(lastactiontime, False)
|
2019-09-23 11:42:40 +02:00
|
|
|
statstr = "Message sent at " + t + ".Waiting for acknowledgement."
|
2014-04-30 04:45:41 +02:00
|
|
|
elif status == "msgsentnoackexpected":
|
2014-08-06 04:01:01 +02:00
|
|
|
t = l10n.formatTimestamp(lastactiontime, False)
|
2019-09-23 11:42:40 +02:00
|
|
|
statstr = "Message sent at " + t + "."
|
2014-04-30 04:45:41 +02:00
|
|
|
elif status == "doingmsgpow":
|
|
|
|
statstr = "The proof of work required to send the message has been queued."
|
2017-06-10 10:07:47 +02:00
|
|
|
elif status == "ackreceived":
|
2014-08-06 04:01:01 +02:00
|
|
|
t = l10n.formatTimestamp(lastactiontime, False)
|
2019-09-23 11:42:40 +02:00
|
|
|
statstr = "Acknowledgment of the message received at " + t + "."
|
2014-04-30 04:45:41 +02:00
|
|
|
elif status == "broadcastqueued":
|
|
|
|
statstr = "Broadcast queued."
|
|
|
|
elif status == "broadcastsent":
|
2014-08-06 04:01:01 +02:00
|
|
|
t = l10n.formatTimestamp(lastactiontime, False)
|
2019-09-23 11:42:40 +02:00
|
|
|
statstr = "Broadcast sent at " + t + "."
|
2014-04-30 04:45:41 +02:00
|
|
|
elif status == "forcepow":
|
|
|
|
statstr = "Forced difficulty override. Message will start sending soon."
|
|
|
|
elif status == "badkey":
|
|
|
|
statstr = "Warning: Could not encrypt message because the recipient's encryption key is no good."
|
|
|
|
elif status == "toodifficult":
|
|
|
|
statstr = "Error: The work demanded by the recipient is more difficult than you are willing to do."
|
|
|
|
else:
|
2014-08-06 04:01:01 +02:00
|
|
|
t = l10n.formatTimestamp(lastactiontime, False)
|
2019-09-23 11:42:40 +02:00
|
|
|
statstr = "Unknown status " + status + " at " + t + "."
|
|
|
|
|
2014-04-30 04:45:41 +02:00
|
|
|
# Load into array
|
2019-09-23 11:42:40 +02:00
|
|
|
sentbox.append([
|
|
|
|
tolabel,
|
|
|
|
toaddr,
|
|
|
|
fromlabel,
|
|
|
|
fromaddr,
|
|
|
|
subject,
|
|
|
|
statstr,
|
|
|
|
ackdata,
|
2014-08-06 04:01:01 +02:00
|
|
|
l10n.formatTimestamp(lastactiontime, False)])
|
2014-04-30 04:45:41 +02:00
|
|
|
sentbox.reverse()
|
2019-09-23 11:42:40 +02:00
|
|
|
|
|
|
|
|
2014-04-29 07:10:33 +02:00
|
|
|
def loadAddrBook():
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Load address book"""
|
2014-04-29 07:10:33 +02:00
|
|
|
sys.stdout = sys.__stdout__
|
2019-09-23 11:42:40 +02:00
|
|
|
print "Loading address book..."
|
2014-04-29 07:10:33 +02:00
|
|
|
sys.stdout = printlog
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-29 07:10:33 +02:00
|
|
|
ret = sqlQuery("SELECT label, address FROM addressbook")
|
|
|
|
for row in ret:
|
|
|
|
label, addr = row
|
|
|
|
label = shared.fixPotentiallyInvalidUTF8Data(label)
|
|
|
|
addrbook.append([label, addr])
|
|
|
|
addrbook.reverse()
|
2019-09-23 11:42:40 +02:00
|
|
|
|
|
|
|
|
2014-04-30 04:45:41 +02:00
|
|
|
def loadSubscriptions():
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Load subscription functionality"""
|
2014-04-30 04:45:41 +02:00
|
|
|
ret = sqlQuery("SELECT label, address, enabled FROM subscriptions")
|
|
|
|
for row in ret:
|
|
|
|
label, address, enabled = row
|
|
|
|
subscriptions.append([label, address, enabled])
|
|
|
|
subscriptions.reverse()
|
2019-09-23 11:42:40 +02:00
|
|
|
|
|
|
|
|
2014-04-30 04:45:41 +02:00
|
|
|
def loadBlackWhiteList():
|
2019-09-23 11:42:40 +02:00
|
|
|
"""load black/white list"""
|
2019-12-27 15:12:57 +01:00
|
|
|
global bwtype
|
2017-01-11 14:27:19 +01:00
|
|
|
bwtype = BMConfigParser().get("bitmessagesettings", "blackwhitelist")
|
2014-04-30 04:45:41 +02:00
|
|
|
if bwtype == "black":
|
|
|
|
ret = sqlQuery("SELECT label, address, enabled FROM blacklist")
|
|
|
|
else:
|
|
|
|
ret = sqlQuery("SELECT label, address, enabled FROM whitelist")
|
|
|
|
for row in ret:
|
|
|
|
label, address, enabled = row
|
|
|
|
blacklist.append([label, address, enabled])
|
|
|
|
blacklist.reverse()
|
2014-04-18 07:48:42 +02:00
|
|
|
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-18 07:48:42 +02:00
|
|
|
def runwrapper():
|
2019-12-27 15:12:57 +01:00
|
|
|
"""Main method"""
|
2014-04-18 07:48:42 +02:00
|
|
|
sys.stdout = printlog
|
2019-09-23 11:42:40 +02:00
|
|
|
# sys.stderr = errlog
|
|
|
|
|
2014-04-29 07:10:33 +02:00
|
|
|
loadInbox()
|
2014-04-30 04:45:41 +02:00
|
|
|
loadSent()
|
2014-04-29 07:10:33 +02:00
|
|
|
loadAddrBook()
|
2014-04-30 04:45:41 +02:00
|
|
|
loadSubscriptions()
|
|
|
|
loadBlackWhiteList()
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-18 07:48:42 +02:00
|
|
|
stdscr = curses.initscr()
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2019-12-27 15:12:57 +01:00
|
|
|
global logpad
|
2014-04-19 20:45:37 +02:00
|
|
|
logpad = curses.newpad(1024, curses.COLS)
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-29 07:10:33 +02:00
|
|
|
stdscr.nodelay(0)
|
2014-04-18 07:48:42 +02:00
|
|
|
curses.curs_set(0)
|
2014-04-29 07:10:33 +02:00
|
|
|
stdscr.timeout(1000)
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-18 07:48:42 +02:00
|
|
|
curses.wrapper(run)
|
2017-02-08 14:19:02 +01:00
|
|
|
doShutdown()
|
2014-04-18 07:48:42 +02:00
|
|
|
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-18 07:48:42 +02:00
|
|
|
def run(stdscr):
|
2019-12-27 15:12:57 +01:00
|
|
|
"""Main loop"""
|
2014-04-19 20:45:37 +02:00
|
|
|
# Schedule inventory lookup data
|
|
|
|
resetlookups()
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-19 20:45:37 +02:00
|
|
|
# Init color pairs
|
2014-04-18 07:48:42 +02:00
|
|
|
if curses.has_colors():
|
2019-12-27 15:12:57 +01:00
|
|
|
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) # red
|
|
|
|
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) # green
|
|
|
|
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK) # yellow
|
|
|
|
curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_BLACK) # blue
|
|
|
|
curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK) # magenta
|
|
|
|
curses.init_pair(6, curses.COLOR_CYAN, curses.COLOR_BLACK) # cyan
|
|
|
|
curses.init_pair(7, curses.COLOR_WHITE, curses.COLOR_BLACK) # white
|
2014-04-18 07:48:42 +02:00
|
|
|
if curses.can_change_color():
|
2019-12-27 15:12:57 +01:00
|
|
|
curses.init_color(8, 500, 500, 500) # gray
|
2014-04-18 07:48:42 +02:00
|
|
|
curses.init_pair(8, 8, 0)
|
2019-12-27 15:12:57 +01:00
|
|
|
curses.init_color(9, 844, 465, 0) # orange
|
2014-04-18 07:48:42 +02:00
|
|
|
curses.init_pair(9, 9, 0)
|
2014-04-19 20:45:37 +02:00
|
|
|
else:
|
2019-12-27 15:12:57 +01:00
|
|
|
curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_BLACK) # grayish
|
|
|
|
curses.init_pair(9, curses.COLOR_YELLOW, curses.COLOR_BLACK) # orangish
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-19 20:45:37 +02:00
|
|
|
# Init list of address in 'Your Identities' tab
|
2018-05-02 18:24:11 +02:00
|
|
|
configSections = BMConfigParser().addresses()
|
2014-04-18 07:48:42 +02:00
|
|
|
for addressInKeysFile in configSections:
|
2017-05-15 12:18:07 +02:00
|
|
|
isEnabled = BMConfigParser().getboolean(addressInKeysFile, "enabled")
|
|
|
|
addresses.append([BMConfigParser().get(addressInKeysFile, "label"), isEnabled, addressInKeysFile])
|
|
|
|
# Set address color
|
|
|
|
if not isEnabled:
|
2019-12-27 15:12:57 +01:00
|
|
|
addresses[len(addresses) - 1].append(8) # gray
|
2017-05-15 12:18:07 +02:00
|
|
|
elif BMConfigParser().safeGetBoolean(addressInKeysFile, 'chan'):
|
2019-12-27 15:12:57 +01:00
|
|
|
addresses[len(addresses) - 1].append(9) # orange
|
2017-05-15 12:18:07 +02:00
|
|
|
elif BMConfigParser().safeGetBoolean(addressInKeysFile, 'mailinglist'):
|
2019-12-27 15:12:57 +01:00
|
|
|
addresses[len(addresses) - 1].append(5) # magenta
|
2017-05-15 12:18:07 +02:00
|
|
|
else:
|
2019-12-27 15:12:57 +01:00
|
|
|
addresses[len(addresses) - 1].append(0) # black
|
2014-04-19 20:45:37 +02:00
|
|
|
addresses.reverse()
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2014-04-29 07:10:33 +02:00
|
|
|
stdscr.clear()
|
2014-04-18 07:48:42 +02:00
|
|
|
redraw(stdscr)
|
2019-12-27 15:12:57 +01:00
|
|
|
while quit_ is False:
|
2014-04-18 07:48:42 +02:00
|
|
|
drawtab(stdscr)
|
|
|
|
handlech(stdscr.getch(), stdscr)
|
|
|
|
|
2019-09-23 11:42:40 +02:00
|
|
|
|
2017-02-08 14:19:02 +01:00
|
|
|
def doShutdown():
|
2019-09-23 11:42:40 +02:00
|
|
|
"""Shutting the app down"""
|
2014-04-18 07:48:42 +02:00
|
|
|
sys.stdout = sys.__stdout__
|
2019-09-23 11:42:40 +02:00
|
|
|
print "Shutting down..."
|
2014-04-18 07:48:42 +02:00
|
|
|
sys.stdout = printlog
|
2017-02-08 13:41:56 +01:00
|
|
|
shutdown.doCleanShutdown()
|
2014-04-18 07:48:42 +02:00
|
|
|
sys.stdout = sys.__stdout__
|
2014-04-19 20:45:37 +02:00
|
|
|
sys.stderr = sys.__stderr__
|
2019-12-27 15:12:57 +01:00
|
|
|
os._exit(0) # pylint: disable=protected-access
|