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
2014-04-19 20:45:37 +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
import os
import sys
import StringIO
2014-05-01 02:03:12 +02:00
from textwrap import *
2014-04-18 07:48:42 +02:00
2014-04-19 20:45:37 +02:00
import time
from time import strftime , localtime
from threading import Timer
import curses
import dialog
from dialog import Dialog
2014-04-29 07:10:33 +02:00
from helper_sql import *
2017-09-30 11:19:44 +02:00
from helper_ackPayload import genAckPayload
2014-04-19 20:45:37 +02:00
2017-02-08 13:41:56 +01:00
from addresses import *
2017-01-11 17:00:00 +01:00
import ConfigParser
2017-02-22 09:34:54 +01:00
from bmconfigparser import BMConfigParser
2017-01-10 21:15:35 +01:00
from inventory import Inventory
2017-02-08 13:41:56 +01:00
import l10n
from pyelliptic . openssl import OpenSSL
import queues
import shared
import shutdown
2018-11-01 15:28:42 +01:00
import network . stats
2014-04-18 07:48:42 +02:00
quit = False
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
class printLog :
def write ( self , output ) :
global log
log + = output
2014-04-19 20:45:37 +02:00
def flush ( self ) :
pass
class errLog :
def write ( self , output ) :
global log
log + = " ! " + output
def flush ( self ) :
pass
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 ) :
r = curses . color_pair ( a )
if r not in range ( 1 , curses . COLOR_PAIRS - 1 ) :
r = curses . color_pair ( 0 )
return r
2014-04-29 07:10:33 +02:00
def ascii ( s ) :
r = " "
for c in s :
if ord ( c ) in range ( 128 ) :
r + = c
return r
2014-04-18 07:48:42 +02:00
def drawmenu ( stdscr ) :
menustr = " "
for i in range ( 0 , len ( menu ) ) :
if menutab == i + 1 :
menustr = menustr [ : - 1 ]
menustr + = " [ "
menustr + = str ( i + 1 ) + menu [ i ]
if menutab == i + 1 :
menustr + = " ] "
elif i != len ( menu ) - 1 :
menustr + = " "
stdscr . addstr ( 2 , 5 , menustr , curses . A_UNDERLINE )
2016-06-30 12:28:17 +02:00
def set_background_title ( d , title ) :
try :
d . set_background_title ( title )
except :
d . add_persistent_args ( ( " --backtitle " , title ) )
def scrollbox ( d , text , height = None , width = None ) :
try :
d . scrollbox ( text , height , width , exit_label = " Continue " )
except :
d . msgbox ( text , height or 0 , width or 0 , ok_label = " Continue " )
2014-04-19 20:45:37 +02:00
def resetlookups ( ) :
2014-04-29 07:10:33 +02: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 ( )
2014-04-18 07:48:42 +02:00
def drawtab ( stdscr ) :
2014-04-19 20:45:37 +02:00
if menutab in range ( 1 , len ( menu ) + 1 ) :
2014-04-18 07:48:42 +02:00
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 )
2014-04-29 07:10:33 +02:00
for i , item in enumerate ( inbox [ max ( min ( len ( inbox ) - curses . LINES + 6 , inboxcur - 5 ) , 0 ) : ] ) :
if 6 + i < curses . LINES :
a = 0
if i == inboxcur - max ( min ( len ( inbox ) - curses . LINES + 6 , inboxcur - 5 ) , 0 ) : # Highlight current address
a = a | curses . A_REVERSE
if item [ 7 ] == False : # If not read, highlight
a = a | curses . A_BOLD
2014-04-30 04:45:41 +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 )
2014-04-19 20:45:37 +02:00
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 )
for i , item in enumerate ( sentbox [ max ( min ( len ( sentbox ) - curses . LINES + 6 , sentcur - 5 ) , 0 ) : ] ) :
if 6 + i < curses . LINES :
a = 0
if i == sentcur - max ( min ( len ( sentbox ) - curses . LINES + 6 , sentcur - 5 ) , 0 ) : # Highlight current address
a = a | curses . A_REVERSE
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 )
2014-04-29 07:10:33 +02:00
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 )
2014-04-29 07:10:33 +02:00
for i , item in enumerate ( addresses [ max ( min ( len ( addresses ) - curses . LINES + 6 , addrcur - 5 ) , 0 ) : ] ) :
2014-04-30 04:45:41 +02:00
if 6 + i < curses . LINES :
a = 0
if i == addrcur - max ( min ( len ( addresses ) - curses . LINES + 6 , addrcur - 5 ) , 0 ) : # Highlight current address
a = a | curses . A_REVERSE
if item [ 1 ] == True and item [ 3 ] not in [ 8 , 9 ] : # Embolden enabled, non-special addresses
a = a | curses . A_BOLD
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 )
2014-04-19 20:45:37 +02:00
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 )
for i , item in enumerate ( subscriptions [ max ( min ( len ( subscriptions ) - curses . LINES + 6 , subcur - 5 ) , 0 ) : ] ) :
if 6 + i < curses . LINES :
a = 0
if i == subcur - max ( min ( len ( subscriptions ) - curses . LINES + 6 , subcur - 5 ) , 0 ) : # Highlight current address
a = a | curses . A_REVERSE
if item [ 2 ] == True : # Embolden enabled subscriptions
a = a | curses . A_BOLD
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 )
2014-04-19 20:45:37 +02:00
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 )
2014-04-29 07:10:33 +02:00
for i , item in enumerate ( addrbook [ max ( min ( len ( addrbook ) - curses . LINES + 6 , abookcur - 5 ) , 0 ) : ] ) :
2014-04-30 04:45:41 +02:00
if 6 + i < curses . LINES :
a = 0
if i == abookcur - max ( min ( len ( addrbook ) - curses . LINES + 6 , abookcur - 5 ) , 0 ) : # Highlight current address
a = a | curses . A_REVERSE
stdscr . addstr ( 5 + i , 5 , item [ 0 ] [ : 34 ] , a )
stdscr . addstr ( 5 + i , 40 , item [ 1 ] [ : 39 ] , a )
2014-04-19 20:45:37 +02:00
elif menutab == 7 : # Blacklist
2014-04-30 04:45:41 +02:00
stdscr . addstr ( 3 , 5 , " Type: " + bwtype )
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 )
for i , item in enumerate ( blacklist [ max ( min ( len ( blacklist ) - curses . LINES + 6 , blackcur - 5 ) , 0 ) : ] ) :
if 7 + i < curses . LINES :
a = 0
if i == blackcur - max ( min ( len ( blacklist ) - curses . LINES + 6 , blackcur - 5 ) , 0 ) : # Highlight current address
a = a | curses . A_REVERSE
if item [ 2 ] == True : # Embolden enabled subscriptions
a = a | curses . A_BOLD
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 )
2014-04-19 20:45:37 +02:00
elif menutab == 8 : # Network status
# 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 :
2014-04-19 20:57:08 +02:00
stdscr . addstr ( 8 + i , 6 , " ? " )
2014-04-19 20:45:37 +02:00
else :
2014-04-19 20:57:08 +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
2014-08-06 04:01:01 +02:00
stdscr . addstr ( 6 , 35 , " Since startup on " + l10n . formatTimestamp ( startuptime , False ) )
2014-04-19 20:45:37 +02:00
stdscr . addstr ( 7 , 40 , " Processed " + str ( shared . numberOfMessagesProcessed ) . ljust ( 4 ) + " person-to-person messages. " )
stdscr . addstr ( 8 , 40 , " Processed " + str ( shared . numberOfBroadcastsProcessed ) . ljust ( 4 ) + " broadcast messages. " )
stdscr . addstr ( 9 , 40 , " Processed " + str ( shared . numberOfPubkeysProcessed ) . ljust ( 4 ) + " public keys. " )
# Inventory data
2014-04-29 07:10:33 +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 :
l = log . split ( ' \n ' )
if n > 512 :
del l [ : ( n - 256 ) ]
logpad . erase ( )
n = len ( l )
for i , item in enumerate ( l ) :
a = 0
if len ( item ) > 0 and item [ 0 ] == ' ! ' :
a = curses . color_pair ( 1 )
item = item [ 1 : ]
logpad . addstr ( i , 0 , item , a )
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 ( )
def redraw ( stdscr ) :
stdscr . erase ( )
stdscr . border ( )
drawmenu ( stdscr )
stdscr . refresh ( )
2014-04-19 20:45:37 +02:00
def dialogreset ( stdscr ) :
stdscr . clear ( )
stdscr . keypad ( 1 )
curses . curs_set ( 0 )
2014-04-18 07:48:42 +02:00
def handlech ( c , stdscr ) :
if c != curses . ERR :
2014-05-01 02:03:12 +02:00
global inboxcur , addrcur , sentcur , subcur , abookcur , blackcur
2014-04-18 07:48:42 +02:00
if c in range ( 256 ) :
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 ' :
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 " )
2014-04-29 07:10:33 +02:00
r , t = d . menu ( " Do what with \" " + inbox [ inboxcur ] [ 5 ] + " \" from \" " + inbox [ inboxcur ] [ 3 ] + " \" ? " ,
choices = [ ( " 1 " , " View message " ) ,
( " 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 :
if t == " 1 " : # View
2016-06-30 12:28:17 +02:00
set_background_title ( d , " \" " + inbox [ inboxcur ] [ 5 ] + " \" from \" " + inbox [ inboxcur ] [ 3 ] + " \" to \" " + inbox [ inboxcur ] [ 1 ] + " \" " )
2014-05-01 02:03:12 +02:00
data = " "
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 " ) ) :
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. " ) )
2014-04-29 07:10:33 +02:00
elif t == " 2 " : # Mark unread
sqlExecute ( " UPDATE inbox SET read=0 WHERE msgid=? " , inbox [ inboxcur ] [ 0 ] )
inbox [ inboxcur ] [ 7 ] = 0
elif t == " 3 " : # Reply
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
if not addresses [ i ] [ 1 ] :
2016-06-30 12:28:17 +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
subject = m [ 5 ]
if not m [ 5 ] [ : 4 ] == " Re: " :
subject = " Re: " + m [ 5 ]
body = " "
ret = sqlQuery ( " SELECT message FROM inbox WHERE msgid=? " , m [ 0 ] )
if ret != [ ] :
body = " \n \n ------------------------------------------------------ \n "
for row in ret :
body , = row
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 )
elif t == " 4 " : # Add to Address Book
addr = inbox [ inboxcur ] [ 4 ]
2014-04-30 04:45:41 +02:00
if addr not in [ item [ 1 ] for i , item in enumerate ( addrbook ) ] :
2014-04-29 07:10:33 +02:00
r , t = d . inputbox ( " Label for address \" " + addr + " \" " )
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. " ) )
2014-04-29 07:10:33 +02:00
elif t == " 5 " : # Save message
2016-06-30 12:28:17 +02:00
set_background_title ( d , " Save \" " + inbox [ inboxcur ] [ 5 ] + " \" as text file " )
2014-04-29 07:10:33 +02:00
r , t = d . inputbox ( " Filename " , init = inbox [ inboxcur ] [ 5 ] + " .txt " )
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
fh = open ( t , " a " ) # Open in append mode just in case
fh . write ( msg )
fh . close ( )
else :
2016-06-30 12:28:17 +02:00
scrollbox ( d , unicode ( " Could not fetch message. " ) )
2014-04-29 07:10:33 +02:00
elif t == " 6 " : # Move to trash
sqlExecute ( " UPDATE inbox SET folder= ' trash ' WHERE msgid=? " , inbox [ inboxcur ] [ 0 ] )
del inbox [ inboxcur ]
2016-06-30 12:28:17 +02:00
scrollbox ( d , unicode ( " Message moved to trash. There is no interface to view your trash, \n but 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 = " "
if addresses [ addrcur ] [ 3 ] != 0 : # if current address is a chan
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 " )
2014-04-30 04:45:41 +02:00
r , t = d . menu ( " Do what with \" " + sentbox [ sentcur ] [ 4 ] + " \" to \" " + sentbox [ sentcur ] [ 0 ] + " \" ? " ,
choices = [ ( " 1 " , " View message " ) ,
( " 2 " , " Move to trash " ) ] )
if r == d . DIALOG_OK :
if t == " 1 " : # View
2016-06-30 12:28:17 +02:00
set_background_title ( d , " \" " + sentbox [ sentcur ] [ 4 ] + " \" from \" " + sentbox [ sentcur ] [ 3 ] + " \" to \" " + sentbox [ sentcur ] [ 1 ] + " \" " )
2014-05-01 02:03:12 +02:00
data = " "
2014-04-30 04:45:41 +02:00
ret = sqlQuery ( " SELECT message FROM sent WHERE subject=? AND ackdata=? " , sentbox [ sentcur ] [ 4 ] , sentbox [ sentcur ] [ 6 ] )
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 " ) ) :
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. " ) )
2014-04-30 04:45:41 +02:00
elif t == " 2 " : # Move to trash
sqlExecute ( " UPDATE sent SET folder= ' trash ' WHERE subject=? AND ackdata=? " , sentbox [ sentcur ] [ 4 ] , sentbox [ sentcur ] [ 6 ] )
del sentbox [ sentcur ]
2016-06-30 12:28:17 +02:00
scrollbox ( d , unicode ( " Message moved to trash. There is no interface to view your trash, \n but 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 :
r , t = d . menu ( " Do what with addresses? " ,
choices = [ ( " 1 " , " Create new address " ) ] )
else :
r , t = d . menu ( " Do what with \" " + addresses [ addrcur ] [ 0 ] + " \" : \" " + addresses [ addrcur ] [ 2 ] + " \" ? " ,
choices = [ ( " 1 " , " Create new address " ) ,
( " 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 :
if t == " 1 " : # Create new address
2016-06-30 12:28:17 +02:00
set_background_title ( d , " Create new address " )
scrollbox ( d , unicode ( " Here you may generate as many addresses as you like. \n "
2014-04-19 20:45:37 +02:00
" Indeed, creating and abandoning addresses is encouraged. \n "
" Deterministic addresses have several pros and cons: \n "
" \n Pros: \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 "
2016-06-30 12:28:17 +02:00
" * If you choose a weak passphrase someone may be able to brute-force it \n and then send and receive messages as you " ) )
2014-04-19 20:45:37 +02:00
r , t = d . menu ( " Choose an address generation technique " ,
choices = [ ( " 1 " , " Use a random number generator " ) ,
( " 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 = " "
if r == d . DIALOG_OK and len ( t ) > 0 :
label = t
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) " ) ] )
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
r , t = d . checklist ( " Miscellaneous options " ,
2016-06-30 12:28:17 +02:00
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
2017-02-08 13:41:56 +01: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 " )
2014-04-19 20:45:37 +02:00
r , t = d . passwordform ( " Enter passphrase " ,
[ ( " Passphrase " , 1 , 1 , " " , 2 , 1 , 64 , 128 ) ,
( " Confirm passphrase " , 3 , 1 , " " , 4 , 1 , 64 , 128 ) ] ,
form_height = 4 , insecure = True )
if r == d . DIALOG_OK :
if t [ 0 ] == t [ 1 ] :
passphrase = t [ 0 ]
r , t = d . rangebox ( " Number of addresses to generate " ,
width = 48 , min = 1 , max = 99 , init = 8 )
if r == d . DIALOG_OK :
number = t
stream = 1
shorten = False
r , t = d . checklist ( " Miscellaneous options " ,
2016-06-30 12:28:17 +02:00
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
2016-06-30 12:28:17 +02:00
scrollbox ( d , unicode ( " In addition to your passphrase, be sure to remember the following numbers: \n "
2014-04-19 20:45:37 +02:00
" \n * Address version number: " + str ( 4 ) + " \n "
2016-06-30 12:28:17 +02:00
" * Stream number: " + str ( stream ) ) )
2017-02-08 13:41:56 +01:00
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 " ) )
2014-04-30 04:45:41 +02:00
elif t == " 2 " : # Send a message
2014-05-01 02:29:04 +02:00
a = " "
if addresses [ addrcur ] [ 3 ] != 0 : # if current address is a chan
a = addresses [ addrcur ] [ 2 ]
sendMessage ( addresses [ addrcur ] [ 2 ] , a )
2014-04-19 20:45:37 +02:00
elif t == " 3 " : # Rename address label
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
elif t == " 4 " : # Enable address
a = addresses [ addrcur ] [ 2 ]
2017-01-11 14:27:19 +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 ' ) :
2014-04-19 20:45:37 +02:00
addresses [ addrcur ] [ 3 ] = 9 # orange
2017-01-11 14:27:19 +01:00
elif BMConfigParser ( ) . safeGetBoolean ( a , ' mailinglist ' ) :
2014-04-19 20:45:37 +02:00
addresses [ addrcur ] [ 3 ] = 5 # magenta
else :
addresses [ addrcur ] [ 3 ] = 0 # black
addresses [ addrcur ] [ 1 ] = True
shared . reloadMyAddressHashes ( ) # Reload address hashes
elif t == " 5 " : # Disable address
a = addresses [ addrcur ] [ 2 ]
2017-01-11 14:27:19 +01:00
BMConfigParser ( ) . set ( a , " enabled " , " false " ) # Set config
2014-04-19 20:45:37 +02:00
addresses [ addrcur ] [ 3 ] = 8 # Set color to gray
# Write config
2017-01-15 10:50:02 +01:00
BMConfigParser ( ) . save ( )
2014-04-19 20:45:37 +02:00
addresses [ addrcur ] [ 1 ] = False
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 " :
2017-01-11 14:27:19 +01:00
BMConfigParser ( ) . remove_section ( addresses [ addrcur ] [ 2 ] )
2017-01-15 10:50:02 +01:00
BMConfigParser ( ) . save ( )
2014-04-30 04:45:41 +02:00
del addresses [ addrcur ]
2014-04-19 20:45:37 +02:00
elif t == " 7 " : # Special address behavior
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 " ) :
2016-06-30 12:28:17 +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 " )
2014-04-19 20:45:37 +02:00
r , t = d . radiolist ( " Select address behavior " ,
2014-04-29 07:10:33 +02:00
choices = [ ( " 1 " , " Behave as a normal address " , not m ) ,
( " 2 " , " Behave as a pseudo-mailing-list address " , m ) ] )
2014-04-19 20:45:37 +02:00
if r == d . DIALOG_OK :
if t == " 1 " and m == True :
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 ] :
addresses [ addrcur ] [ 3 ] = 0 # Set color to black
else :
addresses [ addrcur ] [ 3 ] = 8 # Set color to gray
elif t == " 2 " and m == False :
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 :
mn = " "
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 )
2014-04-19 20:45:37 +02:00
addresses [ addrcur ] [ 3 ] = 6 # Set color to magenta
# 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 :
r , t = d . menu ( " Do what with subscription to \" " + subscriptions [ subcur ] [ 0 ] + " \" ? " ,
choices = [ ( " 1 " , " Add new subscription " ) ] )
else :
r , t = d . menu ( " Do what with subscription to \" " + subscriptions [ subcur ] [ 0 ] + " \" ? " ,
choices = [ ( " 1 " , " Add new subscription " ) ,
( " 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 " :
r , t = d . inpuxbox ( " Type in \" I want to delete this subscription \" " )
if r == d . DIALOG_OK and t == " I want to delete this subscription " :
sqlExecute ( " DELETE FROM subscriptions WHERE label=? AND address=? " , subscriptions [ subcur ] [ 0 ] , subscriptions [ subcur ] [ 1 ] )
shared . reloadBroadcastSendersForWhichImWatching ( )
del subscriptions [ subcur ]
elif t == " 3 " :
sqlExecute ( " UPDATE subscriptions SET enabled=1 WHERE label=? AND address=? " , subscriptions [ subcur ] [ 0 ] , subscriptions [ subcur ] [ 1 ] )
shared . reloadBroadcastSendersForWhichImWatching ( )
subscriptions [ subcur ] [ 2 ] = True
elif t == " 4 " :
sqlExecute ( " UPDATE subscriptions SET enabled=0 WHERE label=? AND address=? " , subscriptions [ subcur ] [ 0 ] , subscriptions [ subcur ] [ 1 ] )
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 :
r , t = d . menu ( " Do what with addressbook? " ,
choices = [ ( " 3 " , " Add new address to Address Book " ) ] )
else :
r , t = d . menu ( " Do what with \" " + addrbook [ abookcur ] [ 0 ] + " \" : \" " + addrbook [ abookcur ] [ 1 ] + " \" " ,
choices = [ ( " 1 " , " Send a message to this address " ) ,
( " 2 " , " Subscribe to this address " ) ,
( " 3 " , " Add new address to Address Book " ) ,
( " 4 " , " Delete this address " ) ] )
2014-04-30 04:45:41 +02:00