Compare commits

...

245 Commits

Author SHA1 Message Date
1c6d4702c0 Added flatpak build manifests with split dependencies 2021-04-27 20:37:46 +05:30
f5fba7d1a8
update changes and rename file name 2021-04-06 13:04:44 +05:30
f075d27fae
add dot in importing 2021-04-05 19:08:10 +05:30
1b8dc18ef6
remove functions imports 2021-04-05 18:28:26 +05:30
06cab993d9
Fix configparser import error 2021-04-01 21:06:22 +05:30
6f9b66ddff
Qt test for UDP setting 2021-03-01 19:55:48 +02:00
79efacffb1
Replaced lost UDPSocket.maxTimeOffset by constants.MAX_TIME_OFFSET
Closes: #1696
2021-03-01 19:55:47 +02:00
6ee6989df2
A minimal test for UDP. Restore expected default settings in tearDown(). 2021-03-01 19:55:30 +02:00
5f9d507717
announceInterval is for AnnounceThread, not UDPSocket 2021-02-22 19:56:24 +02:00
6168d63699
Replace formatting socket.error by exc_info in network.udp 2021-02-22 19:56:24 +02:00
8ff8e0e2cb
Make it possible to disable UDP announcing in settings 2021-02-22 19:56:23 +02:00
ef849d2dd3
Handle old psutil in TestProcess 2021-02-18 17:15:56 +02:00
d8cf148d4a
Replaced print operator by print function in network.asyncore_pollchoose
and unmaintained modules.
2021-02-18 17:15:56 +02:00
2fe2f17688
Don't run tests when build deb 2021-02-18 17:15:56 +02:00
671df69303
Work around deprecation of platform.dist() in recent python 2021-02-18 17:15:56 +02:00
81645eadef
Remove import from debug from openclpow, remove shebang, format 2021-02-18 17:15:56 +02:00
e77238fa07
Support tox and request more warnings:
- make separate tests runner - tests.py; python setup.py test still works
  - tox.ini with coverage config
  - -b: issue warnings about comparing bytearray with unicode
  - export PYTHONWARNINGS=all on stage install
2021-02-18 17:12:43 +02:00
0f8528cc48
Fix python3 issues in test_blindsig:
- simplify imports
 - signatures are of type bytes
 - chain kwarg of pyelliptic.ECCBlindChain is bytes
2021-02-18 17:12:42 +02:00
faed885c34
Fix python3 issues in test_crypto:
- use bytes for python3
 - encode the result of arithmetic.privtopub
 - add test for arithmetic.base10_multiply
2021-02-18 17:12:42 +02:00
5bd3bd4711
Make addresses module available for testing with python3:
- remove import from debug
 - use divmod and bytes
2021-02-18 17:12:42 +02:00
5976a449e2
test_randomtrackingdict: revert bytes to string for python3 2021-02-18 17:12:42 +02:00
da8bd36614
Fix python3 issues in pyelliptic:
- use dotted imports, remove unneeded shebangs
 - openssl._OpenSSL._version is of type bytes
 - use b'\x00' literal instead of chr(0) in eccblind and test_openssl
 - use // and divmod in arithmetic to fit PEP238:
   https://docs.python.org/3/whatsnew/2.2.html#pep-238-changing-the-division-operator
2021-02-18 17:11:36 +02:00
d05255625b
Universal pathmagic returns app dir; activated in setup for python3 2021-02-17 17:11:25 +02:00
f8844f4d74
Use common.skip_python3() to skip tests modules not supporting python3 2021-02-17 17:11:25 +02:00
b3c341951d
Add normal exit in depends if detected python3 2021-02-17 17:11:25 +02:00
6029ec85b6
Add python 3.7. Use general shebangs in scripts to test with python3;
Use 2.7_with_system_site_packages for python2 to run qt tests
as suggested in Travis doc instead of bypassing virtualenv by shebang.
2021-02-17 17:11:24 +02:00
574b60ed0e
Add Dockerfile for running test
- run ./run-tests-in-docker.sh to run travis tests locally
2021-02-16 10:15:15 +01:00
d35c284e13
Move desktop plugin initialization to updateStartOnLogon(); Fixes: #1735 2021-02-15 14:00:52 +02:00
c51108e867
Entry point 'desktop' for plugins managing desktop environment;
desktop_xdg will do it with pyxdg. Fixes: #857
2021-02-12 21:16:19 +02:00
74e039de5d
Added Network category in desktop file 2021-02-12 21:15:49 +02:00
2f5d6214ff
Move addressbook test to bitmessageqt.tests because it uses Qt 2021-02-11 17:07:48 +02:00
26057be6ff
A test for listening port 8444 2021-02-11 16:34:43 +02:00
5052602c21
Add test for BITMESSAGE_HOME 2021-02-11 16:34:38 +02:00
265fb932a8
Instruct git to use LF as line ending for knownnodes.dat test pattern 2021-02-10 16:01:30 +02:00
5b71bd1931
Format and simplify bitmessagemain.spec, exclude unused libs and files 2021-02-09 22:56:44 +02:00
d36e7615a9
remove kivy specification file along with component changes of version from upstream 2021-02-09 19:59:40 +05:30
navjot
f381721bec
remove TestProcessProto import from test_openclpow module 2021-02-04 14:37:26 +05:30
448e9e2f36
Prevent adding bootstrap servers to knownnodes when received in addr 2021-01-22 18:52:34 +02:00
3108115570
Shorten Bootstrapper methods:
handle_close() and set_connection_fully_established()
2021-01-22 18:52:34 +02:00
d6cab9935d
Try to find bootstrap server in knownnodes after bootstrapping 2021-01-22 18:52:34 +02:00
2ac4b1fece
A separate test for dontconnect setting 2021-01-22 18:52:33 +02:00
2b5f605857
Set close_reason for exceptions in network.tls 2021-01-22 18:52:33 +02:00
9540d5fabe
Fixing tor related tests:
- knownnodes.cleanupKnownNodes() should set knownNodesActual = False
   if there are no nodes in stream 1 (repeated bootstrapping)
 - set socksproxytype before _initiate_bootstrap()
 - wait 5 sec in _initiate_bootstrap() to be sure all connections are closed
 - plugins do not work on travis - use socksproxytype = SOCKS5,
   check tor presence by trying to bind on port 9050
 - successfull connection to 3 onion nodes in 6 minutes is not guaranteed -
   check that bitmessage doesn't try non-onion nodes
2021-01-22 18:52:33 +02:00
e9073d736a
Another possible approach for connection check 2021-01-22 18:52:33 +02:00
d9d1cdb5d8
A separate test for connection to bootstrap servers 2021-01-22 18:52:33 +02:00
navjot
7b8bf082ff
add Gpu skip condition and setupclass in test_openclpow module 2021-01-20 16:42:14 +05:30
navjot
1612f9c778
test case for openclpow module 2021-01-20 16:41:33 +05:30
navjot
9c5d329c90
replace print with logger and remove unused file 2021-01-18 23:31:45 +05:30
6ffb912f2a
detach kivy version from upstream 2021-01-16 23:11:19 +05:30
navjot
edc4660c6d
imported helper_addressGenerator module 2021-01-15 15:34:38 +05:30
navjot
bfdb78151c
updated addressbook table in class_sqlThread module 2021-01-14 15:43:30 +05:30
navjot
f146500b58
written test case for addressbook 2021-01-14 15:43:30 +05:30
navjot
42037502ab
fixed Own address should not save in address book issue
- removed redundant code

- written test case for address book own address saving

- fixed CQ issues

- added helper_addressbook module

- Fixed CQ issue of src.helper_addressbook module

- fixed travis-ci checks failing issue
2021-01-14 15:43:30 +05:30
navjot
09439b4a0d
added general exception handler 2021-01-13 20:29:20 +05:30
navjot
5fb8692eb6
ignoring ValueError from proofofwork module 2021-01-13 20:29:20 +05:30
navjot
ac23a397a1
added timer of less then 10 seconds 2021-01-13 14:14:26 +05:30
navjot
14a4f42fc0
remove qt dependency 2021-01-12 20:09:36 +05:30
navjot
16e9319d5f
add helper_addressGenerator module 2021-01-08 17:41:33 +05:30
813492291816
a0e1c0041f
Add missing TTL to API sendMessage 2021-01-07 19:51:12 -05:00
e084d7f53c
objectProcessor waits for sqlThread ready
- fixes #1702
2021-01-03 11:14:27 +01:00
184664d758
SQL operations asserts and code quality
- complain if trying to execute SQL statements without a running
  `.threads.sqlThread`. This is to give better test feedback if used
  incorrectly
- refactor `.helper_sql.sql_ready` as a `threading.Event`
- code quality
2021-01-01 17:54:05 +01:00
navjot
7a010441c3
Fixed flake8 CQ issues 2020-12-30 20:01:33 +05:30
navjot
46e2f04488
move randomtrackingdict.py out side the network dircetory 2020-12-29 13:12:22 +05:30
navjot
a2ab0a02dc
written test case randomtrackingdict dict module 2020-12-28 16:01:23 +05:30
navjot
9fe4ad0489
test case for testing old knownnodes pickle
-test case for testing old knownnodes pickle

-fixed CQ for tests.core module

-implemented shutil.copyfile feature and use small size knownnodes.dat file in test_pattern dir

-remove unnecessary code

-Fixed CQ of tests.core module
2020-12-21 22:50:38 +05:30
navjot
d2a340d012
implemented dependency checks in checkdeps module 2020-11-25 19:52:27 +05:30
navjot
9265235053
fixed network issue when it is set offline 2020-11-23 17:52:20 +05:30
navjot
124e6d9b32
fix for #1656 issue 2020-11-23 17:52:20 +05:30
navjot
1c304125e8
fixed CQ issues 2020-11-21 13:53:10 +05:30
navjot
4681d37377
validate address in insert method and improve test cases 2020-11-21 13:53:10 +05:30
navjot
360539b320
Fixed CQ of class_objectProcessor, bitmessagecurses and bitmessageqt module 2020-11-21 13:53:10 +05:30
navjot
61f7f32dfc
removed unused code and return ackdata from inset method insted of msgid 2020-11-21 13:53:10 +05:30
navjot
beaece254c
omitted unused code and optimized it 2020-11-21 13:53:10 +05:30
navjot
89254064f6
fixed default variables in insert method 2020-11-21 13:53:10 +05:30
navjot
5eff9d6a04
Fixed CQ for tests.core module 2020-11-21 13:53:10 +05:30
navjot
a9e9f25b5d
change helper_sent.insert methods 2020-11-21 13:53:10 +05:30
navjot
0ec15d1d4d
Test case for insert method default values 2020-11-21 13:53:10 +05:30
navjot
1bc3fe7b42
added checks in helper_sent module 2020-11-21 13:53:10 +05:30
navjot
b7d920d529
Fixed CQ for test/core.py module 2020-11-21 13:53:10 +05:30
navjot
0023fc4b3d
Written test case for helper_sent.insert method 2020-11-21 13:53:10 +05:30
navjot
e60d12ddbf
Refactord the uuid creation code and placed it in helper_sent.insert method
refactored on the bases of comments

Fixed CQ of src.helper_sent module

fixed CQ for helper_sent module
2020-11-21 13:53:10 +05:30
navjot
881351033f
replaced insert into sent query with helper_sent.insert method and also replaced empty msgid with uuid 2020-11-21 13:53:10 +05:30
813492291816
601158f6fb
add pendingDownload to return of API clientStatus 2020-11-21 01:00:11 +00:00
cb0710e454
Fix updateStatusBar wrong args order 2020-11-04 16:24:58 +02:00
caf3a3fbbc
A test for updateStatusBar command 2020-11-04 16:24:58 +02:00
695140d57d
Save exceptions in the main thread in excQueue 2020-11-04 16:24:52 +02:00
citizenaspirant
93bf7ad62c
Add apparmor config to data_files for Debian and Ubuntu 2020-11-04 15:47:46 +02:00
84b5f2982c
Allow running pybitmessage -t without tests package 2020-11-04 14:25:21 +02:00
8be89e9a25
Remove deb building overdocumentation 2020-11-04 14:25:21 +02:00
d3fbf17acf
Remove unmaintained debian package 2020-11-04 14:25:20 +02:00
d410cad4b6
stdeb config for building deb 2020-11-04 14:25:15 +02:00
db11d6331f
Optimize setUpClass() and tearDownClass() in test_process 2020-11-03 17:14:00 +02:00
96a784b58b
Merged PeterSurda/teardown-test1:
- reset BMConfigParser before reading config file
  - enable threads name check on posix systems
  - check singleton.lock in TestProcessProto.setUpClass()
2020-11-03 17:14:00 +02:00
b65f2d154a
Common basic cleanup procedure 2020-11-03 17:14:00 +02:00
1bcffd2853
Make TestLogger a subclass of TestProcessProto 2020-11-02 18:01:51 +02:00
cf4e812334
Allow TestProcess subclasses set home dir, use mkdtemp for test_config 2020-11-02 18:01:51 +02:00
affdb2fdc0
Solve problem with subprocess.call() on windows:
- uncomment console_scripts (only for windows) to get exe
 - replace call() with Popen() to avoid blocking
2020-11-02 18:01:50 +02:00
80831754b3
Fail in TestProcessProto.setUp if bitmessage process dies 2020-11-02 11:08:28 +02:00
navjot
6c5bb62123
replaced double quotes with Single quotes in class_singleWorker module 2020-10-31 13:07:51 +05:30
navjot
a7c1018f47
fixed CQ for src.class_singleWorker module 2020-10-31 13:07:51 +05:30
navjot
30044f7516
implemented filter query in sent table on the bases of folder= 'sent' 2020-10-31 13:07:51 +05:30
b650e97edc
Fix statuses for sendBroadcast 2020-10-28 15:25:46 +02:00
navjot
c18b544732
fixed socket error on sendato #1583 2020-10-23 17:54:59 +05:30
navjot
ec922adb36
fixed flake8 code quality issue 2020-10-12 16:44:49 +05:30
navjot
1ec0bd4c42
removed unnecessary import 2020-10-12 16:44:49 +05:30
navjot
263711a4d3
fixed unread trash message listing issue 2020-10-09 16:56:56 +05:30
6b65113bb4
Added missing msgid in HandleGetInboxMessageById() query 2020-10-04 17:24:45 +03:00
380530c839
Experimental APIError codes table 2020-09-14 13:11:43 +03:00
85f306e5f6
Covered more API commands by tests, listed uncovered in TODO 2020-09-14 13:11:43 +03:00
ef5593b3d5
Formatted lines for PEP8, handled pylint warnings, added docstrings 2020-09-14 13:11:43 +03:00
3a8e842e60
Use encodingType arg in sendMessage and sendBroadcast API commands 2020-09-14 13:11:43 +03:00
5b07d2de30
httplib status codes constants in response 2020-09-14 13:11:43 +03:00
6c85bdd498
Also check sent broadcast status and it's presence in sent messages 2020-09-14 13:11:43 +03:00
efff8f95ba
Prefix based command filter 2020-09-14 13:11:42 +03:00
fabbccbeac
Rewrote test_user_password() for xmlrpclib.ProtocolError:
it would be very difficult to return string from BMXMLRPCRequestHandler
2020-09-14 13:11:42 +03:00
06033ed96e
Fixed response for bad username or password and content-type header
(closes #244)
2020-09-14 13:11:42 +03:00
726986c1eb
Implemented JSON-RPC apivariant 2020-09-14 13:11:42 +03:00
6a089e0f88
Decoupled SimpleXMLRPCRequestHandler subclass
and added simple introspection
2020-09-14 13:11:42 +03:00
f4bf3bac2a
Used defusedxml to protect against XML vulnerabilities 2020-09-14 13:11:42 +03:00
2142888cbe
Inherited APIError from xmlrpclib.Fault.
From now on any errors are raised.
2020-09-14 13:11:42 +03:00
25abf66f1d
Reused _verifyAddress() in HandleDecodeAddress() 2020-09-14 13:11:41 +03:00
5925781b9a
Proper message for APIError 0 2020-09-14 13:11:41 +03:00
7cafe402be
Methods to form a dictionary for inbox and sent messages 2020-09-14 13:11:41 +03:00
45b0659e4c
Refactoring the API with metaclass and decorator 2020-09-14 13:11:35 +03:00
1571176082
fixed CQ for bitmessageqt.statusbar module 2020-09-09 12:12:52 +05:30
95fc981ae2
Finish timeOffsetWrongCount
- now notifies in status bar
- fixes #1433
2020-08-31 11:52:30 +02:00
39d28b9b0f
Downgrade pyinstaller for python 2.7 compatibility
- pyinstaller 3.6 is the last one supporting python 2.7 so we're forcing
it for 64bit windows builds
2020-08-28 13:52:31 +02:00
2c5d15e649
winebuid.sh code quality
- code quality only changes
2020-08-27 16:48:02 +02:00
245c8d20e1
Cert removal and pytools compatibility
- remove SSL certificate from winebuild.sh (was causing too many
problems, not worth the effort)
- set pytools version to 2020.2 in winebuild.sh, as that's the last one
to support python2
- fixes #1658
2020-08-27 16:13:20 +02:00
6486b0fc99
fixed CQ for bitmessageqt.safehtmlparser module 2020-07-24 21:04:25 +05:30
035fac1fc5
fixed CQ for bitmessageqt.messagecompose module 2020-07-22 14:08:05 +05:30
d56191ebba
Move knownnodes module into network package 2020-07-21 16:21:43 +03:00
b165a6b4ef
Do addKnownNode recursively for multiple streams 2020-07-21 16:21:43 +03:00
5805840613
A test case for protocol with the test for TCPConnection.local 2020-07-21 16:21:43 +03:00
f9dc8eaacf
Define len() for network.BMConnectionPool 2020-07-21 16:21:43 +03:00
1035d2aec4
Format network.tcp for flake8 2020-07-21 16:21:42 +03:00
54e44eac95
Add or update knownnode for connected Peer for both inbound
and outbound connections when fully established, update lastseen
before closing connection.
2020-07-21 16:21:42 +03:00
d9ddbe8d24
Do not update addrQueue if not added node to own knownnodes
and more checks in knownnodes.addKnownNode moved from bmproto.
2020-07-21 16:21:42 +03:00
0dd49761d0
Populate knownnodes from inventory when singleWorker starts 2020-07-21 16:21:42 +03:00
739ff7b439
Add knownnodes only by knownnodes.addKnownNode(),
now it can update lastseen.
2020-07-21 16:21:36 +03:00
1699c2b015
fixed CQ for bitmessageqt.addressvalidator module 2020-07-20 20:00:48 +05:30
859eeafcfe
fixed CQ for bitmessageqt.messageview module 2020-07-07 19:44:45 +05:30
217a5c0c5b
fixed CQ for bitmessageqt.settings module 2020-06-19 18:15:52 +05:30
277549cff1
fixed CQ for bitmessageqt.sound module 2020-06-18 11:30:33 +05:30
f03bdfb329
Dirty quickfix for #1633 2020-06-15 12:06:37 +03:00
731f75687e
Install needed packages and try to run Qt tests 2020-06-15 12:06:37 +03:00
d6953eb450
New package: bitmessageqt.tests
any test cases from it will be added to tests.core test suite if possible,
e.g. PyQt is functional. TestSupport - minimal test case for support module
to reproduce #1633.
2020-06-15 12:06:31 +03:00
ea109bc21e
fixed CQ for bitmessageqt.dialogs module 2020-06-08 17:07:40 +05:30
e237534335
fixed CQ for bitmessageqt.networkstatus module 2020-06-06 20:08:06 +05:30
e372459737
fixed CQ for bitmessageqt.languagebox module 2020-06-05 15:28:31 +05:30
b750b02963
Fix another unicode bug introduced in 3624234.
Temporary suppressed pylint no-member warning. Closes: #1633
2020-06-01 13:21:46 +03:00
5cfaa9b2fa
fixed CQ for address_dialog python file 2020-05-30 19:17:52 +05:30
lakshya
3f773c78f7
setting, openssl and bmproto quality fixes 2020-05-28 13:43:03 +05:30
c69decaab3
Fix unicode bug introduced in 045a2ef 2020-05-24 14:08:14 +03:00
87e3d63340
Minimal fix for #1449, if search line is empty 2020-05-22 13:17:44 +03:00
36242343c2
Style and formatting changes in support 2020-05-22 13:17:44 +03:00
15d44d85d4
Renamed application class and moved most of init statements to __init__ 2020-05-22 13:17:44 +03:00
7830ac8de5
RetranslateMixin is not needed in most of dialogs 2020-05-22 13:17:44 +03:00
f3e432140c
Proper quit sequence:
close MainWindow and quit the app instead of sys.exit()
2020-05-22 13:17:43 +03:00
08ff39e1ff
Moved myTableWidgetItem to foldertree.MessageList_TimeWidget 2020-05-22 13:17:43 +03:00
aa333a66a6
Minor style changes:
- removed list <-> set conversion in __init__
  - tuples instead of lists if changes aren't needed
  - removed unnecessary variable redefinition in utils
  - rewrote languagebox module a bit
2020-05-22 13:17:43 +03:00
d15e614bb1
Fix streams decoding in BMProto.bm_command_version() 2020-05-22 12:58:04 +03:00
2a62fb79cc
Add test for decoding the version message 2020-05-22 12:58:00 +03:00
7787722452
Search option "To" makes no sense on tab "Subscriptions"
Made "Subject" the default search option
2020-05-11 13:39:13 +03:00
aba61e57a8
flake8 and style fixes and docstrings in helper_search 2020-05-11 13:39:13 +03:00
ef6be53702
Do not convert search option because helper_search compares it
to the result of _translate()
2020-05-11 13:39:13 +03:00
045a2ef443
Update messagelist also if search line cleared 2020-05-11 13:38:16 +03:00
d09782e53d
Obsolete bitmessagemain.connectToStream(), use BMConnectionPool method 2020-05-05 17:30:31 +03:00
c5b77a08fa
Moved addresses demo script into tests.test_crypto 2020-05-05 17:30:31 +03:00
8684d647a3
Use default digestalg='sha256' in highlevelcrypto.sign() 2020-05-05 17:30:30 +03:00
280095b08f
Moved state.openKeysFile() into bitmessageqt where it's used 2020-05-05 17:30:23 +03:00
185ad66ea5
Moved most of variables from shared elsewhere (mostly to state) 2020-05-05 17:27:38 +03:00
7fd6200fb1
Wine build patch for OpenCL frozen mode
- PyOpenCL needs to be patched to work in frozen mode
2020-04-29 12:12:38 +08:00
31fc899060
Protect stopresending* settings from being overriden by zeroes
when lineEditDays and lineEditMonths is blank. Fixes: #1558.
2020-04-28 18:31:44 +03:00
ff1f451691
Blind signature updates
- added serializing and deserializing
- added a signature chain class `ECCBlindSigChain`
- added more tests
2020-03-31 14:13:32 +08:00
213519bd93
Blind chain signature verification
- also adds serialisation, deserialisation and optional metadata
2020-03-14 10:20:06 +08:00
32bb2a6e44
Optionally set git root CA in wine build
- I want to use a https cache for build, that requires to add a new root CA for
  pip, and I can't find a way to do that cleanly  without modifying the
  winebuild.sh script
2020-02-19 21:45:23 +08:00
ac2df26e96
Ignore build directory
- delete obsolete files from build/
- move files from build/ to buildscripts/
- add build/ to .gitignore
2020-02-19 21:16:41 +08:00
73ecf07dec
Wine build cleanup and XP fix
- spec file was cleaned up
- 32bit build runs on XP (downgrade of PyInstaller needed)
2020-02-17 16:03:28 +08:00
3fb34370a7
Wine build script update
- update and clean up and make sure it works
- it builds the binary but I haven't tried to run the binary
- it probably still missing some fine tuning, OpenCL probably doesn't work
2020-02-12 16:16:53 +08:00
11bec55be5
Don't put addresses into queue
- attempt to fix #1598
- seems to work
- addresses won't be uploaded/announced anymore other than after connecting,
  Later I need to find out how to announce them without causing problems, but
  for the time disabling this seems an acceptable drawback
2020-02-05 20:41:36 +08:00
lakshyacis
6f35da4096
Imported packages sequencing and formatting 2020-01-30 12:14:40 +05:30
lakshyacis
6139efc377
Imported packages sequencing and formatting 2 2020-01-27 14:43:25 +05:30
lakshyacis
3211fca953
formatting and shorten line length 2020-01-22 15:55:26 +05:30
lakshyacis
b6a81f1252
Formatting and fix License 2020-01-15 16:17:26 +05:30
lakshyacis
22e22633c2
Added License 2020-01-13 11:21:59 +05:30
lakshyacis
f0bc74e658
Network fixes 2020-01-10 16:51:17 +05:30
lakshyacis
e37d52d950
storage quality fixes 2020-01-08 13:20:11 +05:30
lakshyacis
108b231c1c
sqlite quality fixes 2020-01-08 13:20:10 +05:30
lakshyacis
6fad4f5665
filesystem quality fixes 2020-01-08 13:20:10 +05:30
lakshyacis
81872c7f2f
network code quality fixes 2020-01-08 12:53:04 +05:30
lakshyacis
a31d6c8422
sound_playfile quality fixes 2020-01-07 15:27:17 +05:30
lakshyacis
8338a9ee74
sound_gstreamer docstring fixes 2020-01-07 15:27:16 +05:30
lakshyacis
208090ce5d
sound_canberra docstring and formatting 2020-01-07 15:27:16 +05:30
lakshyacis
e24f4de40e
proxyconfig_stem quality fixes 2020-01-07 15:27:16 +05:30
lakshyacis
ea50485de2
notification_notify2 pylint fixes 2020-01-07 15:27:15 +05:30
lakshyacis
7b0bf84585
menu_qrcode docstring and formatting 2020-01-07 15:27:15 +05:30
lakshyacis
624d96fbb9
indicator_libmessaging docstring and formatting 2020-01-07 15:27:14 +05:30
lakshyacis
8659c5313d
openssl pylint issue fixes 2020-01-07 13:20:31 +05:30
lakshyacis
814aae5166
eccblind quality fixes 2020-01-07 13:20:31 +05:30
lakshyacis
36c24cc09a
cipher quality fixes 2020-01-07 13:20:30 +05:30
lakshyacis
b16515dc09
arithmetic docstring and formatting 2020-01-07 13:20:30 +05:30
lakshyacis
4a369f70c1
formatting and docstring 2020-01-07 12:13:51 +05:30
lakshyacis
21ae6cb9b0
curses fixes 2020-01-06 19:18:05 +05:30
lakshyacis
d9ef4a8e8d
fix spelling mistakes 2020-01-04 18:48:23 +05:30
61f64f72c3
Fixing port for hidden service 2020-01-04 14:28:45 +02:00
1c4d7655c3
Fix socksproxytype in the support message,
made that a separate function getSOCKSProxyType(config) in the settings.
2020-01-04 14:28:45 +02:00
52d5c1ff03
Document proxyconfig_stem 2020-01-04 14:28:45 +02:00
2bddae511a
Fixed some mistakes in tor dependent tests and marked them
for skipping until the finish of debug.
2020-01-04 14:28:45 +02:00
e3ccc3c7c8
Support for socksproxytype plugins in Settings dialog 2020-01-04 14:28:45 +02:00
5160a68c28
Moved start_proxyconfig to helper_startup;
no more prints in helper_startup
2020-01-04 14:28:45 +02:00
44cb975a61
Fixed bug in plugin.get_plugins(), edited docstrings 2020-01-04 14:28:44 +02:00
c35f48bd0b
Fix setting socksproxytype and return in proxyconfig_stem:
socksproxytype is set to SOCKS5 temporary if proxyconfig succeeds.
2020-01-04 14:28:44 +02:00
168c4a5696
Checkdeps fix
- an exception can be triggered if too many requirements are fulfilled
2020-01-03 23:21:54 +01:00
sandakersmann
9119507b03
Changed copyright year to 2020 2019-12-27 18:23:02 +01:00
03316496b7
Stop UDPSocket on socket.error 101 (Network is unreachable) 2019-12-24 12:41:01 +02:00
5a35de6bca
Fix sendOnionPeerObj() broken in 9923e97 2019-12-21 13:14:28 +02:00
c79636863d
If tray is not available, disable settings group "Tray"
and related checkboxes; set checkBoxMinimizeToTray to false by default
2019-12-20 11:25:15 +02:00
a69732f060
Addrthread finish
- addrthread is supposed to spread addresses as they appear. This was never
  finished during migration to asyncore
- conservative to prevent flood and loops
- randomises order
- move protocol constants into a separate file
- move addr packet creation into a separate file
- see #1575
2019-11-30 13:47:24 +01:00
lakshyacis
e47b573b3e
helper_sql pylint fixes 2019-11-25 15:17:40 +05:30
lakshyacis
ece3005f42
helper_sent pylint fixes 2019-11-25 15:17:40 +05:30
lakshyacis
d271996ac1
helper_sent flake8 fixes 2019-11-25 15:17:40 +05:30
lakshyacis
d5f541a2ab
helper_search pylint fixes 2019-11-25 15:17:40 +05:30
lakshyacis
9041b8f644
helper_search flake8 fixes 2019-11-25 15:17:40 +05:30
lakshyacis
28cfe78e67
helper_random pylint fixes 2019-11-25 15:17:40 +05:30
lakshyacis
05cda087d6
helper_msgcoding pylint fixes 2019-11-25 15:17:40 +05:30
lakshyacis
f4c7ac5604
helper_inbox pylint fixes 2019-11-25 15:17:40 +05:30
lakshyacis
27c58b05f3
helper_bitcoin pylint fixes 2019-11-25 15:17:32 +05:30
lakshyacis
31e3d60fb0
helper_ackPayload pylint fixes 2019-11-25 15:13:53 +05:30
lakshyacis
e97d02ed78
depends pylint fixes 2019-11-25 15:13:53 +05:30
lakshyacis
21faf52f2f
debug pylint fixes 2019-11-25 15:13:53 +05:30
lakshyacis
a9991a7a5a
class_sqlThread pylint fixes 2019-11-25 15:13:52 +05:30
lakshyacis
dbbf454c15
class_sqlThread flake8 fixes 2019-11-25 15:13:52 +05:30
lakshyacis
4a54c200d4
class_smtpServer quality fixes 2019-11-25 10:48:35 +05:30
lakshyacis
9923e97279
class_singleWorker quality fixes 2019-11-25 10:48:35 +05:30
lakshyacis
80b2bc1c9a
class_singleCleaner.py quality fixes 2019-11-25 10:48:29 +05:30
lakshyacis
059e82e2a2
class_objectProcessor quality fixes 2019-11-25 10:41:57 +05:30
lakshyacis
e534994ee3
class_addressGenerator quality fixes 2019-11-25 10:41:56 +05:30
lakshyacis
77b8b5aa42
bmconfigparser quality fixes 2019-11-25 10:41:56 +05:30
lakshyacis
af52d95503
bitmessagemain quality fixes 2019-11-25 10:41:55 +05:30
49d731c478
.readthedocs.yml 2019-11-18 13:34:01 +02:00
d9fa6a94f4
More docstrings and formatting fixes in highlevelcrypto and shutdown 2019-11-18 13:34:01 +02:00
a7da0c0eff
Fixed google style docstrings in addresses 2019-11-18 13:34:00 +02:00
aa7e7dd658
Fixed some docstrings in shared and state 2019-11-18 13:34:00 +02:00
f18f534c48
Formatted protocol and its docstrings 2019-11-18 13:34:00 +02:00
253 changed files with 6442 additions and 14427 deletions

3
.gitattributes vendored Normal file
View File

@ -0,0 +1,3 @@
# Pickle files (for testing) should always have UNIX line endings.
# Windows issue like here https://stackoverflow.com/questions/556269
knownnodes.dat text eol=lf

2
.gitignore vendored
View File

@ -17,5 +17,5 @@ dist
*.egg-info *.egg-info
docs/_*/* docs/_*/*
docs/autodoc/ docs/autodoc/
build/sphinx/ build
pyan/ pyan/

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "packages/flatpak/shared-modules"]
path = packages/flatpak/shared-modules
url = https://github.com/flathub/shared-modules.git

9
.readthedocs.yml Normal file
View File

@ -0,0 +1,9 @@
version: 2
python:
version: 2.7
install:
- requirements: docs/requirements.txt
- method: setuptools
path: .
system_packages: true

View File

@ -1,17 +1,22 @@
language: python language: python
cache: pip
dist: bionic
python: python:
- "2.7" - "2.7_with_system_site_packages"
- "3.7"
addons: addons:
apt: apt:
packages: packages:
- build-essential - build-essential
- libcap-dev - libcap-dev
- python-qt4
- tor - tor
- xvfb
install: install:
- pip install -r requirements.txt - pip install -r requirements.txt
- ln -s src pybitmessage # tests environment
- python setup.py install - python setup.py install
- export PYTHONWARNINGS=all
script: script:
- python checkdeps.py - python checkdeps.py
- src/bitmessagemain.py -t - xvfb-run src/bitmessagemain.py -t
- python setup.py test - python -bm tests

View File

@ -1,5 +1,5 @@
Copyright (c) 2012-2016 Jonathan Warren Copyright (c) 2012-2016 Jonathan Warren
Copyright (c) 2012-2019 The Bitmessage Developers Copyright (c) 2012-2020 The Bitmessage Developers
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -6,43 +6,37 @@ RUN apt-get update
# Install dependencies # Install dependencies
RUN apt-get install -yq --no-install-suggests --no-install-recommends \ RUN apt-get install -yq --no-install-suggests --no-install-recommends \
python-msgpack dh-python python-all-dev build-essential libssl-dev \ build-essential libcap-dev libssl-dev \
python-stdeb fakeroot python-pip libcap-dev python-all-dev python-msgpack python-pip python-setuptools
RUN pip install --upgrade pip RUN pip2 install --upgrade pip
EXPOSE 8444 8442 EXPOSE 8444 8442
ENV HOME /home/bitmessage ENV HOME /home/bitmessage
ENV BITMESSAGE_HOME ${HOME} ENV BITMESSAGE_HOME ${HOME}
ENV VER 0.6.3.2
WORKDIR ${HOME} WORKDIR ${HOME}
ADD . ${HOME} ADD . ${HOME}
# Install tests dependencies # Install tests dependencies
RUN pip install -r requirements.txt RUN pip2 install -r requirements.txt
# Install
# Build and install deb RUN python2 setup.py install
RUN python2 setup.py sdist \
&& py2dsc-deb dist/pybitmessage-${VER}.tar.gz \
&& dpkg -i deb_dist/python-pybitmessage_${VER}-1_amd64.deb
# Create a user # Create a user
RUN useradd bitmessage && chown -R bitmessage ${HOME} RUN useradd bitmessage && chown -R bitmessage ${HOME}
USER bitmessage USER bitmessage
# Generate default config
RUN src/bitmessagemain.py -t && mv keys.dat /tmp
# Clean HOME # Clean HOME
RUN rm -rf ${HOME}/* RUN rm -rf ${HOME}/*
# Generate default config
RUN pybitmessage -t
# Setup environment # Setup environment
RUN mv /tmp/keys.dat . \ RUN APIPASS=$(tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo) \
&& APIPASS=$(tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo) \
&& echo "\napiusername: api\napipassword: $APIPASS" \ && echo "\napiusername: api\napipassword: $APIPASS" \
&& echo "apienabled = true\napiinterface = 0.0.0.0\napiusername = api\napipassword = $APIPASS" >> keys.dat && echo "apienabled = true\napiinterface = 0.0.0.0\napiusername = api\napipassword = $APIPASS" >> keys.dat

64
Dockerfile.travis Normal file
View File

@ -0,0 +1,64 @@
FROM ubuntu:bionic AS pybm-travis-bionic
ENV DEBIAN_FRONTEND noninteractive
ENV TRAVIS_SKIP_APT_UPDATE 1
RUN apt-get update
RUN apt-get install -yq --no-install-suggests --no-install-recommends \
software-properties-common
RUN dpkg --add-architecture i386
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt-get -y install sudo
RUN apt-get install -yq --no-install-suggests --no-install-recommends \
# travis xenial bionic
python-setuptools libssl-dev libpq-dev python-prctl python-dev \
python-dev python-virtualenv python-pip virtualenv \
# dpkg
python-minimal python-setuptools python-all python openssl libssl-dev \
dh-apparmor debhelper dh-python python-msgpack python-qt4 python-stdeb \
python-all-dev python-crypto python-psutil \
fakeroot python-pytest \
# Code quality
pylint python-pycodestyle python3-pycodestyle pycodestyle python-flake8 \
python3-flake8 flake8 python-pyflakes python3-pyflakes pyflakes pyflakes3 \
curl \
# Wine
python python-pip wget wine-stable winetricks mingw-w64 wine32 wine64 xvfb \
# Buildbot
python3-dev libffi-dev python3-setuptools \
python3-pip \
# python 3.7
python3.7 python3.7-dev \
# .travis.yml
build-essential libcap-dev tor \
language-pack-en
# cleanup
RUN rm -rf /var/lib/apt/lists/*
RUN useradd -m -U builder
RUN echo 'builder ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# travis2bash
RUN wget -O /usr/local/bin/travis2bash.sh https://git.bitmessage.org/Bitmessage/buildbot-scripts/raw/branch/master/travis2bash.sh
RUN chmod +x /usr/local/bin/travis2bash.sh
# copy sources
COPY . /home/builder/src
RUN chown -R builder.builder /home/builder/src
USER builder
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
WORKDIR /home/builder/src
ENTRYPOINT /usr/local/bin/travis2bash.sh

51
LICENSE
View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2012-2016 Jonathan Warren Copyright (c) 2012-2016 Jonathan Warren
Copyright (c) 2012-2019 The Bitmessage Developers Copyright (c) 2012-2020 The Bitmessage Developers
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in
@ -22,7 +22,7 @@ SOFTWARE.
===== qidenticon.py identicon python implementation with QPixmap output by sendiulo <sendiulo@gmx.net> ===== qidenticon.py identicon python implementation with QPixmap output by sendiulo <sendiulo@gmx.net>
qidenticon.py is Licesensed under FreeBSD License. qidenticon.py is Licensed under FreeBSD License.
(http://www.freebsd.org/copyright/freebsd-license.html) (http://www.freebsd.org/copyright/freebsd-license.html)
Copyright 2013 "Sendiulo". All rights reserved. Copyright 2013 "Sendiulo". All rights reserved.
@ -36,7 +36,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR I
===== based on identicon.py identicon python implementation. by Shin Adachi <shn@glucose.jp> ===== based on identicon.py identicon python implementation. by Shin Adachi <shn@glucose.jp>
identicon.py is Licesensed under FreeBSD License. identicon.py is Licensed under FreeBSD License.
(http://www.freebsd.org/copyright/freebsd-license.html) (http://www.freebsd.org/copyright/freebsd-license.html)
Copyright 1994-2009 Shin Adachi. All rights reserved. Copyright 1994-2009 Shin Adachi. All rights reserved.
@ -47,3 +47,48 @@ Redistribution and use in source and binary forms, with or without modification,
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
===== based on asyncore_pollchoose.py asyncore_pollchoose python implementation. by Sam Rushing <rushing@nightmare.com>
Copyright 1996 by Sam Rushing. All Rights Reserved
Permission to use, copy, modify, and distribute this software and
its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that copyright notice and this permission
notice appear in supporting documentation, and that the name of Sam
Rushing not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
===== based on namecoin.py namecoin.py python implementation by Daniel Kraft <d@domob.eu>
Copyright (C) 2013 by Daniel Kraft <d@domob.eu>
This file is part of the Bitmessage project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,43 +0,0 @@
PyBitmessage(Android)
This sample aims to be as close to a real world example of a mobile. It has a more refined design and also provides a practical example of how a mobile app would interact and communicate with its adresses.
Steps for trying out this sample:
Compile and install the mobile app onto your mobile device or emulator.
Getting Started
This sample uses the kivy as Kivy is an open source, cross-platform Python framework for the development of applications that make use of innovative, multi-touch user interfaces. The aim is to allow for quick and easy interaction design and rapid prototyping whilst making your code reusable and deployable.
Kivy is written in Python and Cython, supports various input devices and has an extensive widget library. With the same codebase, you can target Windows, OS X, Linux, Android and iOS. All Kivy widgets are built with multitouch support.
Kivy in support take Buildozer which is a tool that automates the entire build process. It downloads and sets up all the prequisites for python-for-android, including the android SDK and NDK, then builds an apk that can be automatically pushed to the device.
Buildozer currently works only in Linux, and is an alpha release, but it already works well and can significantly simplify the apk build.
To build this project, use the "Buildozer android release deploy run" command or use.
Buildozer ue=sed for creating application packages easily.The goal is to have one "buildozer.spec" file in your app directory, describing your application requirements and settings such as title, icon, included modules etc. Buildozer will use that spec to create a package for Android, iOS, Windows, OSX and/or Linux.
Installing Requirements
You can create a package for android using the python-for-android project as with using the Buildozer tool to automate the entire process. You can also see Packaging your application for the Kivy Launcher to run kivy programs without compiling them.
You can get buildozer at https://github.com/kivy/buildozer or you can directly install using pip install buildozer
This will install buildozer in your system. Afterwards, navigate to your project directory and run:
buildozer init
This creates a buildozer.spec file controlling your build configuration. You should edit it appropriately with your app name etc. You can set variables to control most or all of the parameters passed to python-for-android.
Install buildozers dependencies.
Finally, plug in your android device and run:
buildozer android debug deploy run >> To build, push and automatically run the apk on your device. Here we used debug as tested in debug mode for now.
Packaging your application for the Kivy Launcher

View File

@ -1,16 +0,0 @@
export LANG=de_DE.UTF-8
export LANGUAGE=de_DE
export LC_CTYPE="de_DE.UTF-8"
export LC_NUMERIC=de_DE.UTF-8
export LC_TIME=de_DE.UTF-8
export LC_COLLATE="de_DE.UTF-8"
export LC_MONETARY=de_DE.UTF-8
export LC_MESSAGES="de_DE.UTF-8"
export LC_PAPER=de_DE.UTF-8
export LC_NAME=de_DE.UTF-8
export LC_ADDRESS=de_DE.UTF-8
export LC_TELEPHONE=de_DE.UTF-8
export LC_MEASUREMENT=de_DE.UTF-8
export LC_IDENTIFICATION=de_DE.UTF-8
export LC_ALL=
python2.7 src/bitmessagemain.py

View File

@ -1,23 +0,0 @@
#!/usr/bin/python2.7
import ctypes
import fnmatch
import os
import sys
import traceback
matches = []
for root, dirnames, filenames in os.walk('src'):
for filename in fnmatch.filter(filenames, '*.py'):
matches.append(os.path.join(root, filename))
for filename in matches:
source = open(filename, 'r').read() + '\n'
try:
compile(source, filename, 'exec')
except Exception as e:
if 'win' in sys.platform:
ctypes.windll.user32.MessageBoxA(0, traceback.format_exc(), "Exception in " + filename, 1)
else:
print "Exception in %s: %s" % (filename, traceback.format_exc())
sys.exit(1)

View File

@ -1,11 +0,0 @@
#!/bin/bash
if [ -z "$1" ]; then
echo "You must specify pull request number"
exit
fi
git pull
git checkout v0.6
git fetch origin pull/"$1"/head:"$1"
git merge --ff-only "$1"

View File

@ -1,173 +0,0 @@
#!/bin/bash
# INIT
MACHINE_TYPE=`uname -m`
BASE_DIR=$(pwd)
PYTHON_VERSION=2.7.15
PYQT_VERSION=4-4.11.4-gpl-Py2.7-Qt4.8.7
OPENSSL_VERSION=1_0_2t
DIRECTORY32BIT=SoftwareDownloads32bit
DIRECTORY64BIT=SoftwareDownloads64bit
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
if [ ! -d "$DIRECTORY64BIT" ]; then
mkdir SoftwareDownloads64bit
cd SoftwareDownloads64bit
else
echo "Directory already exists"
cd SoftwareDownloads64bit
fi
else
if [ ! -d "$DIRECTORY32BIT" ]; then
mkdir SoftwareDownloads32bit
cd SoftwareDownloads32bit
else
echo "Directory 32 bit alrready exists"
cd SoftwareDownloads32bit
fi
fi
#Functions
function install_wine {
wget -nc https://dl.winehq.org/wine-builds/Release.key --no-check-certificate
sudo apt-key add Release.key
sudo apt-add-repository 'https://dl.winehq.org/wine-builds/ubuntu/'
sudo apt-get -y update
sudo apt-get -y install wine1.8 winetricks
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
sudo apt-get -y install wine64-development
env WINEPREFIX=$HOME/.wine64 WINEARCH=win64 winecfg
WINE="env WINEPREFIX=$HOME/.wine64 wine"
export WINEPREFIX
else
sudo apt-get -y install wine32-development
env WINEPREFIX=$HOME/.wine32 WINEARCH=win32 winecfg
WINE="env WINEPREFIX=$HOME/.wine32 wine"
export WINEPREFIX
fi
}
function install_python(){
echo "Download Python2.7"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
# For 64 bit machine
wget -nc wget http://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}.amd64.msi --no-check-certificate
echo "Install Python2.7 for 64 bit"
$WINE msiexec -i python-${PYTHON_VERSION}.amd64.msi /q /norestart
wget -nc https://download.microsoft.com/download/d/2/4/d242c3fb-da5a-4542-ad66-f9661d0a8d19/vcredist_x64.exe --no-check-certificate
$WINE vcredist_x64.exe /q /norestart
echo "Installed vcredist for 64 bit"
$WINE pip install --upgrade pip
else
# For 32 bit machine
wget -nc https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}.msi --no-check-certificate
echo "Install Python2.7 for 32 bit"
$WINE msiexec -i python-${PYTHON_VERSION}.msi /q /norestart
echo "Installing vc_redist for 32 bit "
wget -nc https://download.microsoft.com/download/1/1/1/1116b75a-9ec3-481a-a3c8-1777b5381140/vcredist_x86.exe --no-check-certificate
$WINE vcredist_x86.exe /q /norestart
#insatlled msvcr120.dll for 32 bit system
wget -nc http://www.dll-found.com/zip/m/msvcr120.dll.zip --no-check-certificate
unzip msvcr120.dll.zip
sudo cp msvcr120.dll $HOME/.wine32/drive_c/windows/system32/
$WINE pip install --upgrade pip
fi
}
function install_pyqt(){
echo "Download PyQT"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
# For 64 bit machine
wget -nc --content-disposition https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x64.exe?raw=true --no-check-certificate
$WINE PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x64.exe /q /norestart /silent /verysiling /sp- /suppressmsgboxes
else
# For 32 bit machine
wget -nc --content-disposition https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x32.exe?raw=true --no-check-certificate
$WINE PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x32.exe /q /norestart /silent /verysiling /sp- /suppressmsgboxes
fi
}
function install_openssl(){
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
wget -nc --content-disposition https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/Win64OpenSSL-${OPENSSL_VERSION}.exe?raw=true --no-check-certificate
$WINE Win64OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysiling /sp- /suppressmsgboxes
else
wget -nc --content-disposition https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/Win32OpenSSL-${OPENSSL_VERSION}.exe?raw=true --no-check-certificate
$WINE Win32OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysiling /sp- /suppressmsgboxes
echo "Install PyInstaller 32 bit"
fi
}
function install_pyinstaller()
{
$WINE pip install pyinstaller
echo "Install PyInstaller"
echo "Install Pyopencl"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
wget -nc https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/pyopencl-2015.1-cp27-none-win_amd64.whl --no-check-certificate
$WINE pip install pyopencl-2015.1-cp27-none-win_amd64.whl
$WINE pip install msgpack-python
else
wget -nc --content-disposition https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/pyopencl-2015.1-cp27-none-win_amd64one-win32.whl?raw=true --no-check-certificate
$WINE pip install msgpack-python
$WINE pip install pyopencl-2015.1-cp27-none-win32.whl
fi
echo "Install Message Pack"
}
function build_dll(){
cd $BASE_DIR
rm -rf master.zip
rm -rf PyBitmessage
git clone https://github.com/Bitmessage/PyBitmessage.git
cd PyBitmessage/src/bitmsghash
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
# Do stuff for 64 bit machine
echo "Install MinGW"
sudo apt-get -y install mingw-w64
echo "Create dll"
x86_64-w64-mingw32-g++ -D_WIN32 -Wall -O3 -march=native -I$HOME/.wine64/drive_c/OpenSSL-Win64/include -I/usr/x86_64-w64-mingw32/include -L$HOME/.wine64/drive_c/OpenSSL-Win64/lib -c bitmsghash.cpp
x86_64-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o -D_WIN32 -O3 -march=native -I$HOME/.wine64/drive_c/OpenSSL-Win64/include -L$HOME/.wine64/drive_c/OpenSSL-Win64 -L/usr/lib/x86_64-linux-gnu/wine -fPIC -shared -lcrypt32 -leay32 -lwsock32 -o bitmsghash64.dll -Wl,--out-implib,bitmsghash.a
echo "DLL generated successfully "
cd ..
cp -R bitmsghash ../../../src/
cd ../../../
cd packages/pyinstaller/
env WINEPREFIX=$HOME/.wine64 wine pyinstaller bitmessagemain.spec
else
echo "Install MinGW for 32 bit"
sudo apt-get install mingw-w64
echo "Create dll"
i686-w64-mingw32-g++ -D_WIN32 -Wall -m32 -O3 -march=native -I$HOME/.wine32/drive_c/OpenSSL-Win32/include -I/usr/i686-w64-mingw32/include -L$HOME/.wine32/drive_c/OpenSSL-Win32/lib -c bitmsghash.cpp
i686-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o -D_WIN32 -O3 -march=native -I$HOME/.wine32/drive_c/OpenSSL-Win32/include -L$HOME/.wine32/drive_c/OpenSSL-Win32/lib/MinGW -fPIC -shared -lcrypt32 -leay32 -lwsock32 -o bitmsghash32.dll -Wl,--out-implib,bitmsghash.a
cd ..
cp -R bitmsghash ../../../src/
cd ../../../
cd packages/pyinstaller/
env WINEPREFIX=$HOME/.wine32 wine pyinstaller bitmessagemain.spec
fi
}
install_wine
install_python
install_pyqt
install_openssl
install_pyinstaller
build_dll

189
buildscripts/winbuild.sh Executable file
View File

@ -0,0 +1,189 @@
#!/bin/bash
# INIT
MACHINE_TYPE=$(uname -m)
BASE_DIR=$(pwd)
PYTHON_VERSION=2.7.17
PYQT_VERSION=4-4.11.4-gpl-Py2.7-Qt4.8.7
OPENSSL_VERSION=1_0_2t
SRCPATH=~/Downloads
#Functions
function download_sources_32 {
if [ ! -d ${SRCPATH} ]; then
mkdir -p ${SRCPATH}
fi
wget -P ${SRCPATH} -c -nc --content-disposition \
https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}.msi \
https://download.microsoft.com/download/1/1/1/1116b75a-9ec3-481a-a3c8-1777b5381140/vcredist_x86.exe \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/PyQt${PYQT_VERSION}-x32.exe?raw=true \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/Win32OpenSSL-${OPENSSL_VERSION}.exe?raw=true \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/pyopencl-2015.1-cp27-none-win32.whl?raw=true
}
function download_sources_64 {
if [ ! -d ${SRCPATH} ]; then
mkdir -p ${SRCPATH}
fi
wget -P ${SRCPATH} -c -nc --content-disposition \
http://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}.amd64.msi \
https://download.microsoft.com/download/d/2/4/d242c3fb-da5a-4542-ad66-f9661d0a8d19/vcredist_x64.exe \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/PyQt${PYQT_VERSION}-x64.exe?raw=true \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/Win64OpenSSL-${OPENSSL_VERSION}.exe?raw=true \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/pyopencl-2015.1-cp27-none-win_amd64.whl?raw=true
}
function download_sources {
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
download_sources_64
else
download_sources_32
fi
}
function install_wine {
echo "Setting up wine"
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
export WINEPREFIX=${HOME}/.wine64 WINEARCH=win64
else
export WINEPREFIX=${HOME}/.wine32 WINEARCH=win32
fi
rm -rf "${WINEPREFIX}"
rm -rf packages/pyinstaller/{build,dist}
}
function install_python(){
cd ${SRCPATH} || exit 1
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
echo "Installing Python ${PYTHON_VERSION} 64b"
wine msiexec -i python-${PYTHON_VERSION}.amd64.msi /q /norestart
echo "Installing vcredist for 64 bit"
wine vcredist_x64.exe /q /norestart
else
echo "Installing Python ${PYTHON_VERSION} 32b"
wine msiexec -i python-${PYTHON_VERSION}.msi /q /norestart
# MSVCR 2008 required for Windows XP
cd ${SRCPATH} || exit 1
echo "Installing vc_redist (2008) for 32 bit "
wine vcredist_x86.exe /Q
fi
echo "Installing pytools 2020.2"
# last version compatible with python 2
wine python -m pip install pytools==2020.2
echo "Upgrading pip"
wine python -m pip install --upgrade pip
}
function install_pyqt(){
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
echo "Installing PyQt-${PYQT_VERSION} 64b"
wine PyQt${PYQT_VERSION}-x64.exe /S /WX
else
echo "Installing PyQt-${PYQT_VERSION} 32b"
wine PyQt${PYQT_VERSION}-x32.exe /S /WX
fi
}
function install_openssl(){
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
echo "Installing OpenSSL ${OPENSSL_VERSION} 64b"
wine Win64OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysilent /sp- /suppressmsgboxes
else
echo "Installing OpenSSL ${OPENSSL_VERSION} 32b"
wine Win32OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysilent /sp- /suppressmsgboxes
fi
}
function install_pyinstaller()
{
cd "${BASE_DIR}" || exit 1
echo "Installing PyInstaller"
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
# 3.6 is the last version to support python 2.7
wine python -m pip install -I pyinstaller==3.6
else
# 3.2.1 is the last version to work on XP
# see https://github.com/pyinstaller/pyinstaller/issues/2931
wine python -m pip install -I pyinstaller==3.2.1
fi
}
function install_msgpack()
{
cd "${BASE_DIR}" || exit 1
echo "Installing msgpack"
wine python -m pip install msgpack-python
}
function install_pyopencl()
{
cd "${SRCPATH}" || exit 1
echo "Installing PyOpenCL"
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
wine python -m pip install pyopencl-2015.1-cp27-none-win_amd64.whl
else
wine python -m pip install pyopencl-2015.1-cp27-none-win32.whl
fi
sed -Ei 's/_DEFAULT_INCLUDE_OPTIONS = .*/_DEFAULT_INCLUDE_OPTIONS = [] /' \
"$WINEPREFIX/drive_c/Python27/Lib/site-packages/pyopencl/__init__.py"
}
function build_dll(){
cd "${BASE_DIR}" || exit 1
cd src/bitmsghash || exit 1
if [ "${MACHINE_TYPE}" == 'x86_64' ]; then
echo "Create dll"
x86_64-w64-mingw32-g++ -D_WIN32 -Wall -O3 -march=native \
"-I$HOME/.wine64/drive_c/OpenSSL-Win64/include" \
-I/usr/x86_64-w64-mingw32/include \
"-L$HOME/.wine64/drive_c/OpenSSL-Win64/lib" \
-c bitmsghash.cpp
x86_64-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o \
-D_WIN32 -O3 -march=native \
"-I$HOME/.wine64/drive_c/OpenSSL-Win64/include" \
"-L$HOME/.wine64/drive_c/OpenSSL-Win64" \
-L/usr/lib/x86_64-linux-gnu/wine \
-fPIC -shared -lcrypt32 -leay32 -lwsock32 \
-o bitmsghash64.dll -Wl,--out-implib,bitmsghash.a
else
echo "Create dll"
i686-w64-mingw32-g++ -D_WIN32 -Wall -m32 -O3 -march=native \
"-I$HOME/.wine32/drive_c/OpenSSL-Win32/include" \
-I/usr/i686-w64-mingw32/include \
"-L$HOME/.wine32/drive_c/OpenSSL-Win32/lib" \
-c bitmsghash.cpp
i686-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o \
-D_WIN32 -O3 -march=native \
"-I$HOME/.wine32/drive_c/OpenSSL-Win32/include" \
"-L$HOME/.wine32/drive_c/OpenSSL-Win32/lib/MinGW" \
-fPIC -shared -lcrypt32 -leay32 -lwsock32 \
-o bitmsghash32.dll -Wl,--out-implib,bitmsghash.a
fi
}
function build_exe(){
cd "${BASE_DIR}" || exit 1
cd packages/pyinstaller || exit 1
wine pyinstaller bitmessagemain.spec
}
# prepare on ubuntu
# dpkg --add-architecture i386
# apt update
# apt -y install wget wine-stable wine-development winetricks mingw-w64 wine32 wine64 xvfb
download_sources
if [ "$1" == "--download-only" ]; then
exit
fi
install_wine
install_python
install_pyqt
install_openssl
install_pyopencl
install_msgpack
install_pyinstaller
build_dll
build_exe

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python2 #!/usr/bin/env python
""" """
Check dependendies and give recommendations about how to satisfy them Check dependencies and give recommendations about how to satisfy them
Limitations: Limitations:
@ -144,27 +144,30 @@ for lhs, rhs in EXTRAS_REQUIRE.items():
for x in rhs for x in rhs
if x in EXTRAS_REQUIRE_DEPS if x in EXTRAS_REQUIRE_DEPS
]): ]):
rhs_cmd = ''.join([ try:
CMD, import_module(lhs)
' ', except Exception as e:
' '.join([ rhs_cmd = ''.join([
''. join([ CMD,
xx for xx in EXTRAS_REQUIRE_DEPS[x][OPSYS] ' ',
]) ' '.join([
for x in rhs ''. join([
if x in EXTRAS_REQUIRE_DEPS xx for xx in EXTRAS_REQUIRE_DEPS[x][OPSYS]
]), ])
]) for x in rhs
print( if x in EXTRAS_REQUIRE_DEPS
"Optional dependency `pip install .[{}]` would require `{}`" ]),
" to be run as root".format(lhs, rhs_cmd)) ])
print(
"Optional dependency `pip install .[{}]` would require `{}`"
" to be run as root".format(lhs, rhs_cmd))
if (not compiler or prereqs) and OPSYS in PACKAGE_MANAGER: if (not compiler or prereqs) and OPSYS in PACKAGE_MANAGER:
print("You can install the missing dependencies by running, as root:") print("You can install the missing dependencies by running, as root:")
if not compiler: if not compiler:
compilerToPackages() compilerToPackages()
prereqToPackages() prereqToPackages()
if mandatory: if prereqs and mandatory:
sys.exit(1) sys.exit(1)
else: else:
print("All the dependencies satisfied, you can install PyBitmessage") print("All the dependencies satisfied, you can install PyBitmessage")

View File

@ -6,4 +6,4 @@ Comment=Send encrypted messages
Exec=pybitmessage %F Exec=pybitmessage %F
Icon=pybitmessage Icon=pybitmessage
Terminal=false Terminal=false
Categories=Office;Email; Categories=Office;Email;Network;

View File

@ -2,3 +2,17 @@
li.wy-breadcrumbs-aside > a.fa { li.wy-breadcrumbs-aside > a.fa {
display: none; display: none;
} }
/* Override table width restrictions */
/* @media screen and (min-width: 700px) { */
.wy-table-responsive table td {
/* !important prevents the common CSS stylesheets from overriding
this as on RTD they are loaded after this stylesheet */
white-space: normal !important;
}
.wy-table-responsive {
overflow: visible !important;
}
/* } */

View File

@ -21,12 +21,12 @@ If we are to make bold claims about protecting your privacy we should demonstrat
- looking to audit - looking to audit
- warrant canary - warrant canary
Digital foootprint Digital footprint
------------------ ------------------
Your internet use can reveal metadata you wouldn't expect. This can be connected with other information about you if you're not careful. Your internet use can reveal metadata you wouldn't expect. This can be connected with other information about you if you're not careful.
* Use separate addresses for different puprose * Use separate addresses for different purposes
* Don't make the same mistakes all the time * Don't make the same mistakes all the time
* Your language use is unique. The more you type, the more you fingerprint yourself. The words you know and use often vs the words you don't know or use often. * Your language use is unique. The more you type, the more you fingerprint yourself. The words you know and use often vs the words you don't know or use often.

View File

@ -11,17 +11,17 @@ Bitmessage makes use of fabric_ to define tasks such as building documentation o
Code style and linters Code style and linters
---------------------- ----------------------
We aim to be PEP8 compliant but we recognise that we have a long way still to go. Currently we have style and lint exceptions specified at the most specific place we can. We are ignoring certain issues project-wide in order to avoid alert-blindess, avoid style and lint regressions and to allow continuous integration to hook into the output from the tools. While it is hoped that all new changes pass the checks, fixing some existing violations are mini-projects in themselves. Current thinking on ignorable violations is reflected in the options and comments in setup.cfg. Module and line-level lint warnings represent refactoring opportunities. We aim to be PEP8 compliant but we recognize that we have a long way still to go. Currently we have style and lint exceptions specified at the most specific place we can. We are ignoring certain issues project-wide in order to avoid alert-blindness, avoid style and lint regressions and to allow continuous integration to hook into the output from the tools. While it is hoped that all new changes pass the checks, fixing some existing violations are mini-projects in themselves. Current thinking on ignorable violations is reflected in the options and comments in setup.cfg. Module and line-level lint warnings represent refactoring opportunities.
Pull requests Pull requests
------------- -------------
There is a template at PULL_REQUEST_TEMPLATE.md that appears in the pull-request description. Please replace this text with something appropriate to your changes based off the ideas in the template. There is a template at PULL_REQUEST_TEMPLATE.md that appears in the pull-request description. Please replace this text with something appropriate to your changes based on the ideas in the template.
Bike-shedding Bike-shedding
------------- -------------
Beyond having well-documented, Pythonic code with static analysis tool checks, extensive test coverage and powerful devops tools, what else can we have? Without violating any linters there is room for making arbirary decisions solely for the sake of project consistency. These are the stuff of the pedant's PR comments. Rather than have such conversations in PR comments, we can lay out the result of discussion here. Beyond having well-documented, Pythonic code with static analysis tool checks, extensive test coverage and powerful devops tools, what else can we have? Without violating any linters there is room for making arbitrary decisions solely for the sake of project consistency. These are the stuff of the pedant's PR comments. Rather than have such conversations in PR comments, we can lay out the result of discussion here.
I'm putting up a strawman for each topic here, mostly based on my memory of reading related Stack Overflow articles etc. If contributors feel strongly (and we don't have anything better to do) then maybe we can convince each other to update this section. I'm putting up a strawman for each topic here, mostly based on my memory of reading related Stack Overflow articles etc. If contributors feel strongly (and we don't have anything better to do) then maybe we can convince each other to update this section.
@ -49,7 +49,7 @@ British vs American spelling
Dependency graph Dependency graph
---------------- ----------------
These images are not very useful right now but the aim is to tweak the settings of one or more of them to be informative, and/or divide them up into smaller grapghs. These images are not very useful right now but the aim is to tweak the settings of one or more of them to be informative, and/or divide them up into smaller graphs.
To re-build them, run `fab build_docs:dep_graphs=true`. Note that the dot graph takes a lot of time. To re-build them, run `fab build_docs:dep_graphs=true`. Note that the dot graph takes a lot of time.

View File

@ -1,6 +1,6 @@
# Fabric # Fabric
[Fabric](https://www.fabfile.org) is a Python library for performing devops tasks. You can thing of it a bit like a [Fabric](https://www.fabfile.org) is a Python library for performing devops tasks. You can think of it a bit like a
makefile on steroids for Python. Its api abstracts away the clunky way you would run shell commands in Python, check makefile on steroids for Python. Its api abstracts away the clunky way you would run shell commands in Python, check
return values and manage stdio. Tasks may be targetted at particular hosts or group of hosts. return values and manage stdio. Tasks may be targetted at particular hosts or group of hosts.
@ -46,7 +46,7 @@ Furthermore, you can use -- to run arbitrary shell commands rather than tasks:
There are a number of advantages that should benefit us: There are a number of advantages that should benefit us:
* Common tasks can be writen in Python and executed consistently * Common tasks can be written in Python and executed consistently
* Common tasks are now under source control * Common tasks are now under source control
* All developers can run the same commands, if the underlying command sequence for a task changes (after review, obv) * All developers can run the same commands, if the underlying command sequence for a task changes (after review, obv)
the user does not have to care the user does not have to care

View File

@ -15,7 +15,7 @@ OSX:
https://github.com/Bitmessage/PyBitmessage/releases https://github.com/Bitmessage/PyBitmessage/releases
Wors on OSX 10.7.5 or higher Works on OSX 10.7.5 or higher
Arch linux: Arch linux:

View File

@ -0,0 +1,19 @@
# Last Modified: Wed Apr 29 21:04:08 2020
#include <tunables/global>
/usr/bin/pybitmessage {
#include <abstractions/base>
#include <abstractions/fonts>
#include <abstractions/lightdm>
#include <abstractions/python>
#include <abstractions/user-tmp>
owner /home/*/.ICEauthority r,
owner /home/*/.Xauthority r,
owner /home/*/.config/PyBitmessage/ rw,
owner /home/*/.config/PyBitmessage/* rwk,
owner /home/*/.config/Trolltech.conf rwk,
owner /home/*/.config/Trolltech.conf.* rw,
owner /proc/*/mounts r,
}

View File

@ -0,0 +1,57 @@
{
"id": "org.bitmessage.BaseApp",
"branch": "19.08",
"runtime": "org.freedesktop.Platform",
"sdk": "org.freedesktop.Sdk",
"runtime-version": "19.08",
"separate-locales": false,
"modules": [
"shared-modules/python2.7/python-2.7.json",
"shared-modules/qt4/qt4-4.8.7-minimal.json",
{
"name": "python-sip",
"sources": [
{
"type": "archive",
"url": "https://www.riverbankcomputing.com/static/Downloads/sip/4.19.25/sip-4.19.25.tar.gz",
"sha256": "b39d93e937647807bac23579edbff25fe46d16213f708370072574ab1f1b4211"
}
],
"buildsystem": "simple",
"build-commands": [
"python configure.py --sip-module PyQt4.sip --no-dist-info",
"make",
"make install"
]
},
{
"name": "python-qt4",
"sources": [
{
"type": "archive",
"url": "http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.12.3/PyQt4_gpl_x11-4.12.3.tar.gz",
"sha256": "a00f5abef240a7b5852b7924fa5fdf5174569525dc076cd368a566619e56d472"
}
],
"buildsystem": "simple",
"build-commands": [
"python configure.py -w --confirm-license",
"make",
"make install"
]
},
{
"name" : "PyBitmessage-dependencies",
"buildsystem" : "simple",
"build-options": {
"build-args": [
"--share=network"
]
},
"build-commands": [
"pip --version",
"pip install setuptools msgpack"
]
}
]
}

View File

@ -0,0 +1,48 @@
{
"app-id": "org.bitmessage.PyBitmessage",
"runtime": "org.freedesktop.Platform",
"runtime-version": "19.08",
"branch": "stable",
"sdk": "org.freedesktop.Sdk",
"base": "org.bitmessage.BaseApp",
"command": "pybitmessage",
"base-version":"stable",
"finish-args" : [
"--share=network",
"--socket=x11",
"--share=ipc",
"--filesystem=xdg-config/PyBitmessage:create"
],
"modules": [
{
"name" : "PyBitmessage",
"buildsystem" : "simple",
"build-options": {
"build-args": [
"--share=network"
]
},
"build-commands": [
"python --version",
"pwd",
"ls",
"python checkdeps.py",
"python setup.py install --prefix=/app --exec-prefix=/app",
"sed -i 's~/usr/bin/~/app/bin/~' /app/bin/pybitmessage",
"cat /app/bin/pybitmessage",
"mv /app/share/applications/pybitmessage.desktop /app/share/applications/org.bitmessage.PyBitmessage.desktop",
"sed -i 's~Icon=pybitmessage~Icon=org.bitmessage.PyBitmessage~' /app/share/applications/org.bitmessage.PyBitmessage.desktop",
"mv /app/share/icons/hicolor/scalable/apps/pybitmessage.svg /app/share/icons/hicolor/scalable/apps/org.bitmessage.PyBitmessage.svg",
"mv /app/share/icons/hicolor/24x24/apps/pybitmessage.png /app/share/icons/hicolor/24x24/apps/org.bitmessage.PyBitmessage.png",
"which pybitmessage"
],
"sources" : [
{
"type" : "dir",
"path" : "../../"
}
]
}
]
}

@ -0,0 +1 @@
Subproject commit fd4d38328ccb078b88ad4a891807e593ae8de806

View File

@ -1,106 +1,132 @@
# -*- mode: python -*-
import ctypes import ctypes
import os import os
import time
import sys import sys
import time
if ctypes.sizeof(ctypes.c_voidp) == 4:
arch=32
else:
arch=64
sslName = 'OpenSSL-Win%s' % ("32" if arch == 32 else "64")
site_root = os.path.abspath(HOMEPATH) site_root = os.path.abspath(HOMEPATH)
spec_root = os.path.abspath(SPECPATH) spec_root = os.path.abspath(SPECPATH)
cdrivePath= site_root[0:3] arch = 32 if ctypes.sizeof(ctypes.c_voidp) == 4 else 64
srcPath = spec_root[:-20]+"src\\" cdrivePath = site_root[0:3]
qtPath = site_root+"\\PyQt4\\" srcPath = os.path.join(spec_root[:-20], "src")
openSSLPath = cdrivePath+sslName+"\\" sslName = 'OpenSSL-Win%i' % arch
msvcrDllPath = cdrivePath+"windows\\system32\\" openSSLPath = os.path.join(cdrivePath, sslName)
pythonDllPath = cdrivePath+"Python27\\" msvcrDllPath = os.path.join(cdrivePath, "windows", "system32")
outPath = spec_root+"\\bitmessagemain" outPath = os.path.join(spec_root, "bitmessagemain")
qtBase = "PyQt4"
importPath = srcPath sys.path.insert(0, srcPath)
sys.path.insert(0,importPath) os.chdir(srcPath)
os.chdir(sys.path[0])
from version import softwareVersion
today = time.strftime("%Y%m%d")
snapshot = False snapshot = False
os.rename(os.path.join(srcPath, '__init__.py'), os.path.join(srcPath, '__init__.py.backup')) os.rename(
os.path.join(srcPath, '__init__.py'),
os.path.join(srcPath, '__init__.py.backup'))
# -*- mode: python -*-
a = Analysis( a = Analysis(
[srcPath + 'bitmessagemain.py'], [os.path.join(srcPath, 'bitmessagemain.py')],
pathex=[outPath], pathex=[outPath],
hiddenimports=['pyopencl','numpy', 'win32com' , 'setuptools.msvc' ,'_cffi_backend'], hiddenimports=[
hookspath=None, 'bitmessageqt.languagebox', 'pyopencl', 'numpy', 'win32com',
runtime_hooks=None 'setuptools.msvc', '_cffi_backend'
) ],
hookspath=None,
runtime_hooks=None,
excludes=['bsddb', 'bz2', 'tcl', 'tk', 'Tkinter']
)
os.rename(
os.path.join(srcPath, '__init__.py.backup'),
os.path.join(srcPath, '__init__.py'))
os.rename(os.path.join(srcPath, '__init__.py.backup'), os.path.join(srcPath, '__init__.py'))
def addTranslations(): def addTranslations():
import os
extraDatas = [] extraDatas = []
for file in os.listdir(srcPath + 'translations'): for file_ in os.listdir(os.path.join(srcPath, 'translations')):
if file[-3:] != ".qm": if file_[-3:] != ".qm":
continue continue
extraDatas.append((os.path.join('translations', file), os.path.join(srcPath, 'translations', file), 'DATA')) extraDatas.append((
for file in os.listdir(qtPath + 'translations'): os.path.join('translations', file_),
if file[0:3] != "qt_" or file[5:8] != ".qm": os.path.join(srcPath, 'translations', file_), 'DATA'))
for libdir in sys.path:
qtdir = os.path.join(libdir, qtBase, 'translations')
if os.path.isdir(qtdir):
break
if not os.path.isdir(qtdir):
return extraDatas
for file_ in os.listdir(qtdir):
if file_[0:3] != "qt_" or file_[5:8] != ".qm":
continue continue
extraDatas.append((os.path.join('translations', file), os.path.join(qtPath, 'translations', file), 'DATA')) extraDatas.append((
os.path.join('translations', file_),
os.path.join(qtdir, file_), 'DATA'))
return extraDatas return extraDatas
def addUIs():
import os dir_append = os.path.join(srcPath, 'bitmessageqt')
extraDatas = []
for file in os.listdir(srcPath + 'bitmessageqt'): a.datas += [
if file[-3:] != ".ui": (os.path.join('ui', file_), os.path.join(dir_append, file_), 'DATA')
continue for file_ in os.listdir(dir_append) if file_.endswith('.ui')
extraDatas.append((os.path.join('ui', file), os.path.join(srcPath, 'bitmessageqt', file), 'DATA')) ]
return extraDatas
# append the translations directory # append the translations directory
a.datas += addTranslations() a.datas += addTranslations()
a.datas += addUIs()
excluded_binaries = [
'QtOpenGL4.dll',
'QtSvg4.dll',
'QtXml4.dll',
]
a.binaries = TOC([x for x in a.binaries if x[0] not in excluded_binaries])
a.binaries += [
# No effect: libeay32.dll will be taken from PyQt if installed
('libeay32.dll', os.path.join(openSSLPath, 'libeay32.dll'), 'BINARY'),
(os.path.join('bitmsghash', 'bitmsghash%i.dll' % arch),
os.path.join(srcPath, 'bitmsghash', 'bitmsghash%i.dll' % arch),
'BINARY'),
(os.path.join('bitmsghash', 'bitmsghash.cl'),
os.path.join(srcPath, 'bitmsghash', 'bitmsghash.cl'), 'BINARY'),
(os.path.join('sslkeys', 'cert.pem'),
os.path.join(srcPath, 'sslkeys', 'cert.pem'), 'BINARY'),
(os.path.join('sslkeys', 'key.pem'),
os.path.join(srcPath, 'sslkeys', 'key.pem'), 'BINARY')
]
from version import softwareVersion
today = time.strftime("%Y%m%d")
fname = '%s_%%s_%s.exe' % (
('Bitmessagedev', today) if snapshot else ('Bitmessage', softwareVersion)
) % ("x86" if arch == 32 else "x64")
a.binaries += [('libeay32.dll', openSSLPath + 'libeay32.dll', 'BINARY'),
('python27.dll', pythonDllPath + 'python27.dll', 'BINARY'),
('msvcr120.dll', msvcrDllPath + 'msvcr120.dll','BINARY'),
(os.path.join('bitmsghash', 'bitmsghash%i.dll' % (arch)), os.path.join(srcPath, 'bitmsghash', 'bitmsghash%i.dll' % (arch)), 'BINARY'),
(os.path.join('bitmsghash', 'bitmsghash.cl'), os.path.join(srcPath, 'bitmsghash', 'bitmsghash.cl'), 'BINARY'),
(os.path.join('sslkeys', 'cert.pem'), os.path.join(srcPath, 'sslkeys', 'cert.pem'), 'BINARY'),
(os.path.join('sslkeys', 'key.pem'), os.path.join(srcPath, 'sslkeys', 'key.pem'), 'BINARY')
]
fname = 'Bitmessage_%s_%s.exe' % ("x86" if arch == 32 else "x64", softwareVersion)
if snapshot:
fname = 'Bitmessagedev_%s_%s.exe' % ("x86" if arch == 32 else "x64", today)
pyz = PYZ(a.pure) pyz = PYZ(a.pure)
exe = EXE(pyz, exe = EXE(
a.scripts, pyz,
a.binaries, a.scripts,
a.zipfiles, a.binaries,
a.datas, a.zipfiles,
a.binaries, a.datas,
[], name=fname,
name=fname, debug=False,
debug=False, strip=None,
strip=None, upx=False,
upx=True, console=False, icon=os.path.join(srcPath, 'images', 'can-icon.ico')
console=True, icon= os.path.join(srcPath, 'images', 'can-icon.ico')) )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='main')
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=False,
name='main'
)

View File

@ -1,48 +0,0 @@
#!/bin/bash
APP=pybitmessage
PREV_VERSION=0.4.4
VERSION=0.6.0
RELEASE=1
ARCH_TYPE=all
DIR=${APP}-${VERSION}
CURDIR=`pwd`
SHORTDIR=`basename ${CURDIR}`
if [ $ARCH_TYPE == "x86_64" ]; then
ARCH_TYPE="amd64"
fi
if [ $ARCH_TYPE == "i686" ]; then
ARCH_TYPE="i386"
fi
# Update version numbers automatically - so you don't have to
sed -i 's/VERSION='${PREV_VERSION}'/VERSION='${VERSION}'/g' Makefile rpm.sh arch.sh puppy.sh ebuild.sh slack.sh
sed -i 's/Version: '${PREV_VERSION}'/Version: '${VERSION}'/g' rpmpackage/${APP}.spec
sed -i 's/Release: '${RELEASE}'/Release: '${RELEASE}'/g' rpmpackage/${APP}.spec
sed -i 's/pkgrel='${RELEASE}'/pkgrel='${RELEASE}'/g' archpackage/PKGBUILD
sed -i 's/pkgver='${PREV_VERSION}'/pkgver='${VERSION}'/g' archpackage/PKGBUILD
sed -i "s/-${PREV_VERSION}-/-${VERSION}-/g" puppypackage/*.specs
sed -i "s/|${PREV_VERSION}|/|${VERSION}|/g" puppypackage/*.specs
sed -i 's/VERSION='${PREV_VERSION}'/VERSION='${VERSION}'/g' puppypackage/pinstall.sh puppypackage/puninstall.sh
sed -i 's/-'${PREV_VERSION}'.so/-'${VERSION}'.so/g' debian/*.links
make clean
make
# Change the parent directory name to Debian format
mv ../${SHORTDIR} ../${DIR}
# Create a source archive
make sourcedeb
# Build the package
dpkg-buildpackage -F -us -uc
# Sign files
gpg -ba ../${APP}_${VERSION}-1_${ARCH_TYPE}.deb
gpg -ba ../${APP}_${VERSION}.orig.tar.gz
# Restore the parent directory name
mv ../${DIR} ../${SHORTDIR}

View File

@ -1,483 +0,0 @@
pybitmessage (0.6.0-1) trusty; urgency=low
* Bugfixes
* UI improvements
* performance and security improvements
* integration with email gateway (mailchuck.com)
-- Peter Surda <dev@mailchuck.com> Mon, 2 May 2016 16:25:00 +0200
pybitmessage (0.4.4-1) utopic; urgency=low
* Added ability to limit network transfer rate
* Updated to Protocol Version 3
* Removed use of memoryview so that we can support python 2.7.3
* Make use of l10n for localizations
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Sun, 2 November 2014 12:55:00 +0100
pybitmessage (0.4.3-1) saucy; urgency=low
* Support pyelliptic's updated HMAC algorithm. We'll remove support for the old method after an upgrade period.
* Improved version check
* Refactored decodeBase58 function
* Ignore duplicate messages
* Added bytes received/sent counts and rate on the network information tab
* Fix unicode handling in 'View HTML code as formatted text'
* Refactor handling of packet headers
* Use pointMult function instead of arithmetic.privtopub since it is faster
* Fixed issue where client wasn't waiting for a verack before continuing on with the conversation
* Fixed CPU hogging by implementing tab-based refresh improvements
* Added curses interface
* Added support for IPv6
* Added a 'trustedpeer' option to keys.dat
* Limit maximum object size to 20 MB
* Support email-like > quote characters and reply-below-quote
* Added Japanese and Dutch language files; updated Norwegian and Russian languages files
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Thu, 6 March 2014 20:23:00 +0100
pybitmessage (0.4.2-1) saucy; urgency=low
* Exclude debian directory from orig.tar.gz
* Added Norwegian, Chinese, and Arabic translations
* sock.sendall function isn't atomic.
Let sendDataThread be the only thread which sends data.
* Moved API code to api.py
* Populate comboBoxSendFrom when replying
* Added option to show recent broadcasts when subscribing
* Fixed issue: If Windows username contained an international character,
Bitmessage wouldn't start
* Added some code for FreeBSD compatibility
* Moved responsibility for processing network objects
to the new ObjectProcessorThread
* Refactored main QT module
Moved popup menus initialization to separate methods
Simplified inbox loading
Moved magic strings to the model scope constants so they won't
be created every time.
* Updated list of defaultKnownNodes
* Fixed issue: [Linux] When too many messages arrive too quickly,
exception occurs: "Exceeded maximum number of notifications"
* Fixed issue: creating then deleting an Address in short time crashes
class_singleWorker.py
* Refactored code which displays messages to improve code readability
* load "Sent To" label from subscriptions if available
* Removed code to add chans to our address book as it is no longer necessary
* Added identicons
* Modified addresses.decodeAddress so that API command decodeAddress
works properly
* Added API commands createChan, joinChan, leaveChan, deleteAddress
* In pyelliptic, check the return value of RAND_bytes to make sure enough
random data was generated
* Don't store messages in UI table (and thus in memory), pull from SQL
inventory as needed
* Fix typos in API commands addSubscription and getInboxMessagesByAddress
* Add feature in settings menu to give up resending a message after a
specified period of time
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Thu, 6 March 2014 20:23:00 +0100
pybitmessage (0.4.1-1) raring; urgency=low
* Fixed whitelist bug
* Fixed chan bug
Added addressversion field to pubkeys table
Sending messages to a chan no longer uses anything in the pubkeys table
Sending messages to yourself is now fully supported
* Change _verifyAddress function to support v4 addresses
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Sun, 29 September 2013 09:54:00 +0100
pybitmessage (0.4.0-1) raring; urgency=low
* Raised default demanded difficulty from 1 to 2 for new addresses
* Added v4 addresses:
pubkeys are now encrypted and tagged in the inventory
* Use locks when accessing dictionary inventory
* Refactored the way inv and addr messages are shared
* Give user feedback when disk is full
* Added chan true/false to listAddresses results
* When replying using chan address, send to whole chan not just sender
* Refactored of the way PyBitmessage looks for interesting new objects
in large inv messages from peers
* Show inventory lookup rate on Network Status tab
* Added SqlBulkExecute class
so we can update inventory with only one commit
* Updated Russian translations
* Move duplicated SQL code into helper
* Allow specification of alternate settings dir
via BITMESSAGE_HOME environment variable
* Removed use of gevent. Removed class_bgWorker.py
* Added Sip and PyQt to includes in build_osx.py
* Show number of each message type processed
in the API command clientStatus
* Use fast PoW
unless we're explicitly a frozen (binary) version of the code
* Enable user-set localization in settings
* Fix Archlinux package creation
* Fallback to language only localization when region doesn't match
* Fixed brew install instructions
* Added German translation
* Made inbox and sent messages table panels read-only
* Allow inbox and sent preview panels to resize
* Count RE: as a reply header, just like Re: so we don't chain Re: RE:
* Fix for traceback on OSX
* Added backend ability to understand shorter addresses
* Convert 'API Error' to raise APIError()
* Added option in settings to allow sending to a mobile device
(app not yet done)
* Added ability to start daemon mode when using Bitmessage as a module
* Improved the way client detects locale
* Added API commands:
getInboxMessageIds, getSentMessageIds, listAddressBookEntries,
trashSentMessageByAckData, addAddressBookEntry,
deleteAddressBookEntry, listAddresses2, listSubscriptions
* Set a maximum frequency for playing sounds
* Show Invalid Method error in same format as other API errors
* Update status of separate broadcasts separately
even if the sent data is identical
* Added Namecoin integration
* Internally distinguish peers by IP and port
* Inbox message retrieval API
functions now also returns read status
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Sat, 28 September 2013 09:54:00 +0100
pybitmessage (0.3.5-1) raring; urgency=low
* Inbox message retrieval API functions now also returns read status
* Added right-click option to mark a message as unread
* Prompt user to connect at first startup
* Install into /usr/local by default
* Add a missing rm -f to the uninstall task.
* Use system text color for enabled addresses instead of black
* Added support for Chans
* Start storing msgid in sent table
* Optionally play sounds on connection/disconnection or when messages arrive
* Adding configuration option to listen for connections when using SOCKS
* Added packaging for multiple distros (Arch, Puppy, Slack, etc.)
* Added Russian translation
* Added search support in the UI
* Added 'make uninstall'
* To improve OSX support, use PKCS5_PBKDF2_HMAC_SHA1
if PKCS5_PBKDF2_HMAC is unavailable
* Added better warnings for OSX users who are using old versions of Python
* Repaired debian packaging
* Altered Makefile to avoid needing to chase changes
* Added logger module
* Added bgWorker class for background tasks
* Added use of gevent module
* On not-Windows: Fix insecure keyfile permissions
* Fix 100% CPU usage issue
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Mon, 29 July 2013 22:11:00 +0100
pybitmessage (0.3.4-1) raring; urgency=low
* Switched addr, msg, broadcast, and getpubkey message types
to 8 byte time. Last remaining type is pubkey.
* Added tooltips to show the full subject of messages
* Added Maximum Acceptable Difficulty fields in the settings
* Send out pubkey immediately after generating deterministic
addresses rather than waiting for a request
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Sun, 30 June 2013 11:23:00 +0100
pybitmessage (0.3.3-1) raring; urgency=low
* Remove inbox item from GUI when using API command trashMessage
* Add missing trailing semicolons to pybitmessage.desktop
* Ensure $(DESTDIR)/usr/bin exists
* Update Makefile to correct sandbox violations when built
via Portage (Gentoo)
* Fix message authentication bug
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Sat, 29 June 2013 11:23:00 +0100
pybitmessage (0.3.211-1) raring; urgency=low
* Removed multi-core proof of work
as the multiprocessing module does not work well with
pyinstaller's --onefile option.
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Fri, 28 June 2013 11:23:00 +0100
pybitmessage (0.3.2-1) raring; urgency=low
* Bugfix: Remove remaining references to the old myapp.trayIcon
* Refactored message status-related code. API function getStatus
now returns one of these strings: notfound, msgqueued,
broadcastqueued, broadcastsent, doingpubkeypow, awaitingpubkey,
doingmsgpow, msgsent, or ackreceived
* Moved proof of work to low-priority multi-threaded child
processes
* Added menu option to delete all trashed messages
* Added inv flooding attack mitigation
* On Linux, when selecting Show Bitmessage, do not maximize
automatically
* Store tray icons in bitmessage_icons_rc.py
-- Bob Mottram (4096 bits) <bob@robotics.uk.to> Mon, 03 June 2013 20:17:00 +0100
pybitmessage (0.3.1-1) raring; urgency=low
* Added new API commands: getDeterministicAddress,
addSubscription, deleteSubscription
* TCP Connection timeout for non-fully-established connections
now 20 seconds
* Don't update the time we last communicated with a node unless
the connection is fully established. This will allow us to
forget about active but non-Bitmessage nodes which have made
it into our knownNodes file.
* Prevent incoming connection flooding from crashing
singleListener thread. Client will now only accept one
connection per remote node IP
* Bugfix: Worker thread crashed when doing a POW to send out
a v2 pubkey (bug introduced in 0.3.0)
* Wrap all sock.shutdown functions in error handlers
* Put all 'commit' commands within SQLLocks
* Bugfix: If address book label is blank, Bitmessage wouldn't
show message (bug introduced in 0.3.0)
* Messaging menu item selects the oldest unread message
* Standardize on 'Quit' rather than 'Exit'
* [OSX] Try to seek homebrew installation of OpenSSL
* Prevent multiple instances of the application from running
* Show 'Connected' or 'Connection Lost' indicators
* Use only 9 half-open connections on Windows but 32 for
everyone else
* Added appIndicator (a more functional tray icon) and Ubuntu
Messaging Menu integration
* Changed Debian install directory and run script name based
on Github issue #135
-- Jonathan Warren (4096 bits) <jonathan@bitmessage.org> Sat, 25 May 2013 12:06:00 +0100
pybitmessage (0.3.0-1) raring; urgency=low
* Added new API function: getStatus
* Added error-handling around all sock.sendall() functions
in the receiveData thread so that if there is a problem
sending data, the threads will close gracefully
* Abandoned and removed the connectionsCount data structure;
use the connectedHostsList instead because it has proved to be
more accurate than trying to maintain the connectionsCount
* Added daemon mode. All UI code moved into a module and many
shared objects moved into shared.py
* Truncate display of very long messages to avoid freezing the UI
* Added encrypted broadcasts for v3 addresses or v2 addresses
after 2013-05-28 10:00 UTC
* No longer self.sock.close() from within receiveDataThreads,
let the sendDataThreads do it
* Swapped out the v2 announcements subscription address for a v3
announcements subscription address
* Vacuum the messages.dat file once a month:
will greatly reduce the file size
* Added a settings table in message.dat
* Implemented v3 addresses:
pubkey messages must now include two var_ints: nonce_trials_per_byte
and extra_bytes, and also be signed. When sending a message to a v3
address, the sender must use these values in calculating its POW or
else the message will not be accepted by the receiver.
* Display a privacy warning when selecting 'Send Broadcast from this address'
* Added gitignore file
* Added code in preparation for a switch from 32-bit time to 64-bit time.
Nodes will now advertise themselves as using protocol version 2.
* Don't necessarily delete entries from the inventory after 2.5 days;
leave pubkeys there for 28 days so that we don't process the same ones
many times throughout a month. This was causing the 'pubkeys processed'
indicator on the 'Network Status' tab to not accurately reflect the
number of truly new addresses on the network.
* Use 32 threads for outgoing connections in order to connect quickly
* Fix typo when calling os.environ in the sys.platform=='darwin' case
* Allow the cancelling of a message which is in the process of being
sent by trashing it then restarting Bitmessage
* Bug fix: can't delete address from address book
-- Bob Mottram (4096 bits) <bob@sluggish.dyndns.org> Mon, 6 May 2013 12:06:00 +0100
pybitmessage (0.2.8-1) unstable; urgency=low
* Fixed Ubuntu & OS X issue:
Bitmessage wouldn't receive any objects from peers after restart.
* Inventory flush to disk when exiting program now vastly faster.
* Fixed address generation bug (kept Bitmessage from restarting).
* Improve deserialization of messages
before processing (a 'best practice').
* Change to help Macs find OpenSSL the way Unix systems find it.
* Do not share or accept IPs which are in the private IP ranges.
* Added time-fuzzing
to the embedded time in pubkey and getpubkey messages.
* Added a knownNodes lock
to prevent an exception from sometimes occurring when saving
the data-structure to disk.
* Show unread messages in bold
and do not display new messages automatically.
* Support selecting multiple items
in the inbox, sent box, and address book.
* Use delete key to trash Inbox or Sent messages.
* Display richtext(HTML) messages
from senders in address book or subscriptions (although not
pseudo-mailing-lists; use new right-click option).
* Trim spaces
from the beginning and end of addresses when adding to
address book, subscriptions, and blacklist.
* Improved the display of the time for foreign language users.
-- Bob Mottram (4096 bits) <bob@sluggish.dyndns.org> Tue, 9 Apr 2013 17:44:00 +0100
pybitmessage (0.2.7-1) unstable; urgency=low
* Added debian packaging
* Script to generate debian packages
* SVG icon for Gnome shell, etc
* Source moved int src directory for debian standards compatibility
* Trailing carriage return on COPYING LICENSE and README.md
-- Bob Mottram (4096 bits) <bob@sluggish.dyndns.org> Mon, 1 Apr 2013 17:12:14 +0100

View File

@ -1 +0,0 @@
9

View File

@ -1,21 +0,0 @@
Source: pybitmessage
Section: mail
Priority: extra
Maintainer: Bob Mottram (4096 bits) <bob@robotics.uk.to>
Build-Depends: debhelper (>= 9.0.0), libqt4-dev (>= 4.8.0), python-qt4-dev, libsqlite3-dev
Standards-Version: 3.9.4
Homepage: https://github.com/Bitmessage/PyBitmessage
Vcs-Git: https://github.com/Bitmessage/PyBitmessage.git
Package: pybitmessage
Architecture: all
Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends}, python (>= 2.7), openssl, python-qt4, sqlite3, gst123
Suggests: libmessaging-menu-dev
Description: Send encrypted messages
Bitmessage is a P2P communications protocol used to send encrypted
messages to another person or to many subscribers. It is decentralized and
trustless, meaning that you need-not inherently trust any entities like
root certificate authorities. It uses strong authentication which means
that the sender of a message cannot be spoofed, and it aims to hide
"non-content" data, like the sender and receiver of messages, from passive
eavesdroppers like those running warrantless wiretapping programs.

View File

@ -1,30 +0,0 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name:
Source:
Files: *
Copyright: Copyright 2016 Bob Mottram (4096 bits) <bob@robotics.uk.to>
License: MIT
Files: debian/*
Copyright: Copyright 2016 Bob Mottram (4096 bits) <bob@robotics.uk.to>
License: MIT
License: MIT
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
.
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@
man/pybitmessage.1.gz

View File

@ -1,4 +0,0 @@
#!/bin/sh
cd /usr/share/pybitmessage
exec python bitmessagemain.py

View File

@ -1,43 +0,0 @@
#!/usr/bin/make -f
APP=pybitmessage
PREFIX=/usr
build: build-stamp
make
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
dh_testdir
touch build-stamp
clean:
dh_testdir
dh_testroot
rm -f build-stamp
dh_clean
install: build clean
dh_testdir
dh_testroot
dh_prep
dh_installdirs
${MAKE} install -B DESTDIR=${CURDIR}/debian/${APP} PREFIX=/usr
binary-indep: build install
dh_testdir
dh_testroot
dh_installchangelogs
dh_installdocs
dh_installexamples
dh_installman
dh_link
dh_compress
dh_fixperms
dh_installdeb
dh_gencontrol
dh_md5sums
dh_builddeb
binary-arch: build install
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install

View File

@ -1 +0,0 @@
3.0 (quilt)

View File

@ -1,18 +0,0 @@
src/images/sent.png
src/images/can-icon-16px.png
src/images/addressbook.png
src/images/networkstatus.png
src/images/redicon.png
src/images/subscriptions.png
src/images/blacklist.png
src/images/can-icon-24px.png
src/images/can-icon-24px-red.png
src/images/can-icon-24px-yellow.png
src/images/can-icon-24px-green.png
src/images/identities.png
src/images/yellowicon.png
src/images/inbox.png
src/images/greenicon.png
src/images/can-icon.ico
src/images/send.png
desktop/can-icon.svg

View File

@ -1,4 +1,4 @@
coverage
python_prctl python_prctl
psutil psutil
pycrypto pycrypto
stem

4
run-tests-in-docker.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
docker build -t pybm-travis-bionic -f Dockerfile.travis .
docker run pybm-travis-bionic

View File

@ -1,7 +1,9 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
import os import os
import platform
import shutil import shutil
import sys
from setuptools import setup, Extension from setuptools import setup, Extension
from setuptools.command.install import install from setuptools.command.install import install
@ -10,14 +12,17 @@ from src.version import softwareVersion
EXTRAS_REQUIRE = { EXTRAS_REQUIRE = {
'docs': ['sphinx', 'sphinxcontrib-apidoc', 'm2r'],
'gir': ['pygobject'], 'gir': ['pygobject'],
'json': ['jsonrpclib'],
'notify2': ['notify2'], 'notify2': ['notify2'],
'opencl': ['pyopencl', 'numpy'], 'opencl': ['pyopencl', 'numpy'],
'prctl': ['python_prctl'], # Named threads 'prctl': ['python_prctl'], # Named threads
'qrcode': ['qrcode'], 'qrcode': ['qrcode'],
'sound;platform_system=="Windows"': ['winsound'], 'sound;platform_system=="Windows"': ['winsound'],
'tor': ['stem'], 'tor': ['stem'],
'docs': ['sphinx', 'sphinxcontrib-apidoc', 'm2r'] 'xdg': ['pyxdg'],
'xml': ['defusedxml']
} }
@ -81,6 +86,24 @@ if __name__ == "__main__":
except ImportError: except ImportError:
packages += ['pybitmessage.fallback.umsgpack'] packages += ['pybitmessage.fallback.umsgpack']
data_files = [
('share/applications/',
['desktop/pybitmessage.desktop']),
('share/icons/hicolor/scalable/apps/',
['desktop/icons/scalable/pybitmessage.svg']),
('share/icons/hicolor/24x24/apps/',
['desktop/icons/24x24/pybitmessage.png'])
]
try:
if platform.dist()[0] in ('Debian', 'Ubuntu'):
data_files += [
("etc/apparmor.d/",
['packages/apparmor/pybitmessage'])
]
except AttributeError:
pass # FIXME: use distro for more recent python
dist = setup( dist = setup(
name='pybitmessage', name='pybitmessage',
version=softwareVersion, version=softwareVersion,
@ -96,6 +119,7 @@ if __name__ == "__main__":
#keywords='', #keywords='',
install_requires=installRequires, install_requires=installRequires,
tests_require=requirements, tests_require=requirements,
test_suite='tests.unittest_discover',
extras_require=EXTRAS_REQUIRE, extras_require=EXTRAS_REQUIRE,
classifiers=[ classifiers=[
"License :: OSI Approved :: MIT License" "License :: OSI Approved :: MIT License"
@ -112,14 +136,7 @@ if __name__ == "__main__":
'translations/*.ts', 'translations/*.qm', 'translations/*.ts', 'translations/*.qm',
'images/*.png', 'images/*.ico', 'images/*.icns' 'images/*.png', 'images/*.ico', 'images/*.icns'
]}, ]},
data_files=[ data_files=data_files,
('share/applications/',
['desktop/pybitmessage.desktop']),
('share/icons/hicolor/scalable/apps/',
['desktop/icons/scalable/pybitmessage.svg']),
('share/icons/hicolor/24x24/apps/',
['desktop/icons/24x24/pybitmessage.png'])
],
ext_modules=[bitmsghash], ext_modules=[bitmsghash],
zip_safe=False, zip_safe=False,
entry_points={ entry_points={
@ -141,12 +158,15 @@ if __name__ == "__main__":
'libmessaging =' 'libmessaging ='
'pybitmessage.plugins.indicator_libmessaging [gir]' 'pybitmessage.plugins.indicator_libmessaging [gir]'
], ],
'bitmessage.desktop': [
'freedesktop = pybitmessage.plugins.desktop_xdg [xdg]'
],
'bitmessage.proxyconfig': [ 'bitmessage.proxyconfig': [
'stem = pybitmessage.plugins.proxyconfig_stem [tor]' 'stem = pybitmessage.plugins.proxyconfig_stem [tor]'
], ],
# 'console_scripts': [ 'console_scripts': [
# 'pybitmessage = pybitmessage.bitmessagemain:main' 'pybitmessage = pybitmessage.bitmessagemain:main'
# ] ] if sys.platform[:3] == 'win' else []
}, },
scripts=['src/pybitmessage'], scripts=['src/pybitmessage'],
cmdclass={'install': InstallCmd}, cmdclass={'install': InstallCmd},

View File

@ -1,16 +1,14 @@
""" """
src/addresses.py Operations with addresses
================
""" """
# pylint: disable=redefined-outer-name,inconsistent-return-statements # pylint: disable=redefined-outer-name,inconsistent-return-statements
import hashlib import hashlib
import logging
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from struct import pack, unpack from struct import pack, unpack
from debug import logger
logger = logging.getLogger('default')
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
@ -18,17 +16,16 @@ ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
def encodeBase58(num, alphabet=ALPHABET): def encodeBase58(num, alphabet=ALPHABET):
"""Encode a number in Base X """Encode a number in Base X
`num`: The number to encode Args:
`alphabet`: The alphabet to use for encoding num: The number to encode
alphabet: The alphabet to use for encoding
""" """
if num == 0: if num == 0:
return alphabet[0] return alphabet[0]
arr = [] arr = []
base = len(alphabet) base = len(alphabet)
while num: while num:
rem = num % base num, rem = divmod(num, base)
# print 'num is:', num
num = num // base
arr.append(alphabet[rem]) arr.append(alphabet[rem])
arr.reverse() arr.reverse()
return ''.join(arr) return ''.join(arr)
@ -37,9 +34,9 @@ def encodeBase58(num, alphabet=ALPHABET):
def decodeBase58(string, alphabet=ALPHABET): def decodeBase58(string, alphabet=ALPHABET):
"""Decode a Base X encoded string into the number """Decode a Base X encoded string into the number
Arguments: Args:
- `string`: The encoded string string: The encoded string
- `alphabet`: The alphabet to use for encoding alphabet: The alphabet to use for encoding
""" """
base = len(alphabet) base = len(alphabet)
num = 0 num = 0
@ -152,16 +149,16 @@ def encodeAddress(version, stream, ripe):
'Programming error in encodeAddress: The length of' 'Programming error in encodeAddress: The length of'
' a given ripe hash was not 20.' ' a given ripe hash was not 20.'
) )
if ripe[:2] == '\x00\x00': if ripe[:2] == b'\x00\x00':
ripe = ripe[2:] ripe = ripe[2:]
elif ripe[:1] == '\x00': elif ripe[:1] == b'\x00':
ripe = ripe[1:] ripe = ripe[1:]
elif version == 4: elif version == 4:
if len(ripe) != 20: if len(ripe) != 20:
raise Exception( raise Exception(
'Programming error in encodeAddress: The length of' 'Programming error in encodeAddress: The length of'
' a given ripe hash was not 20.') ' a given ripe hash was not 20.')
ripe = ripe.lstrip('\x00') ripe = ripe.lstrip(b'\x00')
storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe
@ -182,7 +179,8 @@ def decodeAddress(address):
returns (status, address version number, stream number, returns (status, address version number, stream number,
data (almost certainly a ripe hash)) data (almost certainly a ripe hash))
""" """
# pylint: disable=too-many-return-statements,too-many-statements,too-many-return-statements,too-many-branches # pylint: disable=too-many-return-statements,too-many-statements
# pylint: disable=too-many-branches
address = str(address).strip() address = str(address).strip()
@ -194,8 +192,8 @@ def decodeAddress(address):
status = 'invalidcharacters' status = 'invalidcharacters'
return status, 0, 0, '' return status, 0, 0, ''
# after converting to hex, the string will be prepended # after converting to hex, the string will be prepended
# with a 0x and appended with a L # with a 0x and appended with a L in python2
hexdata = hex(integer)[2:-1] hexdata = hex(integer)[2:].rstrip('L')
if len(hexdata) % 2 != 0: if len(hexdata) % 2 != 0:
hexdata = '0' + hexdata hexdata = '0' + hexdata
@ -245,13 +243,13 @@ def decodeAddress(address):
data[bytesUsedByVersionNumber + bytesUsedByStreamNumber:-4] data[bytesUsedByVersionNumber + bytesUsedByStreamNumber:-4]
if len(embeddedRipeData) == 19: if len(embeddedRipeData) == 19:
return status, addressVersionNumber, streamNumber, \ return status, addressVersionNumber, streamNumber, \
'\x00' + embeddedRipeData b'\x00' + embeddedRipeData
elif len(embeddedRipeData) == 20: elif len(embeddedRipeData) == 20:
return status, addressVersionNumber, streamNumber, \ return status, addressVersionNumber, streamNumber, \
embeddedRipeData embeddedRipeData
elif len(embeddedRipeData) == 18: elif len(embeddedRipeData) == 18:
return status, addressVersionNumber, streamNumber, \ return status, addressVersionNumber, streamNumber, \
'\x00\x00' + embeddedRipeData b'\x00\x00' + embeddedRipeData
elif len(embeddedRipeData) < 18: elif len(embeddedRipeData) < 18:
return 'ripetooshort', 0, 0, '' return 'ripetooshort', 0, 0, ''
elif len(embeddedRipeData) > 20: elif len(embeddedRipeData) > 20:
@ -260,7 +258,7 @@ def decodeAddress(address):
elif addressVersionNumber == 4: elif addressVersionNumber == 4:
embeddedRipeData = \ embeddedRipeData = \
data[bytesUsedByVersionNumber + bytesUsedByStreamNumber:-4] data[bytesUsedByVersionNumber + bytesUsedByStreamNumber:-4]
if embeddedRipeData[0:1] == '\x00': if embeddedRipeData[0:1] == b'\x00':
# In order to enforce address non-malleability, encoded # In order to enforce address non-malleability, encoded
# RIPE data must have NULL bytes removed from the front # RIPE data must have NULL bytes removed from the front
return 'encodingproblem', 0, 0, '' return 'encodingproblem', 0, 0, ''
@ -268,7 +266,7 @@ def decodeAddress(address):
return 'ripetoolong', 0, 0, '' return 'ripetoolong', 0, 0, ''
elif len(embeddedRipeData) < 4: elif len(embeddedRipeData) < 4:
return 'ripetooshort', 0, 0, '' return 'ripetooshort', 0, 0, ''
x00string = '\x00' * (20 - len(embeddedRipeData)) x00string = b'\x00' * (20 - len(embeddedRipeData))
return status, addressVersionNumber, streamNumber, \ return status, addressVersionNumber, streamNumber, \
x00string + embeddedRipeData x00string + embeddedRipeData
@ -277,69 +275,3 @@ def addBMIfNotPresent(address):
"""Prepend BM- to an address if it doesn't already have it""" """Prepend BM- to an address if it doesn't already have it"""
address = str(address).strip() address = str(address).strip()
return address if address[:3] == 'BM-' else 'BM-' + address return address if address[:3] == 'BM-' else 'BM-' + address
# TODO: make test case
if __name__ == "__main__":
from pyelliptic import arithmetic
print(
'\nLet us make an address from scratch. Suppose we generate two'
' random 32 byte values and call the first one the signing key'
' and the second one the encryption key:'
)
privateSigningKey = \
'93d0b61371a54b53df143b954035d612f8efa8a3ed1cf842c2186bfd8f876665'
privateEncryptionKey = \
'4b0b73a54e19b059dc274ab69df095fe699f43b17397bca26fdf40f4d7400a3a'
print(
'\nprivateSigningKey = %s\nprivateEncryptionKey = %s' %
(privateSigningKey, privateEncryptionKey)
)
print(
'\nNow let us convert them to public keys by doing'
' an elliptic curve point multiplication.'
)
publicSigningKey = arithmetic.privtopub(privateSigningKey)
publicEncryptionKey = arithmetic.privtopub(privateEncryptionKey)
print(
'\npublicSigningKey = %s\npublicEncryptionKey = %s' %
(publicSigningKey, publicEncryptionKey)
)
print(
'\nNotice that they both begin with the \\x04 which specifies'
' the encoding type. This prefix is not send over the wire.'
' You must strip if off before you send your public key across'
' the wire, and you must add it back when you receive a public key.'
)
publicSigningKeyBinary = \
arithmetic.changebase(publicSigningKey, 16, 256, minlen=64)
publicEncryptionKeyBinary = \
arithmetic.changebase(publicEncryptionKey, 16, 256, minlen=64)
ripe = hashlib.new('ripemd160')
sha = hashlib.new('sha512')
sha.update(publicSigningKeyBinary + publicEncryptionKeyBinary)
ripe.update(sha.digest())
addressVersionNumber = 2
streamNumber = 1
print(
'\nRipe digest that we will encode in the address: %s' %
hexlify(ripe.digest())
)
returnedAddress = \
encodeAddress(addressVersionNumber, streamNumber, ripe.digest())
print('Encoded address: %s' % returnedAddress)
status, addressVersionNumber, streamNumber, data = \
decodeAddress(returnedAddress)
print(
'\nAfter decoding address:\n\tStatus: %s'
'\n\taddressVersionNumber %s'
'\n\tstreamNumber %s'
'\n\tlength of data (the ripe hash): %s'
'\n\tripe data: %s' %
(status, addressVersionNumber, streamNumber, len(data), hexlify(data))
)

1663
src/api.py
View File

@ -1,29 +1,77 @@
# pylint: disable=too-many-locals,too-many-lines,no-self-use,too-many-public-methods,too-many-branches
# pylint: disable=too-many-statements
# Copyright (c) 2012-2016 Jonathan Warren # Copyright (c) 2012-2016 Jonathan Warren
# Copyright (c) 2012-2019 The Bitmessage developers # Copyright (c) 2012-2020 The Bitmessage developers
# pylint: disable=too-many-lines,no-self-use,unused-variable,unused-argument
""" """
This is not what you run to run the Bitmessage API. Instead, enable the API This is not what you run to start the Bitmessage API.
( https://bitmessage.org/wiki/API ) and optionally enable daemon mode Instead, `enable the API <https://bitmessage.org/wiki/API>`_
( https://bitmessage.org/wiki/Daemon ) then run bitmessagemain.py. and optionally `enable daemon mode <https://bitmessage.org/wiki/Daemon>`_
then run the PyBitmessage.
The PyBitmessage API is provided either as
`XML-RPC <http://xmlrpc.scripting.com/spec.html>`_ or
`JSON-RPC <https://www.jsonrpc.org/specification>`_ like in bitcoin.
It's selected according to 'apivariant' setting in config file.
Special value ``apivariant=legacy`` is to mimic the old pre 0.6.3
behaviour when any results are returned as strings of json.
.. list-table:: All config settings related to API:
:header-rows: 0
* - apienabled = true
- if 'false' the `singleAPI` wont start
* - apiinterface = 127.0.0.1
- this is the recommended default
* - apiport = 8442
- the API listens apiinterface:apiport if apiport is not used,
random in range (32767, 65535) otherwice
* - apivariant = xml
- current default for backward compatibility, 'json' is recommended
* - apiusername = username
- set the username
* - apipassword = password
- and the password
* - apinotifypath =
- not really the API setting, this sets a path for the executable to be ran
when certain internal event happens
To use the API concider such simple example:
.. code-block:: python
import jsonrpclib
from pybitmessage import bmconfigparser, helper_startup
helper_startup.loadConfig() # find and load local config file
conf = bmconfigparser.BMConfigParser()
api_uri = "http://%s:%s@127.0.0.1:8442/" % (
conf.safeGet('bitmessagesettings', 'apiusername'),
conf.safeGet('bitmessagesettings', 'apipassword')
)
api = jsonrpclib.ServerProxy(api_uri)
print(api.clientStatus())
For further examples please reference `.tests.test_api`.
""" """
import base64 import base64
import ConfigParser
import errno import errno
import hashlib import hashlib
import httplib
import json import json
import random # nosec import random # nosec
import socket import socket
import subprocess import subprocess
import time import time
import xmlrpclib
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer
from struct import pack from struct import pack
from version import softwareVersion
import defaults import defaults
import helper_inbox import helper_inbox
import helper_sent import helper_sent
@ -33,38 +81,102 @@ import queues
import shared import shared
import shutdown import shutdown
import state import state
from addresses import addBMIfNotPresent, calculateInventoryHash, decodeAddress, decodeVarint, varintDecodeError from addresses import (
addBMIfNotPresent,
calculateInventoryHash,
decodeAddress,
decodeVarint,
varintDecodeError
)
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from debug import logger from debug import logger
from helper_ackPayload import genAckPayload
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery, sqlStoredProcedure from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery, sqlStoredProcedure
from inventory import Inventory from inventory import Inventory
from network.threads import StoppableThread from network.threads import StoppableThread
from version import softwareVersion
try: # TODO: write tests for XML vulnerabilities
from defusedxml.xmlrpc import monkey_patch
except ImportError:
logger.warning(
'defusedxml not available, only use API on a secure, closed network.')
else:
monkey_patch()
str_chan = '[chan]' str_chan = '[chan]'
str_broadcast_subscribers = '[Broadcast subscribers]'
class APIError(Exception): class ErrorCodes(type):
"""APIError exception class""" """Metaclass for :class:`APIError` documenting error codes."""
_CODES = {
0: 'Invalid command parameters number',
1: 'The specified passphrase is blank.',
2: 'The address version number currently must be 3, 4, or 0'
' (which means auto-select).',
3: 'The stream number must be 1 (or 0 which means'
' auto-select). Others aren\'t supported.',
4: 'Why would you ask me to generate 0 addresses for you?',
5: 'You have (accidentally?) specified too many addresses to'
' make. Maximum 999. This check only exists to prevent'
' mischief; if you really want to create more addresses than'
' this, contact the Bitmessage developers and we can modify'
' the check or you can do it yourself by searching the source'
' code for this message.',
6: 'The encoding type must be 2 or 3.',
7: 'Could not decode address',
8: 'Checksum failed for address',
9: 'Invalid characters in address',
10: 'Address version number too high (or zero)',
11: 'The address version number currently must be 2, 3 or 4.'
' Others aren\'t supported. Check the address.',
12: 'The stream number must be 1. Others aren\'t supported.'
' Check the address.',
13: 'Could not find this address in your keys.dat file.',
14: 'Your fromAddress is disabled. Cannot send.',
15: 'Invalid ackData object size.',
16: 'You are already subscribed to that address.',
17: 'Label is not valid UTF-8 data.',
18: 'Chan name does not match address.',
19: 'The length of hash should be 32 bytes (encoded in hex'
' thus 64 characters).',
20: 'Invalid method:',
21: 'Unexpected API Failure',
22: 'Decode error',
23: 'Bool expected in eighteenByteRipe',
24: 'Chan address is already present.',
25: 'Specified address is not a chan address.'
' Use deleteAddress API call instead.',
26: 'Malformed varint in address: ',
27: 'Message is too long.'
}
def __init__(self, error_number, error_message): def __new__(mcs, name, bases, namespace):
super(APIError, self).__init__() result = super(ErrorCodes, mcs).__new__(mcs, name, bases, namespace)
self.error_number = error_number for code in mcs._CODES.iteritems():
self.error_message = error_message # beware: the formatting is adjusted for list-table
result.__doc__ += """ * - %04i
- %s
""" % code
return result
class APIError(xmlrpclib.Fault):
"""
APIError exception class
.. list-table:: Possible error values
:header-rows: 1
:widths: auto
* - Error Number
- Message
"""
__metaclass__ = ErrorCodes
def __str__(self): def __str__(self):
return "API Error %04i: %s" % (self.error_number, self.error_message) return "API Error %04i: %s" % (self.faultCode, self.faultString)
class StoppableXMLRPCServer(SimpleXMLRPCServer):
"""A SimpleXMLRPCServer that honours state.shutdown"""
allow_reuse_address = True
def serve_forever(self):
"""Start the SimpleXMLRPCServer"""
# pylint: disable=arguments-differ
while state.shutdown == 0:
self.handle_request()
# This thread, of which there is only one, runs the API. # This thread, of which there is only one, runs the API.
@ -87,22 +199,52 @@ class singleAPI(StoppableThread):
pass pass
def run(self): def run(self):
"""
The instance of `SimpleXMLRPCServer.SimpleXMLRPCServer` or
:class:`jsonrpclib.SimpleJSONRPCServer` is created and started here
with `BMRPCDispatcher` dispatcher.
"""
port = BMConfigParser().getint('bitmessagesettings', 'apiport') port = BMConfigParser().getint('bitmessagesettings', 'apiport')
try: try:
getattr(errno, 'WSAEADDRINUSE') getattr(errno, 'WSAEADDRINUSE')
except AttributeError: except AttributeError:
errno.WSAEADDRINUSE = errno.EADDRINUSE errno.WSAEADDRINUSE = errno.EADDRINUSE
RPCServerBase = SimpleXMLRPCServer
ct = 'text/xml'
if BMConfigParser().safeGet(
'bitmessagesettings', 'apivariant') == 'json':
try:
from jsonrpclib.SimpleJSONRPCServer import (
SimpleJSONRPCServer as RPCServerBase)
except ImportError:
logger.warning(
'jsonrpclib not available, failing back to XML-RPC')
else:
ct = 'application/json-rpc'
# Nested class. FIXME not found a better solution.
class StoppableRPCServer(RPCServerBase):
"""A SimpleXMLRPCServer that honours state.shutdown"""
allow_reuse_address = True
content_type = ct
def serve_forever(self, poll_interval=None):
"""Start the RPCServer"""
while state.shutdown == 0:
self.handle_request()
for attempt in range(50): for attempt in range(50):
try: try:
if attempt > 0: if attempt > 0:
logger.warning( logger.warning(
'Failed to start API listener on port %s', port) 'Failed to start API listener on port %s', port)
port = random.randint(32767, 65535) port = random.randint(32767, 65535)
se = StoppableXMLRPCServer( se = StoppableRPCServer(
(BMConfigParser().get( (BMConfigParser().get(
'bitmessagesettings', 'apiinterface'), 'bitmessagesettings', 'apiinterface'),
port), port),
MySimpleXMLRPCRequestHandler, True, True) BMXMLRPCRequestHandler, True, encoding='UTF-8')
except socket.error as e: except socket.error as e:
if e.errno in (errno.EADDRINUSE, errno.WSAEADDRINUSE): if e.errno in (errno.EADDRINUSE, errno.WSAEADDRINUSE):
continue continue
@ -113,6 +255,8 @@ class singleAPI(StoppableThread):
'bitmessagesettings', 'apiport', str(port)) 'bitmessagesettings', 'apiport', str(port))
BMConfigParser().save() BMConfigParser().save()
break break
se.register_instance(BMRPCDispatcher())
se.register_introspection_functions() se.register_introspection_functions()
apiNotifyPath = BMConfigParser().safeGet( apiNotifyPath = BMConfigParser().safeGet(
@ -132,14 +276,69 @@ class singleAPI(StoppableThread):
se.serve_forever() se.serve_forever()
class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): class CommandHandler(type):
""" """
This is one of several classes that constitute the API The metaclass for `BMRPCDispatcher` which fills _handlers dict by
methods decorated with @command
This class was written by Vaibhav Bhatia. Modified by Jonathan Warren (Atheros).
http://code.activestate.com/recipes/501148-xmlrpc-serverclient-which-does-cookie-handling-and/
""" """
def __new__(mcs, name, bases, namespace):
# pylint: disable=protected-access
result = super(CommandHandler, mcs).__new__(
mcs, name, bases, namespace)
result.config = BMConfigParser()
result._handlers = {}
apivariant = result.config.safeGet('bitmessagesettings', 'apivariant')
for func in namespace.values():
try:
for alias in getattr(func, '_cmd'):
try:
prefix, alias = alias.split(':')
if apivariant != prefix:
continue
except ValueError:
pass
result._handlers[alias] = func
except AttributeError:
pass
return result
class command(object): # pylint: disable=too-few-public-methods
"""Decorator for API command method"""
def __init__(self, *aliases):
self.aliases = aliases
def __call__(self, func):
if BMConfigParser().safeGet(
'bitmessagesettings', 'apivariant') == 'legacy':
def wrapper(*args):
"""
A wrapper for legacy apivariant which dumps the result
into string of json
"""
result = func(*args)
return result if isinstance(result, (int, str)) \
else json.dumps(result, indent=4)
wrapper.__doc__ = func.__doc__
else:
wrapper = func
# pylint: disable=protected-access
wrapper._cmd = self.aliases
wrapper.__doc__ = """Commands: *%s*
""" % ', '.join(self.aliases) + wrapper.__doc__.lstrip()
return wrapper
# This is one of several classes that constitute the API
# This class was written by Vaibhav Bhatia.
# Modified by Jonathan Warren (Atheros).
# Further modified by the Bitmessage developers
# http://code.activestate.com/recipes/501148
class BMXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
"""The main API handler"""
# pylint: disable=protected-access
def do_POST(self): def do_POST(self):
""" """
Handles the HTTP POST request. Handles the HTTP POST request.
@ -147,8 +346,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
Attempts to interpret all HTTP POST requests as XML-RPC calls, Attempts to interpret all HTTP POST requests as XML-RPC calls,
which are forwarded to the server's _dispatch method for handling. which are forwarded to the server's _dispatch method for handling.
Note: this method is the same as in SimpleXMLRPCRequestHandler, .. note:: this method is the same as in
just hacked to handle cookies `SimpleXMLRPCServer.SimpleXMLRPCRequestHandler`,
just hacked to handle cookies
""" """
# Check that the path is legal # Check that the path is legal
@ -170,22 +370,35 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
size_remaining -= len(L[-1]) size_remaining -= len(L[-1])
data = ''.join(L) data = ''.join(L)
# In previous versions of SimpleXMLRPCServer, _dispatch # pylint: disable=attribute-defined-outside-init
# could be overridden in this class, instead of in self.cookies = []
# SimpleXMLRPCDispatcher. To maintain backwards compatibility,
# check to see if a subclass implements _dispatch and dispatch validuser = self.APIAuthenticateClient()
# using that method if present. if not validuser:
response = self.server._marshaled_dispatch( # pylint: disable=protected-access time.sleep(2)
data, getattr(self, '_dispatch', None) self.send_response(httplib.UNAUTHORIZED)
) self.end_headers()
except BaseException: # This should only happen if the module is buggy return
# "RPC Username or password incorrect or HTTP header"
# " lacks authentication at all."
else:
# In previous versions of SimpleXMLRPCServer, _dispatch
# could be overridden in this class, instead of in
# SimpleXMLRPCDispatcher. To maintain backwards compatibility,
# check to see if a subclass implements _dispatch and dispatch
# using that method if present.
response = self.server._marshaled_dispatch(
data, getattr(self, '_dispatch', None)
)
except Exception: # This should only happen if the module is buggy
# internal error, report as HTTP server error # internal error, report as HTTP server error
self.send_response(500) self.send_response(httplib.INTERNAL_SERVER_ERROR)
self.end_headers() self.end_headers()
else: else:
# got a valid XML RPC response # got a valid XML RPC response
self.send_response(200) self.send_response(httplib.OK)
self.send_header("Content-type", "text/xml") self.send_header("Content-type", self.server.content_type)
self.send_header("Content-length", str(len(response))) self.send_header("Content-length", str(len(response)))
# HACK :start -> sends cookies here # HACK :start -> sends cookies here
@ -206,16 +419,19 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
def APIAuthenticateClient(self): def APIAuthenticateClient(self):
"""Predicate to check for valid API credentials in the request header""" """
Predicate to check for valid API credentials in the request header
"""
if 'Authorization' in self.headers: if 'Authorization' in self.headers:
# handle Basic authentication # handle Basic authentication
_, encstr = self.headers.get('Authorization').split() encstr = self.headers.get('Authorization').split()[1]
emailid, password = encstr.decode('base64').split(':') emailid, password = encstr.decode('base64').split(':')
return ( return (
emailid == BMConfigParser().get('bitmessagesettings', 'apiusername') and emailid == BMConfigParser().get(
password == BMConfigParser().get('bitmessagesettings', 'apipassword') 'bitmessagesettings', 'apiusername'
) ) and password == BMConfigParser().get(
'bitmessagesettings', 'apipassword'))
else: else:
logger.warning( logger.warning(
'Authentication failed because header lacks' 'Authentication failed because header lacks'
@ -224,7 +440,14 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
return False return False
def _decode(self, text, decode_type):
# pylint: disable=no-self-use,no-member,too-many-public-methods
class BMRPCDispatcher(object):
"""This class is used to dispatch API commands"""
__metaclass__ = CommandHandler
@staticmethod
def _decode(text, decode_type):
try: try:
if decode_type == 'hex': if decode_type == 'hex':
return unhexlify(text) return unhexlify(text)
@ -232,29 +455,26 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
return base64.b64decode(text) return base64.b64decode(text)
except Exception as e: except Exception as e:
raise APIError( raise APIError(
22, "Decode error - %s. Had trouble while decoding string: %r" 22, 'Decode error - %s. Had trouble while decoding string: %r'
% (e, text) % (e, text)
) )
return None
def _verifyAddress(self, address): def _verifyAddress(self, address):
status, addressVersionNumber, streamNumber, ripe = \ status, addressVersionNumber, streamNumber, ripe = \
decodeAddress(address) decodeAddress(address)
if status != 'success': if status != 'success':
logger.warning(
'API Error 0007: Could not decode address %s. Status: %s.',
address, status
)
if status == 'checksumfailed': if status == 'checksumfailed':
raise APIError(8, 'Checksum failed for address: ' + address) raise APIError(8, 'Checksum failed for address: ' + address)
if status == 'invalidcharacters': if status == 'invalidcharacters':
raise APIError(9, 'Invalid characters in address: ' + address) raise APIError(9, 'Invalid characters in address: ' + address)
if status == 'versiontoohigh': if status == 'versiontoohigh':
raise APIError(10, 'Address version number too high (or zero) in address: ' + address) raise APIError(
10, 'Address version number too high (or zero) in address: '
+ address)
if status == 'varintmalformed': if status == 'varintmalformed':
raise APIError(26, 'Malformed varint in address: ' + address) raise APIError(26, 'Malformed varint in address: ' + address)
raise APIError(7, 'Could not decode address: %s : %s' % (address, status)) raise APIError(
7, 'Could not decode address: %s : %s' % (address, status))
if addressVersionNumber < 2 or addressVersionNumber > 4: if addressVersionNumber < 2 or addressVersionNumber > 4:
raise APIError( raise APIError(
11, 'The address version number currently must be 2, 3 or 4.' 11, 'The address version number currently must be 2, 3 or 4.'
@ -266,71 +486,108 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
' Check the address.' ' Check the address.'
) )
return (status, addressVersionNumber, streamNumber, ripe) return {
'status': status,
'addressVersion': addressVersionNumber,
'streamNumber': streamNumber,
'ripe': base64.b64encode(ripe)
} if self._method == 'decodeAddress' else (
status, addressVersionNumber, streamNumber, ripe)
@staticmethod
def _dump_inbox_message( # pylint: disable=too-many-arguments
msgid, toAddress, fromAddress, subject, received,
message, encodingtype, read):
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message)
return {
'msgid': hexlify(msgid),
'toAddress': toAddress,
'fromAddress': fromAddress,
'subject': base64.b64encode(subject),
'message': base64.b64encode(message),
'encodingType': encodingtype,
'receivedTime': received,
'read': read
}
@staticmethod
def _dump_sent_message( # pylint: disable=too-many-arguments
msgid, toAddress, fromAddress, subject, lastactiontime,
message, encodingtype, status, ackdata):
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message)
return {
'msgid': hexlify(msgid),
'toAddress': toAddress,
'fromAddress': fromAddress,
'subject': base64.b64encode(subject),
'message': base64.b64encode(message),
'encodingType': encodingtype,
'lastActionTime': lastactiontime,
'status': status,
'ackData': hexlify(ackdata)
}
# Request Handlers # Request Handlers
def HandleListAddresses(self, method): @command('decodeAddress')
"""Handle a request to list addresses""" def HandleDecodeAddress(self, address):
"""
Decode given address and return dict with
status, addressVersion, streamNumber and ripe keys
"""
return self._verifyAddress(address)
data = '{"addresses":[' @command('listAddresses', 'listAddresses2')
for addressInKeysFile in BMConfigParser().addresses(): def HandleListAddresses(self):
status, addressVersionNumber, streamNumber, hash01 = decodeAddress( # pylint: disable=unused-variable """
addressInKeysFile) Returns dict with a list of all used addresses with their properties
if len(data) > 20: in the *addresses* key.
data += ',' """
if BMConfigParser().has_option(addressInKeysFile, 'chan'): data = []
chan = BMConfigParser().getboolean(addressInKeysFile, 'chan') for address in self.config.addresses():
else: streamNumber = decodeAddress(address)[2]
chan = False label = self.config.get(address, 'label')
label = BMConfigParser().get(addressInKeysFile, 'label') if self._method == 'listAddresses2':
if method == 'listAddresses2':
label = base64.b64encode(label) label = base64.b64encode(label)
data += json.dumps({ data.append({
'label': label, 'label': label,
'address': addressInKeysFile, 'address': address,
'stream': streamNumber, 'stream': streamNumber,
'enabled': 'enabled': self.config.safeGetBoolean(address, 'enabled'),
BMConfigParser().getboolean(addressInKeysFile, 'enabled'), 'chan': self.config.safeGetBoolean(address, 'chan')
'chan': chan })
}, indent=4, separators=(',', ': ')) return {'addresses': data}
data += ']}'
return data
def HandleListAddressBookEntries(self, params): # the listAddressbook alias should be removed eventually.
"""Handle a request to list address book entries""" @command('listAddressBookEntries', 'legacy:listAddressbook')
def HandleListAddressBookEntries(self, label=None):
if len(params) == 1: """
label, = params Returns dict with a list of all address book entries (address and label)
label = self._decode(label, "base64") in the *addresses* key.
queryreturn = sqlQuery( """
"SELECT label, address from addressbook WHERE label = ?", queryreturn = sqlQuery(
label) "SELECT label, address from addressbook WHERE label = ?",
elif len(params) > 1: label
raise APIError(0, "Too many paremeters, max 1") ) if label else sqlQuery("SELECT label, address from addressbook")
else: data = []
queryreturn = sqlQuery("SELECT label, address from addressbook") for label, address in queryreturn:
data = '{"addresses":['
for row in queryreturn:
label, address = row
label = shared.fixPotentiallyInvalidUTF8Data(label) label = shared.fixPotentiallyInvalidUTF8Data(label)
if len(data) > 20: data.append({
data += ','
data += json.dumps({
'label': base64.b64encode(label), 'label': base64.b64encode(label),
'address': address}, indent=4, separators=(',', ': ')) 'address': address
data += ']}' })
return data return {'addresses': data}
def HandleAddAddressBookEntry(self, params): # the addAddressbook alias should be deleted eventually.
"""Handle a request to add an address book entry""" @command('addAddressBookEntry', 'legacy:addAddressbook')
def HandleAddAddressBookEntry(self, address, label):
if len(params) != 2: """Add an entry to address book. label must be base64 encoded."""
raise APIError(0, "I need label and address")
address, label = params
label = self._decode(label, "base64") label = self._decode(label, "base64")
address = addBMIfNotPresent(address) address = addBMIfNotPresent(address)
self._verifyAddress(address) self._verifyAddress(address)
# TODO: add unique together constraint in the table
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT address FROM addressbook WHERE address=?", address) "SELECT address FROM addressbook WHERE address=?", address)
if queryreturn != []: if queryreturn != []:
@ -343,12 +600,10 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
queues.UISignalQueue.put(('rerenderAddressBook', '')) queues.UISignalQueue.put(('rerenderAddressBook', ''))
return "Added address %s to address book" % address return "Added address %s to address book" % address
def HandleDeleteAddressBookEntry(self, params): # the deleteAddressbook alias should be deleted eventually.
"""Handle a request to delete an address book entry""" @command('deleteAddressBookEntry', 'legacy:deleteAddressbook')
def HandleDeleteAddressBookEntry(self, address):
if len(params) != 1: """Delete an entry from address book."""
raise APIError(0, "I need an address")
address, = params
address = addBMIfNotPresent(address) address = addBMIfNotPresent(address)
self._verifyAddress(address) self._verifyAddress(address)
sqlExecute('DELETE FROM addressbook WHERE address=?', address) sqlExecute('DELETE FROM addressbook WHERE address=?', address)
@ -357,46 +612,42 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
queues.UISignalQueue.put(('rerenderAddressBook', '')) queues.UISignalQueue.put(('rerenderAddressBook', ''))
return "Deleted address book entry for %s if it existed" % address return "Deleted address book entry for %s if it existed" % address
def HandleCreateRandomAddress(self, params): @command('createRandomAddress')
"""Handle a request to create a random address""" def HandleCreateRandomAddress(
self, label, eighteenByteRipe=False, totalDifficulty=0,
smallMessageDifficulty=0
):
"""
Create one address using the random number generator.
if not params: :param str label: base64 encoded label for the address
raise APIError(0, 'I need parameters!') :param bool eighteenByteRipe: is telling Bitmessage whether to
generate an address with an 18 byte RIPE hash
(as opposed to a 19 byte hash).
"""
elif len(params) == 1: nonceTrialsPerByte = self.config.get(
label, = params 'bitmessagesettings', 'defaultnoncetrialsperbyte'
eighteenByteRipe = False ) if not totalDifficulty else int(
nonceTrialsPerByte = BMConfigParser().get( defaults.networkDefaultProofOfWorkNonceTrialsPerByte
'bitmessagesettings', 'defaultnoncetrialsperbyte') * totalDifficulty)
payloadLengthExtraBytes = BMConfigParser().get( payloadLengthExtraBytes = self.config.get(
'bitmessagesettings', 'defaultpayloadlengthextrabytes') 'bitmessagesettings', 'defaultpayloadlengthextrabytes'
elif len(params) == 2: ) if not smallMessageDifficulty else int(
label, eighteenByteRipe = params defaults.networkDefaultPayloadLengthExtraBytes
nonceTrialsPerByte = BMConfigParser().get( * smallMessageDifficulty)
'bitmessagesettings', 'defaultnoncetrialsperbyte')
payloadLengthExtraBytes = BMConfigParser().get( if not isinstance(eighteenByteRipe, bool):
'bitmessagesettings', 'defaultpayloadlengthextrabytes') raise APIError(
elif len(params) == 3: 23, 'Bool expected in eighteenByteRipe, saw %s instead'
label, eighteenByteRipe, totalDifficulty = params % type(eighteenByteRipe))
nonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
payloadLengthExtraBytes = BMConfigParser().get(
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
elif len(params) == 4:
label, eighteenByteRipe, totalDifficulty, \
smallMessageDifficulty = params
nonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
payloadLengthExtraBytes = int(
defaults.networkDefaultPayloadLengthExtraBytes * smallMessageDifficulty)
else:
raise APIError(0, 'Too many parameters!')
label = self._decode(label, "base64") label = self._decode(label, "base64")
try: try:
unicode(label, 'utf-8') unicode(label, 'utf-8')
except BaseException: except UnicodeDecodeError:
raise APIError(17, 'Label is not valid UTF-8 data.') raise APIError(17, 'Label is not valid UTF-8 data.')
queues.apiAddressGeneratorReturnQueue.queue.clear() queues.apiAddressGeneratorReturnQueue.queue.clear()
# FIXME hard coded stream no
streamNumberForAddress = 1 streamNumberForAddress = 1
queues.addressGeneratorQueue.put(( queues.addressGeneratorQueue.put((
'createRandomAddress', 4, streamNumberForAddress, label, 1, "", 'createRandomAddress', 4, streamNumberForAddress, label, 1, "",
@ -404,94 +655,53 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
)) ))
return queues.apiAddressGeneratorReturnQueue.get() return queues.apiAddressGeneratorReturnQueue.get()
def HandleCreateDeterministicAddresses(self, params): # pylint: disable=too-many-arguments
"""Handle a request to create a deterministic address""" @command('createDeterministicAddresses')
def HandleCreateDeterministicAddresses(
self, passphrase, numberOfAddresses=1, addressVersionNumber=0,
streamNumber=0, eighteenByteRipe=False, totalDifficulty=0,
smallMessageDifficulty=0
):
"""
Create many addresses deterministically using the passphrase.
if not params: :param str passphrase: base64 encoded passphrase
raise APIError(0, 'I need parameters!') :param int numberOfAddresses: number of addresses to create,
up to 999
elif len(params) == 1: *addressVersionNumber* and *streamNumber* may be set to 0
passphrase, = params which will tell Bitmessage to use the most up-to-date
numberOfAddresses = 1 address version and the most available stream.
addressVersionNumber = 0 """
streamNumber = 0
eighteenByteRipe = False
nonceTrialsPerByte = BMConfigParser().get(
'bitmessagesettings', 'defaultnoncetrialsperbyte')
payloadLengthExtraBytes = BMConfigParser().get(
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
elif len(params) == 2: nonceTrialsPerByte = self.config.get(
passphrase, numberOfAddresses = params 'bitmessagesettings', 'defaultnoncetrialsperbyte'
addressVersionNumber = 0 ) if not totalDifficulty else int(
streamNumber = 0 defaults.networkDefaultProofOfWorkNonceTrialsPerByte
eighteenByteRipe = False * totalDifficulty)
nonceTrialsPerByte = BMConfigParser().get( payloadLengthExtraBytes = self.config.get(
'bitmessagesettings', 'defaultnoncetrialsperbyte') 'bitmessagesettings', 'defaultpayloadlengthextrabytes'
payloadLengthExtraBytes = BMConfigParser().get( ) if not smallMessageDifficulty else int(
'bitmessagesettings', 'defaultpayloadlengthextrabytes') defaults.networkDefaultPayloadLengthExtraBytes
* smallMessageDifficulty)
elif len(params) == 3:
passphrase, numberOfAddresses, addressVersionNumber = params
streamNumber = 0
eighteenByteRipe = False
nonceTrialsPerByte = BMConfigParser().get(
'bitmessagesettings', 'defaultnoncetrialsperbyte')
payloadLengthExtraBytes = BMConfigParser().get(
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
elif len(params) == 4:
passphrase, numberOfAddresses, addressVersionNumber, \
streamNumber = params
eighteenByteRipe = False
nonceTrialsPerByte = BMConfigParser().get(
'bitmessagesettings', 'defaultnoncetrialsperbyte')
payloadLengthExtraBytes = BMConfigParser().get(
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
elif len(params) == 5:
passphrase, numberOfAddresses, addressVersionNumber, \
streamNumber, eighteenByteRipe = params
nonceTrialsPerByte = BMConfigParser().get(
'bitmessagesettings', 'defaultnoncetrialsperbyte')
payloadLengthExtraBytes = BMConfigParser().get(
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
elif len(params) == 6:
passphrase, numberOfAddresses, addressVersionNumber, \
streamNumber, eighteenByteRipe, totalDifficulty = params
nonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
payloadLengthExtraBytes = BMConfigParser().get(
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
elif len(params) == 7:
passphrase, numberOfAddresses, addressVersionNumber, \
streamNumber, eighteenByteRipe, totalDifficulty, \
smallMessageDifficulty = params
nonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
payloadLengthExtraBytes = int(
defaults.networkDefaultPayloadLengthExtraBytes * smallMessageDifficulty)
else:
raise APIError(0, 'Too many parameters!')
if not passphrase: if not passphrase:
raise APIError(1, 'The specified passphrase is blank.') raise APIError(1, 'The specified passphrase is blank.')
if not isinstance(eighteenByteRipe, bool): if not isinstance(eighteenByteRipe, bool):
raise APIError( raise APIError(
23, 'Bool expected in eighteenByteRipe, saw %s instead' % 23, 'Bool expected in eighteenByteRipe, saw %s instead'
type(eighteenByteRipe)) % type(eighteenByteRipe))
passphrase = self._decode(passphrase, "base64") passphrase = self._decode(passphrase, "base64")
# 0 means "just use the proper addressVersionNumber" # 0 means "just use the proper addressVersionNumber"
if addressVersionNumber == 0: if addressVersionNumber == 0:
addressVersionNumber = 4 addressVersionNumber = 4
if addressVersionNumber != 3 and addressVersionNumber != 4: if addressVersionNumber not in (3, 4):
raise APIError( raise APIError(
2, 'The address version number currently must be 3, 4, or 0' 2, 'The address version number currently must be 3, 4, or 0'
' (which means auto-select). %i isn\'t supported.' % ' (which means auto-select). %i isn\'t supported.'
addressVersionNumber) % addressVersionNumber)
if streamNumber == 0: # 0 means "just use the most available stream" if streamNumber == 0: # 0 means "just use the most available stream"
streamNumber = 1 streamNumber = 1 # FIXME hard coded stream no
if streamNumber != 1: if streamNumber != 1:
raise APIError( raise APIError(
3, 'The stream number must be 1 (or 0 which means' 3, 'The stream number must be 1 (or 0 which means'
@ -516,27 +726,24 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
'unused API address', numberOfAddresses, passphrase, 'unused API address', numberOfAddresses, passphrase,
eighteenByteRipe, nonceTrialsPerByte, payloadLengthExtraBytes eighteenByteRipe, nonceTrialsPerByte, payloadLengthExtraBytes
)) ))
data = '{"addresses":['
queueReturn = queues.apiAddressGeneratorReturnQueue.get()
for item in queueReturn:
if len(data) > 20:
data += ','
data += "\"" + item + "\""
data += ']}'
return data
def HandleGetDeterministicAddress(self, params): return {'addresses': queues.apiAddressGeneratorReturnQueue.get()}
"""Handle a request to get a deterministic address"""
@command('getDeterministicAddress')
def HandleGetDeterministicAddress(
self, passphrase, addressVersionNumber, streamNumber):
"""
Similar to *createDeterministicAddresses* except that the one
address that is returned will not be added to the Bitmessage
user interface or the keys.dat file.
"""
if len(params) != 3:
raise APIError(0, 'I need exactly 3 parameters.')
passphrase, addressVersionNumber, streamNumber = params
numberOfAddresses = 1 numberOfAddresses = 1
eighteenByteRipe = False eighteenByteRipe = False
if not passphrase: if not passphrase:
raise APIError(1, 'The specified passphrase is blank.') raise APIError(1, 'The specified passphrase is blank.')
passphrase = self._decode(passphrase, "base64") passphrase = self._decode(passphrase, "base64")
if addressVersionNumber != 3 and addressVersionNumber != 4: if addressVersionNumber not in (3, 4):
raise APIError( raise APIError(
2, 'The address version number currently must be 3 or 4. %i' 2, 'The address version number currently must be 3 or 4. %i'
' isn\'t supported.' % addressVersionNumber) ' isn\'t supported.' % addressVersionNumber)
@ -554,16 +761,14 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
)) ))
return queues.apiAddressGeneratorReturnQueue.get() return queues.apiAddressGeneratorReturnQueue.get()
def HandleCreateChan(self, params): @command('createChan')
"""Handle a request to create a chan""" def HandleCreateChan(self, passphrase):
"""
Creates a new chan. passphrase must be base64 encoded.
Returns the corresponding Bitmessage address.
"""
if not params:
raise APIError(0, 'I need parameters.')
elif len(params) == 1:
passphrase, = params
passphrase = self._decode(passphrase, "base64") passphrase = self._decode(passphrase, "base64")
if not passphrase: if not passphrase:
raise APIError(1, 'The specified passphrase is blank.') raise APIError(1, 'The specified passphrase is blank.')
# It would be nice to make the label the passphrase but it is # It would be nice to make the label the passphrase but it is
@ -571,7 +776,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
try: try:
unicode(passphrase, 'utf-8') unicode(passphrase, 'utf-8')
label = str_chan + ' ' + passphrase label = str_chan + ' ' + passphrase
except BaseException: except UnicodeDecodeError:
label = str_chan + ' ' + repr(passphrase) label = str_chan + ' ' + repr(passphrase)
addressVersionNumber = 4 addressVersionNumber = 4
@ -584,18 +789,17 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
passphrase, True passphrase, True
)) ))
queueReturn = queues.apiAddressGeneratorReturnQueue.get() queueReturn = queues.apiAddressGeneratorReturnQueue.get()
if not queueReturn: try:
return queueReturn[0]
except IndexError:
raise APIError(24, 'Chan address is already present.') raise APIError(24, 'Chan address is already present.')
address = queueReturn[0]
return address
def HandleJoinChan(self, params): @command('joinChan')
"""Handle a request to join a chan""" def HandleJoinChan(self, passphrase, suppliedAddress):
"""
Join a chan. passphrase must be base64 encoded. Returns 'success'.
"""
if len(params) < 2:
raise APIError(0, 'I need two parameters.')
elif len(params) == 2:
passphrase, suppliedAddress = params
passphrase = self._decode(passphrase, "base64") passphrase = self._decode(passphrase, "base64")
if not passphrase: if not passphrase:
raise APIError(1, 'The specified passphrase is blank.') raise APIError(1, 'The specified passphrase is blank.')
@ -604,374 +808,287 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
try: try:
unicode(passphrase, 'utf-8') unicode(passphrase, 'utf-8')
label = str_chan + ' ' + passphrase label = str_chan + ' ' + passphrase
except BaseException: except UnicodeDecodeError:
label = str_chan + ' ' + repr(passphrase) label = str_chan + ' ' + repr(passphrase)
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress( # pylint: disable=unused-variable self._verifyAddress(suppliedAddress)
suppliedAddress)
suppliedAddress = addBMIfNotPresent(suppliedAddress) suppliedAddress = addBMIfNotPresent(suppliedAddress)
queues.apiAddressGeneratorReturnQueue.queue.clear() queues.apiAddressGeneratorReturnQueue.queue.clear()
queues.addressGeneratorQueue.put(( queues.addressGeneratorQueue.put((
'joinChan', suppliedAddress, label, passphrase, True 'joinChan', suppliedAddress, label, passphrase, True
)) ))
addressGeneratorReturnValue = \ queueReturn = queues.apiAddressGeneratorReturnQueue.get()
queues.apiAddressGeneratorReturnQueue.get() try:
if queueReturn[0] == 'chan name does not match address':
if addressGeneratorReturnValue[0] == \ raise APIError(18, 'Chan name does not match address.')
'chan name does not match address': except IndexError:
raise APIError(18, 'Chan name does not match address.')
if not addressGeneratorReturnValue:
raise APIError(24, 'Chan address is already present.') raise APIError(24, 'Chan address is already present.')
return "success" return "success"
def HandleLeaveChan(self, params): @command('leaveChan')
"""Handle a request to leave a chan""" def HandleLeaveChan(self, address):
"""
Leave a chan. Returns 'success'.
if not params: .. note:: at this time, the address is still shown in the UI
raise APIError(0, 'I need parameters.') until a restart.
elif len(params) == 1: """
address, = params self._verifyAddress(address)
# pylint: disable=unused-variable
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(address)
address = addBMIfNotPresent(address) address = addBMIfNotPresent(address)
if not BMConfigParser().has_section(address): if not self.config.safeGetBoolean(address, 'chan'):
raise APIError(
13, 'Could not find this address in your keys.dat file.')
if not BMConfigParser().safeGetBoolean(address, 'chan'):
raise APIError( raise APIError(
25, 'Specified address is not a chan address.' 25, 'Specified address is not a chan address.'
' Use deleteAddress API call instead.') ' Use deleteAddress API call instead.')
BMConfigParser().remove_section(address) try:
with open(state.appdata + 'keys.dat', 'wb') as configfile: self.config.remove_section(address)
BMConfigParser().write(configfile) except ConfigParser.NoSectionError:
return 'success'
def HandleDeleteAddress(self, params):
"""Handle a request to delete an address"""
if not params:
raise APIError(0, 'I need parameters.')
elif len(params) == 1:
address, = params
# pylint: disable=unused-variable
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(address)
address = addBMIfNotPresent(address)
if not BMConfigParser().has_section(address):
raise APIError( raise APIError(
13, 'Could not find this address in your keys.dat file.') 13, 'Could not find this address in your keys.dat file.')
BMConfigParser().remove_section(address) self.config.save()
with open(state.appdata + 'keys.dat', 'wb') as configfile: queues.UISignalQueue.put(('rerenderMessagelistFromLabels', ''))
BMConfigParser().write(configfile) queues.UISignalQueue.put(('rerenderMessagelistToLabels', ''))
return "success"
@command('deleteAddress')
def HandleDeleteAddress(self, address):
"""
Permanently delete the address from keys.dat file. Returns 'success'.
"""
self._verifyAddress(address)
address = addBMIfNotPresent(address)
try:
self.config.remove_section(address)
except ConfigParser.NoSectionError:
raise APIError(
13, 'Could not find this address in your keys.dat file.')
self.config.save()
queues.UISignalQueue.put(('writeNewAddressToTable', ('', '', ''))) queues.UISignalQueue.put(('writeNewAddressToTable', ('', '', '')))
shared.reloadMyAddressHashes() shared.reloadMyAddressHashes()
return 'success' return "success"
def HandleGetAllInboxMessages(self, params): # pylint: disable=unused-argument @command('getAllInboxMessages')
"""Handle a request to get all inbox messages""" def HandleGetAllInboxMessages(self):
"""
Returns a dict with all inbox messages in the *inboxMessages* key.
The message is a dict with such keys:
*msgid*, *toAddress*, *fromAddress*, *subject*, *message*,
*encodingType*, *receivedTime*, *read*.
*msgid* is hex encoded string.
*subject* and *message* are base64 encoded.
"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT msgid, toaddress, fromaddress, subject, received, message," "SELECT msgid, toaddress, fromaddress, subject, received, message,"
" encodingtype, read FROM inbox where folder='inbox'" " encodingtype, read FROM inbox WHERE folder='inbox'"
" ORDER BY received" " ORDER BY received"
) )
data = '{"inboxMessages":[' return {"inboxMessages": [
for row in queryreturn: self._dump_inbox_message(*data) for data in queryreturn
msgid, toAddress, fromAddress, subject, received, message, \ ]}
encodingtype, read = row
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message)
if len(data) > 25:
data += ','
data += json.dumps({
'msgid': hexlify(msgid),
'toAddress': toAddress,
'fromAddress': fromAddress,
'subject': base64.b64encode(subject),
'message': base64.b64encode(message),
'encodingType': encodingtype,
'receivedTime': received,
'read': read}, indent=4, separators=(',', ': '))
data += ']}'
return data
def HandleGetAllInboxMessageIds(self, params): # pylint: disable=unused-argument @command('getAllInboxMessageIds', 'getAllInboxMessageIDs')
"""Handle a request to get all inbox message IDs""" def HandleGetAllInboxMessageIds(self):
"""
The same as *getAllInboxMessages* but returns only *msgid*s,
result key - *inboxMessageIds*.
"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT msgid FROM inbox where folder='inbox' ORDER BY received") "SELECT msgid FROM inbox where folder='inbox' ORDER BY received")
data = '{"inboxMessageIds":['
for row in queryreturn:
msgid = row[0]
if len(data) > 25:
data += ','
data += json.dumps(
{'msgid': hexlify(msgid)}, indent=4, separators=(',', ': '))
data += ']}'
return data
def HandleGetInboxMessageById(self, params): return {"inboxMessageIds": [
"""Handle a request to get an inbox messsage by ID""" {'msgid': hexlify(msgid)} for msgid, in queryreturn
]}
if not params: @command('getInboxMessageById', 'getInboxMessageByID')
raise APIError(0, 'I need parameters!') def HandleGetInboxMessageById(self, hid, readStatus=None):
elif len(params) == 1: """
msgid = self._decode(params[0], "hex") Returns a dict with list containing single message in the result
elif len(params) >= 2: key *inboxMessage*. May also return None if message was not found.
msgid = self._decode(params[0], "hex")
readStatus = params[1] :param str hid: hex encoded msgid
:param bool readStatus: sets the message's read status if present
"""
msgid = self._decode(hid, "hex")
if readStatus is not None:
if not isinstance(readStatus, bool): if not isinstance(readStatus, bool):
raise APIError( raise APIError(
23, 'Bool expected in readStatus, saw %s instead.' % 23, 'Bool expected in readStatus, saw %s instead.'
type(readStatus)) % type(readStatus))
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT read FROM inbox WHERE msgid=?", msgid) "SELECT read FROM inbox WHERE msgid=?", msgid)
# UPDATE is slow, only update if status is different # UPDATE is slow, only update if status is different
if queryreturn != [] and (queryreturn[0][0] == 1) != readStatus: try:
sqlExecute( if (queryreturn[0][0] == 1) != readStatus:
"UPDATE inbox set read = ? WHERE msgid=?", sqlExecute(
readStatus, msgid) "UPDATE inbox set read = ? WHERE msgid=?",
queues.UISignalQueue.put(('changedInboxUnread', None)) readStatus, msgid)
queues.UISignalQueue.put(('changedInboxUnread', None))
except IndexError:
pass
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT msgid, toaddress, fromaddress, subject, received, message," "SELECT msgid, toaddress, fromaddress, subject, received, message,"
" encodingtype, read FROM inbox WHERE msgid=?", msgid " encodingtype, read FROM inbox WHERE msgid=?", msgid
) )
data = '{"inboxMessage":[' try:
for row in queryreturn: return {"inboxMessage": [
msgid, toAddress, fromAddress, subject, received, message, \ self._dump_inbox_message(*queryreturn[0])]}
encodingtype, read = row except IndexError:
subject = shared.fixPotentiallyInvalidUTF8Data(subject) pass # FIXME inconsistent
message = shared.fixPotentiallyInvalidUTF8Data(message)
data += json.dumps({
'msgid': hexlify(msgid),
'toAddress': toAddress,
'fromAddress': fromAddress,
'subject': base64.b64encode(subject),
'message': base64.b64encode(message),
'encodingType': encodingtype,
'receivedTime': received,
'read': read}, indent=4, separators=(',', ': '))
data += ']}'
return data
def HandleGetAllSentMessages(self, params): # pylint: disable=unused-argument @command('getAllSentMessages')
"""Handle a request to get all sent messages""" def HandleGetAllSentMessages(self):
"""
The same as *getAllInboxMessages* but for sent,
result key - *sentMessages*. Message dict keys are:
*msgid*, *toAddress*, *fromAddress*, *subject*, *message*,
*encodingType*, *lastActionTime*, *status*, *ackData*.
*ackData* is also a hex encoded string.
"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT msgid, toaddress, fromaddress, subject, lastactiontime," "SELECT msgid, toaddress, fromaddress, subject, lastactiontime,"
" message, encodingtype, status, ackdata FROM sent" " message, encodingtype, status, ackdata FROM sent"
" WHERE folder='sent' ORDER BY lastactiontime" " WHERE folder='sent' ORDER BY lastactiontime"
) )
data = '{"sentMessages":[' return {"sentMessages": [
for row in queryreturn: self._dump_sent_message(*data) for data in queryreturn
msgid, toAddress, fromAddress, subject, lastactiontime, message, \ ]}
encodingtype, status, ackdata = row
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message)
if len(data) > 25:
data += ','
data += json.dumps({
'msgid': hexlify(msgid),
'toAddress': toAddress,
'fromAddress': fromAddress,
'subject': base64.b64encode(subject),
'message': base64.b64encode(message),
'encodingType': encodingtype,
'lastActionTime': lastactiontime,
'status': status,
'ackData': hexlify(ackdata)}, indent=4, separators=(',', ': '))
data += ']}'
return data
def HandleGetAllSentMessageIds(self, params): # pylint: disable=unused-argument @command('getAllSentMessageIds', 'getAllSentMessageIDs')
"""Handle a request to get all sent message IDs""" def HandleGetAllSentMessageIds(self):
"""
The same as *getAllInboxMessageIds* but for sent,
result key - *sentMessageIds*.
"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT msgid FROM sent where folder='sent'" "SELECT msgid FROM sent WHERE folder='sent'"
" ORDER BY lastactiontime" " ORDER BY lastactiontime"
) )
data = '{"sentMessageIds":[' return {"sentMessageIds": [
for row in queryreturn: {'msgid': hexlify(msgid)} for msgid, in queryreturn
msgid = row[0] ]}
if len(data) > 25:
data += ','
data += json.dumps(
{'msgid': hexlify(msgid)}, indent=4, separators=(',', ': '))
data += ']}'
return data
def HandleInboxMessagesByReceiver(self, params): # after some time getInboxMessagesByAddress should be removed
"""Handle a request to get inbox messages by receiver""" @command('getInboxMessagesByReceiver', 'legacy:getInboxMessagesByAddress')
def HandleInboxMessagesByReceiver(self, toAddress):
"""
The same as *getAllInboxMessages* but returns only messages
for toAddress.
"""
if not params:
raise APIError(0, 'I need parameters!')
toAddress = params[0]
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT msgid, toaddress, fromaddress, subject, received, message," "SELECT msgid, toaddress, fromaddress, subject, received,"
" encodingtype FROM inbox WHERE folder='inbox' AND toAddress=?", " message, encodingtype, read FROM inbox WHERE folder='inbox'"
toAddress) " AND toAddress=?", toAddress)
data = '{"inboxMessages":[' return {"inboxMessages": [
for row in queryreturn: self._dump_inbox_message(*data) for data in queryreturn
msgid, toAddress, fromAddress, subject, received, message, \ ]}
encodingtype = row
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message)
if len(data) > 25:
data += ','
data += json.dumps({
'msgid': hexlify(msgid),
'toAddress': toAddress,
'fromAddress': fromAddress,
'subject': base64.b64encode(subject),
'message': base64.b64encode(message),
'encodingType': encodingtype,
'receivedTime': received}, indent=4, separators=(',', ': '))
data += ']}'
return data
def HandleGetSentMessageById(self, params): @command('getSentMessageById', 'getSentMessageByID')
"""Handle a request to get a sent message by ID""" def HandleGetSentMessageById(self, hid):
"""
Similiar to *getInboxMessageById* but doesn't change message's
read status (sent messages have no such field).
Result key is *sentMessage*
"""
if not params: msgid = self._decode(hid, "hex")
raise APIError(0, 'I need parameters!')
msgid = self._decode(params[0], "hex")
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT msgid, toaddress, fromaddress, subject, lastactiontime," "SELECT msgid, toaddress, fromaddress, subject, lastactiontime,"
" message, encodingtype, status, ackdata FROM sent WHERE msgid=?", " message, encodingtype, status, ackdata FROM sent WHERE msgid=?",
msgid msgid
) )
data = '{"sentMessage":[' try:
for row in queryreturn: return {"sentMessage": [
msgid, toAddress, fromAddress, subject, lastactiontime, message, \ self._dump_sent_message(*queryreturn[0])
encodingtype, status, ackdata = row ]}
subject = shared.fixPotentiallyInvalidUTF8Data(subject) except IndexError:
message = shared.fixPotentiallyInvalidUTF8Data(message) pass # FIXME inconsistent
data += json.dumps({
'msgid': hexlify(msgid),
'toAddress': toAddress,
'fromAddress': fromAddress,
'subject': base64.b64encode(subject),
'message': base64.b64encode(message),
'encodingType': encodingtype,
'lastActionTime': lastactiontime,
'status': status,
'ackData': hexlify(ackdata)}, indent=4, separators=(',', ': '))
data += ']}'
return data
def HandleGetSentMessagesByAddress(self, params): @command('getSentMessagesByAddress', 'getSentMessagesBySender')
"""Handle a request to get sent messages by address""" def HandleGetSentMessagesByAddress(self, fromAddress):
"""
The same as *getAllSentMessages* but returns only messages
from fromAddress.
"""
if not params:
raise APIError(0, 'I need parameters!')
fromAddress = params[0]
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT msgid, toaddress, fromaddress, subject, lastactiontime," "SELECT msgid, toaddress, fromaddress, subject, lastactiontime,"
" message, encodingtype, status, ackdata FROM sent" " message, encodingtype, status, ackdata FROM sent"
" WHERE folder='sent' AND fromAddress=? ORDER BY lastactiontime", " WHERE folder='sent' AND fromAddress=? ORDER BY lastactiontime",
fromAddress fromAddress
) )
data = '{"sentMessages":[' return {"sentMessages": [
for row in queryreturn: self._dump_sent_message(*data) for data in queryreturn
msgid, toAddress, fromAddress, subject, lastactiontime, message, \ ]}
encodingtype, status, ackdata = row # pylint: disable=unused-variable
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message)
if len(data) > 25:
data += ','
data += json.dumps({
'msgid': hexlify(msgid),
'toAddress': toAddress,
'fromAddress': fromAddress,
'subject': base64.b64encode(subject),
'message': base64.b64encode(message),
'encodingType': encodingtype,
'lastActionTime': lastactiontime,
'status': status,
'ackData': hexlify(ackdata)}, indent=4, separators=(',', ': '))
data += ']}'
return data
def HandleGetSentMessagesByAckData(self, params): @command('getSentMessageByAckData')
"""Handle a request to get sent messages by ack data""" def HandleGetSentMessagesByAckData(self, ackData):
"""
Similiar to *getSentMessageById* but searches by ackdata
(also hex encoded).
"""
if not params: ackData = self._decode(ackData, "hex")
raise APIError(0, 'I need parameters!')
ackData = self._decode(params[0], "hex")
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT msgid, toaddress, fromaddress, subject, lastactiontime," "SELECT msgid, toaddress, fromaddress, subject, lastactiontime,"
" message, encodingtype, status, ackdata FROM sent" " message, encodingtype, status, ackdata FROM sent"
" WHERE ackdata=?", ackData " WHERE ackdata=?", ackData
) )
data = '{"sentMessage":['
for row in queryreturn:
msgid, toAddress, fromAddress, subject, lastactiontime, message, \
encodingtype, status, ackdata = row
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message)
data += json.dumps({
'msgid': hexlify(msgid),
'toAddress': toAddress,
'fromAddress': fromAddress,
'subject': base64.b64encode(subject),
'message': base64.b64encode(message),
'encodingType': encodingtype,
'lastActionTime': lastactiontime,
'status': status,
'ackData': hexlify(ackdata)}, indent=4, separators=(',', ': '))
data += ']}'
return data
def HandleTrashMessage(self, params): try:
"""Handle a request to trash a message by ID""" return {"sentMessage": [
self._dump_sent_message(*queryreturn[0])
if not params: ]}
raise APIError(0, 'I need parameters!') except IndexError:
msgid = self._decode(params[0], "hex") pass # FIXME inconsistent
@command('trashMessage')
def HandleTrashMessage(self, msgid):
"""
Trash message by msgid (encoded in hex). Returns a simple message
saying that the message was trashed assuming it ever even existed.
Prior existence is not checked.
"""
msgid = self._decode(msgid, "hex")
# Trash if in inbox table # Trash if in inbox table
helper_inbox.trash(msgid) helper_inbox.trash(msgid)
# Trash if in sent table # Trash if in sent table
sqlExecute('''UPDATE sent SET folder='trash' WHERE msgid=?''', msgid) sqlExecute("UPDATE sent SET folder='trash' WHERE msgid=?", msgid)
return 'Trashed message (assuming message existed).' return 'Trashed message (assuming message existed).'
def HandleTrashInboxMessage(self, params): @command('trashInboxMessage')
"""Handle a request to trash an inbox message by ID""" def HandleTrashInboxMessage(self, msgid):
"""Trash inbox message by msgid (encoded in hex)."""
if not params: msgid = self._decode(msgid, "hex")
raise APIError(0, 'I need parameters!')
msgid = self._decode(params[0], "hex")
helper_inbox.trash(msgid) helper_inbox.trash(msgid)
return 'Trashed inbox message (assuming message existed).' return 'Trashed inbox message (assuming message existed).'
def HandleTrashSentMessage(self, params): @command('trashSentMessage')
"""Handle a request to trash a sent message by ID""" def HandleTrashSentMessage(self, msgid):
"""Trash sent message by msgid (encoded in hex)."""
if not params: msgid = self._decode(msgid, "hex")
raise APIError(0, 'I need parameters!')
msgid = self._decode(params[0], "hex")
sqlExecute('''UPDATE sent SET folder='trash' WHERE msgid=?''', msgid) sqlExecute('''UPDATE sent SET folder='trash' WHERE msgid=?''', msgid)
return 'Trashed sent message (assuming message existed).' return 'Trashed sent message (assuming message existed).'
def HandleSendMessage(self, params): @command('sendMessage')
"""Handle a request to send a message""" def HandleSendMessage(
self, toAddress, fromAddress, subject, message,
if not params: encodingType=2, TTL=4 * 24 * 60 * 60
raise APIError(0, 'I need parameters!') ):
"""
elif len(params) == 4: Send the message and return ackdata (hex encoded string).
toAddress, fromAddress, subject, message = params subject and message must be encoded in base64 which may optionally
encodingType = 2 include line breaks. TTL is specified in seconds; values outside
TTL = 4 * 24 * 60 * 60 the bounds of 3600 to 2419200 will be moved to be within those
bounds. TTL defaults to 4 days.
elif len(params) == 5: """
toAddress, fromAddress, subject, message, encodingType = params # pylint: disable=too-many-locals
TTL = 4 * 24 * 60 * 60 if encodingType not in (2, 3):
elif len(params) == 6:
toAddress, fromAddress, subject, message, encodingType, TTL = \
params
if encodingType not in [2, 3]:
raise APIError(6, 'The encoding type must be 2 or 3.') raise APIError(6, 'The encoding type must be 2 or 3.')
subject = self._decode(subject, "base64") subject = self._decode(subject, "base64")
message = self._decode(message, "base64") message = self._decode(message, "base64")
@ -983,12 +1100,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
TTL = 28 * 24 * 60 * 60 TTL = 28 * 24 * 60 * 60
toAddress = addBMIfNotPresent(toAddress) toAddress = addBMIfNotPresent(toAddress)
fromAddress = addBMIfNotPresent(fromAddress) fromAddress = addBMIfNotPresent(fromAddress)
# pylint: disable=unused-variable
status, addressVersionNumber, streamNumber, toRipe = \
self._verifyAddress(toAddress)
self._verifyAddress(fromAddress) self._verifyAddress(fromAddress)
try: try:
fromAddressEnabled = BMConfigParser().getboolean( fromAddressEnabled = self.config.getboolean(
fromAddress, 'enabled') fromAddress, 'enabled')
except BaseException: except BaseException:
raise APIError( raise APIError(
@ -996,58 +1110,31 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
if not fromAddressEnabled: if not fromAddressEnabled:
raise APIError(14, 'Your fromAddress is disabled. Cannot send.') raise APIError(14, 'Your fromAddress is disabled. Cannot send.')
stealthLevel = BMConfigParser().safeGetInt( ackdata = helper_sent.insert(
'bitmessagesettings', 'ackstealthlevel') toAddress=toAddress, fromAddress=fromAddress,
ackdata = genAckPayload(streamNumber, stealthLevel) subject=subject, message=message, encoding=encodingType, ttl=TTL)
t = ('',
toAddress,
toRipe,
fromAddress,
subject,
message,
ackdata,
int(time.time()), # sentTime (this won't change)
int(time.time()), # lastActionTime
0,
'msgqueued',
0,
'sent',
2,
TTL)
helper_sent.insert(t)
toLabel = '' toLabel = ''
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT label FROM addressbook WHERE address=?", toAddress) "SELECT label FROM addressbook WHERE address=?", toAddress)
if queryreturn != []: try:
for row in queryreturn: toLabel, = queryreturn[0][0]
toLabel, = row except IndexError:
pass
queues.UISignalQueue.put(('displayNewSentMessage', ( queues.UISignalQueue.put(('displayNewSentMessage', (
toAddress, toLabel, fromAddress, subject, message, ackdata))) toAddress, toLabel, fromAddress, subject, message, ackdata)))
queues.workerQueue.put(('sendmessage', toAddress)) queues.workerQueue.put(('sendmessage', toAddress))
return hexlify(ackdata) return hexlify(ackdata)
def HandleSendBroadcast(self, params): @command('sendBroadcast')
"""Handle a request to send a broadcast message""" def HandleSendBroadcast(
self, fromAddress, subject, message, encodingType=2,
TTL=4 * 24 * 60 * 60):
"""Send the broadcast message. Similiar to *sendMessage*."""
if not params: if encodingType not in (2, 3):
raise APIError(0, 'I need parameters!')
if len(params) == 3:
fromAddress, subject, message = params
encodingType = 2
TTL = 4 * 24 * 60 * 60
elif len(params) == 4:
fromAddress, subject, message, encodingType = params
TTL = 4 * 24 * 60 * 60
elif len(params) == 5:
fromAddress, subject, message, encodingType, TTL = params
if encodingType not in [2, 3]:
raise APIError(6, 'The encoding type must be 2 or 3.') raise APIError(6, 'The encoding type must be 2 or 3.')
subject = self._decode(subject, "base64") subject = self._decode(subject, "base64")
@ -1061,81 +1148,61 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
fromAddress = addBMIfNotPresent(fromAddress) fromAddress = addBMIfNotPresent(fromAddress)
self._verifyAddress(fromAddress) self._verifyAddress(fromAddress)
try: try:
BMConfigParser().getboolean(fromAddress, 'enabled') self.config.getboolean(fromAddress, 'enabled')
except BaseException: except BaseException:
raise APIError( raise APIError(
13, 'could not find your fromAddress in the keys.dat file.') 13, 'Could not find your fromAddress in the keys.dat file.')
streamNumber = decodeAddress(fromAddress)[2] toAddress = str_broadcast_subscribers
ackdata = genAckPayload(streamNumber, 0)
toAddress = '[Broadcast subscribers]'
ripe = ''
t = ('', ackdata = helper_sent.insert(
toAddress, fromAddress=fromAddress, subject=subject,
ripe, message=message, status='broadcastqueued',
fromAddress, encoding=encodingType)
subject,
message,
ackdata,
int(time.time()), # sentTime (this doesn't change)
int(time.time()), # lastActionTime
0,
'broadcastqueued',
0,
'sent',
2,
TTL)
helper_sent.insert(t)
toLabel = '[Broadcast subscribers]' toLabel = str_broadcast_subscribers
queues.UISignalQueue.put(('displayNewSentMessage', ( queues.UISignalQueue.put(('displayNewSentMessage', (
toAddress, toLabel, fromAddress, subject, message, ackdata))) toAddress, toLabel, fromAddress, subject, message, ackdata)))
queues.workerQueue.put(('sendbroadcast', '')) queues.workerQueue.put(('sendbroadcast', ''))
return hexlify(ackdata) return hexlify(ackdata)
def HandleGetStatus(self, params): @command('getStatus')
"""Handle a request to get the status of a sent message""" def HandleGetStatus(self, ackdata):
"""
Get the status of sent message by its ackdata (hex encoded).
Returns one of these strings: notfound, msgqueued,
broadcastqueued, broadcastsent, doingpubkeypow, awaitingpubkey,
doingmsgpow, forcepow, msgsent, msgsentnoackexpected or ackreceived.
"""
if len(params) != 1:
raise APIError(0, 'I need one parameter!')
ackdata, = params
if len(ackdata) < 76: if len(ackdata) < 76:
# The length of ackData should be at least 38 bytes (76 hex digits) # The length of ackData should be at least 38 bytes (76 hex digits)
raise APIError(15, 'Invalid ackData object size.') raise APIError(15, 'Invalid ackData object size.')
ackdata = self._decode(ackdata, "hex") ackdata = self._decode(ackdata, "hex")
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT status FROM sent where ackdata=?", ackdata) "SELECT status FROM sent where ackdata=?", ackdata)
if queryreturn == []: try:
return queryreturn[0][0]
except IndexError:
return 'notfound' return 'notfound'
for row in queryreturn:
status, = row
return status
def HandleAddSubscription(self, params): @command('addSubscription')
"""Handle a request to add a subscription""" def HandleAddSubscription(self, address, label=''):
"""Subscribe to the address. label must be base64 encoded."""
if not params: if label:
raise APIError(0, 'I need parameters!')
if len(params) == 1:
address, = params
label = ''
if len(params) == 2:
address, label = params
label = self._decode(label, "base64") label = self._decode(label, "base64")
try: try:
unicode(label, 'utf-8') unicode(label, 'utf-8')
except BaseException: except UnicodeDecodeError:
raise APIError(17, 'Label is not valid UTF-8 data.') raise APIError(17, 'Label is not valid UTF-8 data.')
if len(params) > 2:
raise APIError(0, 'I need either 1 or 2 parameters!')
address = addBMIfNotPresent(address)
self._verifyAddress(address) self._verifyAddress(address)
address = addBMIfNotPresent(address)
# First we must check to see if the address is already in the # First we must check to see if the address is already in the
# subscriptions list. # subscriptions list.
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT * FROM subscriptions WHERE address=?", address) "SELECT * FROM subscriptions WHERE address=?", address)
if queryreturn != []: if queryreturn:
raise APIError(16, 'You are already subscribed to that address.') raise APIError(16, 'You are already subscribed to that address.')
sqlExecute( sqlExecute(
"INSERT INTO subscriptions VALUES (?,?,?)", label, address, True) "INSERT INTO subscriptions VALUES (?,?,?)", label, address, True)
@ -1144,37 +1211,43 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
queues.UISignalQueue.put(('rerenderSubscriptions', '')) queues.UISignalQueue.put(('rerenderSubscriptions', ''))
return 'Added subscription.' return 'Added subscription.'
def HandleDeleteSubscription(self, params): @command('deleteSubscription')
"""Handle a request to delete a subscription""" def HandleDeleteSubscription(self, address):
"""
Unsubscribe from the address. The program does not check whether
you were subscribed in the first place.
"""
if len(params) != 1:
raise APIError(0, 'I need 1 parameter!')
address, = params
address = addBMIfNotPresent(address) address = addBMIfNotPresent(address)
sqlExecute('''DELETE FROM subscriptions WHERE address=?''', address) sqlExecute("DELETE FROM subscriptions WHERE address=?", address)
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
queues.UISignalQueue.put(('rerenderMessagelistFromLabels', '')) queues.UISignalQueue.put(('rerenderMessagelistFromLabels', ''))
queues.UISignalQueue.put(('rerenderSubscriptions', '')) queues.UISignalQueue.put(('rerenderSubscriptions', ''))
return 'Deleted subscription if it existed.' return 'Deleted subscription if it existed.'
def ListSubscriptions(self, params): # pylint: disable=unused-argument @command('listSubscriptions')
"""Handle a request to list susbcriptions""" def ListSubscriptions(self):
"""
Returns dict with a list of all subscriptions
in the *subscriptions* key.
"""
# pylint: disable=unused-variable
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT label, address, enabled FROM subscriptions") "SELECT label, address, enabled FROM subscriptions")
data = {'subscriptions': []} data = []
for row in queryreturn: for label, address, enabled in queryreturn:
label, address, enabled = row
label = shared.fixPotentiallyInvalidUTF8Data(label) label = shared.fixPotentiallyInvalidUTF8Data(label)
data['subscriptions'].append({ data.append({
'label': base64.b64encode(label), 'label': base64.b64encode(label),
'address': address, 'address': address,
'enabled': enabled == 1 'enabled': enabled == 1
}) })
return json.dumps(data, indent=4, separators=(',', ': ')) return {'subscriptions': data}
def HandleDisseminatePreEncryptedMsg(self, params): @command('disseminatePreEncryptedMsg')
def HandleDisseminatePreEncryptedMsg(
self, encryptedPayload, requiredAverageProofOfWorkNonceTrialsPerByte,
requiredPayloadLengthExtraBytes):
"""Handle a request to disseminate an encrypted message""" """Handle a request to disseminate an encrypted message"""
# The device issuing this command to PyBitmessage supplies a msg # The device issuing this command to PyBitmessage supplies a msg
@ -1182,38 +1255,28 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
# to be done. PyBitmessage accepts this msg object and sends it out # to be done. PyBitmessage accepts this msg object and sends it out
# to the rest of the Bitmessage network as if it had generated # to the rest of the Bitmessage network as if it had generated
# the message itself. Please do not yet add this to the api doc. # the message itself. Please do not yet add this to the api doc.
if len(params) != 3:
raise APIError(0, 'I need 3 parameter!')
encryptedPayload, requiredAverageProofOfWorkNonceTrialsPerByte, \
requiredPayloadLengthExtraBytes = params
encryptedPayload = self._decode(encryptedPayload, "hex") encryptedPayload = self._decode(encryptedPayload, "hex")
# Let us do the POW and attach it to the front # Let us do the POW and attach it to the front
target = 2**64 / ( target = 2**64 / ((
( len(encryptedPayload) + requiredPayloadLengthExtraBytes + 8) *
len(encryptedPayload) + requiredPayloadLengthExtraBytes + 8 requiredAverageProofOfWorkNonceTrialsPerByte)
) * requiredAverageProofOfWorkNonceTrialsPerByte logger.info(
'(For msg message via API) Doing proof of work. Total required'
' difficulty: %s\nRequired small message difficulty: %s',
float(requiredAverageProofOfWorkNonceTrialsPerByte) /
defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
float(requiredPayloadLengthExtraBytes) /
defaults.networkDefaultPayloadLengthExtraBytes,
) )
with shared.printLock:
print(
'(For msg message via API) Doing proof of work. Total required difficulty:',
float(
requiredAverageProofOfWorkNonceTrialsPerByte
) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
'Required small message difficulty:',
float(requiredPayloadLengthExtraBytes) / defaults.networkDefaultPayloadLengthExtraBytes,
)
powStartTime = time.time() powStartTime = time.time()
initialHash = hashlib.sha512(encryptedPayload).digest() initialHash = hashlib.sha512(encryptedPayload).digest()
trialValue, nonce = proofofwork.run(target, initialHash) trialValue, nonce = proofofwork.run(target, initialHash)
with shared.printLock: logger.info(
print '(For msg message via API) Found proof of work', trialValue, 'Nonce:', nonce '(For msg message via API) Found proof of work %s\nNonce: %s\n'
try: 'POW took %s seconds. %s nonce trials per second.',
print( trialValue, nonce, int(time.time() - powStartTime),
'POW took', int(time.time() - powStartTime), 'seconds.', nonce / (time.time() - powStartTime)
nonce / (time.time() - powStartTime), 'nonce trials per second.', )
)
except BaseException:
pass
encryptedPayload = pack('>Q', nonce) + encryptedPayload encryptedPayload = pack('>Q', nonce) + encryptedPayload
toStreamNumber = decodeVarint(encryptedPayload[16:26])[0] toStreamNumber = decodeVarint(encryptedPayload[16:26])[0]
inventoryHash = calculateInventoryHash(encryptedPayload) inventoryHash = calculateInventoryHash(encryptedPayload)
@ -1223,21 +1286,21 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
objectType, toStreamNumber, encryptedPayload, objectType, toStreamNumber, encryptedPayload,
int(time.time()) + TTL, '' int(time.time()) + TTL, ''
) )
with shared.printLock: logger.info(
print 'Broadcasting inv for msg(API disseminatePreEncryptedMsg command):', hexlify(inventoryHash) 'Broadcasting inv for msg(API disseminatePreEncryptedMsg'
' command): %s', hexlify(inventoryHash))
queues.invQueue.put((toStreamNumber, inventoryHash)) queues.invQueue.put((toStreamNumber, inventoryHash))
def HandleTrashSentMessageByAckDAta(self, params): @command('trashSentMessageByAckData')
"""Handle a request to trash a sent message by ackdata""" def HandleTrashSentMessageByAckDAta(self, ackdata):
"""Trash a sent message by ackdata (hex encoded)"""
# This API method should only be used when msgid is not available # This API method should only be used when msgid is not available
if not params: ackdata = self._decode(ackdata, "hex")
raise APIError(0, 'I need parameters!')
ackdata = self._decode(params[0], "hex")
sqlExecute("UPDATE sent SET folder='trash' WHERE ackdata=?", ackdata) sqlExecute("UPDATE sent SET folder='trash' WHERE ackdata=?", ackdata)
return 'Trashed sent message (assuming message existed).' return 'Trashed sent message (assuming message existed).'
def HandleDissimatePubKey(self, params): # pylint: disable=unused-argument @command('disseminatePubkey')
def HandleDissimatePubKey(self, payload):
"""Handle a request to disseminate a public key""" """Handle a request to disseminate a public key"""
# The device issuing this command to PyBitmessage supplies a pubkey # The device issuing this command to PyBitmessage supplies a pubkey
@ -1245,19 +1308,19 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
# PyBitmessage accepts this pubkey object and sends it out to the rest # PyBitmessage accepts this pubkey object and sends it out to the rest
# of the Bitmessage network as if it had generated the pubkey object # of the Bitmessage network as if it had generated the pubkey object
# itself. Please do not yet add this to the api doc. # itself. Please do not yet add this to the api doc.
if len(params) != 1:
raise APIError(0, 'I need 1 parameter!')
payload, = params
payload = self._decode(payload, "hex") payload = self._decode(payload, "hex")
# Let us do the POW # Let us do the POW
target = 2 ** 64 / (( target = 2 ** 64 / ((
len(payload) + defaults.networkDefaultPayloadLengthExtraBytes + 8 len(payload) + defaults.networkDefaultPayloadLengthExtraBytes + 8
) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte) ) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
print '(For pubkey message via API) Doing proof of work...' logger.info('(For pubkey message via API) Doing proof of work...')
initialHash = hashlib.sha512(payload).digest() initialHash = hashlib.sha512(payload).digest()
trialValue, nonce = proofofwork.run(target, initialHash) trialValue, nonce = proofofwork.run(target, initialHash)
print '(For pubkey message via API) Found proof of work', trialValue, 'Nonce:', nonce logger.info(
'(For pubkey message via API) Found proof of work %s Nonce: %s',
trialValue, nonce
)
payload = pack('>Q', nonce) + payload payload = pack('>Q', nonce) + payload
pubkeyReadPosition = 8 # bypass the nonce pubkeyReadPosition = 8 # bypass the nonce
@ -1266,9 +1329,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
pubkeyReadPosition += 8 pubkeyReadPosition += 8
else: else:
pubkeyReadPosition += 4 pubkeyReadPosition += 4
# pylint: disable=unused-variable addressVersionLength = decodeVarint(
addressVersion, addressVersionLength = decodeVarint( payload[pubkeyReadPosition:pubkeyReadPosition + 10])[1]
payload[pubkeyReadPosition:pubkeyReadPosition + 10])
pubkeyReadPosition += addressVersionLength pubkeyReadPosition += addressVersionLength
pubkeyStreamNumber = decodeVarint( pubkeyStreamNumber = decodeVarint(
payload[pubkeyReadPosition:pubkeyReadPosition + 10])[0] payload[pubkeyReadPosition:pubkeyReadPosition + 10])[0]
@ -1278,19 +1340,19 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
Inventory()[inventoryHash] = ( Inventory()[inventoryHash] = (
objectType, pubkeyStreamNumber, payload, int(time.time()) + TTL, '' objectType, pubkeyStreamNumber, payload, int(time.time()) + TTL, ''
) )
with shared.printLock: logger.info(
print 'broadcasting inv within API command disseminatePubkey with hash:', hexlify(inventoryHash) 'broadcasting inv within API command disseminatePubkey with'
' hash: %s', hexlify(inventoryHash))
queues.invQueue.put((pubkeyStreamNumber, inventoryHash)) queues.invQueue.put((pubkeyStreamNumber, inventoryHash))
def HandleGetMessageDataByDestinationHash(self, params): @command(
'getMessageDataByDestinationHash', 'getMessageDataByDestinationTag')
def HandleGetMessageDataByDestinationHash(self, requestedHash):
"""Handle a request to get message data by destination hash""" """Handle a request to get message data by destination hash"""
# Method will eventually be used by a particular Android app to # Method will eventually be used by a particular Android app to
# select relevant messages. Do not yet add this to the api # select relevant messages. Do not yet add this to the api
# doc. # doc.
if len(params) != 1:
raise APIError(0, 'I need 1 parameter!')
requestedHash, = params
if len(requestedHash) != 32: if len(requestedHash) != 32:
raise APIError( raise APIError(
19, 'The length of hash should be 32 bytes (encoded in hex' 19, 'The length of hash should be 32 bytes (encoded in hex'
@ -1304,8 +1366,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
"SELECT hash, payload FROM inventory WHERE tag = ''" "SELECT hash, payload FROM inventory WHERE tag = ''"
" and objecttype = 2") " and objecttype = 2")
with SqlBulkExecute() as sql: with SqlBulkExecute() as sql:
for row in queryreturn: for hash01, payload in queryreturn:
hash01, payload = row
readPosition = 16 # Nonce length + time length readPosition = 16 # Nonce length + time length
# Stream Number length # Stream Number length
readPosition += decodeVarint( readPosition += decodeVarint(
@ -1315,169 +1376,121 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT payload FROM inventory WHERE tag = ?", requestedHash) "SELECT payload FROM inventory WHERE tag = ?", requestedHash)
data = '{"receivedMessageDatas":[' return {"receivedMessageDatas": [
for row in queryreturn: {'data': hexlify(payload)} for payload, in queryreturn
payload, = row ]}
if len(data) > 25:
data += ','
data += json.dumps(
{'data': hexlify(payload)}, indent=4, separators=(',', ': '))
data += ']}'
return data
def HandleClientStatus(self, params): # pylint: disable=unused-argument @command('clientStatus')
"""Handle a request to get the status of the client""" def HandleClientStatus(self):
"""
Returns the bitmessage status as dict with keys *networkConnections*,
*numberOfMessagesProcessed*, *numberOfBroadcastsProcessed*,
*numberOfPubkeysProcessed*, *pendingDownload*, *networkStatus*,
*softwareName*, *softwareVersion*. *networkStatus* will be one of
these strings: "notConnected",
"connectedButHaveNotReceivedIncomingConnections",
or "connectedAndReceivingIncomingConnections".
"""
connections_num = len(network.stats.connectedHostsList()) connections_num = len(network.stats.connectedHostsList())
if connections_num == 0: if connections_num == 0:
networkStatus = 'notConnected' networkStatus = 'notConnected'
elif shared.clientHasReceivedIncomingConnections: elif state.clientHasReceivedIncomingConnections:
networkStatus = 'connectedAndReceivingIncomingConnections' networkStatus = 'connectedAndReceivingIncomingConnections'
else: else:
networkStatus = 'connectedButHaveNotReceivedIncomingConnections' networkStatus = 'connectedButHaveNotReceivedIncomingConnections'
return json.dumps({ return {
'networkConnections': connections_num, 'networkConnections': connections_num,
'numberOfMessagesProcessed': shared.numberOfMessagesProcessed, 'numberOfMessagesProcessed': state.numberOfMessagesProcessed,
'numberOfBroadcastsProcessed': shared.numberOfBroadcastsProcessed, 'numberOfBroadcastsProcessed': state.numberOfBroadcastsProcessed,
'numberOfPubkeysProcessed': shared.numberOfPubkeysProcessed, 'numberOfPubkeysProcessed': state.numberOfPubkeysProcessed,
'pendingDownload': network.stats.pendingDownload(),
'networkStatus': networkStatus, 'networkStatus': networkStatus,
'softwareName': 'PyBitmessage', 'softwareName': 'PyBitmessage',
'softwareVersion': softwareVersion 'softwareVersion': softwareVersion
}, indent=4, separators=(',', ': ')) }
def HandleDecodeAddress(self, params): @command('helloWorld')
"""Handle a request to decode an address""" def HandleHelloWorld(self, a, b):
# Return a meaningful decoding of an address.
if len(params) != 1:
raise APIError(0, 'I need 1 parameter!')
address, = params
status, addressVersion, streamNumber, ripe = decodeAddress(address)
return json.dumps({
'status': status,
'addressVersion': addressVersion,
'streamNumber': streamNumber,
'ripe': base64.b64encode(ripe)
}, indent=4, separators=(',', ': '))
def HandleHelloWorld(self, params):
"""Test two string params""" """Test two string params"""
a, b = params
return a + '-' + b return a + '-' + b
def HandleAdd(self, params): @command('add')
def HandleAdd(self, a, b):
"""Test two numeric params""" """Test two numeric params"""
a, b = params
return a + b return a + b
def HandleStatusBar(self, params): @command('statusBar')
"""Handle a request to update the status bar""" def HandleStatusBar(self, message):
"""Update GUI statusbar message"""
message, = params
queues.UISignalQueue.put(('updateStatusBar', message)) queues.UISignalQueue.put(('updateStatusBar', message))
def HandleDeleteAndVacuum(self, params): @command('deleteAndVacuum')
"""Handle a request to run the deleteandvacuum stored procedure""" def HandleDeleteAndVacuum(self):
"""Cleanup trashes and vacuum messages database"""
sqlStoredProcedure('deleteandvacuume')
return 'done'
if not params: @command('shutdown')
sqlStoredProcedure('deleteandvacuume') def HandleShutdown(self):
return 'done' """Shutdown the bitmessage. Returns 'done'."""
return None # backward compatible trick because False == 0 is True
state.shutdown = False
def HandleShutdown(self, params): return 'done'
"""Handle a request to shutdown the node"""
if not params:
# backward compatible trick because False == 0 is True
state.shutdown = False
return 'done'
return None
handlers = {}
handlers['helloWorld'] = HandleHelloWorld
handlers['add'] = HandleAdd
handlers['statusBar'] = HandleStatusBar
handlers['listAddresses'] = HandleListAddresses
handlers['listAddressBookEntries'] = HandleListAddressBookEntries
# the listAddressbook alias should be removed eventually.
handlers['listAddressbook'] = HandleListAddressBookEntries
handlers['addAddressBookEntry'] = HandleAddAddressBookEntry
# the addAddressbook alias should be deleted eventually.
handlers['addAddressbook'] = HandleAddAddressBookEntry
handlers['deleteAddressBookEntry'] = HandleDeleteAddressBookEntry
# The deleteAddressbook alias should be deleted eventually.
handlers['deleteAddressbook'] = HandleDeleteAddressBookEntry
handlers['createRandomAddress'] = HandleCreateRandomAddress
handlers['createDeterministicAddresses'] = \
HandleCreateDeterministicAddresses
handlers['getDeterministicAddress'] = HandleGetDeterministicAddress
handlers['createChan'] = HandleCreateChan
handlers['joinChan'] = HandleJoinChan
handlers['leaveChan'] = HandleLeaveChan
handlers['deleteAddress'] = HandleDeleteAddress
handlers['getAllInboxMessages'] = HandleGetAllInboxMessages
handlers['getAllInboxMessageIds'] = HandleGetAllInboxMessageIds
handlers['getAllInboxMessageIDs'] = HandleGetAllInboxMessageIds
handlers['getInboxMessageById'] = HandleGetInboxMessageById
handlers['getInboxMessageByID'] = HandleGetInboxMessageById
handlers['getAllSentMessages'] = HandleGetAllSentMessages
handlers['getAllSentMessageIds'] = HandleGetAllSentMessageIds
handlers['getAllSentMessageIDs'] = HandleGetAllSentMessageIds
handlers['getInboxMessagesByReceiver'] = HandleInboxMessagesByReceiver
# after some time getInboxMessagesByAddress should be removed
handlers['getInboxMessagesByAddress'] = HandleInboxMessagesByReceiver
handlers['getSentMessageById'] = HandleGetSentMessageById
handlers['getSentMessageByID'] = HandleGetSentMessageById
handlers['getSentMessagesByAddress'] = HandleGetSentMessagesByAddress
handlers['getSentMessagesBySender'] = HandleGetSentMessagesByAddress
handlers['getSentMessageByAckData'] = HandleGetSentMessagesByAckData
handlers['trashMessage'] = HandleTrashMessage
handlers['trashInboxMessage'] = HandleTrashInboxMessage
handlers['trashSentMessage'] = HandleTrashSentMessage
handlers['trashSentMessageByAckData'] = HandleTrashSentMessageByAckDAta
handlers['sendMessage'] = HandleSendMessage
handlers['sendBroadcast'] = HandleSendBroadcast
handlers['getStatus'] = HandleGetStatus
handlers['addSubscription'] = HandleAddSubscription
handlers['deleteSubscription'] = HandleDeleteSubscription
handlers['listSubscriptions'] = ListSubscriptions
handlers['disseminatePreEncryptedMsg'] = HandleDisseminatePreEncryptedMsg
handlers['disseminatePubkey'] = HandleDissimatePubKey
handlers['getMessageDataByDestinationHash'] = \
HandleGetMessageDataByDestinationHash
handlers['getMessageDataByDestinationTag'] = \
HandleGetMessageDataByDestinationHash
handlers['clientStatus'] = HandleClientStatus
handlers['decodeAddress'] = HandleDecodeAddress
handlers['deleteAndVacuum'] = HandleDeleteAndVacuum
handlers['shutdown'] = HandleShutdown
def _handle_request(self, method, params): def _handle_request(self, method, params):
if method not in self.handlers: try:
# pylint: disable=attribute-defined-outside-init
self._method = method
func = self._handlers[method]
return func(self, *params)
except KeyError:
raise APIError(20, 'Invalid method: %s' % method) raise APIError(20, 'Invalid method: %s' % method)
result = self.handlers[method](self, params) except TypeError as e:
state.last_api_response = time.time() msg = 'Unexpected API Failure - %s' % e
return result if 'argument' not in str(e):
raise APIError(21, msg)
argcount = len(params)
maxcount = func.func_code.co_argcount
if argcount > maxcount:
msg = (
'Command %s takes at most %s parameters (%s given)'
% (method, maxcount, argcount))
else:
mincount = maxcount - len(func.func_defaults or [])
if argcount < mincount:
msg = (
'Command %s takes at least %s parameters (%s given)'
% (method, mincount, argcount))
raise APIError(0, msg)
finally:
state.last_api_response = time.time()
def _dispatch(self, method, params): def _dispatch(self, method, params):
# pylint: disable=attribute-defined-outside-init _fault = None
self.cookies = []
validuser = self.APIAuthenticateClient()
if not validuser:
time.sleep(2)
return "RPC Username or password incorrect or HTTP header lacks authentication at all."
try: try:
return self._handle_request(method, params) return self._handle_request(method, params)
except APIError as e: except APIError as e:
return str(e) _fault = e
except varintDecodeError as e: except varintDecodeError as e:
logger.error(e) logger.error(e)
return "API Error 0026: Data contains a malformed varint. Some details: %s" % e _fault = APIError(
26, 'Data contains a malformed varint. Some details: %s' % e)
except Exception as e: except Exception as e:
logger.exception(e) logger.exception(e)
_fault = APIError(21, 'Unexpected API Failure - %s' % e)
return "API Error 0021: Unexpected API Failure - %s" % e if _fault:
if self.config.safeGet(
'bitmessagesettings', 'apivariant') == 'legacy':
return str(_fault)
else:
raise _fault # pylint: disable=raising-bad-type
def _listMethods(self):
"""List all API commands"""
return self._handlers.keys()
def _methodHelp(self, method):
return self._handlers[method].__doc__

View File

@ -13,15 +13,15 @@ TODO: fix the following (currently ignored) violations:
""" """
import xmlrpclib
import datetime import datetime
import imghdr import imghdr
import ntpath
import json import json
import socket import ntpath
import time
import sys
import os import os
import socket
import sys
import time
import xmlrpclib
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser

View File

@ -1,8 +1,6 @@
""" """
src/bitmessagecurses/__init__.py Bitmessage commandline interface
================================
""" """
# Copyright (c) 2014 Luke Montalvo <lukemontalvo@gmail.com> # Copyright (c) 2014 Luke Montalvo <lukemontalvo@gmail.com>
# This file adds a alternative commandline interface, feel free to critique and fork # This file adds a alternative commandline interface, feel free to critique and fork
# #
@ -20,21 +18,24 @@ import time
from textwrap import fill from textwrap import fill
from threading import Timer from threading import Timer
from addresses import addBMIfNotPresent, decodeAddress
from bmconfigparser import BMConfigParser
from dialog import Dialog from dialog import Dialog
from helper_ackPayload import genAckPayload import helper_sent
from helper_sql import sqlExecute, sqlQuery
from inventory import Inventory
import l10n import l10n
import network.stats import network.stats
from pyelliptic.openssl import OpenSSL
import queues import queues
import shared import shared
import shutdown import shutdown
import state
from addresses import addBMIfNotPresent, decodeAddress
from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlQuery
from inventory import Inventory
# pylint: disable=global-statement
quit = False # pylint: disable=redefined-builtin quit_ = False
menutab = 1 menutab = 1
menu = ["Inbox", "Send", "Sent", "Your Identities", "Subscriptions", "Address Book", "Blacklist", "Network Status"] menu = ["Inbox", "Send", "Sent", "Your Identities", "Subscriptions", "Address Book", "Blacklist", "Network Status"]
naptime = 100 naptime = 100
@ -61,26 +62,31 @@ bwtype = "black"
BROADCAST_STR = "[Broadcast subscribers]" BROADCAST_STR = "[Broadcast subscribers]"
class printLog: # pylint: disable=no-self-use, no-init, old-style-class class printLog(object):
"""Printing logs""" """Printing logs"""
# pylint: disable=no-self-use
def write(self, output): def write(self, output):
# pylint: disable=global-statement """Write logs"""
global log global log
log += output log += output
def flush(self): def flush(self):
"""Flush logs"""
pass pass
class errLog: # pylint: disable=no-self-use, no-init, old-style-class class errLog(object):
"""Error logs""" """Error logs"""
# pylint: disable=no-self-use
def write(self, output): def write(self, output):
# pylint: disable=global-statement """Write error logs"""
global log global log
log += "!" + output log += "!" + output
def flush(self): def flush(self):
"""Flush error logs"""
pass pass
@ -138,14 +144,15 @@ def scrollbox(d, text, height=None, width=None):
def resetlookups(): def resetlookups():
"""Reset the Inventory Lookups""" """Reset the Inventory Lookups"""
global inventorydata # pylint: disable=global-statement global inventorydata
inventorydata = Inventory().numberOfInventoryLookupsPerformed inventorydata = Inventory().numberOfInventoryLookupsPerformed
Inventory().numberOfInventoryLookupsPerformed = 0 Inventory().numberOfInventoryLookupsPerformed = 0
Timer(1, resetlookups, ()).start() Timer(1, resetlookups, ()).start()
def drawtab(stdscr): # pylint: disable=too-many-branches, too-many-statements def drawtab(stdscr):
"""Method for drawing different tabs""" """Method for drawing different tabs"""
# pylint: disable=too-many-branches, too-many-statements
if menutab in range(1, len(menu) + 1): if menutab in range(1, len(menu) + 1):
if menutab == 1: # Inbox if menutab == 1: # Inbox
stdscr.addstr(3, 5, "To", curses.A_BOLD) stdscr.addstr(3, 5, "To", curses.A_BOLD)
@ -269,11 +276,11 @@ def drawtab(stdscr): # pylint: disable=too-many-branches, too-many-statem
# Uptime and processing data # Uptime and processing data
stdscr.addstr(6, 35, "Since startup on " + l10n.formatTimestamp(startuptime, False)) stdscr.addstr(6, 35, "Since startup on " + l10n.formatTimestamp(startuptime, False))
stdscr.addstr(7, 40, "Processed " + str( stdscr.addstr(7, 40, "Processed " + str(
shared.numberOfMessagesProcessed).ljust(4) + " person-to-person messages.") state.numberOfMessagesProcessed).ljust(4) + " person-to-person messages.")
stdscr.addstr(8, 40, "Processed " + str( stdscr.addstr(8, 40, "Processed " + str(
shared.numberOfBroadcastsProcessed).ljust(4) + " broadcast messages.") state.numberOfBroadcastsProcessed).ljust(4) + " broadcast messages.")
stdscr.addstr(9, 40, "Processed " + str( stdscr.addstr(9, 40, "Processed " + str(
shared.numberOfPubkeysProcessed).ljust(4) + " public keys.") state.numberOfPubkeysProcessed).ljust(4) + " public keys.")
# Inventory data # Inventory data
stdscr.addstr(11, 35, "Inventory lookups per second: " + str(inventorydata).ljust(3)) stdscr.addstr(11, 35, "Inventory lookups per second: " + str(inventorydata).ljust(3))
@ -282,12 +289,12 @@ def drawtab(stdscr): # pylint: disable=too-many-branches, too-many-statem
stdscr.addstr(13, 6, "Log", curses.A_BOLD) stdscr.addstr(13, 6, "Log", curses.A_BOLD)
n = log.count('\n') n = log.count('\n')
if n > 0: if n > 0:
l = log.split('\n') lg = log.split('\n')
if n > 512: if n > 512:
del l[:(n - 256)] del lg[:(n - 256)]
logpad.erase() logpad.erase()
n = len(l) n = len(lg)
for i, item in enumerate(l): for i, item in enumerate(lg):
a = 0 a = 0
if item and item[0] == '!': if item and item[0] == '!':
a = curses.color_pair(1) a = curses.color_pair(1)
@ -314,7 +321,8 @@ def dialogreset(stdscr):
# pylint: disable=too-many-branches, too-many-statements # pylint: disable=too-many-branches, too-many-statements
def handlech(c, stdscr): def handlech(c, stdscr):
# pylint: disable=redefined-outer-name, too-many-nested-blocks, too-many-locals, global-statement """Handle character given on the command-line interface"""
# pylint: disable=redefined-outer-name, too-many-nested-blocks, too-many-locals
if c != curses.ERR: if c != curses.ERR:
global inboxcur, addrcur, sentcur, subcur, abookcur, blackcur global inboxcur, addrcur, sentcur, subcur, abookcur, blackcur
if c in range(256): if c in range(256):
@ -322,8 +330,8 @@ def handlech(c, stdscr):
global menutab global menutab
menutab = int(chr(c)) menutab = int(chr(c))
elif chr(c) == 'q': elif chr(c) == 'q':
global quit global quit_
quit = True quit_ = True
elif chr(c) == '\n': elif chr(c) == '\n':
curses.curs_set(1) curses.curs_set(1)
d = Dialog(dialog="dialog") d = Dialog(dialog="dialog")
@ -363,10 +371,10 @@ def handlech(c, stdscr):
inbox[inboxcur][7] = 1 inbox[inboxcur][7] = 1
else: else:
scrollbox(d, unicode("Could not fetch message.")) scrollbox(d, unicode("Could not fetch message."))
elif t == "2": # Mark unread elif t == "2": # Mark unread
sqlExecute("UPDATE inbox SET read=0 WHERE msgid=?", inbox[inboxcur][0]) sqlExecute("UPDATE inbox SET read=0 WHERE msgid=?", inbox[inboxcur][0])
inbox[inboxcur][7] = 0 inbox[inboxcur][7] = 0
elif t == "3": # Reply elif t == "3": # Reply
curses.curs_set(1) curses.curs_set(1)
m = inbox[inboxcur] m = inbox[inboxcur]
fromaddr = m[4] fromaddr = m[4]
@ -375,7 +383,7 @@ def handlech(c, stdscr):
if fromaddr == item[2] and item[3] != 0: if fromaddr == item[2] and item[3] != 0:
ischan = True ischan = True
break break
if not addresses[i][1]: # pylint: disable=undefined-loop-variable if not addresses[i][1]: # pylint: disable=undefined-loop-variable
scrollbox(d, unicode( scrollbox(d, unicode(
"Sending address disabled, please either enable it" "Sending address disabled, please either enable it"
"or choose a different address.")) "or choose a different address."))
@ -396,7 +404,7 @@ def handlech(c, stdscr):
sendMessage(fromaddr, toaddr, ischan, subject, body, True) sendMessage(fromaddr, toaddr, ischan, subject, body, True)
dialogreset(stdscr) dialogreset(stdscr)
elif t == "4": # Add to Address Book elif t == "4": # Add to Address Book
addr = inbox[inboxcur][4] addr = inbox[inboxcur][4]
if addr not in [item[1] for i, item in enumerate(addrbook)]: if addr not in [item[1] for i, item in enumerate(addrbook)]:
r, t = d.inputbox("Label for address \"" + addr + "\"") r, t = d.inputbox("Label for address \"" + addr + "\"")
@ -409,7 +417,7 @@ def handlech(c, stdscr):
addrbook.reverse() addrbook.reverse()
else: else:
scrollbox(d, unicode("The selected address is already in the Address Book.")) scrollbox(d, unicode("The selected address is already in the Address Book."))
elif t == "5": # Save message elif t == "5": # Save message
set_background_title(d, "Save \"" + inbox[inboxcur][5] + "\" as text file") set_background_title(d, "Save \"" + inbox[inboxcur][5] + "\" as text file")
r, t = d.inputbox("Filename", init=inbox[inboxcur][5] + ".txt") r, t = d.inputbox("Filename", init=inbox[inboxcur][5] + ".txt")
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
@ -418,12 +426,12 @@ def handlech(c, stdscr):
if ret != []: if ret != []:
for row in ret: for row in ret:
msg, = row msg, = row
fh = open(t, "a") # Open in append mode just in case fh = open(t, "a") # Open in append mode just in case
fh.write(msg) fh.write(msg)
fh.close() fh.close()
else: else:
scrollbox(d, unicode("Could not fetch message.")) scrollbox(d, unicode("Could not fetch message."))
elif t == "6": # Move to trash elif t == "6": # Move to trash
sqlExecute("UPDATE inbox SET folder='trash' WHERE msgid=?", inbox[inboxcur][0]) sqlExecute("UPDATE inbox SET folder='trash' WHERE msgid=?", inbox[inboxcur][0])
del inbox[inboxcur] del inbox[inboxcur]
scrollbox(d, unicode( scrollbox(d, unicode(
@ -431,7 +439,7 @@ def handlech(c, stdscr):
" \nbut the message is still on disk if you are desperate to recover it.")) " \nbut the message is still on disk if you are desperate to recover it."))
elif menutab == 2: elif menutab == 2:
a = "" a = ""
if addresses[addrcur][3] != 0: # if current address is a chan if addresses[addrcur][3] != 0: # if current address is a chan
a = addresses[addrcur][2] a = addresses[addrcur][2]
sendMessage(addresses[addrcur][2], a) sendMessage(addresses[addrcur][2], a)
elif menutab == 3: elif menutab == 3:
@ -467,7 +475,7 @@ def handlech(c, stdscr):
scrollbox(d, unicode(ascii(msg)), 30, 80) scrollbox(d, unicode(ascii(msg)), 30, 80)
else: else:
scrollbox(d, unicode("Could not fetch message.")) scrollbox(d, unicode("Could not fetch message."))
elif t == "2": # Move to trash elif t == "2": # Move to trash
sqlExecute( sqlExecute(
"UPDATE sent SET folder='trash' WHERE subject=? AND ackdata=?", "UPDATE sent SET folder='trash' WHERE subject=? AND ackdata=?",
sentbox[sentcur][4], sentbox[sentcur][4],
@ -495,7 +503,7 @@ def handlech(c, stdscr):
("6", "Delete"), ("6", "Delete"),
("7", "Special address behavior")]) ("7", "Special address behavior")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": # Create new address if t == "1": # Create new address
set_background_title(d, "Create new address") set_background_title(d, "Create new address")
scrollbox( scrollbox(
d, unicode( d, unicode(
@ -598,12 +606,12 @@ def handlech(c, stdscr):
str(passphrase), shorten)) str(passphrase), shorten))
else: else:
scrollbox(d, unicode("Passphrases do not match")) scrollbox(d, unicode("Passphrases do not match"))
elif t == "2": # Send a message elif t == "2": # Send a message
a = "" a = ""
if addresses[addrcur][3] != 0: # if current address is a chan if addresses[addrcur][3] != 0: # if current address is a chan
a = addresses[addrcur][2] a = addresses[addrcur][2]
sendMessage(addresses[addrcur][2], a) sendMessage(addresses[addrcur][2], a)
elif t == "3": # Rename address label elif t == "3": # Rename address label
a = addresses[addrcur][2] a = addresses[addrcur][2]
label = addresses[addrcur][0] label = addresses[addrcur][0]
r, t = d.inputbox("New address label", init=label) r, t = d.inputbox("New address label", init=label)
@ -613,35 +621,35 @@ def handlech(c, stdscr):
# Write config # Write config
BMConfigParser().save() BMConfigParser().save()
addresses[addrcur][0] = label addresses[addrcur][0] = label
elif t == "4": # Enable address elif t == "4": # Enable address
a = addresses[addrcur][2] a = addresses[addrcur][2]
BMConfigParser().set(a, "enabled", "true") # Set config BMConfigParser().set(a, "enabled", "true") # Set config
# Write config # Write config
BMConfigParser().save() BMConfigParser().save()
# Change color # Change color
if BMConfigParser().safeGetBoolean(a, 'chan'): if BMConfigParser().safeGetBoolean(a, 'chan'):
addresses[addrcur][3] = 9 # orange addresses[addrcur][3] = 9 # orange
elif BMConfigParser().safeGetBoolean(a, 'mailinglist'): elif BMConfigParser().safeGetBoolean(a, 'mailinglist'):
addresses[addrcur][3] = 5 # magenta addresses[addrcur][3] = 5 # magenta
else: else:
addresses[addrcur][3] = 0 # black addresses[addrcur][3] = 0 # black
addresses[addrcur][1] = True addresses[addrcur][1] = True
shared.reloadMyAddressHashes() # Reload address hashes shared.reloadMyAddressHashes() # Reload address hashes
elif t == "5": # Disable address elif t == "5": # Disable address
a = addresses[addrcur][2] a = addresses[addrcur][2]
BMConfigParser().set(a, "enabled", "false") # Set config BMConfigParser().set(a, "enabled", "false") # Set config
addresses[addrcur][3] = 8 # Set color to gray addresses[addrcur][3] = 8 # Set color to gray
# Write config # Write config
BMConfigParser().save() BMConfigParser().save()
addresses[addrcur][1] = False addresses[addrcur][1] = False
shared.reloadMyAddressHashes() # Reload address hashes shared.reloadMyAddressHashes() # Reload address hashes
elif t == "6": # Delete address elif t == "6": # Delete address
r, t = d.inputbox("Type in \"I want to delete this address\"", width=50) 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": if r == d.DIALOG_OK and t == "I want to delete this address":
BMConfigParser().remove_section(addresses[addrcur][2]) BMConfigParser().remove_section(addresses[addrcur][2])
BMConfigParser().save() BMConfigParser().save()
del addresses[addrcur] del addresses[addrcur]
elif t == "7": # Special address behavior elif t == "7": # Special address behavior
a = addresses[addrcur][2] a = addresses[addrcur][2]
set_background_title(d, "Special address behavior") set_background_title(d, "Special address behavior")
if BMConfigParser().safeGetBoolean(a, "chan"): if BMConfigParser().safeGetBoolean(a, "chan"):
@ -658,9 +666,9 @@ def handlech(c, stdscr):
if t == "1" and m: if t == "1" and m:
BMConfigParser().set(a, "mailinglist", "false") BMConfigParser().set(a, "mailinglist", "false")
if addresses[addrcur][1]: if addresses[addrcur][1]:
addresses[addrcur][3] = 0 # Set color to black addresses[addrcur][3] = 0 # Set color to black
else: else:
addresses[addrcur][3] = 8 # Set color to gray addresses[addrcur][3] = 8 # Set color to gray
elif t == "2" and m is False: elif t == "2" and m is False:
try: try:
mn = BMConfigParser().get(a, "mailinglistname") mn = BMConfigParser().get(a, "mailinglistname")
@ -671,7 +679,7 @@ def handlech(c, stdscr):
mn = t mn = t
BMConfigParser().set(a, "mailinglist", "true") BMConfigParser().set(a, "mailinglist", "true")
BMConfigParser().set(a, "mailinglistname", mn) BMConfigParser().set(a, "mailinglistname", mn)
addresses[addrcur][3] = 6 # Set color to magenta addresses[addrcur][3] = 6 # Set color to magenta
# Write config # Write config
BMConfigParser().save() BMConfigParser().save()
elif menutab == 5: elif menutab == 5:
@ -877,7 +885,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
10, 10,
60) 60)
if r != d.DIALOG_OK: if r != d.DIALOG_OK:
global menutab # pylint: disable=global-statement global menutab
menutab = 6 menutab = 6
return return
recv = t recv = t
@ -890,7 +898,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
if r != d.DIALOG_OK: if r != d.DIALOG_OK:
return return
broadcast = False broadcast = False
if t == "2": # Broadcast if t == "2": # Broadcast
broadcast = True broadcast = True
if subject == "" or reply: if subject == "" or reply:
r, t = d.inputbox("Message subject", width=60, init=subject) r, t = d.inputbox("Message subject", width=60, init=subject)
@ -906,13 +914,12 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
if not broadcast: if not broadcast:
recvlist = [] recvlist = []
for i, item in enumerate(recv.replace(",", ";").split(";")): for _, item in enumerate(recv.replace(",", ";").split(";")):
recvlist.append(item.strip()) recvlist.append(item.strip())
list(set(recvlist)) # Remove exact duplicates list(set(recvlist)) # Remove exact duplicates
for addr in recvlist: for addr in recvlist:
if addr != "": if addr != "":
# pylint: disable=redefined-outer-name status, version, stream = decodeAddress(addr)[:3]
status, version, stream, ripe = decodeAddress(addr)
if status != "success": if status != "success":
set_background_title(d, "Recipient address error") set_background_title(d, "Recipient address error")
err = "Could not decode" + addr + " : " + status + "\n\n" err = "Could not decode" + addr + " : " + status + "\n\n"
@ -957,52 +964,18 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
if not network.stats.connectedHostsList(): if not network.stats.connectedHostsList():
set_background_title(d, "Not connected warning") set_background_title(d, "Not connected warning")
scrollbox(d, unicode("Because you are not currently connected to the network, ")) scrollbox(d, unicode("Because you are not currently connected to the network, "))
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel') helper_sent.insert(
ackdata = genAckPayload(decodeAddress(addr)[2], stealthLevel) toAddress=addr, fromAddress=sender, subject=subject, message=body)
sqlExecute(
"INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
"",
addr,
ripe,
sender,
subject,
body,
ackdata,
int(time.time()), # sentTime (this will never change)
int(time.time()), # lastActionTime
0, # sleepTill time. This will get set when the POW gets done.
"msgqueued",
0, # retryNumber
"sent",
2, # encodingType
BMConfigParser().getint('bitmessagesettings', 'ttl'))
queues.workerQueue.put(("sendmessage", addr)) queues.workerQueue.put(("sendmessage", addr))
else: # Broadcast else: # Broadcast
if recv == "": if recv == "":
set_background_title(d, "Empty sender error") set_background_title(d, "Empty sender error")
scrollbox(d, unicode("You must specify an address to send the message from.")) scrollbox(d, unicode("You must specify an address to send the message from."))
else: else:
# dummy ackdata, no need for stealth # dummy ackdata, no need for stealth
ackdata = genAckPayload(decodeAddress(addr)[2], 0) helper_sent.insert(
recv = BROADCAST_STR fromAddress=sender, subject=subject,
ripe = "" message=body, status='broadcastqueued')
sqlExecute(
"INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
"",
recv,
ripe,
sender,
subject,
body,
ackdata,
int(time.time()), # sentTime (this will never change)
int(time.time()), # lastActionTime
0, # sleepTill time. This will get set when the POW gets done.
"broadcastqueued",
0, # retryNumber
"sent", # folder
2, # encodingType
BMConfigParser().getint('bitmessagesettings', 'ttl'))
queues.workerQueue.put(('sendbroadcast', '')) queues.workerQueue.put(('sendbroadcast', ''))
@ -1010,7 +983,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
def loadInbox(): def loadInbox():
"""Load the list of messages""" """Load the list of messages"""
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
print "Loading inbox messages..." print("Loading inbox messages...")
sys.stdout = printlog sys.stdout = printlog
where = "toaddress || fromaddress || subject || message" where = "toaddress || fromaddress || subject || message"
@ -1039,12 +1012,12 @@ def loadInbox():
fromlabel = "" fromlabel = ""
if BMConfigParser().has_section(fromaddr): if BMConfigParser().has_section(fromaddr):
fromlabel = BMConfigParser().get(fromaddr, "label") fromlabel = BMConfigParser().get(fromaddr, "label")
if fromlabel == "": # Check Address Book if fromlabel == "": # Check Address Book
qr = sqlQuery("SELECT label FROM addressbook WHERE address=?", fromaddr) qr = sqlQuery("SELECT label FROM addressbook WHERE address=?", fromaddr)
if qr != []: if qr != []:
for r in qr: for r in qr:
fromlabel, = r fromlabel, = r
if fromlabel == "": # Check Subscriptions if fromlabel == "": # Check Subscriptions
qr = sqlQuery("SELECT label FROM subscriptions WHERE address=?", fromaddr) qr = sqlQuery("SELECT label FROM subscriptions WHERE address=?", fromaddr)
if qr != []: if qr != []:
for r in qr: for r in qr:
@ -1062,7 +1035,7 @@ def loadInbox():
def loadSent(): def loadSent():
"""Load the messages that sent""" """Load the messages that sent"""
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
print "Loading sent messages..." print("Loading sent messages...")
sys.stdout = printlog sys.stdout = printlog
where = "toaddress || fromaddress || subject || message" where = "toaddress || fromaddress || subject || message"
@ -1148,7 +1121,7 @@ def loadSent():
def loadAddrBook(): def loadAddrBook():
"""Load address book""" """Load address book"""
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
print "Loading address book..." print("Loading address book...")
sys.stdout = printlog sys.stdout = printlog
ret = sqlQuery("SELECT label, address FROM addressbook") ret = sqlQuery("SELECT label, address FROM addressbook")
@ -1170,7 +1143,7 @@ def loadSubscriptions():
def loadBlackWhiteList(): def loadBlackWhiteList():
"""load black/white list""" """load black/white list"""
global bwtype # pylint: disable=global-statement global bwtype
bwtype = BMConfigParser().get("bitmessagesettings", "blackwhitelist") bwtype = BMConfigParser().get("bitmessagesettings", "blackwhitelist")
if bwtype == "black": if bwtype == "black":
ret = sqlQuery("SELECT label, address, enabled FROM blacklist") ret = sqlQuery("SELECT label, address, enabled FROM blacklist")
@ -1183,10 +1156,10 @@ def loadBlackWhiteList():
def runwrapper(): def runwrapper():
"""Main method"""
sys.stdout = printlog sys.stdout = printlog
# sys.stderr = errlog # sys.stderr = errlog
# Load messages from database
loadInbox() loadInbox()
loadSent() loadSent()
loadAddrBook() loadAddrBook()
@ -1195,7 +1168,7 @@ def runwrapper():
stdscr = curses.initscr() stdscr = curses.initscr()
global logpad # pylint: disable=global-statement global logpad
logpad = curses.newpad(1024, curses.COLS) logpad = curses.newpad(1024, curses.COLS)
stdscr.nodelay(0) stdscr.nodelay(0)
@ -1207,26 +1180,27 @@ def runwrapper():
def run(stdscr): def run(stdscr):
"""Main loop"""
# Schedule inventory lookup data # Schedule inventory lookup data
resetlookups() resetlookups()
# Init color pairs # Init color pairs
if curses.has_colors(): if curses.has_colors():
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) # red 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(2, curses.COLOR_GREEN, curses.COLOR_BLACK) # green
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK) # yellow 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(4, curses.COLOR_BLUE, curses.COLOR_BLACK) # blue
curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK) # magenta 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(6, curses.COLOR_CYAN, curses.COLOR_BLACK) # cyan
curses.init_pair(7, curses.COLOR_WHITE, curses.COLOR_BLACK) # white curses.init_pair(7, curses.COLOR_WHITE, curses.COLOR_BLACK) # white
if curses.can_change_color(): if curses.can_change_color():
curses.init_color(8, 500, 500, 500) # gray curses.init_color(8, 500, 500, 500) # gray
curses.init_pair(8, 8, 0) curses.init_pair(8, 8, 0)
curses.init_color(9, 844, 465, 0) # orange curses.init_color(9, 844, 465, 0) # orange
curses.init_pair(9, 9, 0) curses.init_pair(9, 9, 0)
else: else:
curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_BLACK) # grayish curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_BLACK) # grayish
curses.init_pair(9, curses.COLOR_YELLOW, curses.COLOR_BLACK) # orangish curses.init_pair(9, curses.COLOR_YELLOW, curses.COLOR_BLACK) # orangish
# Init list of address in 'Your Identities' tab # Init list of address in 'Your Identities' tab
configSections = BMConfigParser().addresses() configSections = BMConfigParser().addresses()
@ -1235,18 +1209,18 @@ def run(stdscr):
addresses.append([BMConfigParser().get(addressInKeysFile, "label"), isEnabled, addressInKeysFile]) addresses.append([BMConfigParser().get(addressInKeysFile, "label"), isEnabled, addressInKeysFile])
# Set address color # Set address color
if not isEnabled: if not isEnabled:
addresses[len(addresses) - 1].append(8) # gray addresses[len(addresses) - 1].append(8) # gray
elif BMConfigParser().safeGetBoolean(addressInKeysFile, 'chan'): elif BMConfigParser().safeGetBoolean(addressInKeysFile, 'chan'):
addresses[len(addresses) - 1].append(9) # orange addresses[len(addresses) - 1].append(9) # orange
elif BMConfigParser().safeGetBoolean(addressInKeysFile, 'mailinglist'): elif BMConfigParser().safeGetBoolean(addressInKeysFile, 'mailinglist'):
addresses[len(addresses) - 1].append(5) # magenta addresses[len(addresses) - 1].append(5) # magenta
else: else:
addresses[len(addresses) - 1].append(0) # black addresses[len(addresses) - 1].append(0) # black
addresses.reverse() addresses.reverse()
stdscr.clear() stdscr.clear()
redraw(stdscr) redraw(stdscr)
while quit is False: while quit_ is False:
drawtab(stdscr) drawtab(stdscr)
handlech(stdscr.getch(), stdscr) handlech(stdscr.getch(), stdscr)
@ -1254,10 +1228,9 @@ def run(stdscr):
def doShutdown(): def doShutdown():
"""Shutting the app down""" """Shutting the app down"""
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
print "Shutting down..." print("Shutting down...")
sys.stdout = printlog sys.stdout = printlog
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__ sys.stderr = sys.__stderr__
os._exit(0) # pylint: disable=protected-access
os._exit(0) # pylint: disable=protected-access

View File

@ -1,45 +0,0 @@
from helper_sql import *
def search_sql(xAddress="toaddress", account=None, folder="inbox", where=None, what=None, unreadOnly=False):
if what is not None and what != "":
what = "%" + what + "%"
else:
what = None
if folder == "sent":
sqlStatementBase = '''
SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime
FROM sent '''
else:
sqlStatementBase = '''SELECT folder, msgid, toaddress, fromaddress, subject, received, read
FROM inbox '''
sqlStatementParts = []
sqlArguments = []
if account is not None:
if xAddress == 'both':
sqlStatementParts.append("(fromaddress = ? OR toaddress = ?)")
sqlArguments.append(account)
sqlArguments.append(account)
else:
sqlStatementParts.append(xAddress + " = ? ")
sqlArguments.append(account)
if folder is not None:
if folder == "new":
folder = "inbox"
unreadOnly = True
sqlStatementParts.append("folder = ? ")
sqlArguments.append(folder)
else:
sqlStatementParts.append("folder != ?")
sqlArguments.append("trash")
if what is not None:
sqlStatementParts.append("%s LIKE ?" % (where))
sqlArguments.append(what)
if unreadOnly:
sqlStatementParts.append("read = 0")
if len(sqlStatementParts) > 0:
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
if folder == "sent":
sqlStatementBase += " ORDER BY lastactiontime"
return sqlQuery(sqlStatementBase, sqlArguments)

View File

@ -1,354 +0,0 @@
#:import la kivy.adapters.listadapter
#:import factory kivy.factory
#:import mpybit bitmessagekivy.mpybit
#:import C kivy.utils.get_color_from_hex
<Navigator>:
id: nav_drawer
NavigationDrawerIconButton:
Spinner:
pos_hint:{"x":0,"y":.3}
id: btn
background_color: app.theme_cls.primary_dark
text: app.showmeaddresses(name='text')
values: app.showmeaddresses(name='values')
on_text:app.getCurrentAccountData(self.text)
NavigationDrawerIconButton:
icon: 'email-open'
text: "inbox"
on_release: app.root.ids.scr_mngr.current = 'inbox'
NavigationDrawerIconButton:
icon: 'mail-send'
text: "sent"
on_release: app.root.ids.scr_mngr.current = 'sent'
NavigationDrawerIconButton:
icon: 'dropbox'
text: "trash"
on_release: app.root.ids.scr_mngr.current = 'trash'
NavigationDrawerIconButton:
icon: 'email'
text: "drafts"
on_release: app.root.ids.scr_mngr.current = 'dialog'
NavigationDrawerIconButton:
icon: 'markunread-mailbox'
text: "test"
on_release: app.root.ids.scr_mngr.current = 'test'
NavigationDrawerIconButton:
text: "new identity"
icon:'accounts-add'
on_release: app.root.ids.scr_mngr.current = 'newidentity'
BoxLayout:
orientation: 'vertical'
Toolbar:
id: toolbar
title: app.getCurrentAccount()
background_color: app.theme_cls.primary_dark
left_action_items: [['menu', lambda x: app.nav_drawer.toggle()]]
Button:
text:"EXIT"
color: 0,0,0,1
background_color: (0,0,0,0)
size_hint_y: 0.4
size_hint_x: 0.1
pos_hint: {'x': 0.8, 'y':0.4}
on_press: app.say_exit()
ScreenManager:
id: scr_mngr
Inbox:
id:sc1
Sent:
id:sc2
Trash:
id:sc3
Dialog:
id:sc4
Test:
id:sc5
Create:
id:sc6
NewIdentity:
id:sc7
Page:
id:sc8
AddressSuccessful:
id:sc9
Button:
id:create
height:100
size_hint_y: 0.13
size_hint_x: 0.1
pos_hint: {'x': 0.85, 'y': 0.5}
background_color: (0,0,0,0)
on_press: scr_mngr.current = 'create'
Image:
source: 'images/plus.png'
y: self.parent.y - 7.5
x: self.parent.x + self.parent.width - 50
size: 70, 70
<SwipeButton@Carousel>:
text: ''
size_hint_y: None
height: 48
ignore_perpendicular_swipes: True
data_index: 0
min_move: 20 / self.width
on__offset: app.update_index(root.data_index, self.index)
canvas.before:
Color:
rgba: C('FFFFFF33')
Rectangle:
pos: self.pos
size: self.size
Line:
rectangle: self.pos + self.size
Button:
text: 'delete ({}:{})'.format(root.text, root.data_index)
on_press: app.delete(root.data_index)
Button:
text: root.text
on_press: app.getInboxMessageDetail(self.text)
Button:
text: 'archive'
on_press: app.archive(root.data_index)
<Inbox>:
name: 'inbox'
RecycleView:
data: root.data
viewclass: 'SwipeButton'
do_scroll_x: False
scroll_timeout: 100
RecycleBoxLayout:
id:rc
orientation: 'vertical'
size_hint_y: None
height: self.minimum_height
default_size_hint: 1, None
canvas.before:
Color:
rgba: 0,0,0, 1
Rectangle:
pos: self.pos
size: self.size
<Sent>:
name: 'sent'
RecycleView:
data: root.data
viewclass: 'SwipeButton'
do_scroll_x: False
scroll_timeout: 100
RecycleBoxLayout:
id:rc
orientation: 'vertical'
size_hint_y: None
height: self.minimum_height
default_size_hint: 1, None
canvas.before:
Color:
rgba: 0,0,0, 1
Rectangle:
pos: self.pos
size: self.size
<Trash>:
name: 'trash'
RecycleView:
data: root.data
viewclass: 'SwipeButton'
do_scroll_x: False
scroll_timeout: 100
RecycleBoxLayout:
id:rc
orientation: 'vertical'
size_hint_y: None
height: self.minimum_height
default_size_hint: 1, None
canvas.before:
Color:
rgba: 0,0,0, 1
Rectangle:
pos: self.pos
size: self.size
<Dialog>:
name: 'dialog'
Label:
text:"I have a good dialox box"
color: 0,0,0,1
<Test>:
name: 'test'
Label:
text:"I am in test"
color: 0,0,0,1
<Create>:
name: 'create'
GridLayout:
rows: 5
cols: 1
padding: 60,60,60,60
spacing: 50
BoxLayout:
size_hint_y: None
height: '32dp'
Label:
text: 'FROM'
color: 0,0,0,1
Spinner:
size_hint: 1,1
pos_hint: {"x":0,"top":1.}
pos: 10,10
id: spinner_id
text: app.showmeaddresses(name='text')
values: app.showmeaddresses(name='values')
BoxLayout:
size_hint_y: None
height: '32dp'
Label:
text: 'TO'
color: 0,0,0,1
TextInput:
id: recipent
hint_text: 'To'
BoxLayout:
size_hint_y: None
height: '32dp'
Label:
text: 'SUBJECT'
color: 0,0,0,1
TextInput:
id: subject
hint_text: 'SUBJECT'
BoxLayout:
size_hint_y: None
height: '32dp'
Label:
text: 'BODY'
color: 0,0,0,1
TextInput:
id: message
multiline:True
size_hint: 1,2
Button:
text: 'send'
size_hint_y: 0.1
size_hint_x: 0.2
height: '32dp'
pos_hint: {'x': .5, 'y': 0.1}
on_press: root.send()
Button:
text: 'cancel'
size_hint_y: 0.1
size_hint_x: 0.2
height: '32dp'
pos_hint: {'x': .72, 'y': 0.1}
on_press: root.cancel()
<NewIdentity>:
name: 'newidentity'
GridLayout:
padding: '120dp'
cols: 1
Label:
text:"""Here you may generate as many addresses as you like. Indeed, creating and abandoning addresses is encouraged."""
line_height:1.5
text_size:(700,None)
color: 0,0,0,1
BoxLayout:
CheckBox:
canvas.before:
Color:
rgb: 1,0,0
Ellipse:
pos:self.center_x-8, self.center_y-8
size:[16,16]
group: "money"
id:chk
text:"use a random number generator to make an address"
on_active:
root.checked = self.text
active:root.is_active
Label:
text: "use a random number generator to make an address"
color: 0,0,0,1
BoxLayout:
CheckBox:
canvas.before:
Color:
rgb: 1,0,0
Ellipse:
pos:self.center_x-8, self.center_y-8
size:[16,16]
group: "money"
id:chk
text:"use a pseudo number generator to make an address"
on_active:
root.checked = self.text
active:not root.is_active
Label:
text: "use a pseudo number generator to make an address"
color: 0,0,0,1
Label:
color: 0,0,0,1
size_hint_x: .35
markup: True
text: "[b]{}[/b]".format("Randomly generated addresses")
BoxLayout:
size_hint_y: None
height: '32dp'
Label:
text: "Label (not shown to anyone except you)"
color: 0,0,0,1
BoxLayout:
size_hint_y: None
height: '32dp'
TextInput:
id: label
Button:
text: 'Cancel'
size_hint_y: 0.1
size_hint_x: 0.3
height: '32dp'
pos_hint: {'x': .1, 'y': 0.1}
Button:
text: 'Ok'
size_hint_y: 0.1
size_hint_x: 0.3
height: '32dp'
pos_hint: {'x': .5, 'y': 0.1}
on_press: root.generateaddress()
<Page>:
name: 'page'
Label:
text: 'I am on description of my email yooooo'
color: 0,0,0,1
<AddressSuccessful>:
name: 'add_sucess'
Label:
text: 'Successfully created a new bit address'
color: 0,0,0,1

View File

@ -1,393 +0,0 @@
import kivy_helper_search
import os
import queues
import shutdown
import state
import time
from kivy.app import App
from kivy.lang import Builder
from kivy.properties import BooleanProperty
from kivy.clock import Clock
from navigationdrawer import NavigationDrawer
from kivy.properties import ObjectProperty, StringProperty, ListProperty
from kivy.uix.screenmanager import Screen
from kivy.uix.textinput import TextInput
from kivymd.theming import ThemeManager
from kivymd.toolbar import Toolbar
from bmconfigparser import BMConfigParser
from helper_ackPayload import genAckPayload
from addresses import decodeAddress, addBMIfNotPresent
from helper_sql import sqlExecute
statusIconColor = 'red'
class NavigateApp(App, TextInput):
"""Application uses kivy in which base Class of Navigate App inherits from the App class."""
theme_cls = ThemeManager()
nav_drawer = ObjectProperty()
def build(self):
"""Return a main_widget as a root widget.
An application can be built if you return a widget on build(), or if you set
self.root.
"""
main_widget = Builder.load_file(
os.path.join(os.path.dirname(__file__), 'main.kv'))
self.nav_drawer = Navigator()
return main_widget
def getCurrentAccountData(self, text):
"""Get Current Address Account Data."""
state.association = text
self.root.ids.sc1.clear_widgets()
self.root.ids.sc2.clear_widgets()
self.root.ids.sc3.clear_widgets()
self.root.ids.sc1.add_widget(Inbox())
self.root.ids.sc2.add_widget(Sent())
self.root.ids.sc3.add_widget(Trash())
self.root.ids.toolbar.title = BMConfigParser().get(
state.association, 'label') + '({})'.format(state.association)
Inbox()
Sent()
Trash()
def say_exit(self):
"""Exit the application as uses shutdown PyBitmessage."""
print("**************************EXITING FROM APPLICATION*****************************")
App.get_running_app().stop()
shutdown.doCleanShutdown()
@staticmethod
def showmeaddresses(name="text"):
"""Show the addresses in spinner to make as dropdown."""
if name == "text":
return BMConfigParser().addresses()[0]
elif name == "values":
return BMConfigParser().addresses()
def update_index(self, data_index, index):
"""Update index after archieve message to trash."""
if self.root.ids.scr_mngr.current == 'inbox':
self.root.ids.sc1.data[data_index]['index'] = index
elif self.root.ids.scr_mngr.current == 'sent':
self.root.ids.sc2.data[data_index]['index'] = index
elif self.root.ids.scr_mngr.current == 'trash':
self.root.ids.sc3.data[data_index]['index'] = index
def delete(self, data_index):
"""It will make delete using remove function."""
print("delete {}".format(data_index))
self._remove(data_index)
def archive(self, data_index):
"""It will make archieve using remove function."""
print("archive {}".format(data_index))
self._remove(data_index)
def _remove(self, data_index):
"""It will remove message by resetting the values in recycleview data."""
if self.root.ids.scr_mngr.current == 'inbox':
self.root.ids.sc1.data.pop(data_index)
self.root.ids.sc1.data = [{
'data_index': i,
'index': d['index'],
'height': d['height'],
'text': d['text']}
for i, d in enumerate(self.root.ids.sc1.data)
]
elif self.root.ids.scr_mngr.current == 'sent':
self.root.ids.sc2.data.pop(data_index)
self.root.ids.sc2.data = [{
'data_index': i,
'index': d['index'],
'height': d['height'],
'text': d['text']}
for i, d in enumerate(self.root.ids.sc2.data)
]
elif self.root.ids.scr_mngr.current == 'trash':
self.root.ids.sc3.data.pop(data_index)
self.root.ids.sc3.data = [{
'data_index': i,
'index': d['index'],
'height': d['height'],
'text': d['text']}
for i, d in enumerate(self.root.ids.sc3.data)
]
def getInboxMessageDetail(self, instance):
"""It will get message detail after make selected message description."""
try:
self.root.ids.scr_mngr.current = 'page'
except AttributeError:
self.parent.manager.current = 'page'
print('Message Clicked {}'.format(instance))
@staticmethod
def getCurrentAccount():
"""It uses to get current account label."""
return BMConfigParser().get(state.association, 'label') + '({})'.format(state.association)
class Navigator(NavigationDrawer):
"""Navigator class uses NavigationDrawer.
It is an UI panel that shows our app's main navigation menu
It is hidden when not in use, but appears when the user swipes
a finger from the left edge of the screen or, when at the top
level of the app, the user touches the drawer icon in the app bar
"""
image_source = StringProperty('images/qidenticon_two.png')
title = StringProperty('Navigation')
class Inbox(Screen):
"""Inbox Screen uses screen to show widgets of screens."""
data = ListProperty()
def __init__(self, *args, **kwargs):
super(Inbox, self).__init__(*args, **kwargs)
if state.association == '':
state.association = Navigator().ids.btn.text
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method inbox accounts."""
self.inboxaccounts()
print(dt)
def inboxaccounts(self):
"""Load inbox accounts."""
account = state.association
self.loadMessagelist(account, 'All', '')
def loadMessagelist(self, account, where="", what=""):
"""Load Inbox list for inbox messages."""
xAddress = "toaddress"
queryreturn = kivy_helper_search.search_sql(
xAddress, account, 'inbox', where, what, False)
if queryreturn:
self.data = [{
'data_index': i,
'index': 1,
'height': 48,
'text': row[4]}
for i, row in enumerate(queryreturn)
]
else:
self.data = [{
'data_index': 1,
'index': 1,
'height': 48,
'text': "yet no message for this account!!!!!!!!!!!!!"}
]
class Page(Screen):
pass
class AddressSuccessful(Screen):
pass
class Sent(Screen):
"""Sent Screen uses screen to show widgets of screens."""
data = ListProperty()
def __init__(self, *args, **kwargs):
super(Sent, self).__init__(*args, **kwargs)
if state.association == '':
state.association = Navigator().ids.btn.text
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method sent accounts."""
self.sentaccounts()
print(dt)
def sentaccounts(self):
"""Load sent accounts."""
account = state.association
self.loadSent(account, 'All', '')
def loadSent(self, account, where="", what=""):
"""Load Sent list for Sent messages."""
xAddress = 'fromaddress'
queryreturn = kivy_helper_search.search_sql(
xAddress, account, "sent", where, what, False)
if queryreturn:
self.data = [{
'data_index': i,
'index': 1,
'height': 48,
'text': row[2]}
for i, row in enumerate(queryreturn)
]
else:
self.data = [{
'data_index': 1,
'index': 1,
'height': 48,
'text': "yet no message for this account!!!!!!!!!!!!!"}
]
class Trash(Screen):
"""Trash Screen uses screen to show widgets of screens."""
data = ListProperty()
def __init__(self, *args, **kwargs):
super(Trash, self).__init__(*args, **kwargs)
if state.association == '':
state.association = Navigator().ids.btn.text
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method inbox accounts."""
self.inboxaccounts()
print(dt)
def inboxaccounts(self):
"""Load inbox accounts."""
account = state.association
self.loadTrashlist(account, 'All', '')
def loadTrashlist(self, account, where="", what=""):
"""Load Trash list for trashed messages."""
xAddress = "toaddress"
queryreturn = kivy_helper_search.search_sql(
xAddress, account, 'trash', where, what, False)
if queryreturn:
self.data = [{
'data_index': i,
'index': 1,
'height': 48,
'text': row[4]}
for i, row in enumerate(queryreturn)
]
else:
self.data = [{
'data_index': 1,
'index': 1,
'height': 48,
'text': "yet no message for this account!!!!!!!!!!!!!"}
]
class Dialog(Screen):
"""Dialog Screen uses screen to show widgets of screens."""
pass
class Test(Screen):
"""Test Screen uses screen to show widgets of screens."""
pass
class Create(Screen):
"""Create Screen uses screen to show widgets of screens."""
def __init__(self, *args, **kwargs):
super(Create, self).__init__(*args, **kwargs)
def send(self):
"""Send message from one address to another."""
fromAddress = self.ids.spinner_id.text
# For now we are using static address i.e we are not using recipent field value.
toAddress = "BM-2cWyUfBdY2FbgyuCb7abFZ49JYxSzUhNFe"
message = self.ids.message.text
subject = self.ids.subject.text
encoding = 3
print("message: ", self.ids.message.text)
sendMessageToPeople = True
if sendMessageToPeople:
if toAddress != '':
status, addressVersionNumber, streamNumber, ripe = decodeAddress(
toAddress)
if status == 'success':
toAddress = addBMIfNotPresent(toAddress)
if addressVersionNumber > 4 or addressVersionNumber <= 1:
print("addressVersionNumber > 4 or addressVersionNumber <= 1")
if streamNumber > 1 or streamNumber == 0:
print("streamNumber > 1 or streamNumber == 0")
if statusIconColor == 'red':
print("shared.statusIconColor == 'red'")
stealthLevel = BMConfigParser().safeGetInt(
'bitmessagesettings', 'ackstealthlevel')
ackdata = genAckPayload(streamNumber, stealthLevel)
t = ()
sqlExecute(
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''',
'',
toAddress,
ripe,
fromAddress,
subject,
message,
ackdata,
int(time.time()),
int(time.time()),
0,
'msgqueued',
0,
'sent',
encoding,
BMConfigParser().getint('bitmessagesettings', 'ttl'))
toLabel = ''
queues.workerQueue.put(('sendmessage', toAddress))
print("sqlExecute successfully ##### ##################")
self.ids.message.text = ''
self.ids.spinner_id.text = '<select>'
self.ids.subject.text = ''
self.ids.recipent.text = ''
return None
def cancel(self):
"""Reset values for send message."""
self.ids.message.text = ''
self.ids.spinner_id.text = '<select>'
self.ids.subject.text = ''
self.ids.recipent.text = ''
return None
class NewIdentity(Screen):
"""Create new address for PyBitmessage."""
is_active = BooleanProperty(False)
checked = StringProperty("")
# self.manager.parent.ids.create.children[0].source = 'images/plus-4-xxl.png'
def generateaddress(self):
"""Generate new address."""
if self.checked == 'use a random number generator to make an address':
queues.apiAddressGeneratorReturnQueue.queue.clear()
streamNumberForAddress = 1
label = self.ids.label.text
eighteenByteRipe = False
nonceTrialsPerByte = 1000
payloadLengthExtraBytes = 1000
queues.addressGeneratorQueue.put((
'createRandomAddress',
4, streamNumberForAddress,
label, 1, "", eighteenByteRipe,
nonceTrialsPerByte,
payloadLengthExtraBytes)
)
self.manager.current = 'add_sucess'
if __name__ == '__main__':
NavigateApp().run()

View File

@ -1,19 +1,22 @@
#!/usr/bin/python2.7 #!/usr/bin/env python
"""
The PyBitmessage startup script
"""
# Copyright (c) 2012-2016 Jonathan Warren # Copyright (c) 2012-2016 Jonathan Warren
# Copyright (c) 2012-2019 The Bitmessage developers # Copyright (c) 2012-2020 The Bitmessage developers
# Distributed under the MIT/X11 software license. See the accompanying # Distributed under the MIT/X11 software license. See the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
# Right now, PyBitmessage only support connecting to stream 1. It doesn't # Right now, PyBitmessage only support connecting to stream 1. It doesn't
# yet contain logic to expand into further streams. # yet contain logic to expand into further streams.
import os import os
import sys import sys
app_dir = os.path.dirname(os.path.abspath(__file__)) try:
os.chdir(app_dir) import pathmagic
sys.path.insert(0, app_dir) except ImportError:
from pybitmessage import pathmagic
app_dir = pathmagic.setup()
import depends import depends
depends.check_dependencies() depends.check_dependencies()
@ -31,47 +34,26 @@ from struct import pack
import defaults import defaults
import shared import shared
import state
import shutdown import shutdown
import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from debug import logger # this should go before any threads from debug import logger # this should go before any threads
from helper_startup import ( from helper_startup import (
isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections adjustHalfOpenConnectionsLimit, start_proxyconfig)
)
from inventory import Inventory from inventory import Inventory
from knownnodes import readKnownNodes
# Network objects and threads # Network objects and threads
from network import ( from network import (
BMConnectionPool, Dandelion, BMConnectionPool, Dandelion, AddrThread, AnnounceThread, BMNetworkThread,
AddrThread, AnnounceThread, BMNetworkThread, InvThread, ReceiveQueueThread, InvThread, ReceiveQueueThread, DownloadThread, UploadThread
DownloadThread, UploadThread) )
from network.knownnodes import readKnownNodes
from singleinstance import singleinstance from singleinstance import singleinstance
# Synchronous threads # Synchronous threads
from threads import ( from threads import (
set_thread_name, set_thread_name, printLock,
addressGenerator, objectProcessor, singleCleaner, singleWorker, sqlThread) addressGenerator, objectProcessor, singleCleaner, singleWorker, sqlThread)
def connectToStream(streamNumber):
state.streamsInWhichIAmParticipating.append(streamNumber)
if isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
# Some XP and Vista systems can only have 10 outgoing connections
# at a time.
state.maximumNumberOfHalfOpenConnections = 9
else:
state.maximumNumberOfHalfOpenConnections = 64
try:
# don't overload Tor
if BMConfigParser().get(
'bitmessagesettings', 'socksproxytype') != 'none':
state.maximumNumberOfHalfOpenConnections = 4
except:
pass
BMConnectionPool().connectToStream(streamNumber)
def _fixSocket(): def _fixSocket():
if sys.platform.startswith('linux'): if sys.platform.startswith('linux'):
socket.SO_BINDTODEVICE = 25 socket.SO_BINDTODEVICE = 25
@ -85,6 +67,8 @@ def _fixSocket():
addressToString = ctypes.windll.ws2_32.WSAAddressToStringA addressToString = ctypes.windll.ws2_32.WSAAddressToStringA
def inet_ntop(family, host): def inet_ntop(family, host):
"""Converting an IP address in packed
binary format to string format"""
if family == socket.AF_INET: if family == socket.AF_INET:
if len(host) != 4: if len(host) != 4:
raise ValueError("invalid IPv4 host") raise ValueError("invalid IPv4 host")
@ -106,6 +90,8 @@ def _fixSocket():
stringToAddress = ctypes.windll.ws2_32.WSAStringToAddressA stringToAddress = ctypes.windll.ws2_32.WSAStringToAddressA
def inet_pton(family, host): def inet_pton(family, host):
"""Converting an IP address in string format
to a packed binary format"""
buf = "\0" * 28 buf = "\0" * 28
lengthBuf = pack("I", len(buf)) lengthBuf = pack("I", len(buf))
if stringToAddress(str(host), if stringToAddress(str(host),
@ -146,9 +132,9 @@ def signal_handler(signum, frame):
if thread.name not in ("PyBitmessage", "MainThread"): if thread.name not in ("PyBitmessage", "MainThread"):
return return
logger.error("Got signal %i", signum) logger.error("Got signal %i", signum)
# there are possible non-UI variants to run bitmessage which should shutdown # there are possible non-UI variants to run bitmessage
# especially test-mode # which should shutdown especially test-mode
if shared.thisapp.daemon or not state.enableGUI: if state.thisapp.daemon or not state.enableGUI:
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
else: else:
print('# Thread: %s(%d)' % (thread.name, thread.ident)) print('# Thread: %s(%d)' % (thread.name, thread.ident))
@ -160,37 +146,19 @@ def signal_handler(signum, frame):
' because the UI captures the signal.') ' because the UI captures the signal.')
class Main: class Main(object):
@staticmethod """Main PyBitmessage class"""
def start_proxyconfig(config):
"""Check socksproxytype and start any proxy configuration plugin"""
proxy_type = config.safeGet('bitmessagesettings', 'socksproxytype')
if proxy_type not in ('none', 'SOCKS4a', 'SOCKS5'):
# pylint: disable=relative-import
from plugins.plugin import get_plugin
try:
proxyconfig_start = time.time()
if not get_plugin('proxyconfig', name=proxy_type)(config):
raise TypeError
except TypeError:
logger.error(
'Failed to run proxy config plugin %s',
proxy_type, exc_info=True)
shutdown.doCleanShutdown()
sys.exit(2)
else:
logger.info(
'Started proxy config plugin %s in %s sec',
proxy_type, time.time() - proxyconfig_start)
def start(self): def start(self):
"""Start main application"""
# pylint: disable=too-many-statements,too-many-branches,too-many-locals
_fixSocket() _fixSocket()
adjustHalfOpenConnectionsLimit()
config = BMConfigParser() config = BMConfigParser()
daemon = config.safeGetBoolean('bitmessagesettings', 'daemon') daemon = config.safeGetBoolean('bitmessagesettings', 'daemon')
try: try:
opts, args = getopt.getopt( opts, _ = getopt.getopt(
sys.argv[1:], "hcdt", sys.argv[1:], "hcdt",
["help", "curses", "daemon", "test"]) ["help", "curses", "daemon", "test"])
@ -198,7 +166,7 @@ class Main:
self.usage() self.usage()
sys.exit(2) sys.exit(2)
for opt, arg in opts: for opt, _ in opts:
if opt in ("-h", "--help"): if opt in ("-h", "--help"):
self.usage() self.usage()
sys.exit() sys.exit()
@ -221,6 +189,8 @@ class Main:
'bitmessagesettings', 'apiusername', 'username') 'bitmessagesettings', 'apiusername', 'username')
config.set( config.set(
'bitmessagesettings', 'apipassword', 'password') 'bitmessagesettings', 'apipassword', 'password')
config.set(
'bitmessagesettings', 'apivariant', 'legacy')
config.set( config.set(
'bitmessagesettings', 'apinotifypath', 'bitmessagesettings', 'apinotifypath',
os.path.join(app_dir, 'tests', 'apinotify_handler.py') os.path.join(app_dir, 'tests', 'apinotify_handler.py')
@ -243,10 +213,10 @@ class Main:
' \'-c\' as a commandline argument.' ' \'-c\' as a commandline argument.'
) )
# is the application already running? If yes then exit. # is the application already running? If yes then exit.
shared.thisapp = singleinstance("", daemon) state.thisapp = singleinstance("", daemon)
if daemon: if daemon:
with shared.printLock: with printLock:
print('Running as a daemon. Send TERM signal to end.') print('Running as a daemon. Send TERM signal to end.')
self.daemonize() self.daemonize()
@ -342,8 +312,8 @@ class Main:
# start network components if networking is enabled # start network components if networking is enabled
if state.enableNetwork: if state.enableNetwork:
self.start_proxyconfig(config) start_proxyconfig()
BMConnectionPool() BMConnectionPool().connectToStream(1)
asyncoreThread = BMNetworkThread() asyncoreThread = BMNetworkThread()
asyncoreThread.daemon = True asyncoreThread.daemon = True
asyncoreThread.start() asyncoreThread.start()
@ -351,9 +321,10 @@ class Main:
receiveQueueThread = ReceiveQueueThread(i) receiveQueueThread = ReceiveQueueThread(i)
receiveQueueThread.daemon = True receiveQueueThread.daemon = True
receiveQueueThread.start() receiveQueueThread.start()
announceThread = AnnounceThread() if config.safeGetBoolean('bitmessagesettings', 'udp'):
announceThread.daemon = True state.announceThread = AnnounceThread()
announceThread.start() state.announceThread.daemon = True
state.announceThread.start()
state.invThread = InvThread() state.invThread = InvThread()
state.invThread.daemon = True state.invThread.daemon = True
state.invThread.start() state.invThread.start()
@ -367,8 +338,6 @@ class Main:
state.uploadThread.daemon = True state.uploadThread.daemon = True
state.uploadThread.start() state.uploadThread.start()
connectToStream(1)
if config.safeGetBoolean('bitmessagesettings', 'upnp'): if config.safeGetBoolean('bitmessagesettings', 'upnp'):
import upnp import upnp
upnpThread = upnp.uPnPThread() upnpThread = upnp.uPnPThread()
@ -384,10 +353,6 @@ class Main:
print('Running with curses') print('Running with curses')
import bitmessagecurses import bitmessagecurses
bitmessagecurses.runwrapper() bitmessagecurses.runwrapper()
elif state.kivy:
config.remove_option('bitmessagesettings', 'dontconnect')
from bitmessagekivy.mpybit import NavigateApp
NavigateApp().run()
else: else:
import bitmessageqt import bitmessageqt
bitmessageqt.run() bitmessageqt.run()
@ -398,37 +363,43 @@ class Main:
while state.shutdown == 0: while state.shutdown == 0:
time.sleep(1) time.sleep(1)
if ( if (
state.testmode and time.time() - state.last_api_response >= 30): state.testmode
and time.time() - state.last_api_response >= 30
):
self.stop() self.stop()
elif not state.enableGUI: elif not state.enableGUI:
from tests import core as test_core # pylint: disable=relative-import
test_core_result = test_core.run(self)
state.enableGUI = True state.enableGUI = True
try:
# pylint: disable=relative-import
from tests import core as test_core
except ImportError:
self.stop()
return
test_core_result = test_core.run()
self.stop() self.stop()
test_core.cleanup() test_core.cleanup()
sys.exit( sys.exit(not test_core_result.wasSuccessful())
'Core tests failed!'
if test_core_result.errors or test_core_result.failures
else 0
)
def daemonize(self): @staticmethod
def daemonize():
"""Running as a daemon. Send signal in end."""
grandfatherPid = os.getpid() grandfatherPid = os.getpid()
parentPid = None parentPid = None
try: try:
if os.fork(): if os.fork():
# unlock # unlock
shared.thisapp.cleanup() state.thisapp.cleanup()
# wait until grandchild ready # wait until grandchild ready
while True: while True:
time.sleep(1) time.sleep(1)
os._exit(0) os._exit(0) # pylint: disable=protected-access
except AttributeError: except AttributeError:
# fork not implemented # fork not implemented
pass pass
else: else:
parentPid = os.getpid() parentPid = os.getpid()
shared.thisapp.lock() # relock state.thisapp.lock() # relock
os.umask(0) os.umask(0)
try: try:
@ -439,17 +410,17 @@ class Main:
try: try:
if os.fork(): if os.fork():
# unlock # unlock
shared.thisapp.cleanup() state.thisapp.cleanup()
# wait until child ready # wait until child ready
while True: while True:
time.sleep(1) time.sleep(1)
os._exit(0) os._exit(0) # pylint: disable=protected-access
except AttributeError: except AttributeError:
# fork not implemented # fork not implemented
pass pass
else: else:
shared.thisapp.lock() # relock state.thisapp.lock() # relock
shared.thisapp.lockPid = None # indicate we're the final child state.thisapp.lockPid = None # indicate we're the final child
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()
if not sys.platform.startswith('win'): if not sys.platform.startswith('win'):
@ -464,14 +435,18 @@ class Main:
os.kill(parentPid, signal.SIGTERM) os.kill(parentPid, signal.SIGTERM)
os.kill(grandfatherPid, signal.SIGTERM) os.kill(grandfatherPid, signal.SIGTERM)
def setSignalHandler(self): @staticmethod
def setSignalHandler():
"""Setting the Signal Handler"""
signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGTERM, signal_handler)
# signal.signal(signal.SIGINT, signal.SIG_DFL) # signal.signal(signal.SIGINT, signal.SIG_DFL)
def usage(self): @staticmethod
print 'Usage: ' + sys.argv[0] + ' [OPTIONS]' def usage():
print ''' """Displaying the usages"""
print('Usage: ' + sys.argv[0] + ' [OPTIONS]')
print('''
Options: Options:
-h, --help show this help message and exit -h, --help show this help message and exit
-c, --curses use curses (text mode) interface -c, --curses use curses (text mode) interface
@ -479,15 +454,19 @@ Options:
-t, --test dryrun, make testing -t, --test dryrun, make testing
All parameters are optional. All parameters are optional.
''' ''')
def stop(self): @staticmethod
with shared.printLock: def stop():
"""Stop main application"""
with printLock:
print('Stopping Bitmessage Deamon.') print('Stopping Bitmessage Deamon.')
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
# TODO: nice function but no one is using this # .. todo:: nice function but no one is using this
def getApiAddress(self): @staticmethod
def getApiAddress():
"""This function returns API address and port"""
if not BMConfigParser().safeGetBoolean( if not BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'apienabled'): 'bitmessagesettings', 'apienabled'):
return None return None
@ -497,6 +476,7 @@ All parameters are optional.
def main(): def main():
"""Triggers main module"""
mainprogram = Main() mainprogram = Main()
mainprogram.start() mainprogram.start()

View File

@ -7,6 +7,7 @@ import locale
import os import os
import random import random
import string import string
import subprocess
import sys import sys
import textwrap import textwrap
import threading import threading
@ -17,10 +18,11 @@ from sqlite3 import register_adapter
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from PyQt4.QtNetwork import QLocalSocket, QLocalServer from PyQt4.QtNetwork import QLocalSocket, QLocalServer
import shared
import state
from debug import logger from debug import logger
from tr import _translate from tr import _translate
from addresses import decodeAddress, addBMIfNotPresent from addresses import decodeAddress, addBMIfNotPresent
import shared
from bitmessageui import Ui_MainWindow from bitmessageui import Ui_MainWindow
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
import namecoin import namecoin
@ -29,11 +31,12 @@ from migrationwizard import Ui_MigrationWizard
from foldertree import ( from foldertree import (
AccountMixin, Ui_FolderWidget, Ui_AddressWidget, Ui_SubscriptionWidget, AccountMixin, Ui_FolderWidget, Ui_AddressWidget, Ui_SubscriptionWidget,
MessageList_AddressWidget, MessageList_SubjectWidget, MessageList_AddressWidget, MessageList_SubjectWidget,
Ui_AddressBookWidgetItemLabel, Ui_AddressBookWidgetItemAddress) Ui_AddressBookWidgetItemLabel, Ui_AddressBookWidgetItemAddress,
MessageList_TimeWidget)
import settingsmixin import settingsmixin
import support import support
from helper_ackPayload import genAckPayload
from helper_sql import sqlQuery, sqlExecute, sqlExecuteChunked, sqlStoredProcedure from helper_sql import sqlQuery, sqlExecute, sqlExecuteChunked, sqlStoredProcedure
import helper_addressbook
import helper_search import helper_search
import l10n import l10n
from utils import str_broadcast_subscribers, avatarize from utils import str_broadcast_subscribers, avatarize
@ -47,11 +50,11 @@ import paths
from proofofwork import getPowType from proofofwork import getPowType
import queues import queues
import shutdown import shutdown
import state
from statusbar import BMStatusBar from statusbar import BMStatusBar
import sound import sound
# This is needed for tray icon # This is needed for tray icon
import bitmessage_icons_rc # noqa:F401 pylint: disable=unused-import import bitmessage_icons_rc # noqa:F401 pylint: disable=unused-import
import helper_sent
try: try:
from plugins.plugin import get_plugin, get_plugins from plugins.plugin import get_plugin, get_plugins
@ -72,6 +75,15 @@ def powQueueSize():
return queue_len return queue_len
def openKeysFile():
"""Open keys file with an external editor"""
keysfile = os.path.join(state.appdata, 'keys.dat')
if 'linux' in sys.platform:
subprocess.call(["xdg-open", keysfile])
elif sys.platform.startswith('win'):
os.startfile(keysfile) # pylint: disable=no-member
class MyForm(settingsmixin.SMainWindow): class MyForm(settingsmixin.SMainWindow):
# the maximum frequency of message sounds in seconds # the maximum frequency of message sounds in seconds
@ -214,19 +226,19 @@ class MyForm(settingsmixin.SMainWindow):
if connectSignal: if connectSignal:
self.connect(self.ui.tableWidgetInbox, QtCore.SIGNAL( self.connect(self.ui.tableWidgetInbox, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuInbox) self.on_context_menuInbox)
self.ui.tableWidgetInboxSubscriptions.setContextMenuPolicy( self.ui.tableWidgetInboxSubscriptions.setContextMenuPolicy(
QtCore.Qt.CustomContextMenu) QtCore.Qt.CustomContextMenu)
if connectSignal: if connectSignal:
self.connect(self.ui.tableWidgetInboxSubscriptions, QtCore.SIGNAL( self.connect(self.ui.tableWidgetInboxSubscriptions, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuInbox) self.on_context_menuInbox)
self.ui.tableWidgetInboxChans.setContextMenuPolicy( self.ui.tableWidgetInboxChans.setContextMenuPolicy(
QtCore.Qt.CustomContextMenu) QtCore.Qt.CustomContextMenu)
if connectSignal: if connectSignal:
self.connect(self.ui.tableWidgetInboxChans, QtCore.SIGNAL( self.connect(self.ui.tableWidgetInboxChans, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuInbox) self.on_context_menuInbox)
def init_identities_popup_menu(self, connectSignal=True): def init_identities_popup_menu(self, connectSignal=True):
# Popup menu for the Your Identities tab # Popup menu for the Your Identities tab
@ -266,7 +278,7 @@ class MyForm(settingsmixin.SMainWindow):
if connectSignal: if connectSignal:
self.connect(self.ui.treeWidgetYourIdentities, QtCore.SIGNAL( self.connect(self.ui.treeWidgetYourIdentities, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuYourIdentities) self.on_context_menuYourIdentities)
# load all gui.menu plugins with prefix 'address' # load all gui.menu plugins with prefix 'address'
self.menu_plugins = {'address': []} self.menu_plugins = {'address': []}
@ -316,7 +328,7 @@ class MyForm(settingsmixin.SMainWindow):
if connectSignal: if connectSignal:
self.connect(self.ui.treeWidgetChans, QtCore.SIGNAL( self.connect(self.ui.treeWidgetChans, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuChan) self.on_context_menuChan)
def init_addressbook_popup_menu(self, connectSignal=True): def init_addressbook_popup_menu(self, connectSignal=True):
# Popup menu for the Address Book page # Popup menu for the Address Book page
@ -353,7 +365,7 @@ class MyForm(settingsmixin.SMainWindow):
if connectSignal: if connectSignal:
self.connect(self.ui.tableWidgetAddressBook, QtCore.SIGNAL( self.connect(self.ui.tableWidgetAddressBook, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuAddressBook) self.on_context_menuAddressBook)
def init_subscriptions_popup_menu(self, connectSignal=True): def init_subscriptions_popup_menu(self, connectSignal=True):
# Actions # Actions
@ -382,7 +394,7 @@ class MyForm(settingsmixin.SMainWindow):
if connectSignal: if connectSignal:
self.connect(self.ui.treeWidgetSubscriptions, QtCore.SIGNAL( self.connect(self.ui.treeWidgetSubscriptions, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuSubscriptions) self.on_context_menuSubscriptions)
def init_sent_popup_menu(self, connectSignal=True): def init_sent_popup_menu(self, connectSignal=True):
# Actions # Actions
@ -413,13 +425,13 @@ class MyForm(settingsmixin.SMainWindow):
treeWidget.header().setSortIndicator( treeWidget.header().setSortIndicator(
0, QtCore.Qt.AscendingOrder) 0, QtCore.Qt.AscendingOrder)
# init dictionary # init dictionary
db = getSortedSubscriptions(True) db = getSortedSubscriptions(True)
for address in db: for address in db:
for folder in folders: for folder in folders:
if not folder in db[address]: if folder not in db[address]:
db[address][folder] = {} db[address][folder] = {}
if treeWidget.isSortingEnabled(): if treeWidget.isSortingEnabled():
treeWidget.setSortingEnabled(False) treeWidget.setSortingEnabled(False)
@ -431,8 +443,8 @@ class MyForm(settingsmixin.SMainWindow):
toAddress = widget.address toAddress = widget.address
else: else:
toAddress = None toAddress = None
if not toAddress in db: if toAddress not in db:
treeWidget.takeTopLevelItem(i) treeWidget.takeTopLevelItem(i)
# no increment # no increment
continue continue
@ -462,7 +474,7 @@ class MyForm(settingsmixin.SMainWindow):
widget.setUnreadCount(unread) widget.setUnreadCount(unread)
db.pop(toAddress, None) db.pop(toAddress, None)
i += 1 i += 1
i = 0 i = 0
for toAddress in db: for toAddress in db:
widget = Ui_SubscriptionWidget(treeWidget, i, toAddress, db[toAddress]["inbox"]['count'], db[toAddress]["inbox"]['label'], db[toAddress]["inbox"]['enabled']) widget = Ui_SubscriptionWidget(treeWidget, i, toAddress, db[toAddress]["inbox"]['count'], db[toAddress]["inbox"]['label'], db[toAddress]["inbox"]['enabled'])
@ -477,23 +489,22 @@ class MyForm(settingsmixin.SMainWindow):
j += 1 j += 1
widget.setUnreadCount(unread) widget.setUnreadCount(unread)
i += 1 i += 1
treeWidget.setSortingEnabled(True)
treeWidget.setSortingEnabled(True)
def rerenderTabTreeMessages(self): def rerenderTabTreeMessages(self):
self.rerenderTabTree('messages') self.rerenderTabTree('messages')
def rerenderTabTreeChans(self): def rerenderTabTreeChans(self):
self.rerenderTabTree('chan') self.rerenderTabTree('chan')
def rerenderTabTree(self, tab): def rerenderTabTree(self, tab):
if tab == 'messages': if tab == 'messages':
treeWidget = self.ui.treeWidgetYourIdentities treeWidget = self.ui.treeWidgetYourIdentities
elif tab == 'chan': elif tab == 'chan':
treeWidget = self.ui.treeWidgetChans treeWidget = self.ui.treeWidgetChans
folders = Ui_FolderWidget.folderWeight.keys() folders = Ui_FolderWidget.folderWeight.keys()
# sort ascending when creating # sort ascending when creating
if treeWidget.topLevelItemCount() == 0: if treeWidget.topLevelItemCount() == 0:
treeWidget.header().setSortIndicator( treeWidget.header().setSortIndicator(
@ -501,7 +512,7 @@ class MyForm(settingsmixin.SMainWindow):
# init dictionary # init dictionary
db = {} db = {}
enabled = {} enabled = {}
for toAddress in getSortedAccounts(): for toAddress in getSortedAccounts():
isEnabled = BMConfigParser().getboolean( isEnabled = BMConfigParser().getboolean(
toAddress, 'enabled') toAddress, 'enabled')
@ -520,7 +531,7 @@ class MyForm(settingsmixin.SMainWindow):
db[toAddress] = {} db[toAddress] = {}
for folder in folders: for folder in folders:
db[toAddress][folder] = 0 db[toAddress][folder] = 0
enabled[toAddress] = isEnabled enabled[toAddress] = isEnabled
# get number of (unread) messages # get number of (unread) messages
@ -538,10 +549,10 @@ class MyForm(settingsmixin.SMainWindow):
db[None]["sent"] = 0 db[None]["sent"] = 0
db[None]["trash"] = 0 db[None]["trash"] = 0
enabled[None] = True enabled[None] = True
if treeWidget.isSortingEnabled(): if treeWidget.isSortingEnabled():
treeWidget.setSortingEnabled(False) treeWidget.setSortingEnabled(False)
widgets = {} widgets = {}
i = 0 i = 0
while i < treeWidget.topLevelItemCount(): while i < treeWidget.topLevelItemCount():
@ -550,8 +561,8 @@ class MyForm(settingsmixin.SMainWindow):
toAddress = widget.address toAddress = widget.address
else: else:
toAddress = None toAddress = None
if not toAddress in db: if toAddress not in db:
treeWidget.takeTopLevelItem(i) treeWidget.takeTopLevelItem(i)
# no increment # no increment
continue continue
@ -560,8 +571,9 @@ class MyForm(settingsmixin.SMainWindow):
while j < widget.childCount(): while j < widget.childCount():
subwidget = widget.child(j) subwidget = widget.child(j)
try: try:
subwidget.setUnreadCount(db[toAddress][subwidget.folderName]) subwidget.setUnreadCount(
if subwidget.folderName not in ["new", "trash", "sent"]: db[toAddress][subwidget.folderName])
if subwidget.folderName not in ("new", "trash", "sent"):
unread += db[toAddress][subwidget.folderName] unread += db[toAddress][subwidget.folderName]
db[toAddress].pop(subwidget.folderName, None) db[toAddress].pop(subwidget.folderName, None)
except: except:
@ -577,13 +589,13 @@ class MyForm(settingsmixin.SMainWindow):
if toAddress is not None and tab == 'messages' and folder == "new": if toAddress is not None and tab == 'messages' and folder == "new":
continue continue
subwidget = Ui_FolderWidget(widget, j, toAddress, f, c) subwidget = Ui_FolderWidget(widget, j, toAddress, f, c)
if subwidget.folderName not in ["new", "trash", "sent"]: if subwidget.folderName not in ("new", "trash", "sent"):
unread += c unread += c
j += 1 j += 1
widget.setUnreadCount(unread) widget.setUnreadCount(unread)
db.pop(toAddress, None) db.pop(toAddress, None)
i += 1 i += 1
i = 0 i = 0
for toAddress in db: for toAddress in db:
widget = Ui_AddressWidget(treeWidget, i, toAddress, db[toAddress]["inbox"], enabled[toAddress]) widget = Ui_AddressWidget(treeWidget, i, toAddress, db[toAddress]["inbox"], enabled[toAddress])
@ -593,12 +605,12 @@ class MyForm(settingsmixin.SMainWindow):
if toAddress is not None and tab == 'messages' and folder == "new": if toAddress is not None and tab == 'messages' and folder == "new":
continue continue
subwidget = Ui_FolderWidget(widget, j, toAddress, folder, db[toAddress][folder]) subwidget = Ui_FolderWidget(widget, j, toAddress, folder, db[toAddress][folder])
if subwidget.folderName not in ["new", "trash", "sent"]: if subwidget.folderName not in ("new", "trash", "sent"):
unread += db[toAddress][folder] unread += db[toAddress][folder]
j += 1 j += 1
widget.setUnreadCount(unread) widget.setUnreadCount(unread)
i += 1 i += 1
treeWidget.setSortingEnabled(True) treeWidget.setSortingEnabled(True)
def __init__(self, parent=None): def __init__(self, parent=None):
@ -628,8 +640,6 @@ class MyForm(settingsmixin.SMainWindow):
BMConfigParser().remove_section(addressInKeysFile) BMConfigParser().remove_section(addressInKeysFile)
BMConfigParser().save() BMConfigParser().save()
self.updateStartOnLogon()
self.change_translation() self.change_translation()
# e.g. for editing labels # e.g. for editing labels
@ -730,9 +740,6 @@ class MyForm(settingsmixin.SMainWindow):
QtCore.QObject.connect(self.pushButtonStatusIcon, QtCore.SIGNAL( QtCore.QObject.connect(self.pushButtonStatusIcon, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonStatusIcon) "clicked()"), self.click_pushButtonStatusIcon)
self.numberOfMessagesProcessed = 0
self.numberOfBroadcastsProcessed = 0
self.numberOfPubkeysProcessed = 0
self.unreadCount = 0 self.unreadCount = 0
# Set the icon sizes for the identicons # Set the icon sizes for the identicons
@ -799,7 +806,7 @@ class MyForm(settingsmixin.SMainWindow):
self.rerenderComboBoxSendFrom() self.rerenderComboBoxSendFrom()
self.rerenderComboBoxSendFromBroadcast() self.rerenderComboBoxSendFromBroadcast()
# Put the TTL slider in the correct spot # Put the TTL slider in the correct spot
TTL = BMConfigParser().getint('bitmessagesettings', 'ttl') TTL = BMConfigParser().getint('bitmessagesettings', 'ttl')
if TTL < 3600: # an hour if TTL < 3600: # an hour
@ -814,6 +821,15 @@ class MyForm(settingsmixin.SMainWindow):
self.initSettings() self.initSettings()
self.resetNamecoinConnection() self.resetNamecoinConnection()
self.sqlInit()
self.indicatorInit()
self.notifierInit()
self.updateStartOnLogon()
self.ui.updateNetworkSwitchMenuLabel()
self._firstrun = BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'dontconnect')
self._contact_selected = None self._contact_selected = None
@ -827,26 +843,28 @@ class MyForm(settingsmixin.SMainWindow):
self._contact_selected = None self._contact_selected = None
def updateStartOnLogon(self): def updateStartOnLogon(self):
# Configure Bitmessage to start on startup (or remove the """
# configuration) based on the setting in the keys.dat file Configure Bitmessage to start on startup (or remove the
if 'win32' in sys.platform or 'win64' in sys.platform: configuration) based on the setting in the keys.dat file
# Auto-startup for Windows """
startonlogon = BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'startonlogon')
if sys.platform.startswith('win'): # Auto-startup for Windows
RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
self.settings = QtCore.QSettings( settings = QtCore.QSettings(
RUN_PATH, QtCore.QSettings.NativeFormat) RUN_PATH, QtCore.QSettings.NativeFormat)
# In case the user moves the program and the registry entry is # In case the user moves the program and the registry entry is
# no longer valid, this will delete the old registry entry. # no longer valid, this will delete the old registry entry.
self.settings.remove("PyBitmessage") if startonlogon:
if BMConfigParser().getboolean( settings.setValue("PyBitmessage", sys.argv[0])
'bitmessagesettings', 'startonlogon' else:
): settings.remove("PyBitmessage")
self.settings.setValue("PyBitmessage", sys.argv[0]) else:
elif 'darwin' in sys.platform: try: # get desktop plugin if any
# startup for mac self.desktop = get_plugin('desktop')()
pass self.desktop.adjust_startonlogon(startonlogon)
elif 'linux' in sys.platform: except (NameError, TypeError):
# startup for linux self.desktop = False
pass
def updateTTL(self, sliderPosition): def updateTTL(self, sliderPosition):
TTL = int(sliderPosition ** 3.199 + 3600) TTL = int(sliderPosition ** 3.199 + 3600)
@ -963,40 +981,30 @@ class MyForm(settingsmixin.SMainWindow):
Switch unread for item of msgid and related items in Switch unread for item of msgid and related items in
other STableWidgets "All Accounts" and "Chans" other STableWidgets "All Accounts" and "Chans"
""" """
related = [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxChans] status = widget.item(row, 0).unread
if status != unread:
return
widgets = [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxChans]
rrow = None
try: try:
related.remove(widget) widgets.remove(widget)
related = related.pop() related = widgets.pop()
except ValueError: except ValueError:
rrow = None pass
related = []
else: else:
# maybe use instead: # maybe use instead:
# rrow = related.row(msgid), msgid should be QTableWidgetItem # rrow = related.row(msgid), msgid should be QTableWidgetItem
# related = related.findItems(msgid, QtCore.Qt.MatchExactly), # related = related.findItems(msgid, QtCore.Qt.MatchExactly),
# returns an empty list # returns an empty list
for rrow in xrange(related.rowCount()): for rrow in range(related.rowCount()):
if msgid == str(related.item(rrow, 3).data( if related.item(rrow, 3).data() == msgid:
QtCore.Qt.UserRole).toPyObject()):
break break
else:
rrow = None
status = widget.item(row, 0).unread for col in range(widget.columnCount()):
if status == unread: widget.item(row, col).setUnread(not status)
font = QtGui.QFont() if rrow:
font.setBold(not status) related.item(rrow, col).setUnread(not status)
widget.item(row, 3).setFont(font)
for col in (0, 1, 2):
widget.item(row, col).setUnread(not status)
try:
related.item(rrow, 3).setFont(font)
except (TypeError, AttributeError):
pass
else:
for col in (0, 1, 2):
related.item(rrow, col).setUnread(not status)
# Here we need to update unread count for: # Here we need to update unread count for:
# - all widgets if there is no args # - all widgets if there is no args
@ -1081,43 +1089,46 @@ class MyForm(settingsmixin.SMainWindow):
if sortingEnabled: if sortingEnabled:
tableWidget.setSortingEnabled(False) tableWidget.setSortingEnabled(False)
tableWidget.insertRow(0) tableWidget.insertRow(0)
for i in range(len(items)): for i, item in enumerate(items):
tableWidget.setItem(0, i, items[i]) tableWidget.setItem(0, i, item)
if sortingEnabled: if sortingEnabled:
tableWidget.setSortingEnabled(True) tableWidget.setSortingEnabled(True)
def addMessageListItemSent(self, tableWidget, toAddress, fromAddress, subject, status, ackdata, lastactiontime): def addMessageListItemSent(
acct = accountClass(fromAddress) self, tableWidget, toAddress, fromAddress, subject,
if acct is None: status, ackdata, lastactiontime
acct = BMAccount(fromAddress) ):
acct = accountClass(fromAddress) or BMAccount(fromAddress)
acct.parseMessage(toAddress, fromAddress, subject, "") acct.parseMessage(toAddress, fromAddress, subject, "")
items = []
MessageList_AddressWidget(items, str(toAddress), unicode(acct.toLabel, 'utf-8'))
MessageList_AddressWidget(items, str(fromAddress), unicode(acct.fromLabel, 'utf-8'))
MessageList_SubjectWidget(items, str(subject), unicode(acct.subject, 'utf-8', 'replace'))
if status == 'awaitingpubkey': if status == 'awaitingpubkey':
statusText = _translate( statusText = _translate(
"MainWindow", "Waiting for their encryption key. Will request it again soon.") "MainWindow",
"Waiting for their encryption key. Will request it again soon."
)
elif status == 'doingpowforpubkey': elif status == 'doingpowforpubkey':
statusText = _translate( statusText = _translate(
"MainWindow", "Doing work necessary to request encryption key.") "MainWindow", "Doing work necessary to request encryption key."
)
elif status == 'msgqueued': elif status == 'msgqueued':
statusText = _translate( statusText = _translate("MainWindow", "Queued.")
"MainWindow", "Queued.")
elif status == 'msgsent': elif status == 'msgsent':
statusText = _translate("MainWindow", "Message sent. Waiting for acknowledgement. Sent at %1").arg( statusText = _translate(
l10n.formatTimestamp(lastactiontime)) "MainWindow",
"Message sent. Waiting for acknowledgement. Sent at %1"
).arg(l10n.formatTimestamp(lastactiontime))
elif status == 'msgsentnoackexpected': elif status == 'msgsentnoackexpected':
statusText = _translate("MainWindow", "Message sent. Sent at %1").arg( statusText = _translate(
l10n.formatTimestamp(lastactiontime)) "MainWindow", "Message sent. Sent at %1"
).arg(l10n.formatTimestamp(lastactiontime))
elif status == 'doingmsgpow': elif status == 'doingmsgpow':
statusText = _translate( statusText = _translate(
"MainWindow", "Doing work necessary to send message.") "MainWindow", "Doing work necessary to send message.")
elif status == 'ackreceived': elif status == 'ackreceived':
statusText = _translate("MainWindow", "Acknowledgement of the message received %1").arg( statusText = _translate(
l10n.formatTimestamp(lastactiontime)) "MainWindow",
"Acknowledgement of the message received %1"
).arg(l10n.formatTimestamp(lastactiontime))
elif status == 'broadcastqueued': elif status == 'broadcastqueued':
statusText = _translate( statusText = _translate(
"MainWindow", "Broadcast queued.") "MainWindow", "Broadcast queued.")
@ -1128,58 +1139,64 @@ class MyForm(settingsmixin.SMainWindow):
statusText = _translate("MainWindow", "Broadcast on %1").arg( statusText = _translate("MainWindow", "Broadcast on %1").arg(
l10n.formatTimestamp(lastactiontime)) l10n.formatTimestamp(lastactiontime))
elif status == 'toodifficult': elif status == 'toodifficult':
statusText = _translate("MainWindow", "Problem: The work demanded by the recipient is more difficult than you are willing to do. %1").arg( statusText = _translate(
l10n.formatTimestamp(lastactiontime)) "MainWindow",
"Problem: The work demanded by the recipient is more"
" difficult than you are willing to do. %1"
).arg(l10n.formatTimestamp(lastactiontime))
elif status == 'badkey': elif status == 'badkey':
statusText = _translate("MainWindow", "Problem: The recipient\'s encryption key is no good. Could not encrypt message. %1").arg( statusText = _translate(
l10n.formatTimestamp(lastactiontime)) "MainWindow",
"Problem: The recipient\'s encryption key is no good."
" Could not encrypt message. %1"
).arg(l10n.formatTimestamp(lastactiontime))
elif status == 'forcepow': elif status == 'forcepow':
statusText = _translate( statusText = _translate(
"MainWindow", "Forced difficulty override. Send should start soon.") "MainWindow",
"Forced difficulty override. Send should start soon.")
else: else:
statusText = _translate("MainWindow", "Unknown status: %1 %2").arg(status).arg( statusText = _translate(
"MainWindow", "Unknown status: %1 %2").arg(status).arg(
l10n.formatTimestamp(lastactiontime)) l10n.formatTimestamp(lastactiontime))
newItem = myTableWidgetItem(statusText)
newItem.setToolTip(statusText) items = [
newItem.setData(QtCore.Qt.UserRole, QtCore.QByteArray(ackdata)) MessageList_AddressWidget(
newItem.setData(33, int(lastactiontime)) toAddress, unicode(acct.toLabel, 'utf-8')),
newItem.setFlags( MessageList_AddressWidget(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) fromAddress, unicode(acct.fromLabel, 'utf-8')),
items.append(newItem) MessageList_SubjectWidget(
str(subject), unicode(acct.subject, 'utf-8', 'replace')),
MessageList_TimeWidget(
statusText, False, lastactiontime, ackdata)]
self.addMessageListItem(tableWidget, items) self.addMessageListItem(tableWidget, items)
return acct return acct
def addMessageListItemInbox(self, tableWidget, msgfolder, msgid, toAddress, fromAddress, subject, received, read): def addMessageListItemInbox(
font = QtGui.QFont() self, tableWidget, toAddress, fromAddress, subject,
font.setBold(True) msgid, received, read
):
if toAddress == str_broadcast_subscribers: if toAddress == str_broadcast_subscribers:
acct = accountClass(fromAddress) acct = accountClass(fromAddress)
else: else:
acct = accountClass(toAddress) acct = accountClass(toAddress) or accountClass(fromAddress)
if acct is None:
acct = accountClass(fromAddress)
if acct is None: if acct is None:
acct = BMAccount(fromAddress) acct = BMAccount(fromAddress)
acct.parseMessage(toAddress, fromAddress, subject, "") acct.parseMessage(toAddress, fromAddress, subject, "")
items = [] items = [
#to MessageList_AddressWidget(
MessageList_AddressWidget(items, toAddress, unicode(acct.toLabel, 'utf-8'), not read) toAddress, unicode(acct.toLabel, 'utf-8'), not read),
# from MessageList_AddressWidget(
MessageList_AddressWidget(items, fromAddress, unicode(acct.fromLabel, 'utf-8'), not read) fromAddress, unicode(acct.fromLabel, 'utf-8'), not read),
# subject MessageList_SubjectWidget(
MessageList_SubjectWidget(items, str(subject), unicode(acct.subject, 'utf-8', 'replace'), not read) str(subject), unicode(acct.subject, 'utf-8', 'replace'),
# time received not read),
time_item = myTableWidgetItem(l10n.formatTimestamp(received)) MessageList_TimeWidget(
time_item.setToolTip(l10n.formatTimestamp(received)) l10n.formatTimestamp(received), not read, received, msgid)
time_item.setData(QtCore.Qt.UserRole, QtCore.QByteArray(msgid)) ]
time_item.setData(33, int(received))
time_item.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
if not read:
time_item.setFont(font)
items.append(time_item)
self.addMessageListItem(tableWidget, items) self.addMessageListItem(tableWidget, items)
return acct return acct
# Load Sent items from database # Load Sent items from database
@ -1194,35 +1211,40 @@ class MyForm(settingsmixin.SMainWindow):
xAddress = 'both' xAddress = 'both'
else: else:
tableWidget.setColumnHidden(0, False) tableWidget.setColumnHidden(0, False)
if account is None: tableWidget.setColumnHidden(1, bool(account))
tableWidget.setColumnHidden(1, False)
else:
tableWidget.setColumnHidden(1, True)
xAddress = 'fromaddress' xAddress = 'fromaddress'
tableWidget.setUpdatesEnabled(False) queryreturn = helper_search.search_sql(
tableWidget.setSortingEnabled(False) xAddress, account, "sent", where, what, False)
tableWidget.setRowCount(0)
queryreturn = helper_search.search_sql(xAddress, account, "sent", where, what, False)
for row in queryreturn: for row in queryreturn:
toAddress, fromAddress, subject, status, ackdata, lastactiontime = row self.addMessageListItemSent(tableWidget, *row)
self.addMessageListItemSent(tableWidget, toAddress, fromAddress, subject, status, ackdata, lastactiontime)
tableWidget.horizontalHeader().setSortIndicator( tableWidget.horizontalHeader().setSortIndicator(
3, QtCore.Qt.DescendingOrder) 3, QtCore.Qt.DescendingOrder)
tableWidget.setSortingEnabled(True) tableWidget.setSortingEnabled(True)
tableWidget.horizontalHeaderItem(3).setText(_translate("MainWindow", "Sent", None)) tableWidget.horizontalHeaderItem(3).setText(
_translate("MainWindow", "Sent"))
tableWidget.setUpdatesEnabled(True) tableWidget.setUpdatesEnabled(True)
# Load messages from database file # Load messages from database file
def loadMessagelist(self, tableWidget, account, folder="inbox", where="", what="", unreadOnly = False): def loadMessagelist(
self, tableWidget, account, folder="inbox", where="", what="",
unreadOnly=False
):
tableWidget.setUpdatesEnabled(False)
tableWidget.setSortingEnabled(False)
tableWidget.setRowCount(0)
if folder == 'sent': if folder == 'sent':
self.loadSent(tableWidget, account, where, what) self.loadSent(tableWidget, account, where, what)
return return
if tableWidget == self.ui.tableWidgetInboxSubscriptions: if tableWidget == self.ui.tableWidgetInboxSubscriptions:
xAddress = "fromaddress" xAddress = "fromaddress"
if not what:
where = _translate("MainWindow", "To")
what = str_broadcast_subscribers
else: else:
xAddress = "toaddress" xAddress = "toaddress"
if account is not None: if account is not None:
@ -1232,21 +1254,21 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget.setColumnHidden(0, False) tableWidget.setColumnHidden(0, False)
tableWidget.setColumnHidden(1, False) tableWidget.setColumnHidden(1, False)
tableWidget.setUpdatesEnabled(False) queryreturn = helper_search.search_sql(
tableWidget.setSortingEnabled(False) xAddress, account, folder, where, what, unreadOnly)
tableWidget.setRowCount(0)
queryreturn = helper_search.search_sql(xAddress, account, folder, where, what, unreadOnly)
for row in queryreturn: for row in queryreturn:
msgfolder, msgid, toAddress, fromAddress, subject, received, read = row toAddress, fromAddress, subject, _, msgid, received, read = row
self.addMessageListItemInbox(tableWidget, msgfolder, msgid, toAddress, fromAddress, subject, received, read) self.addMessageListItemInbox(
tableWidget, toAddress, fromAddress, subject,
msgid, received, read)
tableWidget.horizontalHeader().setSortIndicator( tableWidget.horizontalHeader().setSortIndicator(
3, QtCore.Qt.DescendingOrder) 3, QtCore.Qt.DescendingOrder)
tableWidget.setSortingEnabled(True) tableWidget.setSortingEnabled(True)
tableWidget.selectRow(0) tableWidget.selectRow(0)
tableWidget.horizontalHeaderItem(3).setText(_translate("MainWindow", "Received", None)) tableWidget.horizontalHeaderItem(3).setText(
_translate("MainWindow", "Received"))
tableWidget.setUpdatesEnabled(True) tableWidget.setUpdatesEnabled(True)
# create application indicator # create application indicator
@ -1402,9 +1424,11 @@ class MyForm(settingsmixin.SMainWindow):
def sqlInit(self): def sqlInit(self):
register_adapter(QtCore.QByteArray, str) register_adapter(QtCore.QByteArray, str)
# Try init the distro specific appindicator,
# for example the Ubuntu MessagingMenu
def indicatorInit(self): def indicatorInit(self):
"""
Try init the distro specific appindicator,
for example the Ubuntu MessagingMenu
"""
def _noop_update(*args, **kwargs): def _noop_update(*args, **kwargs):
pass pass
@ -1473,9 +1497,9 @@ class MyForm(settingsmixin.SMainWindow):
def handleKeyPress(self, event, focus=None): def handleKeyPress(self, event, focus=None):
"""This method handles keypress events for all widgets on MyForm""" """This method handles keypress events for all widgets on MyForm"""
messagelist = self.getCurrentMessagelist() messagelist = self.getCurrentMessagelist()
folder = self.getCurrentFolder()
if event.key() == QtCore.Qt.Key_Delete: if event.key() == QtCore.Qt.Key_Delete:
if isinstance(focus, MessageView) or isinstance(focus, QtGui.QTableWidget): if isinstance(focus, (MessageView, QtGui.QTableWidget)):
folder = self.getCurrentFolder()
if folder == "sent": if folder == "sent":
self.on_action_SentTrash() self.on_action_SentTrash()
else: else:
@ -1511,17 +1535,18 @@ class MyForm(settingsmixin.SMainWindow):
self.ui.lineEditTo.setFocus() self.ui.lineEditTo.setFocus()
event.ignore() event.ignore()
elif event.key() == QtCore.Qt.Key_F: elif event.key() == QtCore.Qt.Key_F:
searchline = self.getCurrentSearchLine(retObj=True) try:
if searchline: self.getCurrentSearchLine(retObj=True).setFocus()
searchline.setFocus() except AttributeError:
pass
event.ignore() event.ignore()
if not event.isAccepted(): if not event.isAccepted():
return return
if isinstance(focus, MessageView): if isinstance(focus, MessageView):
return MessageView.keyPressEvent(focus, event) return MessageView.keyPressEvent(focus, event)
elif isinstance(focus, QtGui.QTableWidget): if isinstance(focus, QtGui.QTableWidget):
return QtGui.QTableWidget.keyPressEvent(focus, event) return QtGui.QTableWidget.keyPressEvent(focus, event)
elif isinstance(focus, QtGui.QTreeWidget): if isinstance(focus, QtGui.QTreeWidget):
return QtGui.QTreeWidget.keyPressEvent(focus, event) return QtGui.QTreeWidget.keyPressEvent(focus, event)
# menu button 'manage keys' # menu button 'manage keys'
@ -1546,7 +1571,7 @@ class MyForm(settingsmixin.SMainWindow):
reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open keys.dat?"), _translate( reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open keys.dat?"), _translate(
"MainWindow", "You may manage your keys by editing the keys.dat file stored in\n %1 \nIt is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.)").arg(state.appdata), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) "MainWindow", "You may manage your keys by editing the keys.dat file stored in\n %1 \nIt is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.)").arg(state.appdata), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes: if reply == QtGui.QMessageBox.Yes:
shared.openKeysFile() openKeysFile()
# menu button 'delete all treshed messages' # menu button 'delete all treshed messages'
def click_actionDeleteAllTrashedMessages(self): def click_actionDeleteAllTrashedMessages(self):
@ -1619,6 +1644,7 @@ class MyForm(settingsmixin.SMainWindow):
dialog = dialogs.ConnectDialog(self) dialog = dialogs.ConnectDialog(self)
if dialog.exec_(): if dialog.exec_():
if dialog.radioButtonConnectNow.isChecked(): if dialog.radioButtonConnectNow.isChecked():
self.ui.updateNetworkSwitchMenuLabel(False)
BMConfigParser().remove_option( BMConfigParser().remove_option(
'bitmessagesettings', 'dontconnect') 'bitmessagesettings', 'dontconnect')
BMConfigParser().save() BMConfigParser().save()
@ -1668,7 +1694,7 @@ class MyForm(settingsmixin.SMainWindow):
if color == 'red': if color == 'red':
self.pushButtonStatusIcon.setIcon( self.pushButtonStatusIcon.setIcon(
QtGui.QIcon(":/newPrefix/images/redicon.png")) QtGui.QIcon(":/newPrefix/images/redicon.png"))
shared.statusIconColor = 'red' state.statusIconColor = 'red'
# if the connection is lost then show a notification # if the connection is lost then show a notification
if self.connected and _notifications_enabled: if self.connected and _notifications_enabled:
self.notifierShow( self.notifierShow(
@ -1694,7 +1720,7 @@ class MyForm(settingsmixin.SMainWindow):
self.statusbar.clearMessage() self.statusbar.clearMessage()
self.pushButtonStatusIcon.setIcon( self.pushButtonStatusIcon.setIcon(
QtGui.QIcon(":/newPrefix/images/yellowicon.png")) QtGui.QIcon(":/newPrefix/images/yellowicon.png"))
shared.statusIconColor = 'yellow' state.statusIconColor = 'yellow'
# if a new connection has been established then show a notification # if a new connection has been established then show a notification
if not self.connected and _notifications_enabled: if not self.connected and _notifications_enabled:
self.notifierShow( self.notifierShow(
@ -1712,7 +1738,7 @@ class MyForm(settingsmixin.SMainWindow):
self.statusbar.clearMessage() self.statusbar.clearMessage()
self.pushButtonStatusIcon.setIcon( self.pushButtonStatusIcon.setIcon(
QtGui.QIcon(":/newPrefix/images/greenicon.png")) QtGui.QIcon(":/newPrefix/images/greenicon.png"))
shared.statusIconColor = 'green' state.statusIconColor = 'green'
if not self.connected and _notifications_enabled: if not self.connected and _notifications_enabled:
self.notifierShow( self.notifierShow(
'Bitmessage', 'Bitmessage',
@ -1735,7 +1761,7 @@ class MyForm(settingsmixin.SMainWindow):
self.drawTrayIcon(iconFileName, self.findInboxUnreadCount()) self.drawTrayIcon(iconFileName, self.findInboxUnreadCount())
def calcTrayIcon(self, iconFileName, inboxUnreadCount): def calcTrayIcon(self, iconFileName, inboxUnreadCount):
pixmap = QtGui.QPixmap(":/newPrefix/images/"+iconFileName) pixmap = QtGui.QPixmap(":/newPrefix/images/" + iconFileName)
if inboxUnreadCount > 0: if inboxUnreadCount > 0:
# choose font and calculate font parameters # choose font and calculate font parameters
fontName = "Lucida" fontName = "Lucida"
@ -1747,7 +1773,8 @@ class MyForm(settingsmixin.SMainWindow):
rect = fontMetrics.boundingRect(txt) rect = fontMetrics.boundingRect(txt)
# margins that we add in the top-right corner # margins that we add in the top-right corner
marginX = 2 marginX = 2
marginY = 0 # it looks like -2 is also ok due to the error of metric # it looks like -2 is also ok due to the error of metric
marginY = 0
# if it renders too wide we need to change it to a plus symbol # if it renders too wide we need to change it to a plus symbol
if rect.width() > 20: if rect.width() > 20:
txt = "+" txt = "+"
@ -1787,11 +1814,18 @@ class MyForm(settingsmixin.SMainWindow):
return self.unreadCount return self.unreadCount
def updateSentItemStatusByToAddress(self, toAddress, textToDisplay): def updateSentItemStatusByToAddress(self, toAddress, textToDisplay):
for sent in [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxSubscriptions, self.ui.tableWidgetInboxChans]: for sent in (
self.ui.tableWidgetInbox,
self.ui.tableWidgetInboxSubscriptions,
self.ui.tableWidgetInboxChans
):
treeWidget = self.widgetConvert(sent) treeWidget = self.widgetConvert(sent)
if self.getCurrentFolder(treeWidget) != "sent": if self.getCurrentFolder(treeWidget) != "sent":
continue continue
if treeWidget in [self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans] and self.getCurrentAccount(treeWidget) != toAddress: if treeWidget in (
self.ui.treeWidgetSubscriptions,
self.ui.treeWidgetChans
) and self.getCurrentAccount(treeWidget) != toAddress:
continue continue
for i in range(sent.rowCount()): for i in range(sent.rowCount()):
@ -1811,15 +1845,17 @@ class MyForm(settingsmixin.SMainWindow):
def updateSentItemStatusByAckdata(self, ackdata, textToDisplay): def updateSentItemStatusByAckdata(self, ackdata, textToDisplay):
if type(ackdata) is str: if type(ackdata) is str:
ackdata = QtCore.QByteArray(ackdata) ackdata = QtCore.QByteArray(ackdata)
for sent in [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxSubscriptions, self.ui.tableWidgetInboxChans]: for sent in (
self.ui.tableWidgetInbox,
self.ui.tableWidgetInboxSubscriptions,
self.ui.tableWidgetInboxChans
):
treeWidget = self.widgetConvert(sent) treeWidget = self.widgetConvert(sent)
if self.getCurrentFolder(treeWidget) != "sent": if self.getCurrentFolder(treeWidget) != "sent":
continue continue
for i in range(sent.rowCount()): for i in range(sent.rowCount()):
toAddress = sent.item( toAddress = sent.item(i, 0).data(QtCore.Qt.UserRole)
i, 0).data(QtCore.Qt.UserRole) tableAckdata = sent.item(i, 3).data()
tableAckdata = sent.item(
i, 3).data(QtCore.Qt.UserRole).toPyObject()
status, addressVersionNumber, streamNumber, ripe = decodeAddress( status, addressVersionNumber, streamNumber, ripe = decodeAddress(
toAddress) toAddress)
if ackdata == tableAckdata: if ackdata == tableAckdata:
@ -1843,8 +1879,7 @@ class MyForm(settingsmixin.SMainWindow):
): ):
i = None i = None
for i in range(inbox.rowCount()): for i in range(inbox.rowCount()):
if msgid == \ if msgid == inbox.item(i, 3).data():
inbox.item(i, 3).data(QtCore.Qt.UserRole).toPyObject():
break break
else: else:
continue continue
@ -1919,11 +1954,13 @@ class MyForm(settingsmixin.SMainWindow):
newRows[address] = [label, AccountMixin.NORMAL] newRows[address] = [label, AccountMixin.NORMAL]
completerList = [] completerList = []
for address in sorted(oldRows, key = lambda x: oldRows[x][2], reverse = True): for address in sorted(
if address in newRows: oldRows, key=lambda x: oldRows[x][2], reverse=True
completerList.append(unicode(newRows[address][0], encoding="UTF-8") + " <" + address + ">") ):
newRows.pop(address) try:
else: completerList.append(
newRows.pop(address)[0] + " <" + address + ">")
except KeyError:
self.ui.tableWidgetAddressBook.removeRow(oldRows[address][2]) self.ui.tableWidgetAddressBook.removeRow(oldRows[address][2])
for address in newRows: for address in newRows:
addRow(address, newRows[address][0], newRows[address][1]) addRow(address, newRows[address][0], newRows[address][1])
@ -1996,11 +2033,14 @@ class MyForm(settingsmixin.SMainWindow):
acct = accountClass(fromAddress) acct = accountClass(fromAddress)
if sendMessageToPeople: # To send a message to specific people (rather than broadcast) # To send a message to specific people (rather than broadcast)
toAddressesList = [s.strip() if sendMessageToPeople:
for s in toAddresses.replace(',', ';').split(';')] toAddressesList = set([
toAddressesList = list(set( s.strip() for s in toAddresses.replace(',', ';').split(';')
toAddressesList)) # remove duplicate addresses. If the user has one address with a BM- and the same address without the BM-, this will not catch it. They'll send the message to the person twice. ])
# remove duplicate addresses. If the user has one address
# with a BM- and the same address without the BM-, this will
# not catch it. They'll send the message to the person twice.
for toAddress in toAddressesList: for toAddress in toAddressesList:
if toAddress != '': if toAddress != '':
# label plus address # label plus address
@ -2035,8 +2075,7 @@ class MyForm(settingsmixin.SMainWindow):
).arg(email) ).arg(email)
) )
return return
status, addressVersionNumber, streamNumber, ripe = decodeAddress( status, addressVersionNumber, streamNumber = decodeAddress(toAddress)[:3]
toAddress)
if status != 'success': if status != 'success':
try: try:
toAddress = unicode(toAddress, 'utf-8', 'ignore') toAddress = unicode(toAddress, 'utf-8', 'ignore')
@ -2119,7 +2158,7 @@ class MyForm(settingsmixin.SMainWindow):
"MainWindow", "Concerning the address %1, Bitmessage cannot handle stream numbers of %2. Perhaps upgrade Bitmessage to the latest version.").arg(toAddress).arg(str(streamNumber))) "MainWindow", "Concerning the address %1, Bitmessage cannot handle stream numbers of %2. Perhaps upgrade Bitmessage to the latest version.").arg(toAddress).arg(str(streamNumber)))
continue continue
self.statusbar.clearMessage() self.statusbar.clearMessage()
if shared.statusIconColor == 'red': if state.statusIconColor == 'red':
self.updateStatusBar(_translate( self.updateStatusBar(_translate(
"MainWindow", "MainWindow",
"Warning: You are currently not connected." "Warning: You are currently not connected."
@ -2127,29 +2166,9 @@ class MyForm(settingsmixin.SMainWindow):
" send the message but it won\'t send until" " send the message but it won\'t send until"
" you connect.") " you connect.")
) )
stealthLevel = BMConfigParser().safeGetInt( ackdata = helper_sent.insert(
'bitmessagesettings', 'ackstealthlevel') toAddress=toAddress, fromAddress=fromAddress,
ackdata = genAckPayload(streamNumber, stealthLevel) subject=subject, message=message, encoding=encoding)
t = ()
sqlExecute(
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''',
'',
toAddress,
ripe,
fromAddress,
subject,
message,
ackdata,
int(time.time()), # sentTime (this will never change)
int(time.time()), # lastActionTime
0, # sleepTill time. This will get set when the POW gets done.
'msgqueued',
0, # retryNumber
'sent', # folder
encoding, # encodingtype
BMConfigParser().getint('bitmessagesettings', 'ttl')
)
toLabel = '' toLabel = ''
queryreturn = sqlQuery('''select label from addressbook where address=?''', queryreturn = sqlQuery('''select label from addressbook where address=?''',
toAddress) toAddress)
@ -2183,31 +2202,16 @@ class MyForm(settingsmixin.SMainWindow):
# We don't actually need the ackdata for acknowledgement since # We don't actually need the ackdata for acknowledgement since
# this is a broadcast message, but we can use it to update the # this is a broadcast message, but we can use it to update the
# user interface when the POW is done generating. # user interface when the POW is done generating.
streamNumber = decodeAddress(fromAddress)[2]
ackdata = genAckPayload(streamNumber, 0)
toAddress = str_broadcast_subscribers toAddress = str_broadcast_subscribers
ripe = ''
t = ('', # msgid. We don't know what this will be until the POW is done. # msgid. We don't know what this will be until the POW is done.
toAddress, ackdata = helper_sent.insert(
ripe, fromAddress=fromAddress,
fromAddress, subject=subject, message=message,
subject, status='broadcastqueued', encoding=encoding)
message,
ackdata,
int(time.time()), # sentTime (this will never change)
int(time.time()), # lastActionTime
0, # sleepTill time. This will get set when the POW gets done.
'broadcastqueued',
0, # retryNumber
'sent', # folder
encoding, # encoding type
BMConfigParser().getint('bitmessagesettings', 'ttl')
)
sqlExecute(
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
toLabel = str_broadcast_subscribers toLabel = str_broadcast_subscribers
self.displayNewSentMessage( self.displayNewSentMessage(
toAddress, toLabel, fromAddress, subject, message, ackdata) toAddress, toLabel, fromAddress, subject, message, ackdata)
@ -2308,54 +2312,88 @@ class MyForm(settingsmixin.SMainWindow):
# receives a message to an address that is acting as a # receives a message to an address that is acting as a
# pseudo-mailing-list. The message will be broadcast out. This function # pseudo-mailing-list. The message will be broadcast out. This function
# puts the message on the 'Sent' tab. # puts the message on the 'Sent' tab.
def displayNewSentMessage(self, toAddress, toLabel, fromAddress, subject, message, ackdata): def displayNewSentMessage(
self, toAddress, toLabel, fromAddress, subject,
message, ackdata):
acct = accountClass(fromAddress) acct = accountClass(fromAddress)
acct.parseMessage(toAddress, fromAddress, subject, message) acct.parseMessage(toAddress, fromAddress, subject, message)
tab = -1 tab = -1
for sent in [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxSubscriptions, self.ui.tableWidgetInboxChans]: for sent in (
self.ui.tableWidgetInbox,
self.ui.tableWidgetInboxSubscriptions,
self.ui.tableWidgetInboxChans
):
tab += 1 tab += 1
if tab == 1: if tab == 1:
tab = 2 tab = 2
treeWidget = self.widgetConvert(sent) treeWidget = self.widgetConvert(sent)
if self.getCurrentFolder(treeWidget) != "sent": if self.getCurrentFolder(treeWidget) != "sent":
continue continue
if treeWidget == self.ui.treeWidgetYourIdentities and self.getCurrentAccount(treeWidget) not in (fromAddress, None, False): if treeWidget == self.ui.treeWidgetYourIdentities \
and self.getCurrentAccount(treeWidget) not in (
fromAddress, None, False):
continue continue
elif treeWidget in [self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans] and self.getCurrentAccount(treeWidget) != toAddress: elif treeWidget in (
self.ui.treeWidgetSubscriptions,
self.ui.treeWidgetChans
) and self.getCurrentAccount(treeWidget) != toAddress:
continue continue
elif not helper_search.check_match(toAddress, fromAddress, subject, message, self.getCurrentSearchOption(tab), self.getCurrentSearchLine(tab)): elif not helper_search.check_match(
toAddress, fromAddress, subject, message,
self.getCurrentSearchOption(tab),
self.getCurrentSearchLine(tab)
):
continue continue
self.addMessageListItemSent(sent, toAddress, fromAddress, subject, "msgqueued", ackdata, time.time()) self.addMessageListItemSent(
self.getAccountTextedit(acct).setPlainText(unicode(message, 'utf-8', 'replace')) sent, toAddress, fromAddress, subject,
"msgqueued", ackdata, time.time())
self.getAccountTextedit(acct).setPlainText(message)
sent.setCurrentCell(0, 0) sent.setCurrentCell(0, 0)
def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject, message): def displayNewInboxMessage(
if toAddress == str_broadcast_subscribers: self, inventoryHash, toAddress, fromAddress, subject, message):
acct = accountClass(fromAddress) acct = accountClass(
else: fromAddress if toAddress == str_broadcast_subscribers
acct = accountClass(toAddress) else toAddress
)
inbox = self.getAccountMessagelist(acct) inbox = self.getAccountMessagelist(acct)
ret = None ret = treeWidget = None
tab = -1 tab = -1
for treeWidget in [self.ui.treeWidgetYourIdentities, self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans]: for treeWidget in (
self.ui.treeWidgetYourIdentities,
self.ui.treeWidgetSubscriptions,
self.ui.treeWidgetChans
):
tab += 1 tab += 1
if tab == 1: if tab == 1:
tab = 2 tab = 2
tableWidget = self.widgetConvert(treeWidget) if not helper_search.check_match(
if not helper_search.check_match(toAddress, fromAddress, subject, message, self.getCurrentSearchOption(tab), self.getCurrentSearchLine(tab)): toAddress, fromAddress, subject, message,
self.getCurrentSearchOption(tab),
self.getCurrentSearchLine(tab)
):
continue continue
if tableWidget == inbox and self.getCurrentAccount(treeWidget) == acct.address and self.getCurrentFolder(treeWidget) in ["inbox", None]: tableWidget = self.widgetConvert(treeWidget)
ret = self.addMessageListItemInbox(inbox, "inbox", inventoryHash, toAddress, fromAddress, subject, time.time(), 0) current_account = self.getCurrentAccount(treeWidget)
elif treeWidget == self.ui.treeWidgetYourIdentities and self.getCurrentAccount(treeWidget) is None and self.getCurrentFolder(treeWidget) in ["inbox", "new", None]: current_folder = self.getCurrentFolder(treeWidget)
ret = self.addMessageListItemInbox(tableWidget, "inbox", inventoryHash, toAddress, fromAddress, subject, time.time(), 0) # pylint: disable=too-many-boolean-expressions
if ((tableWidget == inbox
and current_account == acct.address
and current_folder in ("inbox", None))
or (treeWidget == self.ui.treeWidgetYourIdentities
and current_account is None
and current_folder in ("inbox", "new", None))):
ret = self.addMessageListItemInbox(
tableWidget, toAddress, fromAddress, subject,
inventoryHash, time.time(), False)
if ret is None: if ret is None:
acct.parseMessage(toAddress, fromAddress, subject, "") acct.parseMessage(toAddress, fromAddress, subject, "")
else: else:
acct = ret acct = ret
# pylint:disable=undefined-loop-variable
self.propagateUnreadCount(widget=treeWidget if ret else None) self.propagateUnreadCount(widget=treeWidget if ret else None)
if BMConfigParser().getboolean( if BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'showtraynotifications'): 'bitmessagesettings', 'showtraynotifications'):
self.notifierShow( self.notifierShow(
_translate("MainWindow", "New Message"), _translate("MainWindow", "New Message"),
@ -2363,16 +2401,22 @@ class MyForm(settingsmixin.SMainWindow):
unicode(acct.fromLabel, 'utf-8')), unicode(acct.fromLabel, 'utf-8')),
sound.SOUND_UNKNOWN sound.SOUND_UNKNOWN
) )
if self.getCurrentAccount() is not None and ((self.getCurrentFolder(treeWidget) != "inbox" and self.getCurrentFolder(treeWidget) is not None) or self.getCurrentAccount(treeWidget) != acct.address): if self.getCurrentAccount() is not None and (
# Ubuntu should notify of new message irespective of (self.getCurrentFolder(treeWidget) != "inbox"
and self.getCurrentFolder(treeWidget) is not None)
or self.getCurrentAccount(treeWidget) != acct.address):
# Ubuntu should notify of new message irrespective of
# whether it's in current message list or not # whether it's in current message list or not
self.indicatorUpdate(True, to_label=acct.toLabel) self.indicatorUpdate(True, to_label=acct.toLabel)
# cannot find item to pass here ):
if hasattr(acct, "feedback") \ try:
and acct.feedback != GatewayAccount.ALL_OK: if acct.feedback != GatewayAccount.ALL_OK:
if acct.feedback == GatewayAccount.REGISTRATION_DENIED: if acct.feedback == GatewayAccount.REGISTRATION_DENIED:
dialogs.EmailGatewayDialog( dialogs.EmailGatewayDialog(
self, BMConfigParser(), acct).exec_() self, BMConfigParser(), acct).exec_()
# possible other branches?
except AttributeError:
pass
def click_pushButtonAddAddressBook(self, dialog=None): def click_pushButtonAddAddressBook(self, dialog=None):
if not dialog: if not dialog:
@ -2395,15 +2439,15 @@ class MyForm(settingsmixin.SMainWindow):
)) ))
return return
self.addEntryToAddressBook(address, label) if helper_addressbook.insert(label=label, address=address):
self.rerenderMessagelistFromLabels()
def addEntryToAddressBook(self, address, label): self.rerenderMessagelistToLabels()
if shared.isAddressInMyAddressBook(address): self.rerenderAddressBook()
return else:
sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', label, address) self.updateStatusBar(_translate(
self.rerenderMessagelistFromLabels() "MainWindow",
self.rerenderMessagelistToLabels() "Error: You cannot add your own address in the address book."
self.rerenderAddressBook() ))
def addSubscription(self, address, label): def addSubscription(self, address, label):
# This should be handled outside of this function, for error displaying # This should be handled outside of this function, for error displaying
@ -2525,17 +2569,11 @@ class MyForm(settingsmixin.SMainWindow):
if idCount == 0: if idCount == 0:
return return
font = QtGui.QFont()
font.setBold(False)
msgids = [] msgids = []
for i in range(0, idCount): for i in range(0, idCount):
msgids.append(str(tableWidget.item( msgids.append(tableWidget.item(i, 3).data())
i, 3).data(QtCore.Qt.UserRole).toPyObject())) for col in xrange(tableWidget.columnCount()):
tableWidget.item(i, 0).setUnread(False) tableWidget.item(i, col).setUnread(False)
tableWidget.item(i, 1).setUnread(False)
tableWidget.item(i, 2).setUnread(False)
tableWidget.item(i, 3).setFont(font)
markread = sqlExecuteChunked( markread = sqlExecuteChunked(
"UPDATE inbox SET read = 1 WHERE msgid IN({0}) AND read=0", "UPDATE inbox SET read = 1 WHERE msgid IN({0}) AND read=0",
@ -2603,10 +2641,8 @@ class MyForm(settingsmixin.SMainWindow):
) + "\n\n" + ) + "\n\n" +
_translate( _translate(
"MainWindow", "Wait until these tasks finish?"), "MainWindow", "Wait until these tasks finish?"),
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
QtGui.QMessageBox.Cancel, | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Cancel)
QtGui.QMessageBox.Cancel
)
if reply == QtGui.QMessageBox.No: if reply == QtGui.QMessageBox.No:
waitForPow = False waitForPow = False
elif reply == QtGui.QMessageBox.Cancel: elif reply == QtGui.QMessageBox.Cancel:
@ -2623,16 +2659,14 @@ class MyForm(settingsmixin.SMainWindow):
" synchronisation finishes?", None, " synchronisation finishes?", None,
QtCore.QCoreApplication.CodecForTr, pendingDownload() QtCore.QCoreApplication.CodecForTr, pendingDownload()
), ),
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
QtGui.QMessageBox.Cancel, | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Cancel)
QtGui.QMessageBox.Cancel
)
if reply == QtGui.QMessageBox.Yes: if reply == QtGui.QMessageBox.Yes:
self.wait = waitForSync = True self.wait = waitForSync = True
elif reply == QtGui.QMessageBox.Cancel: elif reply == QtGui.QMessageBox.Cancel:
return return
if shared.statusIconColor == 'red' and not BMConfigParser().safeGetBoolean( if state.statusIconColor == 'red' and not BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'dontconnect'): 'bitmessagesettings', 'dontconnect'):
reply = QtGui.QMessageBox.question( reply = QtGui.QMessageBox.question(
self, _translate("MainWindow", "Not connected"), self, _translate("MainWindow", "Not connected"),
@ -2642,10 +2676,8 @@ class MyForm(settingsmixin.SMainWindow):
" quit now, it may cause delivery delays. Wait until" " quit now, it may cause delivery delays. Wait until"
" connected and the synchronisation finishes?" " connected and the synchronisation finishes?"
), ),
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
QtGui.QMessageBox.Cancel, | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Cancel)
QtGui.QMessageBox.Cancel
)
if reply == QtGui.QMessageBox.Yes: if reply == QtGui.QMessageBox.Yes:
waitForConnection = True waitForConnection = True
self.wait = waitForSync = True self.wait = waitForSync = True
@ -2660,7 +2692,7 @@ class MyForm(settingsmixin.SMainWindow):
if waitForConnection: if waitForConnection:
self.updateStatusBar(_translate( self.updateStatusBar(_translate(
"MainWindow", "Waiting for network connection...")) "MainWindow", "Waiting for network connection..."))
while shared.statusIconColor == 'red': while state.statusIconColor == 'red':
time.sleep(0.5) time.sleep(0.5)
QtCore.QCoreApplication.processEvents( QtCore.QCoreApplication.processEvents(
QtCore.QEventLoop.AllEvents, 1000 QtCore.QEventLoop.AllEvents, 1000
@ -2752,6 +2784,7 @@ class MyForm(settingsmixin.SMainWindow):
QtCore.QEventLoop.AllEvents, 1000 QtCore.QEventLoop.AllEvents, 1000
) )
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
self.updateStatusBar(_translate( self.updateStatusBar(_translate(
"MainWindow", "Stopping notifications... %1%").arg(90)) "MainWindow", "Stopping notifications... %1%").arg(90))
self.tray.hide() self.tray.hide()
@ -2760,20 +2793,21 @@ class MyForm(settingsmixin.SMainWindow):
"MainWindow", "Shutdown imminent... %1%").arg(100)) "MainWindow", "Shutdown imminent... %1%").arg(100))
logger.info("Shutdown complete") logger.info("Shutdown complete")
super(MyForm, myapp).close() self.close()
# return # FIXME: rewrite loops with timer instead
sys.exit() if self.wait:
self.destroy()
app.quit()
# window close event
def closeEvent(self, event): def closeEvent(self, event):
self.appIndicatorHide() """window close event"""
event.ignore()
trayonclose = BMConfigParser().safeGetBoolean( trayonclose = BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'trayonclose') 'bitmessagesettings', 'trayonclose')
if trayonclose:
event.ignore() self.appIndicatorHide()
if not trayonclose: else:
# quit the application # custom quit method
self.quit() self.quit()
def on_action_InboxMessageForceHtml(self): def on_action_InboxMessageForceHtml(self):
@ -2812,8 +2846,7 @@ class MyForm(settingsmixin.SMainWindow):
# modified = 0 # modified = 0
for row in tableWidget.selectedIndexes(): for row in tableWidget.selectedIndexes():
currentRow = row.row() currentRow = row.row()
msgid = str(tableWidget.item( msgid = tableWidget.item(currentRow, 3).data()
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
msgids.add(msgid) msgids.add(msgid)
# if not tableWidget.item(currentRow, 0).unread: # if not tableWidget.item(currentRow, 0).unread:
# modified += 1 # modified += 1
@ -2839,13 +2872,13 @@ class MyForm(settingsmixin.SMainWindow):
# Format predefined text on message reply. # Format predefined text on message reply.
def quoted_text(self, message): def quoted_text(self, message):
if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'replybelow'): if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'replybelow'):
return '\n\n------------------------------------------------------\n' + message return '\n\n------------------------------------------------------\n' + message
quoteWrapper = textwrap.TextWrapper(
replace_whitespace=False, initial_indent='> ',
subsequent_indent='> ', break_long_words=False,
break_on_hyphens=False)
quoteWrapper = textwrap.TextWrapper(replace_whitespace = False,
initial_indent = '> ',
subsequent_indent = '> ',
break_long_words = False,
break_on_hyphens = False)
def quote_line(line): def quote_line(line):
# Do quote empty lines. # Do quote empty lines.
if line == '' or line.isspace(): if line == '' or line.isspace():
@ -2858,18 +2891,20 @@ class MyForm(settingsmixin.SMainWindow):
return quoteWrapper.fill(line) return quoteWrapper.fill(line)
return '\n'.join([quote_line(l) for l in message.splitlines()]) + '\n\n' return '\n'.join([quote_line(l) for l in message.splitlines()]) + '\n\n'
def setSendFromComboBox(self, address = None): def setSendFromComboBox(self, address=None):
if address is None: if address is None:
messagelist = self.getCurrentMessagelist() messagelist = self.getCurrentMessagelist()
if messagelist: if not messagelist:
currentInboxRow = messagelist.currentRow() return
address = messagelist.item( currentInboxRow = messagelist.currentRow()
currentInboxRow, 0).address address = messagelist.item(currentInboxRow, 0).address
for box in [self.ui.comboBoxSendFrom, self.ui.comboBoxSendFromBroadcast]: for box in (
listOfAddressesInComboBoxSendFrom = [str(box.itemData(i).toPyObject()) for i in range(box.count())] self.ui.comboBoxSendFrom, self.ui.comboBoxSendFromBroadcast
if address in listOfAddressesInComboBoxSendFrom: ):
currentIndex = listOfAddressesInComboBoxSendFrom.index(address) for i in range(box.count()):
box.setCurrentIndex(currentIndex) if str(box.itemData(i).toPyObject()) == address:
box.setCurrentIndex(i)
break
else: else:
box.setCurrentIndex(0) box.setCurrentIndex(0)
@ -2901,8 +2936,7 @@ class MyForm(settingsmixin.SMainWindow):
acct = accountClass(toAddressAtCurrentInboxRow) acct = accountClass(toAddressAtCurrentInboxRow)
fromAddressAtCurrentInboxRow = tableWidget.item( fromAddressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, column_from).address currentInboxRow, column_from).address
msgid = str(tableWidget.item( msgid = tableWidget.item(currentInboxRow, 3).data()
currentInboxRow, 3).data(QtCore.Qt.UserRole).toPyObject())
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT message FROM inbox WHERE msgid=?", msgid "SELECT message FROM inbox WHERE msgid=?", msgid
) or sqlQuery("SELECT message FROM sent WHERE ackdata=?", msgid) ) or sqlQuery("SELECT message FROM sent WHERE ackdata=?", msgid)
@ -2985,7 +3019,7 @@ class MyForm(settingsmixin.SMainWindow):
quotedText = self.quoted_text( quotedText = self.quoted_text(
unicode(messageAtCurrentInboxRow, 'utf-8', 'replace')) unicode(messageAtCurrentInboxRow, 'utf-8', 'replace'))
widget['message'].setPlainText(quotedText) widget['message'].setPlainText(quotedText)
if acct.subject[0:3] in ['Re:', 'RE:']: if acct.subject[0:3] in ('Re:', 'RE:'):
widget['subject'].setText( widget['subject'].setText(
tableWidget.item(currentInboxRow, 2).label) tableWidget.item(currentInboxRow, 2).label)
else: else:
@ -3001,7 +3035,6 @@ class MyForm(settingsmixin.SMainWindow):
if not tableWidget: if not tableWidget:
return return
currentInboxRow = tableWidget.currentRow() currentInboxRow = tableWidget.currentRow()
# tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject()
addressAtCurrentInboxRow = tableWidget.item( addressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, 1).data(QtCore.Qt.UserRole) currentInboxRow, 1).data(QtCore.Qt.UserRole)
self.ui.tabWidget.setCurrentIndex( self.ui.tabWidget.setCurrentIndex(
@ -3015,7 +3048,6 @@ class MyForm(settingsmixin.SMainWindow):
if not tableWidget: if not tableWidget:
return return
currentInboxRow = tableWidget.currentRow() currentInboxRow = tableWidget.currentRow()
# tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject()
addressAtCurrentInboxRow = tableWidget.item( addressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, 1).data(QtCore.Qt.UserRole) currentInboxRow, 1).data(QtCore.Qt.UserRole)
recipientAddress = tableWidget.item( recipientAddress = tableWidget.item(
@ -3039,23 +3071,28 @@ class MyForm(settingsmixin.SMainWindow):
"Error: You cannot add the same address to your blacklist" "Error: You cannot add the same address to your blacklist"
" twice. Try renaming the existing one if you want.")) " twice. Try renaming the existing one if you want."))
def deleteRowFromMessagelist(self, row = None, inventoryHash = None, ackData = None, messageLists = None): def deleteRowFromMessagelist(
self, row=None, inventoryHash=None, ackData=None, messageLists=None
):
if messageLists is None: if messageLists is None:
messageLists = (self.ui.tableWidgetInbox, self.ui.tableWidgetInboxChans, self.ui.tableWidgetInboxSubscriptions) messageLists = (
self.ui.tableWidgetInbox,
self.ui.tableWidgetInboxChans,
self.ui.tableWidgetInboxSubscriptions
)
elif type(messageLists) not in (list, tuple): elif type(messageLists) not in (list, tuple):
messageLists = (messageLists) messageLists = (messageLists,)
for messageList in messageLists: for messageList in messageLists:
if row is not None: if row is not None:
inventoryHash = str(messageList.item(row, 3).data( inventoryHash = messageList.item(row, 3).data()
QtCore.Qt.UserRole).toPyObject())
messageList.removeRow(row) messageList.removeRow(row)
elif inventoryHash is not None: elif inventoryHash is not None:
for i in range(messageList.rowCount() - 1, -1, -1): for i in range(messageList.rowCount() - 1, -1, -1):
if messageList.item(i, 3).data(QtCore.Qt.UserRole).toPyObject() == inventoryHash: if messageList.item(i, 3).data() == inventoryHash:
messageList.removeRow(i) messageList.removeRow(i)
elif ackData is not None: elif ackData is not None:
for i in range(messageList.rowCount() - 1, -1, -1): for i in range(messageList.rowCount() - 1, -1, -1):
if messageList.item(i, 3).data(QtCore.Qt.UserRole).toPyObject() == ackData: if messageList.item(i, 3).data() == ackData:
messageList.removeRow(i) messageList.removeRow(i)
# Send item on the Inbox tab to trash # Send item on the Inbox tab to trash
@ -3065,24 +3102,25 @@ class MyForm(settingsmixin.SMainWindow):
return return
currentRow = 0 currentRow = 0
folder = self.getCurrentFolder() folder = self.getCurrentFolder()
shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier shifted = QtGui.QApplication.queryKeyboardModifiers() \
tableWidget.setUpdatesEnabled(False); & QtCore.Qt.ShiftModifier
inventoryHashesToTrash = [] tableWidget.setUpdatesEnabled(False)
inventoryHashesToTrash = set()
# ranges in reversed order # ranges in reversed order
for r in sorted(tableWidget.selectedRanges(), key=lambda r: r.topRow())[::-1]: for r in sorted(
for i in range(r.bottomRow()-r.topRow()+1): tableWidget.selectedRanges(), key=lambda r: r.topRow()
inventoryHashToTrash = str(tableWidget.item( )[::-1]:
r.topRow()+i, 3).data(QtCore.Qt.UserRole).toPyObject()) for i in range(r.bottomRow() - r.topRow() + 1):
if inventoryHashToTrash in inventoryHashesToTrash: inventoryHashesToTrash.add(
continue tableWidget.item(r.topRow() + i, 3).data())
inventoryHashesToTrash.append(inventoryHashToTrash)
currentRow = r.topRow() currentRow = r.topRow()
self.getCurrentMessageTextedit().setText("") self.getCurrentMessageTextedit().setText("")
tableWidget.model().removeRows(r.topRow(), r.bottomRow()-r.topRow()+1) tableWidget.model().removeRows(
r.topRow(), r.bottomRow() - r.topRow() + 1)
idCount = len(inventoryHashesToTrash) idCount = len(inventoryHashesToTrash)
sqlExecuteChunked( sqlExecuteChunked(
("DELETE FROM inbox" if folder == "trash" or shifted else ("DELETE FROM inbox" if folder == "trash" or shifted else
"UPDATE inbox SET folder='trash'") + "UPDATE inbox SET folder='trash', read=1") +
" WHERE msgid IN ({0})", idCount, *inventoryHashesToTrash) " WHERE msgid IN ({0})", idCount, *inventoryHashesToTrash)
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1) tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
tableWidget.setUpdatesEnabled(True) tableWidget.setUpdatesEnabled(True)
@ -3095,22 +3133,23 @@ class MyForm(settingsmixin.SMainWindow):
return return
currentRow = 0 currentRow = 0
tableWidget.setUpdatesEnabled(False) tableWidget.setUpdatesEnabled(False)
inventoryHashesToTrash = [] inventoryHashesToTrash = set()
# ranges in reversed order # ranges in reversed order
for r in sorted(tableWidget.selectedRanges(), key=lambda r: r.topRow())[::-1]: for r in sorted(
for i in range(r.bottomRow()-r.topRow()+1): tableWidget.selectedRanges(), key=lambda r: r.topRow()
inventoryHashToTrash = str(tableWidget.item( )[::-1]:
r.topRow()+i, 3).data(QtCore.Qt.UserRole).toPyObject()) for i in range(r.bottomRow() - r.topRow() + 1):
if inventoryHashToTrash in inventoryHashesToTrash: inventoryHashesToTrash.add(
continue tableWidget.item(r.topRow() + i, 3).data())
inventoryHashesToTrash.append(inventoryHashToTrash)
currentRow = r.topRow() currentRow = r.topRow()
self.getCurrentMessageTextedit().setText("") self.getCurrentMessageTextedit().setText("")
tableWidget.model().removeRows(r.topRow(), r.bottomRow()-r.topRow()+1) tableWidget.model().removeRows(
r.topRow(), r.bottomRow() - r.topRow() + 1)
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1) tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
idCount = len(inventoryHashesToTrash) idCount = len(inventoryHashesToTrash)
sqlExecuteChunked('''UPDATE inbox SET folder='inbox' WHERE msgid IN({0})''', sqlExecuteChunked(
idCount, *inventoryHashesToTrash) "UPDATE inbox SET folder='inbox' WHERE msgid IN({0})",
idCount, *inventoryHashesToTrash)
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1) tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
tableWidget.setUpdatesEnabled(True) tableWidget.setUpdatesEnabled(True)
self.propagateUnreadCount() self.propagateUnreadCount()
@ -3128,8 +3167,7 @@ class MyForm(settingsmixin.SMainWindow):
subjectAtCurrentInboxRow = '' subjectAtCurrentInboxRow = ''
# Retrieve the message data out of the SQL database # Retrieve the message data out of the SQL database
msgid = str(tableWidget.item( msgid = tableWidget.item(currentInboxRow, 3).data()
currentInboxRow, 3).data(QtCore.Qt.UserRole).toPyObject())
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''select message from inbox where msgid=?''', msgid) '''select message from inbox where msgid=?''', msgid)
if queryreturn != []: if queryreturn != []:
@ -3157,8 +3195,7 @@ class MyForm(settingsmixin.SMainWindow):
shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier
while tableWidget.selectedIndexes() != []: while tableWidget.selectedIndexes() != []:
currentRow = tableWidget.selectedIndexes()[0].row() currentRow = tableWidget.selectedIndexes()[0].row()
ackdataToTrash = str(tableWidget.item( ackdataToTrash = tableWidget.item(currentRow, 3).data()
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
sqlExecute( sqlExecute(
"DELETE FROM sent" if folder == "trash" or shifted else "DELETE FROM sent" if folder == "trash" or shifted else
"UPDATE sent SET folder='trash'" "UPDATE sent SET folder='trash'"
@ -3381,13 +3418,13 @@ class MyForm(settingsmixin.SMainWindow):
return None return None
def getCurrentTreeWidget(self): def getCurrentTreeWidget(self):
currentIndex = self.ui.tabWidget.currentIndex(); currentIndex = self.ui.tabWidget.currentIndex()
treeWidgetList = [ treeWidgetList = (
self.ui.treeWidgetYourIdentities, self.ui.treeWidgetYourIdentities,
False, False,
self.ui.treeWidgetSubscriptions, self.ui.treeWidgetSubscriptions,
self.ui.treeWidgetChans self.ui.treeWidgetChans
] )
if currentIndex >= 0 and currentIndex < len(treeWidgetList): if currentIndex >= 0 and currentIndex < len(treeWidgetList):
return treeWidgetList[currentIndex] return treeWidgetList[currentIndex]
else: else:
@ -3405,18 +3442,16 @@ class MyForm(settingsmixin.SMainWindow):
return self.ui.treeWidgetYourIdentities return self.ui.treeWidgetYourIdentities
def getCurrentMessagelist(self): def getCurrentMessagelist(self):
currentIndex = self.ui.tabWidget.currentIndex(); currentIndex = self.ui.tabWidget.currentIndex()
messagelistList = [ messagelistList = (
self.ui.tableWidgetInbox, self.ui.tableWidgetInbox,
False, False,
self.ui.tableWidgetInboxSubscriptions, self.ui.tableWidgetInboxSubscriptions,
self.ui.tableWidgetInboxChans, self.ui.tableWidgetInboxChans,
] )
if currentIndex >= 0 and currentIndex < len(messagelistList): if currentIndex >= 0 and currentIndex < len(messagelistList):
return messagelistList[currentIndex] return messagelistList[currentIndex]
else:
return False
def getAccountMessagelist(self, account): def getAccountMessagelist(self, account):
try: try:
if account.type == AccountMixin.CHAN: if account.type == AccountMixin.CHAN:
@ -3433,24 +3468,18 @@ class MyForm(settingsmixin.SMainWindow):
if messagelist: if messagelist:
currentRow = messagelist.currentRow() currentRow = messagelist.currentRow()
if currentRow >= 0: if currentRow >= 0:
msgid = str(messagelist.item( return messagelist.item(currentRow, 3).data()
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
# data is saved at the 4. column of the table...
return msgid
return False
def getCurrentMessageTextedit(self): def getCurrentMessageTextedit(self):
currentIndex = self.ui.tabWidget.currentIndex() currentIndex = self.ui.tabWidget.currentIndex()
messagelistList = [ messagelistList = (
self.ui.textEditInboxMessage, self.ui.textEditInboxMessage,
False, False,
self.ui.textEditInboxMessageSubscriptions, self.ui.textEditInboxMessageSubscriptions,
self.ui.textEditInboxMessageChans, self.ui.textEditInboxMessageChans,
] )
if currentIndex >= 0 and currentIndex < len(messagelistList): if currentIndex >= 0 and currentIndex < len(messagelistList):
return messagelistList[currentIndex] return messagelistList[currentIndex]
else:
return False
def getAccountTextedit(self, account): def getAccountTextedit(self, account):
try: try:
@ -3466,33 +3495,28 @@ class MyForm(settingsmixin.SMainWindow):
def getCurrentSearchLine(self, currentIndex=None, retObj=False): def getCurrentSearchLine(self, currentIndex=None, retObj=False):
if currentIndex is None: if currentIndex is None:
currentIndex = self.ui.tabWidget.currentIndex() currentIndex = self.ui.tabWidget.currentIndex()
messagelistList = [ messagelistList = (
self.ui.inboxSearchLineEdit, self.ui.inboxSearchLineEdit,
False, False,
self.ui.inboxSearchLineEditSubscriptions, self.ui.inboxSearchLineEditSubscriptions,
self.ui.inboxSearchLineEditChans, self.ui.inboxSearchLineEditChans,
] )
if currentIndex >= 0 and currentIndex < len(messagelistList): if currentIndex >= 0 and currentIndex < len(messagelistList):
if retObj: return (
return messagelistList[currentIndex] messagelistList[currentIndex] if retObj
else: else messagelistList[currentIndex].text().toUtf8().data())
return messagelistList[currentIndex].text().toUtf8().data()
else:
return None
def getCurrentSearchOption(self, currentIndex=None): def getCurrentSearchOption(self, currentIndex=None):
if currentIndex is None: if currentIndex is None:
currentIndex = self.ui.tabWidget.currentIndex() currentIndex = self.ui.tabWidget.currentIndex()
messagelistList = [ messagelistList = (
self.ui.inboxSearchOption, self.ui.inboxSearchOption,
False, False,
self.ui.inboxSearchOptionSubscriptions, self.ui.inboxSearchOptionSubscriptions,
self.ui.inboxSearchOptionChans, self.ui.inboxSearchOptionChans,
] )
if currentIndex >= 0 and currentIndex < len(messagelistList): if currentIndex >= 0 and currentIndex < len(messagelistList):
return messagelistList[currentIndex].currentText().toUtf8().data() return messagelistList[currentIndex].currentText()
else:
return None
# Group of functions for the Your Identities dialog box # Group of functions for the Your Identities dialog box
def getCurrentItem(self, treeWidget=None): def getCurrentItem(self, treeWidget=None):
@ -3596,12 +3620,11 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget = self.getCurrentMessagelist() tableWidget = self.getCurrentMessagelist()
currentColumn = tableWidget.currentColumn() currentColumn = tableWidget.currentColumn()
currentRow = tableWidget.currentRow() currentRow = tableWidget.currentRow()
if currentColumn not in [0, 1, 2]: # to, from, subject currentFolder = self.getCurrentFolder()
if self.getCurrentFolder() == "sent": if currentColumn not in (0, 1, 2): # to, from, subject
currentColumn = 0 currentColumn = 0 if currentFolder == "sent" else 1
else:
currentColumn = 1 if currentFolder == "sent":
if self.getCurrentFolder() == "sent":
myAddress = tableWidget.item(currentRow, 1).data(QtCore.Qt.UserRole) myAddress = tableWidget.item(currentRow, 1).data(QtCore.Qt.UserRole)
otherAddress = tableWidget.item(currentRow, 0).data(QtCore.Qt.UserRole) otherAddress = tableWidget.item(currentRow, 0).data(QtCore.Qt.UserRole)
else: else:
@ -3614,18 +3637,18 @@ class MyForm(settingsmixin.SMainWindow):
text = str(tableWidget.item(currentRow, currentColumn).label) text = str(tableWidget.item(currentRow, currentColumn).label)
else: else:
text = tableWidget.item(currentRow, currentColumn).data(QtCore.Qt.UserRole) text = tableWidget.item(currentRow, currentColumn).data(QtCore.Qt.UserRole)
text = unicode(str(text), 'utf-8', 'ignore')
clipboard = QtGui.QApplication.clipboard() clipboard = QtGui.QApplication.clipboard()
clipboard.setText(text) clipboard.setText(text)
#set avatar functions # set avatar functions
def on_action_TreeWidgetSetAvatar(self): def on_action_TreeWidgetSetAvatar(self):
address = self.getCurrentAccount() address = self.getCurrentAccount()
self.setAvatar(address) self.setAvatar(address)
def on_action_AddressBookSetAvatar(self): def on_action_AddressBookSetAvatar(self):
self.on_action_SetAvatar(self.ui.tableWidgetAddressBook) self.on_action_SetAvatar(self.ui.tableWidgetAddressBook)
def on_action_SetAvatar(self, thisTableWidget): def on_action_SetAvatar(self, thisTableWidget):
currentRow = thisTableWidget.currentRow() currentRow = thisTableWidget.currentRow()
addressAtCurrentRow = thisTableWidget.item( addressAtCurrentRow = thisTableWidget.item(
@ -3635,19 +3658,36 @@ class MyForm(settingsmixin.SMainWindow):
thisTableWidget.item( thisTableWidget.item(
currentRow, 0).setIcon(avatarize(addressAtCurrentRow)) currentRow, 0).setIcon(avatarize(addressAtCurrentRow))
# TODO: reuse utils
def setAvatar(self, addressAtCurrentRow): def setAvatar(self, addressAtCurrentRow):
if not os.path.exists(state.appdata + 'avatars/'): if not os.path.exists(state.appdata + 'avatars/'):
os.makedirs(state.appdata + 'avatars/') os.makedirs(state.appdata + 'avatars/')
hash = hashlib.md5(addBMIfNotPresent(addressAtCurrentRow)).hexdigest() hash = hashlib.md5(addBMIfNotPresent(addressAtCurrentRow)).hexdigest()
extensions = ['PNG', 'GIF', 'JPG', 'JPEG', 'SVG', 'BMP', 'MNG', 'PBM', 'PGM', 'PPM', 'TIFF', 'XBM', 'XPM', 'TGA'] extensions = [
# http://pyqt.sourceforge.net/Docs/PyQt4/qimagereader.html#supportedImageFormats 'PNG', 'GIF', 'JPG', 'JPEG', 'SVG', 'BMP', 'MNG', 'PBM',
names = {'BMP':'Windows Bitmap', 'GIF':'Graphic Interchange Format', 'JPG':'Joint Photographic Experts Group', 'JPEG':'Joint Photographic Experts Group', 'MNG':'Multiple-image Network Graphics', 'PNG':'Portable Network Graphics', 'PBM':'Portable Bitmap', 'PGM':'Portable Graymap', 'PPM':'Portable Pixmap', 'TIFF':'Tagged Image File Format', 'XBM':'X11 Bitmap', 'XPM':'X11 Pixmap', 'SVG':'Scalable Vector Graphics', 'TGA':'Targa Image Format'} 'PGM', 'PPM', 'TIFF', 'XBM', 'XPM', 'TGA']
names = {
'BMP': 'Windows Bitmap',
'GIF': 'Graphic Interchange Format',
'JPG': 'Joint Photographic Experts Group',
'JPEG': 'Joint Photographic Experts Group',
'MNG': 'Multiple-image Network Graphics',
'PNG': 'Portable Network Graphics',
'PBM': 'Portable Bitmap',
'PGM': 'Portable Graymap',
'PPM': 'Portable Pixmap',
'TIFF': 'Tagged Image File Format',
'XBM': 'X11 Bitmap',
'XPM': 'X11 Pixmap',
'SVG': 'Scalable Vector Graphics',
'TGA': 'Targa Image Format'}
filters = [] filters = []
all_images_filter = [] all_images_filter = []
current_files = [] current_files = []
for ext in extensions: for ext in extensions:
filters += [ names[ext] + ' (*.' + ext.lower() + ')' ] filters += [names[ext] + ' (*.' + ext.lower() + ')']
all_images_filter += [ '*.' + ext.lower() ] all_images_filter += ['*.' + ext.lower()]
upper = state.appdata + 'avatars/' + hash + '.' + ext.upper() upper = state.appdata + 'avatars/' + hash + '.' + ext.upper()
lower = state.appdata + 'avatars/' + hash + '.' + ext.lower() lower = state.appdata + 'avatars/' + hash + '.' + ext.lower()
if os.path.isfile(lower): if os.path.isfile(lower):
@ -3658,28 +3698,34 @@ class MyForm(settingsmixin.SMainWindow):
filters[1:1] = ['All files (*.*)'] filters[1:1] = ['All files (*.*)']
sourcefile = QtGui.QFileDialog.getOpenFileName( sourcefile = QtGui.QFileDialog.getOpenFileName(
self, _translate("MainWindow", "Set avatar..."), self, _translate("MainWindow", "Set avatar..."),
filter = ';;'.join(filters) filter=';;'.join(filters)
) )
# determine the correct filename (note that avatars don't use the suffix) # determine the correct filename (note that avatars don't use the suffix)
destination = state.appdata + 'avatars/' + hash + '.' + sourcefile.split('.')[-1] destination = state.appdata + 'avatars/' + hash + '.' + sourcefile.split('.')[-1]
exists = QtCore.QFile.exists(destination) exists = QtCore.QFile.exists(destination)
if sourcefile == '': if sourcefile == '':
# ask for removal of avatar # ask for removal of avatar
if exists | (len(current_files)>0): if exists | (len(current_files) > 0):
displayMsg = _translate("MainWindow", "Do you really want to remove this avatar?") displayMsg = _translate(
"MainWindow", "Do you really want to remove this avatar?")
overwrite = QtGui.QMessageBox.question( overwrite = QtGui.QMessageBox.question(
self, 'Message', displayMsg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) self, 'Message', displayMsg,
QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
else: else:
overwrite = QtGui.QMessageBox.No overwrite = QtGui.QMessageBox.No
else: else:
# ask whether to overwrite old avatar # ask whether to overwrite old avatar
if exists | (len(current_files)>0): if exists | (len(current_files) > 0):
displayMsg = _translate("MainWindow", "You have already set an avatar for this address. Do you really want to overwrite it?") displayMsg = _translate(
"MainWindow",
"You have already set an avatar for this address."
" Do you really want to overwrite it?")
overwrite = QtGui.QMessageBox.question( overwrite = QtGui.QMessageBox.question(
self, 'Message', displayMsg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) self, 'Message', displayMsg,
QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
else: else:
overwrite = QtGui.QMessageBox.No overwrite = QtGui.QMessageBox.No
# copy the image file to the appdata folder # copy the image file to the appdata folder
if (not exists) | (overwrite == QtGui.QMessageBox.Yes): if (not exists) | (overwrite == QtGui.QMessageBox.Yes):
if overwrite == QtGui.QMessageBox.Yes: if overwrite == QtGui.QMessageBox.Yes:
@ -3865,8 +3911,7 @@ class MyForm(settingsmixin.SMainWindow):
# Check to see if this item is toodifficult and display an additional # Check to see if this item is toodifficult and display an additional
# menu option (Force Send) if it is. # menu option (Force Send) if it is.
if currentRow >= 0: if currentRow >= 0:
ackData = str(self.ui.tableWidgetInbox.item( ackData = self.ui.tableWidgetInbox.item(currentRow, 3).data()
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
queryreturn = sqlQuery('''SELECT status FROM sent where ackdata=?''', ackData) queryreturn = sqlQuery('''SELECT status FROM sent where ackdata=?''', ackData)
for row in queryreturn: for row in queryreturn:
status, = row status, = row
@ -3877,25 +3922,27 @@ class MyForm(settingsmixin.SMainWindow):
def inboxSearchLineEditUpdated(self, text): def inboxSearchLineEditUpdated(self, text):
# dynamic search for too short text is slow # dynamic search for too short text is slow
if len(str(text)) < 3: text = text.toUtf8()
if 0 < len(text) < 3:
return return
messagelist = self.getCurrentMessagelist() messagelist = self.getCurrentMessagelist()
searchOption = self.getCurrentSearchOption()
if messagelist: if messagelist:
searchOption = self.getCurrentSearchOption()
account = self.getCurrentAccount() account = self.getCurrentAccount()
folder = self.getCurrentFolder() folder = self.getCurrentFolder()
self.loadMessagelist(messagelist, account, folder, searchOption, str(text)) self.loadMessagelist(
messagelist, account, folder, searchOption, text)
def inboxSearchLineEditReturnPressed(self): def inboxSearchLineEditReturnPressed(self):
logger.debug("Search return pressed") logger.debug("Search return pressed")
searchLine = self.getCurrentSearchLine() searchLine = self.getCurrentSearchLine()
messagelist = self.getCurrentMessagelist() messagelist = self.getCurrentMessagelist()
if len(str(searchLine)) < 3: if messagelist and len(str(searchLine)) < 3:
searchOption = self.getCurrentSearchOption() searchOption = self.getCurrentSearchOption()
account = self.getCurrentAccount() account = self.getCurrentAccount()
folder = self.getCurrentFolder() folder = self.getCurrentFolder()
self.loadMessagelist(messagelist, account, folder, searchOption, searchLine) self.loadMessagelist(
if messagelist: messagelist, account, folder, searchOption, searchLine)
messagelist.setFocus() messagelist.setFocus()
def treeWidgetItemClicked(self): def treeWidgetItemClicked(self):
@ -3921,7 +3968,7 @@ class MyForm(settingsmixin.SMainWindow):
if (not isinstance(item, Ui_AddressWidget)) or (not self.getCurrentTreeWidget()) or self.getCurrentTreeWidget().currentItem() is None: if (not isinstance(item, Ui_AddressWidget)) or (not self.getCurrentTreeWidget()) or self.getCurrentTreeWidget().currentItem() is None:
return return
# not visible # not visible
if (not self.getCurrentItem()) or (not isinstance (self.getCurrentItem(), Ui_AddressWidget)): if (not self.getCurrentItem()) or (not isinstance(self.getCurrentItem(), Ui_AddressWidget)):
return return
# only currently selected item # only currently selected item
if item.address != self.getCurrentAccount(): if item.address != self.getCurrentAccount():
@ -3929,7 +3976,7 @@ class MyForm(settingsmixin.SMainWindow):
# "All accounts" can't be renamed # "All accounts" can't be renamed
if item.type == AccountMixin.ALL: if item.type == AccountMixin.ALL:
return return
newLabel = unicode(item.text(0), 'utf-8', 'ignore') newLabel = unicode(item.text(0), 'utf-8', 'ignore')
oldLabel = item.defaultLabel() oldLabel = item.defaultLabel()
@ -3954,12 +4001,12 @@ class MyForm(settingsmixin.SMainWindow):
self.recurDepth -= 1 self.recurDepth -= 1
def tableWidgetInboxItemClicked(self): def tableWidgetInboxItemClicked(self):
folder = self.getCurrentFolder()
messageTextedit = self.getCurrentMessageTextedit() messageTextedit = self.getCurrentMessageTextedit()
if not messageTextedit: if not messageTextedit:
return return
msgid = self.getCurrentMessageId() msgid = self.getCurrentMessageId()
folder = self.getCurrentFolder()
if msgid: if msgid:
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''SELECT message FROM %s WHERE %s=?''' % ( '''SELECT message FROM %s WHERE %s=?''' % (
@ -4020,12 +4067,15 @@ class MyForm(settingsmixin.SMainWindow):
self.rerenderAddressBook() self.rerenderAddressBook()
def updateStatusBar(self, data): def updateStatusBar(self, data):
if type(data) is tuple or type(data) is list: try:
option = data[1] message, option = data
message = data[0] except ValueError:
else:
option = 0 option = 0
message = data message = data
except TypeError:
logger.debug(
'Invalid argument for updateStatusBar!', exc_info=True)
if message != "": if message != "":
logger.info('Status bar: ' + message) logger.info('Status bar: ' + message)
@ -4041,19 +4091,16 @@ class MyForm(settingsmixin.SMainWindow):
# Check to see whether we can connect to namecoin. # Check to see whether we can connect to namecoin.
# Hide the 'Fetch Namecoin ID' button if we can't. # Hide the 'Fetch Namecoin ID' button if we can't.
if BMConfigParser().safeGetBoolean( if BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'dontconnect' 'bitmessagesettings', 'dontconnect'
) or self.namecoin.test()[0] == 'failed': ) or self.namecoin.test()[0] == 'failed':
logger.warning( logger.warning(
'There was a problem testing for a Namecoin daemon. Hiding the' 'There was a problem testing for a Namecoin daemon.'
' Fetch Namecoin ID button') ' Hiding the Fetch Namecoin ID button')
self.ui.pushButtonFetchNamecoinID.hide() self.ui.pushButtonFetchNamecoinID.hide()
else: else:
self.ui.pushButtonFetchNamecoinID.show() self.ui.pushButtonFetchNamecoinID.show()
def initSettings(self): def initSettings(self):
QtCore.QCoreApplication.setOrganizationName("PyBitmessage")
QtCore.QCoreApplication.setOrganizationDomain("bitmessage.org")
QtCore.QCoreApplication.setApplicationName("pybitmessageqt")
self.loadSettings() self.loadSettings()
for attr, obj in self.ui.__dict__.iteritems(): for attr, obj in self.ui.__dict__.iteritems():
if hasattr(obj, "__class__") and \ if hasattr(obj, "__class__") and \
@ -4063,20 +4110,11 @@ class MyForm(settingsmixin.SMainWindow):
obj.loadSettings() obj.loadSettings()
# In order for the time columns on the Inbox and Sent tabs to be sorted
# correctly (rather than alphabetically), we need to overload the <
# operator and use this class instead of QTableWidgetItem.
class myTableWidgetItem(QtGui.QTableWidgetItem):
def __lt__(self, other):
return int(self.data(33).toPyObject()) < int(other.data(33).toPyObject())
app = None app = None
myapp = None myapp = None
class MySingleApplication(QtGui.QApplication): class BitmessageQtApplication(QtGui.QApplication):
""" """
Listener to allow our Qt form to get focus when another instance of the Listener to allow our Qt form to get focus when another instance of the
application is open. application is open.
@ -4089,8 +4127,12 @@ class MySingleApplication(QtGui.QApplication):
uuid = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c' uuid = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c'
def __init__(self, *argv): def __init__(self, *argv):
super(MySingleApplication, self).__init__(*argv) super(BitmessageQtApplication, self).__init__(*argv)
id = MySingleApplication.uuid id = BitmessageQtApplication.uuid
QtCore.QCoreApplication.setOrganizationName("PyBitmessage")
QtCore.QCoreApplication.setOrganizationDomain("bitmessage.org")
QtCore.QCoreApplication.setApplicationName("pybitmessageqt")
self.server = None self.server = None
self.is_running = False self.is_running = False
@ -4118,6 +4160,8 @@ class MySingleApplication(QtGui.QApplication):
self.server.listen(id) self.server.listen(id)
self.server.newConnection.connect(self.on_new_connection) self.server.newConnection.connect(self.on_new_connection)
self.setStyleSheet("QStatusBar::item { border: 0px solid black }")
def __del__(self): def __del__(self):
if self.server: if self.server:
self.server.close() self.server.close()
@ -4130,34 +4174,28 @@ class MySingleApplication(QtGui.QApplication):
def init(): def init():
global app global app
if not app: if not app:
app = MySingleApplication(sys.argv) app = BitmessageQtApplication(sys.argv)
return app return app
def run(): def run():
global myapp global myapp
app = init() app = init()
app.setStyleSheet("QStatusBar::item { border: 0px solid black }")
myapp = MyForm() myapp = MyForm()
myapp.sqlInit()
myapp.appIndicatorInit(app) myapp.appIndicatorInit(app)
myapp.indicatorInit()
myapp.notifierInit()
myapp._firstrun = BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'dontconnect')
if myapp._firstrun: if myapp._firstrun:
myapp.showConnectDialog() # ask the user if we may connect myapp.showConnectDialog() # ask the user if we may connect
myapp.ui.updateNetworkSwitchMenuLabel()
# try: # try:
# if BMConfigParser().get('bitmessagesettings', 'mailchuck') < 1: # if BMConfigParser().get('bitmessagesettings', 'mailchuck') < 1:
# myapp.showMigrationWizard(BMConfigParser().get('bitmessagesettings', 'mailchuck')) # myapp.showMigrationWizard(BMConfigParser().get('bitmessagesettings', 'mailchuck'))
# except: # except:
# myapp.showMigrationWizard(0) # myapp.showMigrationWizard(0)
# only show after wizards and connect dialogs have completed # only show after wizards and connect dialogs have completed
if not BMConfigParser().getboolean('bitmessagesettings', 'startintray'): if not BMConfigParser().getboolean('bitmessagesettings', 'startintray'):
myapp.show() myapp.show()
sys.exit(app.exec_()) app.exec_()

View File

@ -46,7 +46,7 @@
<item alignment="Qt::AlignLeft"> <item alignment="Qt::AlignLeft">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Copyright © 2012-2016 Jonathan Warren&lt;br/&gt;Copyright © 2012-2019 The Bitmessage Developers&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Copyright © 2012-2016 Jonathan Warren&lt;br/&gt;Copyright © 2012-2020 The Bitmessage Developers&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeft</set> <set>Qt::AlignLeft</set>

View File

@ -1,9 +1,7 @@
""" """
src/bitmessageqt/address_dialogs.py Dialogs that work with BM address.
===================================
""" """
# pylint: disable=attribute-defined-outside-init # pylint: disable=attribute-defined-outside-init,too-few-public-methods,relative-import
import hashlib import hashlib
@ -14,13 +12,11 @@ import widgets
from account import AccountMixin, GatewayAccount, MailchuckAccount, accountClass, getSortedAccounts from account import AccountMixin, GatewayAccount, MailchuckAccount, accountClass, getSortedAccounts
from addresses import addBMIfNotPresent, decodeAddress, encodeVarint from addresses import addBMIfNotPresent, decodeAddress, encodeVarint
from inventory import Inventory from inventory import Inventory
from retranslateui import RetranslateMixin
from tr import _translate from tr import _translate
class AddressCheckMixin(object): class AddressCheckMixin(object):
"""Base address validation class for QT UI""" """Base address validation class for QT UI"""
# pylint: disable=too-few-public-methods
def __init__(self): def __init__(self):
self.valid = False self.valid = False
@ -33,7 +29,9 @@ class AddressCheckMixin(object):
pass pass
def addressChanged(self, QString): def addressChanged(self, QString):
"""Address validation callback, performs validation and gives feedback""" """
Address validation callback, performs validation and gives feedback
"""
status, addressVersion, streamNumber, ripe = decodeAddress( status, addressVersion, streamNumber, ripe = decodeAddress(
str(QString)) str(QString))
self.valid = status == 'success' self.valid = status == 'success'
@ -102,8 +100,8 @@ class AddressDataDialog(QtGui.QDialog, AddressCheckMixin):
super(AddressDataDialog, self).accept() super(AddressDataDialog, self).accept()
class AddAddressDialog(AddressDataDialog, RetranslateMixin): class AddAddressDialog(AddressDataDialog):
"""QDialog for adding a new address, with validation and translation""" """QDialog for adding a new address"""
def __init__(self, parent=None, address=None): def __init__(self, parent=None, address=None):
super(AddAddressDialog, self).__init__(parent) super(AddAddressDialog, self).__init__(parent)
@ -113,8 +111,8 @@ class AddAddressDialog(AddressDataDialog, RetranslateMixin):
self.lineEditAddress.setText(address) self.lineEditAddress.setText(address)
class NewAddressDialog(QtGui.QDialog, RetranslateMixin): class NewAddressDialog(QtGui.QDialog):
"""QDialog for generating a new address, with translation""" """QDialog for generating a new address"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(NewAddressDialog, self).__init__(parent) super(NewAddressDialog, self).__init__(parent)
@ -175,8 +173,8 @@ class NewAddressDialog(QtGui.QDialog, RetranslateMixin):
)) ))
class NewSubscriptionDialog(AddressDataDialog, RetranslateMixin): class NewSubscriptionDialog(AddressDataDialog):
"""QDialog for subscribing to an address, with validation and translation""" """QDialog for subscribing to an address"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(NewSubscriptionDialog, self).__init__(parent) super(NewSubscriptionDialog, self).__init__(parent)
@ -193,8 +191,8 @@ class NewSubscriptionDialog(AddressDataDialog, RetranslateMixin):
else: else:
Inventory().flush() Inventory().flush()
doubleHashOfAddressData = hashlib.sha512(hashlib.sha512( doubleHashOfAddressData = hashlib.sha512(hashlib.sha512(
encodeVarint(addressVersion) + encodeVarint(addressVersion)
encodeVarint(streamNumber) + ripe + encodeVarint(streamNumber) + ripe
).digest()).digest() ).digest()).digest()
tag = doubleHashOfAddressData[32:] tag = doubleHashOfAddressData[32:]
self.recent = Inventory().by_type_and_tag(3, tag) self.recent = Inventory().by_type_and_tag(3, tag)
@ -218,8 +216,8 @@ class NewSubscriptionDialog(AddressDataDialog, RetranslateMixin):
)) ))
class RegenerateAddressesDialog(QtGui.QDialog, RetranslateMixin): class RegenerateAddressesDialog(QtGui.QDialog):
"""QDialog for regenerating deterministic addresses, with translation""" """QDialog for regenerating deterministic addresses"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(RegenerateAddressesDialog, self).__init__(parent) super(RegenerateAddressesDialog, self).__init__(parent)
widgets.load('regenerateaddresses.ui', self) widgets.load('regenerateaddresses.ui', self)
@ -227,8 +225,10 @@ class RegenerateAddressesDialog(QtGui.QDialog, RetranslateMixin):
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self)) QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
class SpecialAddressBehaviorDialog(QtGui.QDialog, RetranslateMixin): class SpecialAddressBehaviorDialog(QtGui.QDialog):
"""QDialog for special address behaviour (e.g. mailing list functionality), with translation""" """
QDialog for special address behaviour (e.g. mailing list functionality)
"""
def __init__(self, parent=None, config=None): def __init__(self, parent=None, config=None):
super(SpecialAddressBehaviorDialog, self).__init__(parent) super(SpecialAddressBehaviorDialog, self).__init__(parent)
@ -256,11 +256,7 @@ class SpecialAddressBehaviorDialog(QtGui.QDialog, RetranslateMixin):
self.radioButtonBehaviorMailingList.click() self.radioButtonBehaviorMailingList.click()
else: else:
self.radioButtonBehaveNormalAddress.click() self.radioButtonBehaveNormalAddress.click()
try: mailingListName = config.safeGet(self.address, 'mailinglistname', '')
mailingListName = config.get(
self.address, 'mailinglistname')
except:
mailingListName = ''
self.lineEditMailingListName.setText( self.lineEditMailingListName.setText(
unicode(mailingListName, 'utf-8') unicode(mailingListName, 'utf-8')
) )
@ -294,8 +290,8 @@ class SpecialAddressBehaviorDialog(QtGui.QDialog, RetranslateMixin):
self.parent.rerenderMessagelistToLabels() self.parent.rerenderMessagelistToLabels()
class EmailGatewayDialog(QtGui.QDialog, RetranslateMixin): class EmailGatewayDialog(QtGui.QDialog):
"""QDialog for email gateway control, with translation""" """QDialog for email gateway control"""
def __init__(self, parent, config=None, account=None): def __init__(self, parent, config=None, account=None):
super(EmailGatewayDialog, self).__init__(parent) super(EmailGatewayDialog, self).__init__(parent)
widgets.load('emailgateway.ui', self) widgets.load('emailgateway.ui', self)

View File

@ -1,14 +1,29 @@
"""
Address validator module.
"""
# pylint: disable=too-many-branches,too-many-arguments
from PyQt4 import QtGui from PyQt4 import QtGui
from Queue import Empty from Queue import Empty
from addresses import decodeAddress, addBMIfNotPresent
from account import getSortedAccounts from account import getSortedAccounts
from addresses import decodeAddress, addBMIfNotPresent
from queues import apiAddressGeneratorReturnQueue, addressGeneratorQueue from queues import apiAddressGeneratorReturnQueue, addressGeneratorQueue
from tr import _translate from tr import _translate
from utils import str_chan from utils import str_chan
class AddressPassPhraseValidatorMixin():
def setParams(self, passPhraseObject=None, addressObject=None, feedBackObject=None, buttonBox=None, addressMandatory=True): class AddressPassPhraseValidatorMixin(object):
"""Bitmessage address or passphrase validator class for Qt UI"""
def setParams(
self,
passPhraseObject=None,
addressObject=None,
feedBackObject=None,
buttonBox=None,
addressMandatory=True,
):
"""Initialisation"""
self.addressObject = addressObject self.addressObject = addressObject
self.passPhraseObject = passPhraseObject self.passPhraseObject = passPhraseObject
self.feedBackObject = feedBackObject self.feedBackObject = feedBackObject
@ -19,6 +34,7 @@ class AddressPassPhraseValidatorMixin():
self.okButtonLabel = self.buttonBox.button(QtGui.QDialogButtonBox.Ok).text() self.okButtonLabel = self.buttonBox.button(QtGui.QDialogButtonBox.Ok).text()
def setError(self, string): def setError(self, string):
"""Indicate that the validation is pending or failed"""
if string is not None and self.feedBackObject is not None: if string is not None and self.feedBackObject is not None:
font = QtGui.QFont() font = QtGui.QFont()
font.setBold(True) font.setBold(True)
@ -29,11 +45,14 @@ class AddressPassPhraseValidatorMixin():
if self.buttonBox: if self.buttonBox:
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
if string is not None and self.feedBackObject is not None: if string is not None and self.feedBackObject is not None:
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setText(_translate("AddressValidator", "Invalid")) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setText(
_translate("AddressValidator", "Invalid"))
else: else:
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setText(_translate("AddressValidator", "Validating...")) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setText(
_translate("AddressValidator", "Validating..."))
def setOK(self, string): def setOK(self, string):
"""Indicate that the validation succeeded"""
if string is not None and self.feedBackObject is not None: if string is not None and self.feedBackObject is not None:
font = QtGui.QFont() font = QtGui.QFont()
font.setBold(False) font.setBold(False)
@ -46,12 +65,13 @@ class AddressPassPhraseValidatorMixin():
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setText(self.okButtonLabel) self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setText(self.okButtonLabel)
def checkQueue(self): def checkQueue(self):
"""Validator queue loop"""
gotOne = False gotOne = False
# wait until processing is done # wait until processing is done
if not addressGeneratorQueue.empty(): if not addressGeneratorQueue.empty():
self.setError(None) self.setError(None)
return return None
while True: while True:
try: try:
@ -60,25 +80,30 @@ class AddressPassPhraseValidatorMixin():
if gotOne: if gotOne:
break break
else: else:
return return None
else: else:
gotOne = True gotOne = True
if len(addressGeneratorReturnValue) == 0: if not addressGeneratorReturnValue:
self.setError(_translate("AddressValidator", "Address already present as one of your identities.")) self.setError(_translate("AddressValidator", "Address already present as one of your identities."))
return (QtGui.QValidator.Intermediate, 0) return (QtGui.QValidator.Intermediate, 0)
if addressGeneratorReturnValue[0] == 'chan name does not match address': if addressGeneratorReturnValue[0] == 'chan name does not match address':
self.setError(_translate("AddressValidator", "Although the Bitmessage address you entered was valid, it doesn\'t match the chan name.")) self.setError(
_translate(
"AddressValidator",
"Although the Bitmessage address you "
"entered was valid, it doesn't match the chan name."))
return (QtGui.QValidator.Intermediate, 0) return (QtGui.QValidator.Intermediate, 0)
self.setOK(_translate("MainWindow", "Passphrase and address appear to be valid.")) self.setOK(_translate("MainWindow", "Passphrase and address appear to be valid."))
def returnValid(self): def returnValid(self):
"""Return the value of whether the validation was successful"""
if self.isValid: if self.isValid:
return QtGui.QValidator.Acceptable return QtGui.QValidator.Acceptable
else: return QtGui.QValidator.Intermediate
return QtGui.QValidator.Intermediate
def validate(self, s, pos): def validate(self, s, pos):
"""Top level validator method"""
if self.addressObject is None: if self.addressObject is None:
address = None address = None
else: else:
@ -105,9 +130,15 @@ class AddressPassPhraseValidatorMixin():
# version too high # version too high
if decodeAddress(address)[0] == 'versiontoohigh': if decodeAddress(address)[0] == 'versiontoohigh':
self.setError(_translate("AddressValidator", "Address too new. Although that Bitmessage address might be valid, its version number is too new for us to handle. Perhaps you need to upgrade Bitmessage.")) self.setError(
_translate(
"AddressValidator",
"Address too new. Although that Bitmessage"
" address might be valid, its version number"
" is too new for us to handle. Perhaps you need"
" to upgrade Bitmessage."))
return (QtGui.QValidator.Intermediate, pos) return (QtGui.QValidator.Intermediate, pos)
# invalid # invalid
if decodeAddress(address)[0] != 'success': if decodeAddress(address)[0] != 'success':
self.setError(_translate("AddressValidator", "The Bitmessage address is not valid.")) self.setError(_translate("AddressValidator", "The Bitmessage address is not valid."))
@ -122,23 +153,28 @@ class AddressPassPhraseValidatorMixin():
if address is None: if address is None:
addressGeneratorQueue.put(('createChan', 4, 1, str_chan + ' ' + str(passPhrase), passPhrase, False)) addressGeneratorQueue.put(('createChan', 4, 1, str_chan + ' ' + str(passPhrase), passPhrase, False))
else: else:
addressGeneratorQueue.put(('joinChan', addBMIfNotPresent(address), str_chan + ' ' + str(passPhrase), passPhrase, False)) addressGeneratorQueue.put(
('joinChan', addBMIfNotPresent(address),
"{} {}".format(str_chan, passPhrase), passPhrase, False))
if self.buttonBox.button(QtGui.QDialogButtonBox.Ok).hasFocus(): if self.buttonBox.button(QtGui.QDialogButtonBox.Ok).hasFocus():
return (self.returnValid(), pos) return (self.returnValid(), pos)
else: return (QtGui.QValidator.Intermediate, pos)
return (QtGui.QValidator.Intermediate, pos)
def checkData(self): def checkData(self):
"""Validator Qt signal interface"""
return self.validate("", 0) return self.validate("", 0)
class AddressValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin): class AddressValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin):
"""AddressValidator class for Qt UI"""
def __init__(self, parent=None, passPhraseObject=None, feedBackObject=None, buttonBox=None, addressMandatory=True): def __init__(self, parent=None, passPhraseObject=None, feedBackObject=None, buttonBox=None, addressMandatory=True):
super(AddressValidator, self).__init__(parent) super(AddressValidator, self).__init__(parent)
self.setParams(passPhraseObject, parent, feedBackObject, buttonBox, addressMandatory) self.setParams(passPhraseObject, parent, feedBackObject, buttonBox, addressMandatory)
class PassPhraseValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin): class PassPhraseValidator(QtGui.QValidator, AddressPassPhraseValidatorMixin):
"""PassPhraseValidator class for Qt UI"""
def __init__(self, parent=None, addressObject=None, feedBackObject=None, buttonBox=None, addressMandatory=False): def __init__(self, parent=None, addressObject=None, feedBackObject=None, buttonBox=None, addressMandatory=False):
super(PassPhraseValidator, self).__init__(parent) super(PassPhraseValidator, self).__init__(parent)
self.setParams(parent, addressObject, feedBackObject, buttonBox, addressMandatory) self.setParams(parent, addressObject, feedBackObject, buttonBox, addressMandatory)

View File

@ -104,6 +104,7 @@ class Ui_MainWindow(object):
self.inboxSearchOption.addItem(_fromUtf8("")) self.inboxSearchOption.addItem(_fromUtf8(""))
self.inboxSearchOption.addItem(_fromUtf8("")) self.inboxSearchOption.addItem(_fromUtf8(""))
self.inboxSearchOption.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) self.inboxSearchOption.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
self.inboxSearchOption.setCurrentIndex(3)
self.horizontalSplitterSearch.addWidget(self.inboxSearchOption) self.horizontalSplitterSearch.addWidget(self.inboxSearchOption)
self.horizontalSplitterSearch.handle(1).setEnabled(False) self.horizontalSplitterSearch.handle(1).setEnabled(False)
self.horizontalSplitterSearch.setStretchFactor(0, 1) self.horizontalSplitterSearch.setStretchFactor(0, 1)
@ -403,8 +404,8 @@ class Ui_MainWindow(object):
self.inboxSearchOptionSubscriptions.addItem(_fromUtf8("")) self.inboxSearchOptionSubscriptions.addItem(_fromUtf8(""))
self.inboxSearchOptionSubscriptions.addItem(_fromUtf8("")) self.inboxSearchOptionSubscriptions.addItem(_fromUtf8(""))
self.inboxSearchOptionSubscriptions.addItem(_fromUtf8("")) self.inboxSearchOptionSubscriptions.addItem(_fromUtf8(""))
self.inboxSearchOptionSubscriptions.addItem(_fromUtf8(""))
self.inboxSearchOptionSubscriptions.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) self.inboxSearchOptionSubscriptions.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
self.inboxSearchOptionSubscriptions.setCurrentIndex(2)
self.horizontalSplitter_2.addWidget(self.inboxSearchOptionSubscriptions) self.horizontalSplitter_2.addWidget(self.inboxSearchOptionSubscriptions)
self.horizontalSplitter_2.handle(1).setEnabled(False) self.horizontalSplitter_2.handle(1).setEnabled(False)
self.horizontalSplitter_2.setStretchFactor(0, 1) self.horizontalSplitter_2.setStretchFactor(0, 1)
@ -504,6 +505,7 @@ class Ui_MainWindow(object):
self.inboxSearchOptionChans.addItem(_fromUtf8("")) self.inboxSearchOptionChans.addItem(_fromUtf8(""))
self.inboxSearchOptionChans.addItem(_fromUtf8("")) self.inboxSearchOptionChans.addItem(_fromUtf8(""))
self.inboxSearchOptionChans.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) self.inboxSearchOptionChans.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
self.inboxSearchOptionChans.setCurrentIndex(3)
self.horizontalSplitter_6.addWidget(self.inboxSearchOptionChans) self.horizontalSplitter_6.addWidget(self.inboxSearchOptionChans)
self.horizontalSplitter_6.handle(1).setEnabled(False) self.horizontalSplitter_6.handle(1).setEnabled(False)
self.horizontalSplitter_6.setStretchFactor(0, 1) self.horizontalSplitter_6.setStretchFactor(0, 1)
@ -719,10 +721,9 @@ class Ui_MainWindow(object):
self.pushButtonAddSubscription.setText(_translate("MainWindow", "Add new Subscription", None)) self.pushButtonAddSubscription.setText(_translate("MainWindow", "Add new Subscription", None))
self.inboxSearchLineEditSubscriptions.setPlaceholderText(_translate("MainWindow", "Search", None)) self.inboxSearchLineEditSubscriptions.setPlaceholderText(_translate("MainWindow", "Search", None))
self.inboxSearchOptionSubscriptions.setItemText(0, _translate("MainWindow", "All", None)) self.inboxSearchOptionSubscriptions.setItemText(0, _translate("MainWindow", "All", None))
self.inboxSearchOptionSubscriptions.setItemText(1, _translate("MainWindow", "To", None)) self.inboxSearchOptionSubscriptions.setItemText(1, _translate("MainWindow", "From", None))
self.inboxSearchOptionSubscriptions.setItemText(2, _translate("MainWindow", "From", None)) self.inboxSearchOptionSubscriptions.setItemText(2, _translate("MainWindow", "Subject", None))
self.inboxSearchOptionSubscriptions.setItemText(3, _translate("MainWindow", "Subject", None)) self.inboxSearchOptionSubscriptions.setItemText(3, _translate("MainWindow", "Message", None))
self.inboxSearchOptionSubscriptions.setItemText(4, _translate("MainWindow", "Message", None))
self.tableWidgetInboxSubscriptions.setSortingEnabled(True) self.tableWidgetInboxSubscriptions.setSortingEnabled(True)
item = self.tableWidgetInboxSubscriptions.horizontalHeaderItem(0) item = self.tableWidgetInboxSubscriptions.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "To", None)) item.setText(_translate("MainWindow", "To", None))
@ -770,6 +771,8 @@ class Ui_MainWindow(object):
self.actionRegenerateDeterministicAddresses.setText(_translate("MainWindow", "Regenerate deterministic addresses", None)) self.actionRegenerateDeterministicAddresses.setText(_translate("MainWindow", "Regenerate deterministic addresses", None))
self.actionDeleteAllTrashedMessages.setText(_translate("MainWindow", "Delete all trashed messages", None)) self.actionDeleteAllTrashedMessages.setText(_translate("MainWindow", "Delete all trashed messages", None))
self.actionJoinChan.setText(_translate("MainWindow", "Join / Create chan", None)) self.actionJoinChan.setText(_translate("MainWindow", "Join / Create chan", None))
self.updateNetworkSwitchMenuLabel()
import bitmessage_icons_rc import bitmessage_icons_rc

View File

@ -1,8 +1,7 @@
""" """
src/bitmessageqt/dialogs.py Custom dialog classes
===========================
""" """
# pylint: disable=too-few-public-methods
from PyQt4 import QtGui from PyQt4 import QtGui
import paths import paths
@ -13,7 +12,6 @@ from address_dialogs import (
SpecialAddressBehaviorDialog SpecialAddressBehaviorDialog
) )
from newchandialog import NewChanDialog from newchandialog import NewChanDialog
from retranslateui import RetranslateMixin
from settings import SettingsDialog from settings import SettingsDialog
from tr import _translate from tr import _translate
from version import softwareVersion from version import softwareVersion
@ -27,7 +25,7 @@ __all__ = [
] ]
class AboutDialog(QtGui.QDialog, RetranslateMixin): class AboutDialog(QtGui.QDialog):
"""The `About` dialog""" """The `About` dialog"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(AboutDialog, self).__init__(parent) super(AboutDialog, self).__init__(parent)
@ -47,7 +45,7 @@ class AboutDialog(QtGui.QDialog, RetranslateMixin):
try: try:
self.label_2.setText( self.label_2.setText(
self.label_2.text().replace( self.label_2.text().replace(
'2019', str(last_commit.get('time').year) '2020', str(last_commit.get('time').year)
)) ))
except AttributeError: except AttributeError:
pass pass
@ -55,7 +53,7 @@ class AboutDialog(QtGui.QDialog, RetranslateMixin):
self.setFixedSize(QtGui.QWidget.sizeHint(self)) self.setFixedSize(QtGui.QWidget.sizeHint(self))
class IconGlossaryDialog(QtGui.QDialog, RetranslateMixin): class IconGlossaryDialog(QtGui.QDialog):
"""The `Icon Glossary` dialog, explaining the status icon colors""" """The `Icon Glossary` dialog, explaining the status icon colors"""
def __init__(self, parent=None, config=None): def __init__(self, parent=None, config=None):
super(IconGlossaryDialog, self).__init__(parent) super(IconGlossaryDialog, self).__init__(parent)
@ -71,7 +69,7 @@ class IconGlossaryDialog(QtGui.QDialog, RetranslateMixin):
self.setFixedSize(QtGui.QWidget.sizeHint(self)) self.setFixedSize(QtGui.QWidget.sizeHint(self))
class HelpDialog(QtGui.QDialog, RetranslateMixin): class HelpDialog(QtGui.QDialog):
"""The `Help` dialog""" """The `Help` dialog"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(HelpDialog, self).__init__(parent) super(HelpDialog, self).__init__(parent)
@ -79,7 +77,7 @@ class HelpDialog(QtGui.QDialog, RetranslateMixin):
self.setFixedSize(QtGui.QWidget.sizeHint(self)) self.setFixedSize(QtGui.QWidget.sizeHint(self))
class ConnectDialog(QtGui.QDialog, RetranslateMixin): class ConnectDialog(QtGui.QDialog):
"""The `Connect` dialog""" """The `Connect` dialog"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(ConnectDialog, self).__init__(parent) super(ConnectDialog, self).__init__(parent)

View File

@ -1,8 +1,8 @@
""" """
src/bitmessageqt/foldertree.py Folder tree and messagelist widgets definitions.
==============================
""" """
# pylint: disable=too-many-arguments,bad-super-call,attribute-defined-outside-init # pylint: disable=too-many-arguments,bad-super-call
# pylint: disable=attribute-defined-outside-init
from cgi import escape from cgi import escape
@ -20,6 +20,8 @@ _translate("MainWindow", "new")
_translate("MainWindow", "sent") _translate("MainWindow", "sent")
_translate("MainWindow", "trash") _translate("MainWindow", "trash")
TimestampRole = QtCore.Qt.UserRole + 1
class AccountMixin(object): class AccountMixin(object):
"""UI-related functionality for accounts""" """UI-related functionality for accounts"""
@ -334,13 +336,14 @@ class Ui_SubscriptionWidget(Ui_AddressWidget):
class BMTableWidgetItem(QtGui.QTableWidgetItem, SettingsMixin): class BMTableWidgetItem(QtGui.QTableWidgetItem, SettingsMixin):
"""A common abstract class for Table widget item""" """A common abstract class for Table widget item"""
def __init__(self, parent=None, label=None, unread=False): def __init__(self, label=None, unread=False):
super(QtGui.QTableWidgetItem, self).__init__() super(QtGui.QTableWidgetItem, self).__init__()
self.setLabel(label) self.setLabel(label)
self.setUnread(unread) self.setUnread(unread)
self._setup() self._setup()
if parent is not None:
parent.append(self) def _setup(self):
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
def setLabel(self, label): def setLabel(self, label):
"""Set object label""" """Set object label"""
@ -353,7 +356,7 @@ class BMTableWidgetItem(QtGui.QTableWidgetItem, SettingsMixin):
def data(self, role): def data(self, role):
"""Return object data (QT UI)""" """Return object data (QT UI)"""
if role in ( if role in (
QtCore.Qt.DisplayRole, QtCore.Qt.EditRole, QtCore.Qt.ToolTipRole QtCore.Qt.DisplayRole, QtCore.Qt.EditRole, QtCore.Qt.ToolTipRole
): ):
return self.label return self.label
elif role == QtCore.Qt.FontRole: elif role == QtCore.Qt.FontRole:
@ -367,7 +370,9 @@ class BMAddressWidget(BMTableWidgetItem, AccountMixin):
"""A common class for Table widget item with account""" """A common class for Table widget item with account"""
def _setup(self): def _setup(self):
super(BMAddressWidget, self)._setup()
self.setEnabled(True) self.setEnabled(True)
self.setType()
def _getLabel(self): def _getLabel(self):
return self.label return self.label
@ -387,14 +392,9 @@ class BMAddressWidget(BMTableWidgetItem, AccountMixin):
class MessageList_AddressWidget(BMAddressWidget): class MessageList_AddressWidget(BMAddressWidget):
"""Address item in a messagelist""" """Address item in a messagelist"""
def __init__(self, parent, address=None, label=None, unread=False): def __init__(self, address=None, label=None, unread=False):
self.setAddress(address) self.setAddress(address)
super(MessageList_AddressWidget, self).__init__(parent, label, unread) super(MessageList_AddressWidget, self).__init__(label, unread)
def _setup(self):
self.isEnabled = True
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.setType()
def setLabel(self, label=None): def setLabel(self, label=None):
"""Set label""" """Set label"""
@ -443,12 +443,9 @@ class MessageList_AddressWidget(BMAddressWidget):
class MessageList_SubjectWidget(BMTableWidgetItem): class MessageList_SubjectWidget(BMTableWidgetItem):
"""Message list subject item""" """Message list subject item"""
def __init__(self, parent, subject=None, label=None, unread=False): def __init__(self, subject=None, label=None, unread=False):
self.setSubject(subject) self.setSubject(subject)
super(MessageList_SubjectWidget, self).__init__(parent, label, unread) super(MessageList_SubjectWidget, self).__init__(label, unread)
def _setup(self):
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
def setSubject(self, subject): def setSubject(self, subject):
"""Set subject""" """Set subject"""
@ -469,6 +466,37 @@ class MessageList_SubjectWidget(BMTableWidgetItem):
return super(QtGui.QTableWidgetItem, self).__lt__(other) return super(QtGui.QTableWidgetItem, self).__lt__(other)
# In order for the time columns on the Inbox and Sent tabs to be sorted
# correctly (rather than alphabetically), we need to overload the <
# operator and use this class instead of QTableWidgetItem.
class MessageList_TimeWidget(BMTableWidgetItem):
"""
A subclass of QTableWidgetItem for received (lastactiontime) field.
'<' operator is overloaded to sort by TimestampRole == 33
msgid is available by QtCore.Qt.UserRole
"""
def __init__(self, label=None, unread=False, timestamp=None, msgid=''):
super(MessageList_TimeWidget, self).__init__(label, unread)
self.setData(QtCore.Qt.UserRole, QtCore.QByteArray(msgid))
self.setData(TimestampRole, int(timestamp))
def __lt__(self, other):
return self.data(TimestampRole) < other.data(TimestampRole)
def data(self, role=QtCore.Qt.UserRole):
"""
Returns expected python types for QtCore.Qt.UserRole and TimestampRole
custom roles and super for any Qt role
"""
data = super(MessageList_TimeWidget, self).data(role)
if role == TimestampRole:
return int(data.toPyObject())
if role == QtCore.Qt.UserRole:
return str(data.toPyObject())
return data
class Ui_AddressBookWidgetItem(BMAddressWidget): class Ui_AddressBookWidgetItem(BMAddressWidget):
"""Addressbook item""" """Addressbook item"""
# pylint: disable=unused-argument # pylint: disable=unused-argument
@ -518,8 +546,8 @@ class Ui_AddressBookWidgetItem(BMAddressWidget):
class Ui_AddressBookWidgetItemLabel(Ui_AddressBookWidgetItem): class Ui_AddressBookWidgetItemLabel(Ui_AddressBookWidgetItem):
"""Addressbook label item""" """Addressbook label item"""
def __init__(self, address, label, acc_type): def __init__(self, address, label, acc_type):
super(Ui_AddressBookWidgetItemLabel, self).__init__(label, acc_type)
self.address = address self.address = address
super(Ui_AddressBookWidgetItemLabel, self).__init__(label, acc_type)
def data(self, role): def data(self, role):
"""Return object data""" """Return object data"""
@ -530,9 +558,8 @@ class Ui_AddressBookWidgetItemLabel(Ui_AddressBookWidgetItem):
class Ui_AddressBookWidgetItemAddress(Ui_AddressBookWidgetItem): class Ui_AddressBookWidgetItemAddress(Ui_AddressBookWidgetItem):
"""Addressbook address item""" """Addressbook address item"""
def __init__(self, address, label, acc_type): def __init__(self, address, label, acc_type):
super(Ui_AddressBookWidgetItemAddress, self).__init__(address, acc_type)
self.address = address self.address = address
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) super(Ui_AddressBookWidgetItemAddress, self).__init__(address, acc_type)
def data(self, role): def data(self, role):
"""Return object data""" """Return object data"""

View File

@ -1,32 +1,45 @@
"""Language Box Module for Locale Settings"""
# pylint: disable=too-few-public-methods,bad-continuation
import glob import glob
import os import os
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from bmconfigparser import BMConfigParser
import paths import paths
from bmconfigparser import BMConfigParser
class LanguageBox(QtGui.QComboBox): class LanguageBox(QtGui.QComboBox):
languageName = {"system": "System Settings", "eo": "Esperanto", "en_pirate": "Pirate English"} """LanguageBox class for Qt UI"""
def __init__(self, parent = None): languageName = {
"system": "System Settings", "eo": "Esperanto",
"en_pirate": "Pirate English"
}
def __init__(self, parent=None):
super(QtGui.QComboBox, self).__init__(parent) super(QtGui.QComboBox, self).__init__(parent)
self.populate() self.populate()
def populate(self): def populate(self):
"""Populates drop down list with all available languages."""
self.clear() self.clear()
localesPath = os.path.join (paths.codePath(), 'translations') localesPath = os.path.join(paths.codePath(), 'translations')
self.addItem(QtGui.QApplication.translate("settingsDialog", "System Settings", "system"), "system") self.addItem(QtGui.QApplication.translate(
"settingsDialog", "System Settings", "system"), "system")
self.setCurrentIndex(0) self.setCurrentIndex(0)
self.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically) self.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
for translationFile in sorted(glob.glob(os.path.join(localesPath, "bitmessage_*.qm"))): for translationFile in sorted(
localeShort = os.path.split(translationFile)[1].split("_", 1)[1][:-3] glob.glob(os.path.join(localesPath, "bitmessage_*.qm"))
locale = QtCore.QLocale(QtCore.QString(localeShort)) ):
localeShort = \
os.path.split(translationFile)[1].split("_", 1)[1][:-3]
if localeShort in LanguageBox.languageName: if localeShort in LanguageBox.languageName:
self.addItem(LanguageBox.languageName[localeShort], localeShort) self.addItem(
elif locale.nativeLanguageName() == "": LanguageBox.languageName[localeShort], localeShort)
self.addItem(localeShort, localeShort)
else: else:
self.addItem(locale.nativeLanguageName(), localeShort) locale = QtCore.QLocale(localeShort)
self.addItem(
locale.nativeLanguageName() or localeShort, localeShort)
configuredLocale = BMConfigParser().safeGet( configuredLocale = BMConfigParser().safeGet(
'bitmessagesettings', 'userlocale', "system") 'bitmessagesettings', 'userlocale', "system")

View File

@ -1,23 +1,37 @@
"""
Message editor with a wheel zoom functionality
"""
# pylint: disable=bad-continuation
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
class MessageCompose(QtGui.QTextEdit): class MessageCompose(QtGui.QTextEdit):
"""Editor class with wheel zoom functionality"""
def __init__(self, parent = 0): def __init__(self, parent=0):
super(MessageCompose, self).__init__(parent) super(MessageCompose, self).__init__(parent)
self.setAcceptRichText(False) # we'll deal with this later when we have a new message format self.setAcceptRichText(False)
self.defaultFontPointSize = self.currentFont().pointSize() self.defaultFontPointSize = self.currentFont().pointSize()
def wheelEvent(self, event): def wheelEvent(self, event):
if (QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ControlModifier) == QtCore.Qt.ControlModifier and event.orientation() == QtCore.Qt.Vertical: """Mouse wheel scroll event handler"""
if (
QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ControlModifier
) == QtCore.Qt.ControlModifier and event.orientation() == QtCore.Qt.Vertical:
if event.delta() > 0: if event.delta() > 0:
self.zoomIn(1) self.zoomIn(1)
else: else:
self.zoomOut(1) self.zoomOut(1)
zoom = self.currentFont().pointSize() * 100 / self.defaultFontPointSize zoom = self.currentFont().pointSize() * 100 / self.defaultFontPointSize
QtGui.QApplication.activeWindow().statusBar().showMessage(QtGui.QApplication.translate("MainWindow", "Zoom level %1%").arg(str(zoom))) QtGui.QApplication.activeWindow().statusBar().showMessage(
QtGui.QApplication.translate("MainWindow", "Zoom level %1%").arg(
str(zoom)
)
)
else: else:
# in QTextEdit, super does not zoom, only scroll # in QTextEdit, super does not zoom, only scroll
super(MessageCompose, self).wheelEvent(event) super(MessageCompose, self).wheelEvent(event)
def reset(self): def reset(self):
"""Clear the edit content"""
self.setText('') self.setText('')

View File

@ -1,12 +1,14 @@
""" """
src/bitmessageqt/messageview.py Custom message viewer with support for switching between HTML and plain
=============================== text rendering, HTML sanitization, lazy rendering (as you scroll down),
zoom and URL click warning popup
""" """
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from safehtmlparser import SafeHTMLParser from safehtmlparser import SafeHTMLParser
from tr import _translate
class MessageView(QtGui.QTextBrowser): class MessageView(QtGui.QTextBrowser):
@ -49,11 +51,12 @@ class MessageView(QtGui.QTextBrowser):
"""Mouse wheel scroll event handler""" """Mouse wheel scroll event handler"""
# super will actually automatically take care of zooming # super will actually automatically take care of zooming
super(MessageView, self).wheelEvent(event) super(MessageView, self).wheelEvent(event)
if (QtGui.QApplication.queryKeyboardModifiers() & if (
QtCore.Qt.ControlModifier) == QtCore.Qt.ControlModifier and event.orientation() == QtCore.Qt.Vertical: QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ControlModifier
) == QtCore.Qt.ControlModifier and event.orientation() == QtCore.Qt.Vertical:
zoom = self.currentFont().pointSize() * 100 / self.defaultFontPointSize zoom = self.currentFont().pointSize() * 100 / self.defaultFontPointSize
QtGui.QApplication.activeWindow().statusBar().showMessage( QtGui.QApplication.activeWindow().statusBar().showMessage(_translate(
QtGui.QApplication.translate("MainWindow", "Zoom level %1%").arg(str(zoom))) "MainWindow", "Zoom level %1%").arg(str(zoom)))
def setWrappingWidth(self, width=None): def setWrappingWidth(self, width=None):
"""Set word-wrapping width""" """Set word-wrapping width"""

View File

@ -1,20 +1,17 @@
""" """
src/bitmessageqt/networkstatus.py Network status tab widget definition.
=================================
""" """
import time import time
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
import knownnodes
import l10n import l10n
import network.stats import network.stats
import shared import state
import widgets import widgets
from inventory import Inventory from inventory import Inventory
from network import BMConnectionPool from network import BMConnectionPool, knownnodes
from retranslateui import RetranslateMixin from retranslateui import RetranslateMixin
from tr import _translate from tr import _translate
from uisignaler import UISignaler from uisignaler import UISignaler
@ -34,8 +31,6 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
header.setSortIndicator(0, QtCore.Qt.AscendingOrder) header.setSortIndicator(0, QtCore.Qt.AscendingOrder)
self.startup = time.localtime() self.startup = time.localtime()
self.labelStartupTime.setText(_translate("networkstatus", "Since startup on %1").arg(
l10n.formatTimestamp(self.startup)))
self.UISignalThread = UISignaler.get() self.UISignalThread = UISignaler.get()
# pylint: disable=no-member # pylint: disable=no-member
@ -96,8 +91,8 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
"Object(s) to be synced: %n", "Object(s) to be synced: %n",
None, None,
QtCore.QCoreApplication.CodecForTr, QtCore.QCoreApplication.CodecForTr,
network.stats.pendingDownload() + network.stats.pendingDownload()
network.stats.pendingUpload())) + network.stats.pendingUpload()))
def updateNumberOfMessagesProcessed(self): def updateNumberOfMessagesProcessed(self):
"""Update the counter for number of processed messages""" """Update the counter for number of processed messages"""
@ -108,7 +103,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
"Processed %n person-to-person message(s).", "Processed %n person-to-person message(s).",
None, None,
QtCore.QCoreApplication.CodecForTr, QtCore.QCoreApplication.CodecForTr,
shared.numberOfMessagesProcessed)) state.numberOfMessagesProcessed))
def updateNumberOfBroadcastsProcessed(self): def updateNumberOfBroadcastsProcessed(self):
"""Update the counter for the number of processed broadcasts""" """Update the counter for the number of processed broadcasts"""
@ -119,7 +114,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
"Processed %n broadcast message(s).", "Processed %n broadcast message(s).",
None, None,
QtCore.QCoreApplication.CodecForTr, QtCore.QCoreApplication.CodecForTr,
shared.numberOfBroadcastsProcessed)) state.numberOfBroadcastsProcessed))
def updateNumberOfPubkeysProcessed(self): def updateNumberOfPubkeysProcessed(self):
"""Update the counter for the number of processed pubkeys""" """Update the counter for the number of processed pubkeys"""
@ -130,7 +125,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
"Processed %n public key(s).", "Processed %n public key(s).",
None, None,
QtCore.QCoreApplication.CodecForTr, QtCore.QCoreApplication.CodecForTr,
shared.numberOfPubkeysProcessed)) state.numberOfPubkeysProcessed))
def updateNumberOfBytes(self): def updateNumberOfBytes(self):
""" """
@ -207,7 +202,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
self.tableWidgetConnectionCount.item(0, 0).setData(QtCore.Qt.UserRole, destination) self.tableWidgetConnectionCount.item(0, 0).setData(QtCore.Qt.UserRole, destination)
self.tableWidgetConnectionCount.item(0, 1).setData(QtCore.Qt.UserRole, outbound) self.tableWidgetConnectionCount.item(0, 1).setData(QtCore.Qt.UserRole, outbound)
else: else:
if len(BMConnectionPool().inboundConnections) == 0: if not BMConnectionPool().inboundConnections:
self.window().setStatusIcon('yellow') self.window().setStatusIcon('yellow')
for i in range(self.tableWidgetConnectionCount.rowCount()): for i in range(self.tableWidgetConnectionCount.rowCount()):
if self.tableWidgetConnectionCount.item(i, 0).data(QtCore.Qt.UserRole).toPyObject() != destination: if self.tableWidgetConnectionCount.item(i, 0).data(QtCore.Qt.UserRole).toPyObject() != destination:
@ -225,9 +220,9 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
# FYI: The 'singlelistener' thread sets the icon color to green when it # FYI: The 'singlelistener' thread sets the icon color to green when it
# receives an incoming connection, meaning that the user's firewall is # receives an incoming connection, meaning that the user's firewall is
# configured correctly. # configured correctly.
if self.tableWidgetConnectionCount.rowCount() and shared.statusIconColor == 'red': if self.tableWidgetConnectionCount.rowCount() and state.statusIconColor == 'red':
self.window().setStatusIcon('yellow') self.window().setStatusIcon('yellow')
elif self.tableWidgetConnectionCount.rowCount() == 0 and shared.statusIconColor != "red": elif self.tableWidgetConnectionCount.rowCount() == 0 and state.statusIconColor != "red":
self.window().setStatusIcon('red') self.window().setStatusIcon('red')
# timer driven # timer driven
@ -240,6 +235,15 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
self.updateNumberOfObjectsToBeSynced() self.updateNumberOfObjectsToBeSynced()
def retranslateUi(self): def retranslateUi(self):
"""Conventional Qt Designer method for dynamic l10n"""
super(NetworkStatus, self).retranslateUi() super(NetworkStatus, self).retranslateUi()
self.labelStartupTime.setText(_translate("networkstatus", "Since startup on %1").arg( self.labelTotalConnections.setText(
l10n.formatTimestamp(self.startup))) _translate(
"networkstatus", "Total Connections: %1").arg(
str(self.tableWidgetConnectionCount.rowCount())))
self.labelStartupTime.setText(_translate(
"networkstatus", "Since startup on %1"
).arg(l10n.formatTimestamp(self.startup)))
self.updateNumberOfMessagesProcessed()
self.updateNumberOfBroadcastsProcessed()
self.updateNumberOfPubkeysProcessed()

View File

@ -1,354 +0,0 @@
#!/usr/bin/env python2.7
from PyQt4 import QtCore, QtGui
class NewAddressWizardIntroPage(QtGui.QWizardPage):
def __init__(self):
super(QtGui.QWizardPage, self).__init__()
self.setTitle("Creating a new address")
label = QtGui.QLabel("This wizard will help you create as many addresses as you like. Indeed, creating and abandoning addresses is encouraged.\n\n"
"What type of address would you like? Would you like to send emails or not?\n"
"You can still change your mind later, and register/unregister with an email service provider.\n\n")
label.setWordWrap(True)
self.emailAsWell = QtGui.QRadioButton("Combined email and bitmessage address")
self.onlyBM = QtGui.QRadioButton("Bitmessage-only address (no email)")
self.emailAsWell.setChecked(True)
self.registerField("emailAsWell", self.emailAsWell)
self.registerField("onlyBM", self.onlyBM)
layout = QtGui.QVBoxLayout()
layout.addWidget(label)
layout.addWidget(self.emailAsWell)
layout.addWidget(self.onlyBM)
self.setLayout(layout)
def nextId(self):
if self.emailAsWell.isChecked():
return 4
else:
return 1
class NewAddressWizardRngPassphrasePage(QtGui.QWizardPage):
def __init__(self):
super(QtGui.QWizardPage, self).__init__()
self.setTitle("Random or Passphrase")
label = QtGui.QLabel("<html><head/><body><p>You may generate addresses by using either random numbers or by using a passphrase. "
"If you use a passphrase, the address is called a &quot;deterministic&quot; address. "
"The \'Random Number\' option is selected by default but deterministic addresses have several pros and cons:</p>"
"<table border=0><tr><td><span style=\" font-weight:600;\">Pros:</span></td><td><span style=\" font-weight:600;\">Cons:</span></td></tr>"
"<tr><td>You can recreate your addresses on any computer from memory. "
"You need-not worry about backing up your keys.dat file as long as you can remember your passphrase.</td>"
"<td>You must remember (or write down) your passphrase if you expect to be able "
"to recreate your keys if they are lost. "
# "You must remember the address version number and the stream number along with your passphrase. "
"If you choose a weak passphrase and someone on the Internet can brute-force it, they can read your messages and send messages as you."
"</p></body></html>")
label.setWordWrap(True)
self.randomAddress = QtGui.QRadioButton("Use a random number generator to make an address")
self.deterministicAddress = QtGui.QRadioButton("Use a passphrase to make an address")
self.randomAddress.setChecked(True)
layout = QtGui.QVBoxLayout()
layout.addWidget(label)
layout.addWidget(self.randomAddress)
layout.addWidget(self.deterministicAddress)
self.setLayout(layout)
def nextId(self):
if self.randomAddress.isChecked():
return 2
else:
return 3
class NewAddressWizardRandomPage(QtGui.QWizardPage):
def __init__(self, addresses):
super(QtGui.QWizardPage, self).__init__()
self.setTitle("Random")
label = QtGui.QLabel("Random address.")
label.setWordWrap(True)
labelLabel = QtGui.QLabel("Label (not shown to anyone except you):")
self.labelLineEdit = QtGui.QLineEdit()
self.radioButtonMostAvailable = QtGui.QRadioButton("Use the most available stream\n"
"(best if this is the first of many addresses you will create)")
self.radioButtonExisting = QtGui.QRadioButton("Use the same stream as an existing address\n"
"(saves you some bandwidth and processing power)")
self.radioButtonMostAvailable.setChecked(True)
self.comboBoxExisting = QtGui.QComboBox()
self.comboBoxExisting.setEnabled(False)
self.comboBoxExisting.setEditable(True)
for address in addresses:
self.comboBoxExisting.addItem(address)
# self.comboBoxExisting.setObjectName(_fromUtf8("comboBoxExisting"))
self.checkBoxEighteenByteRipe = QtGui.QCheckBox("Spend several minutes of extra computing time to make the address(es) 1 or 2 characters shorter")
layout = QtGui.QGridLayout()
layout.addWidget(label, 0, 0)
layout.addWidget(labelLabel, 1, 0)
layout.addWidget(self.labelLineEdit, 2, 0)
layout.addWidget(self.radioButtonMostAvailable, 3, 0)
layout.addWidget(self.radioButtonExisting, 4, 0)
layout.addWidget(self.comboBoxExisting, 5, 0)
layout.addWidget(self.checkBoxEighteenByteRipe, 6, 0)
self.setLayout(layout)
QtCore.QObject.connect(self.radioButtonExisting, QtCore.SIGNAL("toggled(bool)"), self.comboBoxExisting.setEnabled)
self.registerField("label", self.labelLineEdit)
self.registerField("radioButtonMostAvailable", self.radioButtonMostAvailable)
self.registerField("radioButtonExisting", self.radioButtonExisting)
self.registerField("comboBoxExisting", self.comboBoxExisting)
# self.emailAsWell = QtGui.QRadioButton("Combined email and bitmessage account")
# self.onlyBM = QtGui.QRadioButton("Bitmessage-only account (no email)")
# self.emailAsWell.setChecked(True)
def nextId(self):
return 6
class NewAddressWizardPassphrasePage(QtGui.QWizardPage):
def __init__(self):
super(QtGui.QWizardPage, self).__init__()
self.setTitle("Passphrase")
label = QtGui.QLabel("Deterministric address.")
label.setWordWrap(True)
passphraseLabel = QtGui.QLabel("Passphrase")
self.lineEditPassphrase = QtGui.QLineEdit()
self.lineEditPassphrase.setEchoMode(QtGui.QLineEdit.Password)
self.lineEditPassphrase.setInputMethodHints(QtCore.Qt.ImhHiddenText|QtCore.Qt.ImhNoAutoUppercase|QtCore.Qt.ImhNoPredictiveText)
retypePassphraseLabel = QtGui.QLabel("Retype passphrase")
self.lineEditPassphraseAgain = QtGui.QLineEdit()
self.lineEditPassphraseAgain.setEchoMode(QtGui.QLineEdit.Password)
numberLabel = QtGui.QLabel("Number of addresses to make based on your passphrase:")
self.spinBoxNumberOfAddressesToMake = QtGui.QSpinBox()
self.spinBoxNumberOfAddressesToMake.setMinimum(1)
self.spinBoxNumberOfAddressesToMake.setProperty("value", 8)
# self.spinBoxNumberOfAddressesToMake.setObjectName(_fromUtf8("spinBoxNumberOfAddressesToMake"))
label2 = QtGui.QLabel("In addition to your passphrase, you must remember these numbers:")
label3 = QtGui.QLabel("Address version number: 4")
label4 = QtGui.QLabel("Stream number: 1")
layout = QtGui.QGridLayout()
layout.addWidget(label, 0, 0, 1, 4)
layout.addWidget(passphraseLabel, 1, 0, 1, 4)
layout.addWidget(self.lineEditPassphrase, 2, 0, 1, 4)
layout.addWidget(retypePassphraseLabel, 3, 0, 1, 4)
layout.addWidget(self.lineEditPassphraseAgain, 4, 0, 1, 4)
layout.addWidget(numberLabel, 5, 0, 1, 3)
layout.addWidget(self.spinBoxNumberOfAddressesToMake, 5, 3)
layout.setColumnMinimumWidth(3, 1)
layout.addWidget(label2, 6, 0, 1, 4)
layout.addWidget(label3, 7, 0, 1, 2)
layout.addWidget(label4, 7, 2, 1, 2)
self.setLayout(layout)
def nextId(self):
return 6
class NewAddressWizardEmailProviderPage(QtGui.QWizardPage):
def __init__(self):
super(QtGui.QWizardPage, self).__init__()
self.setTitle("Choose email provider")
label = QtGui.QLabel("Currently only Mailchuck email gateway is available "
"(@mailchuck.com email address). In the future, maybe other gateways will be available. "
"Press Next.")
label.setWordWrap(True)
# self.mailchuck = QtGui.QRadioButton("Mailchuck email gateway (@mailchuck.com)")
# self.mailchuck.setChecked(True)
layout = QtGui.QVBoxLayout()
layout.addWidget(label)
# layout.addWidget(self.mailchuck)
self.setLayout(layout)
def nextId(self):
return 5
class NewAddressWizardEmailAddressPage(QtGui.QWizardPage):
def __init__(self):
super(QtGui.QWizardPage, self).__init__()
self.setTitle("Email address")
label = QtGui.QLabel("Choosing an email address. Address must end with @mailchuck.com")
label.setWordWrap(True)
self.specificEmail = QtGui.QRadioButton("Pick your own email address:")
self.specificEmail.setChecked(True)
self.emailLineEdit = QtGui.QLineEdit()
self.randomEmail = QtGui.QRadioButton("Generate a random email address")
QtCore.QObject.connect(self.specificEmail, QtCore.SIGNAL("toggled(bool)"), self.emailLineEdit.setEnabled)
layout = QtGui.QVBoxLayout()
layout.addWidget(label)
layout.addWidget(self.specificEmail)
layout.addWidget(self.emailLineEdit)
layout.addWidget(self.randomEmail)
self.setLayout(layout)
def nextId(self):
return 6
class NewAddressWizardWaitPage(QtGui.QWizardPage):
def __init__(self):
super(QtGui.QWizardPage, self).__init__()
self.setTitle("Wait")
self.label = QtGui.QLabel("Wait!")
self.label.setWordWrap(True)
self.progressBar = QtGui.QProgressBar()
self.progressBar.setMinimum(0)
self.progressBar.setMaximum(100)
self.progressBar.setValue(0)
# self.emailAsWell = QtGui.QRadioButton("Combined email and bitmessage account")
# self.onlyBM = QtGui.QRadioButton("Bitmessage-only account (no email)")
# self.emailAsWell.setChecked(True)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.label)
layout.addWidget(self.progressBar)
# layout.addWidget(self.emailAsWell)
# layout.addWidget(self.onlyBM)
self.setLayout(layout)
def update(self, i):
if i == 101 and self.wizard().currentId() == 6:
self.wizard().button(QtGui.QWizard.NextButton).click()
return
elif i == 101:
print "haha"
return
self.progressBar.setValue(i)
if i == 50:
self.emit(QtCore.SIGNAL('completeChanged()'))
def isComplete(self):
# print "val = " + str(self.progressBar.value())
if self.progressBar.value() >= 50:
return True
else:
return False
def initializePage(self):
if self.field("emailAsWell").toBool():
val = "yes/"
else:
val = "no/"
if self.field("onlyBM").toBool():
val += "yes"
else:
val += "no"
self.label.setText("Wait! " + val)
# self.wizard().button(QtGui.QWizard.NextButton).setEnabled(False)
self.progressBar.setValue(0)
self.thread = NewAddressThread()
self.connect(self.thread, self.thread.signal, self.update)
self.thread.start()
def nextId(self):
return 10
class NewAddressWizardConclusionPage(QtGui.QWizardPage):
def __init__(self):
super(QtGui.QWizardPage, self).__init__()
self.setTitle("All done!")
label = QtGui.QLabel("You successfully created a new address.")
label.setWordWrap(True)
layout = QtGui.QVBoxLayout()
layout.addWidget(label)
self.setLayout(layout)
class Ui_NewAddressWizard(QtGui.QWizard):
def __init__(self, addresses):
super(QtGui.QWizard, self).__init__()
self.pages = {}
page = NewAddressWizardIntroPage()
self.setPage(0, page)
self.setStartId(0)
page = NewAddressWizardRngPassphrasePage()
self.setPage(1, page)
page = NewAddressWizardRandomPage(addresses)
self.setPage(2, page)
page = NewAddressWizardPassphrasePage()
self.setPage(3, page)
page = NewAddressWizardEmailProviderPage()
self.setPage(4, page)
page = NewAddressWizardEmailAddressPage()
self.setPage(5, page)
page = NewAddressWizardWaitPage()
self.setPage(6, page)
page = NewAddressWizardConclusionPage()
self.setPage(10, page)
self.setWindowTitle("New address wizard")
self.adjustSize()
self.show()
class NewAddressThread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
self.signal = QtCore.SIGNAL("signal")
def __del__(self):
self.wait()
def createDeterministic(self):
pass
def createPassphrase(self):
pass
def broadcastAddress(self):
pass
def registerMailchuck(self):
pass
def waitRegistration(self):
pass
def run(self):
import time
for i in range(1, 101):
time.sleep(0.1) # artificial time delay
self.emit(self.signal, i)
self.emit(self.signal, 101)
# self.terminate()
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
wizard = Ui_NewAddressWizard(["a", "b", "c", "d"])
if (wizard.exec_()):
print "Email: " + ("yes" if wizard.field("emailAsWell").toBool() else "no")
print "BM: " + ("yes" if wizard.field("onlyBM").toBool() else "no")
else:
print "Wizard cancelled"
sys.exit()

View File

@ -9,13 +9,13 @@ from PyQt4 import QtCore, QtGui
import widgets import widgets
from addresses import addBMIfNotPresent from addresses import addBMIfNotPresent
from addressvalidator import AddressValidator, PassPhraseValidator from addressvalidator import AddressValidator, PassPhraseValidator
from queues import UISignalQueue, addressGeneratorQueue, apiAddressGeneratorReturnQueue from queues import (
from retranslateui import RetranslateMixin addressGeneratorQueue, apiAddressGeneratorReturnQueue, UISignalQueue)
from tr import _translate from tr import _translate
from utils import str_chan from utils import str_chan
class NewChanDialog(QtGui.QDialog, RetranslateMixin): class NewChanDialog(QtGui.QDialog):
"""The `New Chan` dialog""" """The `New Chan` dialog"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(NewChanDialog, self).__init__(parent) super(NewChanDialog, self).__init__(parent)

View File

@ -65,6 +65,8 @@ class SafeHTMLParser(HTMLParser):
HTMLParser.__init__(self, *args, **kwargs) HTMLParser.__init__(self, *args, **kwargs)
self.reset() self.reset()
self.reset_safe() self.reset_safe()
self.has_html = None
self.allow_picture = None
def reset_safe(self): def reset_safe(self):
"""Reset runtime variables specific to this class""" """Reset runtime variables specific to this class"""
@ -92,7 +94,7 @@ class SafeHTMLParser(HTMLParser):
if url.scheme not in self.src_schemes: if url.scheme not in self.src_schemes:
val = "" val = ""
self.sanitised += " " + quote_plus(attr) self.sanitised += " " + quote_plus(attr)
if not (val is None): if val is not None:
self.sanitised += "=\"" + val + "\"" self.sanitised += "=\"" + val + "\""
if inspect.stack()[1][3] == "handle_startendtag": if inspect.stack()[1][3] == "handle_startendtag":
self.sanitised += "/" self.sanitised += "/"

View File

@ -1,25 +1,42 @@
"""
This module setting file is for settings
"""
import ConfigParser
import os import os
import sys import sys
import tempfile
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
import debug import debug
import defaults import defaults
import knownnodes
import namecoin import namecoin
import openclpow import openclpow
import paths import paths
import queues import queues
import shared
import state import state
import tempfile
import widgets import widgets
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlStoredProcedure from helper_sql import sqlExecute, sqlStoredProcedure
from helper_startup import start_proxyconfig
from network import knownnodes, AnnounceThread
from network.asyncore_pollchoose import set_rates from network.asyncore_pollchoose import set_rates
from tr import _translate from tr import _translate
def getSOCKSProxyType(config):
"""Get user socksproxytype setting from *config*"""
try:
result = ConfigParser.SafeConfigParser.get(
config, 'bitmessagesettings', 'socksproxytype')
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
return None
else:
if result.lower() in ('', 'none', 'false'):
result = None
return result
class SettingsDialog(QtGui.QDialog): class SettingsDialog(QtGui.QDialog):
"""The "Settings" dialog""" """The "Settings" dialog"""
def __init__(self, parent=None, firstrun=False): def __init__(self, parent=None, firstrun=False):
@ -32,6 +49,18 @@ class SettingsDialog(QtGui.QDialog):
self.net_restart_needed = False self.net_restart_needed = False
self.timer = QtCore.QTimer() self.timer = QtCore.QTimer()
if self.config.safeGetBoolean('bitmessagesettings', 'dontconnect'):
self.firstrun = False
try:
import pkg_resources
except ImportError:
pass
else:
# Append proxy types defined in plugins
for ep in pkg_resources.iter_entry_points(
'bitmessage.proxyconfig'):
self.comboBoxProxyType.addItem(ep.name)
self.lineEditMaxOutboundConnections.setValidator( self.lineEditMaxOutboundConnections.setValidator(
QtGui.QIntValidator(0, 8, self.lineEditMaxOutboundConnections)) QtGui.QIntValidator(0, 8, self.lineEditMaxOutboundConnections))
@ -47,20 +76,33 @@ class SettingsDialog(QtGui.QDialog):
def adjust_from_config(self, config): def adjust_from_config(self, config):
"""Adjust all widgets state according to config settings""" """Adjust all widgets state according to config settings"""
# pylint: disable=too-many-branches,too-many-statements # pylint: disable=too-many-branches,too-many-statements
self.checkBoxStartOnLogon.setChecked( if not self.parent.tray.isSystemTrayAvailable():
config.getboolean('bitmessagesettings', 'startonlogon')) self.groupBoxTray.setEnabled(False)
self.checkBoxMinimizeToTray.setChecked( self.groupBoxTray.setTitle(_translate(
config.getboolean('bitmessagesettings', 'minimizetotray')) "MainWindow", "Tray (not available in your system)"))
self.checkBoxTrayOnClose.setChecked( for setting in (
config.safeGetBoolean('bitmessagesettings', 'trayonclose')) 'minimizetotray', 'trayonclose', 'startintray'):
config.set('bitmessagesettings', setting, 'false')
else:
self.checkBoxMinimizeToTray.setChecked(
config.getboolean('bitmessagesettings', 'minimizetotray'))
self.checkBoxTrayOnClose.setChecked(
config.safeGetBoolean('bitmessagesettings', 'trayonclose'))
self.checkBoxStartInTray.setChecked(
config.getboolean('bitmessagesettings', 'startintray'))
self.checkBoxHideTrayConnectionNotifications.setChecked( self.checkBoxHideTrayConnectionNotifications.setChecked(
config.getboolean("bitmessagesettings", "hidetrayconnectionnotifications")) config.getboolean(
'bitmessagesettings', 'hidetrayconnectionnotifications'))
self.checkBoxShowTrayNotifications.setChecked( self.checkBoxShowTrayNotifications.setChecked(
config.getboolean('bitmessagesettings', 'showtraynotifications')) config.getboolean('bitmessagesettings', 'showtraynotifications'))
self.checkBoxStartInTray.setChecked(
config.getboolean('bitmessagesettings', 'startintray')) self.checkBoxStartOnLogon.setChecked(
config.getboolean('bitmessagesettings', 'startonlogon'))
self.checkBoxWillinglySendToMobile.setChecked( self.checkBoxWillinglySendToMobile.setChecked(
config.safeGetBoolean('bitmessagesettings', 'willinglysendtomobile')) config.safeGetBoolean(
'bitmessagesettings', 'willinglysendtomobile'))
self.checkBoxUseIdenticons.setChecked( self.checkBoxUseIdenticons.setChecked(
config.safeGetBoolean('bitmessagesettings', 'useidenticons')) config.safeGetBoolean('bitmessagesettings', 'useidenticons'))
self.checkBoxReplyBelow.setChecked( self.checkBoxReplyBelow.setChecked(
@ -73,28 +115,31 @@ class SettingsDialog(QtGui.QDialog):
tempfile.NamedTemporaryFile( tempfile.NamedTemporaryFile(
dir=paths.lookupExeFolder(), delete=True dir=paths.lookupExeFolder(), delete=True
).close() # should autodelete ).close() # should autodelete
except: except Exception:
self.checkBoxPortableMode.setDisabled(True) self.checkBoxPortableMode.setDisabled(True)
if 'darwin' in sys.platform: if 'darwin' in sys.platform:
self.checkBoxStartOnLogon.setDisabled(True)
self.checkBoxStartOnLogon.setText(_translate(
"MainWindow", "Start-on-login not yet supported on your OS."))
self.checkBoxMinimizeToTray.setDisabled(True) self.checkBoxMinimizeToTray.setDisabled(True)
self.checkBoxMinimizeToTray.setText(_translate( self.checkBoxMinimizeToTray.setText(_translate(
"MainWindow", "Minimize-to-tray not yet supported on your OS.")) "MainWindow",
"Minimize-to-tray not yet supported on your OS."))
self.checkBoxShowTrayNotifications.setDisabled(True) self.checkBoxShowTrayNotifications.setDisabled(True)
self.checkBoxShowTrayNotifications.setText(_translate( self.checkBoxShowTrayNotifications.setText(_translate(
"MainWindow", "Tray notifications not yet supported on your OS.")) "MainWindow",
elif 'linux' in sys.platform: "Tray notifications not yet supported on your OS."))
if 'win' not in sys.platform and not self.parent.desktop:
self.checkBoxStartOnLogon.setDisabled(True) self.checkBoxStartOnLogon.setDisabled(True)
self.checkBoxStartOnLogon.setText(_translate( self.checkBoxStartOnLogon.setText(_translate(
"MainWindow", "Start-on-login not yet supported on your OS.")) "MainWindow", "Start-on-login not yet supported on your OS."))
# On the Network settings tab: # On the Network settings tab:
self.lineEditTCPPort.setText(str( self.lineEditTCPPort.setText(str(
config.get('bitmessagesettings', 'port'))) config.get('bitmessagesettings', 'port')))
self.checkBoxUPnP.setChecked( self.checkBoxUPnP.setChecked(
config.safeGetBoolean('bitmessagesettings', 'upnp')) config.safeGetBoolean('bitmessagesettings', 'upnp'))
self.checkBoxUDP.setChecked(
config.safeGetBoolean('bitmessagesettings', 'udp'))
self.checkBoxAuthentication.setChecked( self.checkBoxAuthentication.setChecked(
config.getboolean('bitmessagesettings', 'socksauthentication')) config.getboolean('bitmessagesettings', 'socksauthentication'))
self.checkBoxSocksListen.setChecked( self.checkBoxSocksListen.setChecked(
@ -102,21 +147,11 @@ class SettingsDialog(QtGui.QDialog):
self.checkBoxOnionOnly.setChecked( self.checkBoxOnionOnly.setChecked(
config.safeGetBoolean('bitmessagesettings', 'onionservicesonly')) config.safeGetBoolean('bitmessagesettings', 'onionservicesonly'))
proxy_type = config.safeGet( self._proxy_type = getSOCKSProxyType(config)
'bitmessagesettings', 'socksproxytype', 'none') self.comboBoxProxyType.setCurrentIndex(
if proxy_type == 'none': 0 if not self._proxy_type
self.comboBoxProxyType.setCurrentIndex(0) else self.comboBoxProxyType.findText(self._proxy_type))
self.lineEditSocksHostname.setEnabled(False) self.comboBoxProxyTypeChanged(self.comboBoxProxyType.currentIndex())
self.lineEditSocksPort.setEnabled(False)
self.lineEditSocksUsername.setEnabled(False)
self.lineEditSocksPassword.setEnabled(False)
self.checkBoxAuthentication.setEnabled(False)
self.checkBoxSocksListen.setEnabled(False)
self.checkBoxOnionOnly.setEnabled(False)
elif proxy_type == 'SOCKS4a':
self.comboBoxProxyType.setCurrentIndex(1)
elif proxy_type == 'SOCKS5':
self.comboBoxProxyType.setCurrentIndex(2)
self.lineEditSocksHostname.setText( self.lineEditSocksHostname.setText(
config.get('bitmessagesettings', 'sockshostname')) config.get('bitmessagesettings', 'sockshostname'))
@ -204,7 +239,7 @@ class SettingsDialog(QtGui.QDialog):
self.checkBoxAuthentication.setEnabled(False) self.checkBoxAuthentication.setEnabled(False)
self.checkBoxSocksListen.setEnabled(False) self.checkBoxSocksListen.setEnabled(False)
self.checkBoxOnionOnly.setEnabled(False) self.checkBoxOnionOnly.setEnabled(False)
elif comboBoxIndex in (1, 2): else:
self.lineEditSocksHostname.setEnabled(True) self.lineEditSocksHostname.setEnabled(True)
self.lineEditSocksPort.setEnabled(True) self.lineEditSocksPort.setEnabled(True)
self.checkBoxAuthentication.setEnabled(True) self.checkBoxAuthentication.setEnabled(True)
@ -293,7 +328,8 @@ class SettingsDialog(QtGui.QDialog):
self.lineEditTCPPort.text()): self.lineEditTCPPort.text()):
self.config.set( self.config.set(
'bitmessagesettings', 'port', str(self.lineEditTCPPort.text())) 'bitmessagesettings', 'port', str(self.lineEditTCPPort.text()))
if not self.config.safeGetBoolean('bitmessagesettings', 'dontconnect'): if not self.config.safeGetBoolean(
'bitmessagesettings', 'dontconnect'):
self.net_restart_needed = True self.net_restart_needed = True
if self.checkBoxUPnP.isChecked() != self.config.safeGetBoolean( if self.checkBoxUPnP.isChecked() != self.config.safeGetBoolean(
@ -306,27 +342,39 @@ class SettingsDialog(QtGui.QDialog):
upnpThread = upnp.uPnPThread() upnpThread = upnp.uPnPThread()
upnpThread.start() upnpThread.start()
proxy_type = self.config.safeGet( udp_enabled = self.checkBoxUDP.isChecked()
'bitmessagesettings', 'socksproxytype', 'none') if udp_enabled != self.config.safeGetBoolean(
if ( 'bitmessagesettings', 'udp'):
proxy_type == 'none' and self.config.set('bitmessagesettings', 'udp', str(udp_enabled))
self.comboBoxProxyType.currentText()[0:5] == 'SOCKS' and if udp_enabled:
shared.statusIconColor != 'red' announceThread = AnnounceThread()
): announceThread.daemon = True
self.net_restart_needed = True announceThread.start()
if ( else:
proxy_type[0:5] == 'SOCKS' and try:
self.comboBoxProxyType.currentText()[0:5] != 'SOCKS' state.announceThread.stopThread()
): except AttributeError:
pass
proxytype_index = self.comboBoxProxyType.currentIndex()
if proxytype_index == 0:
if self._proxy_type and state.statusIconColor != 'red':
self.net_restart_needed = True
elif state.statusIconColor == 'red' and self.config.safeGetBoolean(
'bitmessagesettings', 'dontconnect'):
self.net_restart_needed = False
elif self.comboBoxProxyType.currentText() != self._proxy_type:
self.net_restart_needed = True self.net_restart_needed = True
self.parent.statusbar.clearMessage() self.parent.statusbar.clearMessage()
self.config.set( self.config.set(
'bitmessagesettings', 'socksproxytype', 'bitmessagesettings', 'socksproxytype',
str(self.comboBoxProxyType.currentText()) 'none' if self.comboBoxProxyType.currentIndex() == 0
if self.comboBoxProxyType.currentText()[0:5] == 'SOCKS' else str(self.comboBoxProxyType.currentText())
else 'none'
) )
if proxytype_index > 2: # last literal proxytype in ui
start_proxyconfig()
self.config.set('bitmessagesettings', 'socksauthentication', str( self.config.set('bitmessagesettings', 'socksauthentication', str(
self.checkBoxAuthentication.isChecked())) self.checkBoxAuthentication.isChecked()))
self.config.set('bitmessagesettings', 'sockshostname', str( self.config.set('bitmessagesettings', 'sockshostname', str(
@ -339,8 +387,11 @@ class SettingsDialog(QtGui.QDialog):
self.lineEditSocksPassword.text())) self.lineEditSocksPassword.text()))
self.config.set('bitmessagesettings', 'sockslisten', str( self.config.set('bitmessagesettings', 'sockslisten', str(
self.checkBoxSocksListen.isChecked())) self.checkBoxSocksListen.isChecked()))
if self.checkBoxOnionOnly.isChecked() \ if (
and not self.config.safeGetBoolean('bitmessagesettings', 'onionservicesonly'): self.checkBoxOnionOnly.isChecked()
and not self.config.safeGetBoolean(
'bitmessagesettings', 'onionservicesonly')
):
self.net_restart_needed = True self.net_restart_needed = True
self.config.set('bitmessagesettings', 'onionservicesonly', str( self.config.set('bitmessagesettings', 'onionservicesonly', str(
self.checkBoxOnionOnly.isChecked())) self.checkBoxOnionOnly.isChecked()))
@ -383,14 +434,14 @@ class SettingsDialog(QtGui.QDialog):
self.config.set( self.config.set(
'bitmessagesettings', 'defaultnoncetrialsperbyte', 'bitmessagesettings', 'defaultnoncetrialsperbyte',
str(int( str(int(
float(self.lineEditTotalDifficulty.text()) * float(self.lineEditTotalDifficulty.text())
defaults.networkDefaultProofOfWorkNonceTrialsPerByte))) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
if float(self.lineEditSmallMessageDifficulty.text()) >= 1: if float(self.lineEditSmallMessageDifficulty.text()) >= 1:
self.config.set( self.config.set(
'bitmessagesettings', 'defaultpayloadlengthextrabytes', 'bitmessagesettings', 'defaultpayloadlengthextrabytes',
str(int( str(int(
float(self.lineEditSmallMessageDifficulty.text()) * float(self.lineEditSmallMessageDifficulty.text())
defaults.networkDefaultPayloadLengthExtraBytes))) * defaults.networkDefaultPayloadLengthExtraBytes)))
if self.comboBoxOpenCL.currentText().toUtf8() != self.config.safeGet( if self.comboBoxOpenCL.currentText().toUtf8() != self.config.safeGet(
'bitmessagesettings', 'opencl'): 'bitmessagesettings', 'opencl'):
@ -402,40 +453,38 @@ class SettingsDialog(QtGui.QDialog):
acceptableDifficultyChanged = False acceptableDifficultyChanged = False
if ( if (
float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1 or float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1
float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0 or float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0
): ):
if self.config.get( if self.config.get(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte' 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte'
) != str(int( ) != str(int(
float(self.lineEditMaxAcceptableTotalDifficulty.text()) * float(self.lineEditMaxAcceptableTotalDifficulty.text())
defaults.networkDefaultProofOfWorkNonceTrialsPerByte) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)):
):
# the user changed the max acceptable total difficulty # the user changed the max acceptable total difficulty
acceptableDifficultyChanged = True acceptableDifficultyChanged = True
self.config.set( self.config.set(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte', 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte',
str(int( str(int(
float(self.lineEditMaxAcceptableTotalDifficulty.text()) * float(self.lineEditMaxAcceptableTotalDifficulty.text())
defaults.networkDefaultProofOfWorkNonceTrialsPerByte)) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte))
) )
if ( if (
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0 or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0
): ):
if self.config.get( if self.config.get(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes' 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes'
) != str(int( ) != str(int(
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) * float(self.lineEditMaxAcceptableSmallMessageDifficulty.text())
defaults.networkDefaultPayloadLengthExtraBytes) * defaults.networkDefaultPayloadLengthExtraBytes)):
):
# the user changed the max acceptable small message difficulty # the user changed the max acceptable small message difficulty
acceptableDifficultyChanged = True acceptableDifficultyChanged = True
self.config.set( self.config.set(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes',
str(int( str(int(
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) * float(self.lineEditMaxAcceptableSmallMessageDifficulty.text())
defaults.networkDefaultPayloadLengthExtraBytes)) * defaults.networkDefaultPayloadLengthExtraBytes))
) )
if acceptableDifficultyChanged: if acceptableDifficultyChanged:
# It might now be possible to send msgs which were previously # It might now be possible to send msgs which were previously
@ -448,6 +497,8 @@ class SettingsDialog(QtGui.QDialog):
" WHERE status='toodifficult'") " WHERE status='toodifficult'")
queues.workerQueue.put(('sendmessage', '')) queues.workerQueue.put(('sendmessage', ''))
stopResendingDefaults = False
# UI setting to stop trying to send messages after X days/months # UI setting to stop trying to send messages after X days/months
# I'm open to changing this UI to something else if someone has a better idea. # I'm open to changing this UI to something else if someone has a better idea.
if self.lineEditDays.text() == '' and self.lineEditMonths.text() == '': if self.lineEditDays.text() == '' and self.lineEditMonths.text() == '':
@ -455,7 +506,8 @@ class SettingsDialog(QtGui.QDialog):
# default behavior. The input is blank/blank # default behavior. The input is blank/blank
self.config.set('bitmessagesettings', 'stopresendingafterxdays', '') self.config.set('bitmessagesettings', 'stopresendingafterxdays', '')
self.config.set('bitmessagesettings', 'stopresendingafterxmonths', '') self.config.set('bitmessagesettings', 'stopresendingafterxmonths', '')
shared.maximumLengthOfTimeToBotherResendingMessages = float('inf') state.maximumLengthOfTimeToBotherResendingMessages = float('inf')
stopResendingDefaults = True
try: try:
days = float(self.lineEditDays.text()) days = float(self.lineEditDays.text())
@ -468,10 +520,10 @@ class SettingsDialog(QtGui.QDialog):
self.lineEditMonths.setText("0") self.lineEditMonths.setText("0")
months = 0.0 months = 0.0
if days >= 0 and months >= 0: if days >= 0 and months >= 0 and not stopResendingDefaults:
shared.maximumLengthOfTimeToBotherResendingMessages = \ state.maximumLengthOfTimeToBotherResendingMessages = \
days * 24 * 60 * 60 + months * 60 * 60 * 24 * 365 / 12 days * 24 * 60 * 60 + months * 60 * 60 * 24 * 365 / 12
if shared.maximumLengthOfTimeToBotherResendingMessages < 432000: if state.maximumLengthOfTimeToBotherResendingMessages < 432000:
# If the time period is less than 5 hours, we give # If the time period is less than 5 hours, we give
# zero values to all fields. No message will be sent again. # zero values to all fields. No message will be sent again.
QtGui.QMessageBox.about( QtGui.QMessageBox.about(
@ -488,7 +540,7 @@ class SettingsDialog(QtGui.QDialog):
'bitmessagesettings', 'stopresendingafterxdays', '0') 'bitmessagesettings', 'stopresendingafterxdays', '0')
self.config.set( self.config.set(
'bitmessagesettings', 'stopresendingafterxmonths', '0') 'bitmessagesettings', 'stopresendingafterxmonths', '0')
shared.maximumLengthOfTimeToBotherResendingMessages = 0.0 state.maximumLengthOfTimeToBotherResendingMessages = 0.0
else: else:
self.config.set( self.config.set(
'bitmessagesettings', 'stopresendingafterxdays', str(days)) 'bitmessagesettings', 'stopresendingafterxdays', str(days))
@ -510,8 +562,8 @@ class SettingsDialog(QtGui.QDialog):
self.parent.updateStartOnLogon() self.parent.updateStartOnLogon()
if ( if (
state.appdata != paths.lookupExeFolder() and state.appdata != paths.lookupExeFolder()
self.checkBoxPortableMode.isChecked() and self.checkBoxPortableMode.isChecked()
): ):
# If we are NOT using portable mode now but the user selected # If we are NOT using portable mode now but the user selected
# that we should... # that we should...
@ -529,12 +581,12 @@ class SettingsDialog(QtGui.QDialog):
try: try:
os.remove(previousAppdataLocation + 'debug.log') os.remove(previousAppdataLocation + 'debug.log')
os.remove(previousAppdataLocation + 'debug.log.1') os.remove(previousAppdataLocation + 'debug.log.1')
except: except Exception:
pass pass
if ( if (
state.appdata == paths.lookupExeFolder() and state.appdata == paths.lookupExeFolder()
not self.checkBoxPortableMode.isChecked() and not self.checkBoxPortableMode.isChecked()
): ):
# If we ARE using portable mode now but the user selected # If we ARE using portable mode now but the user selected
# that we shouldn't... # that we shouldn't...
@ -552,5 +604,5 @@ class SettingsDialog(QtGui.QDialog):
try: try:
os.remove(paths.lookupExeFolder() + 'debug.log') os.remove(paths.lookupExeFolder() + 'debug.log')
os.remove(paths.lookupExeFolder() + 'debug.log.1') os.remove(paths.lookupExeFolder() + 'debug.log.1')
except: except Exception:
pass pass

View File

@ -75,7 +75,7 @@
<string>Minimize to tray</string> <string>Minimize to tray</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
@ -231,7 +231,7 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="3" column="0">
<widget class="QGroupBox" name="groupBox_3"> <widget class="QGroupBox" name="groupBox_3">
<property name="title"> <property name="title">
<string>Bandwidth limit</string> <string>Bandwidth limit</string>
@ -322,7 +322,7 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="2" column="0">
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
<string>Proxy server / Tor</string> <string>Proxy server / Tor</string>
@ -419,12 +419,12 @@
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>SOCKS4a</string> <string notr="true">SOCKS4a</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string>SOCKS5</string> <string notr="true">SOCKS5</string>
</property> </property>
</item> </item>
</widget> </widget>
@ -432,7 +432,14 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="1" column="0">
<widget class="QCheckBox" name="checkBoxUDP">
<property name="text">
<string>Announce self by UDP</string>
</property>
</widget>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Sound Module"""
# sound type constants # sound type constants
SOUND_NONE = 0 SOUND_NONE = 0
@ -12,10 +13,12 @@ SOUND_CONNECTION_GREEN = 5
# returns true if the given sound category is a connection sound # returns true if the given sound category is a connection sound
# rather than a received message sound # rather than a received message sound
def is_connection_sound(category): def is_connection_sound(category):
"""Check if sound type is related to connectivity"""
return category in ( return category in (
SOUND_CONNECTED, SOUND_CONNECTED,
SOUND_DISCONNECTED, SOUND_DISCONNECTED,
SOUND_CONNECTION_GREEN SOUND_CONNECTION_GREEN
) )
extensions = ('wav', 'mp3', 'oga') extensions = ('wav', 'mp3', 'oga')

View File

@ -1,8 +1,12 @@
from PyQt4 import QtCore, QtGui # pylint: disable=unused-argument
from Queue import Queue """Status bar Module"""
from time import time from time import time
from PyQt4 import QtGui
class BMStatusBar(QtGui.QStatusBar): class BMStatusBar(QtGui.QStatusBar):
"""Status bar with queue and priorities"""
duration = 10000 duration = 10000
deleteAfter = 60 deleteAfter = 60
@ -13,6 +17,9 @@ class BMStatusBar(QtGui.QStatusBar):
self.iterator = 0 self.iterator = 0
def timerEvent(self, event): def timerEvent(self, event):
"""an event handler which allows to queue and prioritise messages to
show in the status bar, for example if many messages come very quickly
after one another, it adds delays and so on"""
while len(self.important) > 0: while len(self.important) > 0:
self.iterator += 1 self.iterator += 1
try: try:
@ -30,9 +37,3 @@ class BMStatusBar(QtGui.QStatusBar):
self.important.append([message, time()]) self.important.append([message, time()])
self.iterator = len(self.important) - 2 self.iterator = len(self.important) - 2
self.timerEvent(None) self.timerEvent(None)
def showMessage(self, message, timeout=0):
super(BMStatusBar, self).showMessage(message, timeout)
def clearMessage(self):
super(BMStatusBar, self).clearMessage()

View File

@ -1,32 +1,43 @@
"""Composing support request message functions."""
# pylint: disable=no-member
import ctypes import ctypes
from PyQt4 import QtCore, QtGui
import ssl import ssl
import sys import sys
import time import time
from PyQt4 import QtCore
import account import account
from bmconfigparser import BMConfigParser
from debug import logger
import defaults import defaults
from foldertree import AccountMixin import network.stats
from helper_sql import *
from l10n import getTranslationLanguage
from openclpow import openclAvailable, openclEnabled
import paths import paths
import proofofwork import proofofwork
from pyelliptic.openssl import OpenSSL
import queues import queues
import network.stats
import state import state
from bmconfigparser import BMConfigParser
from foldertree import AccountMixin
from helper_sql import sqlExecute, sqlQuery
from l10n import getTranslationLanguage
from openclpow import openclEnabled
from pyelliptic.openssl import OpenSSL
from settings import getSOCKSProxyType
from version import softwareVersion from version import softwareVersion
from tr import _translate
# this is BM support address going to Peter Surda # this is BM support address going to Peter Surda
OLD_SUPPORT_ADDRESS = 'BM-2cTkCtMYkrSPwFTpgcBrMrf5d8oZwvMZWK' OLD_SUPPORT_ADDRESS = 'BM-2cTkCtMYkrSPwFTpgcBrMrf5d8oZwvMZWK'
SUPPORT_ADDRESS = 'BM-2cUdgkDDAahwPAU6oD2A7DnjqZz3hgY832' SUPPORT_ADDRESS = 'BM-2cUdgkDDAahwPAU6oD2A7DnjqZz3hgY832'
SUPPORT_LABEL = 'PyBitmessage support' SUPPORT_LABEL = _translate("Support", "PyBitmessage support")
SUPPORT_MY_LABEL = 'My new address' SUPPORT_MY_LABEL = _translate("Support", "My new address")
SUPPORT_SUBJECT = 'Support request' SUPPORT_SUBJECT = 'Support request'
SUPPORT_MESSAGE = '''You can use this message to send a report to one of the PyBitmessage core developers regarding PyBitmessage or the mailchuck.com email service. If you are using PyBitmessage involuntarily, for example because your computer was infected with ransomware, this is not an appropriate venue for resolving such issues. SUPPORT_MESSAGE = _translate("Support", '''
You can use this message to send a report to one of the PyBitmessage core \
developers regarding PyBitmessage or the mailchuck.com email service. \
If you are using PyBitmessage involuntarily, for example because \
your computer was infected with ransomware, this is not an appropriate venue \
for resolving such issues.
Please describe what you are trying to do: Please describe what you are trying to do:
@ -36,7 +47,8 @@ Please describe what happens instead:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Please write above this line and if possible, keep the information about your environment below intact. Please write above this line and if possible, keep the information about your \
environment below intact.
PyBitmessage version: {} PyBitmessage version: {}
Operating system: {} Operating system: {}
@ -51,15 +63,19 @@ Locale: {}
SOCKS: {} SOCKS: {}
UPnP: {} UPnP: {}
Connected hosts: {} Connected hosts: {}
''' ''')
def checkAddressBook(myapp): def checkAddressBook(myapp):
sqlExecute('''DELETE from addressbook WHERE address=?''', OLD_SUPPORT_ADDRESS) sqlExecute('DELETE from addressbook WHERE address=?', OLD_SUPPORT_ADDRESS)
queryreturn = sqlQuery('''SELECT * FROM addressbook WHERE address=?''', SUPPORT_ADDRESS) queryreturn = sqlQuery('SELECT * FROM addressbook WHERE address=?', SUPPORT_ADDRESS)
if queryreturn == []: if queryreturn == []:
sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', str(QtGui.QApplication.translate("Support", SUPPORT_LABEL)), SUPPORT_ADDRESS) sqlExecute(
'INSERT INTO addressbook VALUES (?,?)',
SUPPORT_LABEL.toUtf8(), SUPPORT_ADDRESS)
myapp.rerenderAddressBook() myapp.rerenderAddressBook()
def checkHasNormalAddress(): def checkHasNormalAddress():
for address in account.getSortedAccounts(): for address in account.getSortedAccounts():
acct = account.accountClass(address) acct = account.accountClass(address)
@ -67,23 +83,33 @@ def checkHasNormalAddress():
return address return address
return False return False
def createAddressIfNeeded(myapp): def createAddressIfNeeded(myapp):
if not checkHasNormalAddress(): if not checkHasNormalAddress():
queues.addressGeneratorQueue.put(('createRandomAddress', 4, 1, str(QtGui.QApplication.translate("Support", SUPPORT_MY_LABEL)), 1, "", False, defaults.networkDefaultProofOfWorkNonceTrialsPerByte, defaults.networkDefaultPayloadLengthExtraBytes)) queues.addressGeneratorQueue.put((
'createRandomAddress', 4, 1,
str(SUPPORT_MY_LABEL.toUtf8()),
1, "", False,
defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
defaults.networkDefaultPayloadLengthExtraBytes
))
while state.shutdown == 0 and not checkHasNormalAddress(): while state.shutdown == 0 and not checkHasNormalAddress():
time.sleep(.2) time.sleep(.2)
myapp.rerenderComboBoxSendFrom() myapp.rerenderComboBoxSendFrom()
return checkHasNormalAddress() return checkHasNormalAddress()
def createSupportMessage(myapp): def createSupportMessage(myapp):
checkAddressBook(myapp) checkAddressBook(myapp)
address = createAddressIfNeeded(myapp) address = createAddressIfNeeded(myapp)
if state.shutdown: if state.shutdown:
return return
myapp.ui.lineEditSubject.setText(str(QtGui.QApplication.translate("Support", SUPPORT_SUBJECT))) myapp.ui.lineEditSubject.setText(SUPPORT_SUBJECT)
addrIndex = myapp.ui.comboBoxSendFrom.findData(address, QtCore.Qt.UserRole, QtCore.Qt.MatchFixedString | QtCore.Qt.MatchCaseSensitive) addrIndex = myapp.ui.comboBoxSendFrom.findData(
if addrIndex == -1: # something is very wrong address, QtCore.Qt.UserRole,
QtCore.Qt.MatchFixedString | QtCore.Qt.MatchCaseSensitive)
if addrIndex == -1: # something is very wrong
return return
myapp.ui.comboBoxSendFrom.setCurrentIndex(addrIndex) myapp.ui.comboBoxSendFrom.setCurrentIndex(addrIndex)
myapp.ui.lineEditTo.setText(SUPPORT_ADDRESS) myapp.ui.lineEditTo.setText(SUPPORT_ADDRESS)
@ -106,8 +132,9 @@ def createSupportMessage(myapp):
pass pass
architecture = "32" if ctypes.sizeof(ctypes.c_voidp) == 4 else "64" architecture = "32" if ctypes.sizeof(ctypes.c_voidp) == 4 else "64"
pythonversion = sys.version pythonversion = sys.version
opensslversion = "%s (Python internal), %s (external for PyElliptic)" % (ssl.OPENSSL_VERSION, OpenSSL._version) opensslversion = "%s (Python internal), %s (external for PyElliptic)" % (
ssl.OPENSSL_VERSION, OpenSSL._version)
frozen = "N/A" frozen = "N/A"
if paths.frozen: if paths.frozen:
@ -118,12 +145,13 @@ def createSupportMessage(myapp):
BMConfigParser().safeGet('bitmessagesettings', 'opencl') BMConfigParser().safeGet('bitmessagesettings', 'opencl')
) if openclEnabled() else "None" ) if openclEnabled() else "None"
locale = getTranslationLanguage() locale = getTranslationLanguage()
socks = BMConfigParser().safeGet( socks = getSOCKSProxyType(BMConfigParser()) or "N/A"
'bitmessagesettings', 'socksproxytype', "N/A")
upnp = BMConfigParser().safeGet('bitmessagesettings', 'upnp', "N/A") upnp = BMConfigParser().safeGet('bitmessagesettings', 'upnp', "N/A")
connectedhosts = len(network.stats.connectedHostsList()) connectedhosts = len(network.stats.connectedHostsList())
myapp.ui.textEditMessage.setText(str(QtGui.QApplication.translate("Support", SUPPORT_MESSAGE)).format(version, os, architecture, pythonversion, opensslversion, frozen, portablemode, cpow, openclpow, locale, socks, upnp, connectedhosts)) myapp.ui.textEditMessage.setText(unicode(SUPPORT_MESSAGE, 'utf-8').format(
version, os, architecture, pythonversion, opensslversion, frozen,
portablemode, cpow, openclpow, locale, socks, upnp, connectedhosts))
# single msg tab # single msg tab
myapp.ui.tabWidgetSend.setCurrentIndex( myapp.ui.tabWidgetSend.setCurrentIndex(

View File

@ -0,0 +1,11 @@
"""bitmessageqt tests"""
from addressbook import TestAddressbook
from main import TestMain, TestUISignaler
from settings import TestSettings
from support import TestSupport
__all__ = [
"TestAddressbook", "TestMain", "TestSettings", "TestSupport",
"TestUISignaler"
]

View File

@ -0,0 +1,17 @@
import helper_addressbook
from bitmessageqt.support import createAddressIfNeeded
from main import TestBase
class TestAddressbook(TestBase):
"""Test case for addressbook"""
def test_add_own_address_to_addressbook(self):
"""Checking own address adding in addressbook"""
try:
address = createAddressIfNeeded(self.window)
self.assertFalse(
helper_addressbook.insert(label='test', address=address))
except IndexError:
self.fail("Can't generate addresses")

View File

@ -0,0 +1,60 @@
"""Common definitions for bitmessageqt tests"""
import Queue
import sys
import unittest
from PyQt4 import QtCore, QtGui
import bitmessageqt
import queues
from tr import _translate
class TestBase(unittest.TestCase):
"""Base class for bitmessageqt test case"""
def setUp(self):
self.app = (
QtGui.QApplication.instance()
or bitmessageqt.BitmessageQtApplication(sys.argv))
self.window = self.app.activeWindow()
if not self.window:
self.window = bitmessageqt.MyForm()
self.window.appIndicatorInit(self.app)
def tearDown(self):
# self.app.deleteLater()
while True:
try:
thread, exc = queues.excQueue.get(block=False)
except Queue.Empty:
return
if thread == 'tests':
self.fail('Exception in the main thread: %s' % exc)
class TestMain(unittest.TestCase):
"""Test case for main window - basic features"""
def test_translate(self):
"""Check the results of _translate() with various args"""
self.assertIsInstance(
_translate("MainWindow", "Test"),
QtCore.QString
)
class TestUISignaler(TestBase):
"""Test case for UISignalQueue"""
def test_updateStatusBar(self):
"""Check arguments order of updateStatusBar command"""
queues.UISignalQueue.put((
'updateStatusBar', (
_translate("test", "Testing updateStatusBar..."), 1)
))
QtCore.QTimer.singleShot(60, self.app.quit)
self.app.exec_()
# self.app.processEvents(QtCore.QEventLoop.AllEvents, 60)

View File

@ -0,0 +1,34 @@
import threading
import time
from main import TestBase
from bmconfigparser import BMConfigParser
from bitmessageqt import settings
class TestSettings(TestBase):
"""A test case for the "Settings" dialog"""
def setUp(self):
super(TestSettings, self).setUp()
self.dialog = settings.SettingsDialog(self.window)
def test_udp(self):
"""Test the effect of checkBoxUDP"""
udp_setting = BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'udp')
self.assertEqual(udp_setting, self.dialog.checkBoxUDP.isChecked())
self.dialog.checkBoxUDP.setChecked(not udp_setting)
self.dialog.accept()
self.assertEqual(
not udp_setting,
BMConfigParser().safeGetBoolean('bitmessagesettings', 'udp'))
time.sleep(5)
for thread in threading.enumerate():
if thread.name == 'Announcer': # find Announcer thread
if udp_setting:
self.fail(
'Announcer thread is running while udp set to False')
break
else:
if not udp_setting:
self.fail('No Announcer thread found while udp set to True')

View File

@ -0,0 +1,33 @@
# from PyQt4 import QtTest
import sys
from shared import isAddressInMyAddressBook
from main import TestBase
class TestSupport(TestBase):
"""A test case for support module"""
SUPPORT_ADDRESS = 'BM-2cUdgkDDAahwPAU6oD2A7DnjqZz3hgY832'
SUPPORT_SUBJECT = 'Support request'
def test(self):
"""trigger menu action "Contact Support" and check the result"""
ui = self.window.ui
self.assertEqual(ui.lineEditTo.text(), '')
self.assertEqual(ui.lineEditSubject.text(), '')
ui.actionSupport.trigger()
self.assertTrue(
isAddressInMyAddressBook(self.SUPPORT_ADDRESS))
self.assertEqual(
ui.tabWidget.currentIndex(), ui.tabWidget.indexOf(ui.send))
self.assertEqual(
ui.lineEditTo.text(), self.SUPPORT_ADDRESS)
self.assertEqual(
ui.lineEditSubject.text(), self.SUPPORT_SUBJECT)
self.assertIn(
sys.version, ui.textEditMessage.toPlainText())

View File

@ -1,13 +1,16 @@
from PyQt4 import QtGui
import hashlib import hashlib
import os import os
from PyQt4 import QtGui
import state
from addresses import addBMIfNotPresent from addresses import addBMIfNotPresent
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
import state
str_broadcast_subscribers = '[Broadcast subscribers]' str_broadcast_subscribers = '[Broadcast subscribers]'
str_chan = '[chan]' str_chan = '[chan]'
def identiconize(address): def identiconize(address):
size = 48 size = 48
@ -28,32 +31,40 @@ def identiconize(address):
# the identicons to decrease the risk of attacks where someone creates # the identicons to decrease the risk of attacks where someone creates
# an address to mimic someone else's identicon. # an address to mimic someone else's identicon.
identiconsuffix = BMConfigParser().get('bitmessagesettings', 'identiconsuffix') identiconsuffix = BMConfigParser().get('bitmessagesettings', 'identiconsuffix')
if (identicon_lib[:len('qidenticon')] == 'qidenticon'): if identicon_lib[:len('qidenticon')] == 'qidenticon':
# print identicon_lib
# originally by: # originally by:
# :Author:Shin Adachi <shn@glucose.jp> # :Author:Shin Adachi <shn@glucose.jp>
# Licesensed under FreeBSD License. # Licesensed under FreeBSD License.
# stripped from PIL and uses QT instead (by sendiulo, same license) # stripped from PIL and uses QT instead (by sendiulo, same license)
import qidenticon import qidenticon
hash = hashlib.md5(addBMIfNotPresent(address)+identiconsuffix).hexdigest() icon_hash = hashlib.md5(
use_two_colors = (identicon_lib[:len('qidenticon_two')] == 'qidenticon_two') addBMIfNotPresent(address) + identiconsuffix).hexdigest()
opacity = int(not((identicon_lib == 'qidenticon_x') | (identicon_lib == 'qidenticon_two_x') | (identicon_lib == 'qidenticon_b') | (identicon_lib == 'qidenticon_two_b')))*255 use_two_colors = identicon_lib[:len('qidenticon_two')] == 'qidenticon_two'
opacity = int(
identicon_lib not in (
'qidenticon_x', 'qidenticon_two_x',
'qidenticon_b', 'qidenticon_two_b'
)) * 255
penwidth = 0 penwidth = 0
image = qidenticon.render_identicon(int(hash, 16), size, use_two_colors, opacity, penwidth) image = qidenticon.render_identicon(
int(icon_hash, 16), size, use_two_colors, opacity, penwidth)
# filename = './images/identicons/'+hash+'.png' # filename = './images/identicons/'+hash+'.png'
# image.save(filename) # image.save(filename)
idcon = QtGui.QIcon() idcon = QtGui.QIcon()
idcon.addPixmap(image, QtGui.QIcon.Normal, QtGui.QIcon.Off) idcon.addPixmap(image, QtGui.QIcon.Normal, QtGui.QIcon.Off)
return idcon return idcon
elif identicon_lib == 'pydenticon': elif identicon_lib == 'pydenticon':
# print identicon_lib # Here you could load pydenticon.py
# Here you could load pydenticon.py (just put it in the "src" folder of your Bitmessage source) # (just put it in the "src" folder of your Bitmessage source)
from pydenticon import Pydenticon from pydenticon import Pydenticon
# It is not included in the source, because it is licensed under GPLv3 # It is not included in the source, because it is licensed under GPLv3
# GPLv3 is a copyleft license that would influence our licensing # GPLv3 is a copyleft license that would influence our licensing
# Find the source here: http://boottunes.googlecode.com/svn-history/r302/trunk/src/pydenticon.py # Find the source here:
# note that it requires PIL to be installed: http://www.pythonware.com/products/pil/ # https://github.com/azaghal/pydenticon
idcon_render = Pydenticon(addBMIfNotPresent(address)+identiconsuffix, size*3) # note that it requires pillow (or PIL) to be installed:
# https://python-pillow.org/
idcon_render = Pydenticon(
addBMIfNotPresent(address) + identiconsuffix, size * 3)
rendering = idcon_render._render() rendering = idcon_render._render()
data = rendering.convert("RGBA").tostring("raw", "RGBA") data = rendering.convert("RGBA").tostring("raw", "RGBA")
qim = QtGui.QImage(data, size, size, QtGui.QImage.Format_ARGB32) qim = QtGui.QImage(data, size, size, QtGui.QImage.Format_ARGB32)
@ -62,32 +73,31 @@ def identiconize(address):
idcon.addPixmap(pix, QtGui.QIcon.Normal, QtGui.QIcon.Off) idcon.addPixmap(pix, QtGui.QIcon.Normal, QtGui.QIcon.Off)
return idcon return idcon
def avatarize(address): def avatarize(address):
""" """
loads a supported image for the given address' hash form 'avatars' folder Loads a supported image for the given address' hash form 'avatars' folder
falls back to default avatar if 'default.*' file exists falls back to default avatar if 'default.*' file exists
falls back to identiconize(address) falls back to identiconize(address)
""" """
idcon = QtGui.QIcon() idcon = QtGui.QIcon()
hash = hashlib.md5(addBMIfNotPresent(address)).hexdigest() icon_hash = hashlib.md5(addBMIfNotPresent(address)).hexdigest()
str_broadcast_subscribers = '[Broadcast subscribers]'
if address == str_broadcast_subscribers: if address == str_broadcast_subscribers:
# don't hash [Broadcast subscribers] # don't hash [Broadcast subscribers]
hash = address icon_hash = address
# http://pyqt.sourceforge.net/Docs/PyQt4/qimagereader.html#supportedImageFormats # https://www.riverbankcomputing.com/static/Docs/PyQt4/qimagereader.html#supportedImageFormats
# print QImageReader.supportedImageFormats ()
# QImageReader.supportedImageFormats () # QImageReader.supportedImageFormats ()
extensions = ['PNG', 'GIF', 'JPG', 'JPEG', 'SVG', 'BMP', 'MNG', 'PBM', 'PGM', 'PPM', 'TIFF', 'XBM', 'XPM', 'TGA'] extensions = [
'PNG', 'GIF', 'JPG', 'JPEG', 'SVG', 'BMP', 'MNG', 'PBM', 'PGM', 'PPM',
'TIFF', 'XBM', 'XPM', 'TGA']
# try to find a specific avatar # try to find a specific avatar
for ext in extensions: for ext in extensions:
lower_hash = state.appdata + 'avatars/' + hash + '.' + ext.lower() lower_hash = state.appdata + 'avatars/' + icon_hash + '.' + ext.lower()
upper_hash = state.appdata + 'avatars/' + hash + '.' + ext.upper() upper_hash = state.appdata + 'avatars/' + icon_hash + '.' + ext.upper()
if os.path.isfile(lower_hash): if os.path.isfile(lower_hash):
# print 'found avatar of ', address
idcon.addFile(lower_hash) idcon.addFile(lower_hash)
return idcon return idcon
elif os.path.isfile(upper_hash): elif os.path.isfile(upper_hash):
# print 'found avatar of ', address
idcon.addFile(upper_hash) idcon.addFile(upper_hash)
return idcon return idcon
# if we haven't found any, try to find a default avatar # if we haven't found any, try to find a default avatar

View File

@ -2,13 +2,22 @@
BMConfigParser class definition and default configuration settings BMConfigParser class definition and default configuration settings
""" """
import ConfigParser import sys
import shutil if sys.version_info[0] == 3:
import os # python 3
from datetime import datetime import configparser as ConfigParser
SafeConfigParser = ConfigParser.ConfigParser
else:
# python 2
import ConfigParser
SafeConfigParser = ConfigParser.SafeConfigParser
import state import state
from singleton import Singleton from singleton import Singleton
import os
import shutil
from datetime import datetime
BMConfigDefaults = { BMConfigDefaults = {
"bitmessagesettings": { "bitmessagesettings": {
@ -19,34 +28,37 @@ BMConfigDefaults = {
"maxtotalconnections": 200, "maxtotalconnections": 200,
"maxuploadrate": 0, "maxuploadrate": 0,
"apiinterface": "127.0.0.1", "apiinterface": "127.0.0.1",
"apiport": 8442 "apiport": 8442,
"udp": "True"
}, },
"threads": { "threads": {
"receive": 3, "receive": 3,
}, },
"network": { "network": {
"bind": '', "bind": "",
"dandelion": 90, "dandelion": 90,
}, },
"inventory": { "inventory": {
"storage": "sqlite", "storage": "sqlite",
"acceptmismatch": False, "acceptmismatch": "False",
}, },
"knownnodes": { "knownnodes": {
"maxnodes": 20000, "maxnodes": 20000,
}, },
"zlib": { "zlib": {
'maxsize': 1048576 "maxsize": 1048576
} }
} }
@Singleton @Singleton
class BMConfigParser(ConfigParser.SafeConfigParser): class BMConfigParser(SafeConfigParser):
""" """
Singleton class inherited from :class:`ConfigParser.SafeConfigParser` Singleton class inherited from :class:`ConfigParser.SafeConfigParser`
with additional methods specific to bitmessage config. with additional methods specific to bitmessage config.
""" """
# pylint: disable=too-many-ancestors
_temp = {} _temp = {}
@ -58,25 +70,47 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
raise ValueError("Invalid value %s" % value) raise ValueError("Invalid value %s" % value)
return ConfigParser.ConfigParser.set(self, section, option, value) return ConfigParser.ConfigParser.set(self, section, option, value)
def get(self, section, option, raw=False, variables=None): def get(self, section, option, raw=False, vars=None):
try: if sys.version_info[0] == 3:
if section == "bitmessagesettings" and option == "timeformat": # pylint: disable=arguments-differ
try:
if section == "bitmessagesettings" and option == "timeformat":
return ConfigParser.ConfigParser.get(
self, section, option)
try:
return self._temp[section][option]
except KeyError:
pass
return ConfigParser.ConfigParser.get( return ConfigParser.ConfigParser.get(
self, section, option, raw, variables) self, section, option)
except ConfigParser.InterpolationError:
return ConfigParser.ConfigParser.get(
self, section, option)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e:
try:
return BMConfigDefaults[section][option]
except (KeyError, ValueError, AttributeError):
raise e
else:
# pylint: disable=arguments-differ
try: try:
return self._temp[section][option] if section == "bitmessagesettings" and option == "timeformat":
except KeyError: return ConfigParser.ConfigParser.get(
pass self, section, option, raw, vars)
return ConfigParser.ConfigParser.get( try:
self, section, option, True, variables) return self._temp[section][option]
except ConfigParser.InterpolationError: except KeyError:
return ConfigParser.ConfigParser.get( pass
self, section, option, True, variables) return ConfigParser.ConfigParser.get(
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e: self, section, option, True, vars)
try: except ConfigParser.InterpolationError:
return BMConfigDefaults[section][option] return ConfigParser.ConfigParser.get(
except (KeyError, ValueError, AttributeError): self, section, option, True, vars)
raise e except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e:
try:
return BMConfigDefaults[section][option]
except (KeyError, ValueError, AttributeError):
raise e
def setTemp(self, section, option, value=None): def setTemp(self, section, option, value=None):
"""Temporary set option to value, not saving.""" """Temporary set option to value, not saving."""
@ -86,6 +120,7 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
self._temp[section] = {option: value} self._temp[section] = {option: value}
def safeGetBoolean(self, section, field): def safeGetBoolean(self, section, field):
"""Return value as boolean, False on exceptions"""
try: try:
return self.getboolean(section, field) return self.getboolean(section, field)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
@ -93,6 +128,8 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
return False return False
def safeGetInt(self, section, field, default=0): def safeGetInt(self, section, field, default=0):
"""Return value as integer, default on exceptions,
0 if default missing"""
try: try:
return self.getint(section, field) return self.getint(section, field)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
@ -100,6 +137,7 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
return default return default
def safeGet(self, section, option, default=None): def safeGet(self, section, option, default=None):
"""Return value as is, default on exceptions, None if default missing"""
try: try:
return self.get(section, option) return self.get(section, option)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
@ -107,13 +145,27 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
return default return default
def items(self, section, raw=False, variables=None): def items(self, section, raw=False, variables=None):
"""Return section variables as parent,
but override the "raw" argument to always True"""
# pylint: disable=arguments-differ
return ConfigParser.ConfigParser.items(self, section, True, variables) return ConfigParser.ConfigParser.items(self, section, True, variables)
def addresses(self): @staticmethod
return filter( def addresses():
lambda x: x.startswith('BM-'), BMConfigParser().sections()) """Return a list of local bitmessage addresses (from section labels)"""
return [
x for x in BMConfigParser().sections() if x.startswith('BM-')]
def _reset(self):
"""Reset current config. There doesn't appear to be a built in
method for this"""
sections = self.sections()
for x in sections:
self.remove_section(x)
def read(self, filenames): def read(self, filenames):
"""Read config and populate defaults"""
self._reset()
ConfigParser.ConfigParser.read(self, filenames) ConfigParser.ConfigParser.read(self, filenames)
for section in self.sections(): for section in self.sections():
for option in self.options(section): for option in self.options(section):
@ -132,6 +184,7 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
continue continue
def save(self): def save(self):
"""Save the runtime config onto the filesystem"""
fileName = os.path.join(state.appdata, 'keys.dat') fileName = os.path.join(state.appdata, 'keys.dat')
fileNameBak = '.'.join([ fileNameBak = '.'.join([
fileName, datetime.now().strftime("%Y%j%H%M%S%f"), 'bak']) fileName, datetime.now().strftime("%Y%j%H%M%S%f"), 'bak'])
@ -153,12 +206,15 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
os.remove(fileNameBak) os.remove(fileNameBak)
def validate(self, section, option, value): def validate(self, section, option, value):
"""Input validator interface (using factory pattern)"""
try: try:
return getattr(self, 'validate_%s_%s' % (section, option))(value) return getattr(self, 'validate_%s_%s' % (section, option))(value)
except AttributeError: except AttributeError:
return True return True
def validate_bitmessagesettings_maxoutboundconnections(self, value): @staticmethod
def validate_bitmessagesettings_maxoutboundconnections(value):
"""Reject maxoutboundconnections that are too high or too low"""
try: try:
value = int(value) value = int(value)
except ValueError: except ValueError:
@ -166,3 +222,4 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
if value < 0 or value > 8: if value < 0 or value > 8:
return False return False
return True return True

View File

@ -1,6 +1,6 @@
"""Building osx.""" """Building osx."""
from glob import glob
import os import os
from glob import glob
from PyQt4 import QtCore from PyQt4 import QtCore
from setuptools import setup from setuptools import setup
@ -13,8 +13,14 @@ DATA_FILES = [
('bitmsghash', ['bitmsghash/bitmsghash.cl', 'bitmsghash/bitmsghash.so']), ('bitmsghash', ['bitmsghash/bitmsghash.cl', 'bitmsghash/bitmsghash.so']),
('translations', glob('translations/*.qm')), ('translations', glob('translations/*.qm')),
('ui', glob('bitmessageqt/*.ui')), ('ui', glob('bitmessageqt/*.ui')),
('translations', glob(str(QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)) + '/qt_??.qm')), (
('translations', glob(str(QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)) + '/qt_??_??.qm')), 'translations',
glob(os.path.join(str(QtCore.QLibraryInfo.location(
QtCore.QLibraryInfo.TranslationsPath)), 'qt_??.qm'))),
(
'translations',
glob(os.path.join(str(QtCore.QLibraryInfo.location(
QtCore.QLibraryInfo.TranslationsPath)), 'qt_??_??.qm'))),
] ]
setup( setup(

View File

@ -1,275 +0,0 @@
[app]
# (str) Title of your application
title = PyBitmessage
# (str) Package name
package.name = PyBitmessage
# (str) Package domain (needed for android/ios packaging)
package.domain = org.test
# (str) Source code where the main.py live
source.dir = .
# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas
# (list) List of inclusions using pattern matching
#source.include_patterns = assets/*,images/*.png
# (list) Source files to exclude (let empty to not exclude anything)
#source.exclude_exts = spec
# (list) List of directory to exclude (let empty to not exclude anything)
#source.exclude_dirs = tests, bin
# (list) List of exclusions using pattern matching
#source.exclude_patterns = license,images/*/*.jpg
# (str) Application versioning (method 1)
version = 0.1
# (str) Application versioning (method 2)
# version.regex = __version__ = ['"](.*)['"]
# version.filename = %(source.dir)s/main.py
# (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy
requirements = python2, sqlite3, kivy, openssl
# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes
# requirements.source.kivy = ../../kivy
#requirements.source.sqlite3 =
# (list) Garden requirements
#garden_requirements =
# (str) Presplash of the application
#presplash.filename = %(source.dir)s/data/presplash.png
# (str) Icon of the application
#icon.filename = %(source.dir)s/data/icon.png
# (str) Supported orientation (one of landscape, portrait or all)
orientation = portrait
# (list) List of service to declare
#services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY
#
# OSX Specific
#
#
# author = © Copyright Info
# change the major version of python used by the app
#osx.python_version = 2
# Kivy version to use
osx.kivy_version = 1.9.1
#
# Android specific
#
# (bool) Indicate if the application should be fullscreen or not
fullscreen = 0
# (string) Presplash background color (for new android toolchain)
# Supported formats are: #RRGGBB #AARRGGBB or one of the following names:
# red, blue, green, black, white, gray, cyan, magenta, yellow, lightgray,
# darkgray, grey, lightgrey, darkgrey, aqua, fuchsia, lime, maroon, navy,
# olive, purple, silver, teal.
#android.presplash_color = #FFFFFF
# (list) Permissions
android.permissions = INTERNET
# (int) Android API to use
#android.api = 19
# (int) Minimum API required
#android.minapi = 9
# (int) Android SDK version to use
#android.sdk = 20
# (str) Android NDK version to use
#android.ndk = 9c
# (bool) Use --private data storage (True) or --dir public storage (False)
#android.private_storage = True
# (str) Android NDK directory (if empty, it will be automatically downloaded.)
#android.ndk_path =
# (str) Android SDK directory (if empty, it will be automatically downloaded.)
#android.sdk_path =
# (str) ANT directory (if empty, it will be automatically downloaded.)
#android.ant_path =
# (bool) If True, then skip trying to update the Android sdk
# This can be useful to avoid excess Internet downloads or save time
# when an update is due and you just want to test/build your package
# android.skip_update = False
# (str) Android entry point, default is ok for Kivy-based app
#android.entrypoint = org.renpy.android.PythonActivity
# (list) Pattern to whitelist for the whole project
#android.whitelist =
android.whitelist = /usr/lib/komodo-edit/python/lib/python2.7/lib-dynload/_sqlite3.so
# (str) Path to a custom whitelist file
#android.whitelist_src =
# (str) Path to a custom blacklist file
#android.blacklist_src =
# (list) List of Java .jar files to add to the libs so that pyjnius can access
# their classes. Don't add jars that you do not need, since extra jars can slow
# down the build process. Allows wildcards matching, for example:
# OUYA-ODK/libs/*.jar
#android.add_jars = foo.jar,bar.jar,path/to/more/*.jar
# (list) List of Java files to add to the android project (can be java or a
# directory containing the files)
#android.add_src =
# (list) Android AAR archives to add (currently works only with sdl2_gradle
# bootstrap)
#android.add_aars =
# (list) Gradle dependencies to add (currently works only with sdl2_gradle
# bootstrap)
#android.gradle_dependencies =
, /home/cis/Downloads/libssl1.0.2_1.0.2l-2+deb9u2_amd64
# (str) python-for-android branch to use, defaults to stable
#p4a.branch = stable
# (str) OUYA Console category. Should be one of GAME or APP
# If you leave this blank, OUYA support will not be enabled
#android.ouya.category = GAME
# (str) Filename of OUYA Console icon. It must be a 732x412 png image.
#android.ouya.icon.filename = %(source.dir)s/data/ouya_icon.png
# (str) XML file to include as an intent filters in <activity> tag
#android.manifest.intent_filters =
# (list) Android additionnal libraries to copy into libs/armeabi
#android.add_libs_armeabi = libs/android/*.so
#android.add_libs_armeabi_v7a = libs/android-v7/*.so
#android.add_libs_x86 = libs/android-x86/*.so
#android.add_libs_mips = libs/android-mips/*.so
# (bool) Indicate whether the screen should stay on
# Don't forget to add the WAKE_LOCK permission if you set this to True
#android.wakelock = False
# (list) Android application meta-data to set (key=value format)
#android.meta_data =
# (list) Android library project to add (will be added in the
# project.properties automatically.)
#android.library_references =
# (str) Android logcat filters to use
#android.logcat_filters = *:S python:D
# (bool) Copy library instead of making a libpymodules.so
#android.copy_libs = 1
# (str) The Android arch to build for, choices: armeabi-v7a, arm64-v8a, x86
android.arch = armeabi-v7a
#
# Python for android (p4a) specific
#
# (str) python-for-android git clone directory (if empty, it will be automatically cloned from github)
#p4a.source_dir =
# (str) The directory in which python-for-android should look for your own build recipes (if any)
#p4a.local_recipes =
# (str) Filename to the hook for p4a
#p4a.hook =
# (str) Bootstrap to use for android builds
# p4a.bootstrap = sdl2
#
# iOS specific
#
# (str) Path to a custom kivy-ios folder
#ios.kivy_ios_dir = ../kivy-ios
# (str) Name of the certificate to use for signing the debug version
# Get a list of available identities: buildozer ios list_identities
#ios.codesign.debug = "iPhone Developer: <lastname> <firstname> (<hexstring>)"
# (str) Name of the certificate to use for signing the release version
#ios.codesign.release = %(ios.codesign.debug)s
[buildozer]
# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
log_level = 2
# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
warn_on_root = 1
# (str) Path to build artifact storage, absolute or relative to spec file
# build_dir = ./.buildozer
# (str) Path to build output (i.e. .apk, .ipa) storage
# bin_dir = ./bin
# -----------------------------------------------------------------------------
# List as sections
#
# You can define all the "list" as [section:key].
# Each line will be considered as a option to the list.
# Let's take [app] / source.exclude_patterns.
# Instead of doing:
#
#[app]
#source.exclude_patterns = license,data/audio/*.wav,data/images/original/*
#
# This can be translated into:
#
#[app:source.exclude_patterns]
#license
#data/audio/*.wav
#data/images/original/*
#
# -----------------------------------------------------------------------------
# Profiles
#
# You can extend section / key with a profile
# For example, you want to deploy a demo version of your application without
# HD content. You could first change the title to add "(demo)" in the name
# and extend the excluded directories to remove the HD content.
#
#[app@demo]
#title = My Application (demo)
#
#[app:source.exclude_patterns@demo]
#images/hd/*
#
# Then, invoke the command line with the "demo" profile:
#
#buildozer --profile demo android debug

View File

@ -1,23 +1,26 @@
"""
import time A thread for creating addresses
"""
import hashlib import hashlib
import time
from binascii import hexlify from binascii import hexlify
import defaults
import highlevelcrypto
import queues
import shared
import state
import tr
from addresses import decodeAddress, encodeAddress, encodeVarint
from bmconfigparser import BMConfigParser
from fallback import RIPEMD160Hash
from network import StoppableThread
from pyelliptic import arithmetic from pyelliptic import arithmetic
from pyelliptic.openssl import OpenSSL from pyelliptic.openssl import OpenSSL
import tr
import queues
import state
import shared
import defaults
import highlevelcrypto
from bmconfigparser import BMConfigParser
from addresses import decodeAddress, encodeAddress, encodeVarint
from fallback import RIPEMD160Hash
from network import StoppableThread
class addressGenerator(StoppableThread): class addressGenerator(StoppableThread):
"""A thread for creating addresses"""
name = "addressGenerator" name = "addressGenerator"
@ -33,6 +36,8 @@ class addressGenerator(StoppableThread):
Process the requests for addresses generation Process the requests for addresses generation
from `.queues.addressGeneratorQueue` from `.queues.addressGeneratorQueue`
""" """
# pylint: disable=too-many-locals, too-many-branches
# pylint: disable=protected-access, too-many-statements
while state.shutdown == 0: while state.shutdown == 0:
queueValue = queues.addressGeneratorQueue.get() queueValue = queues.addressGeneratorQueue.get()
nonceTrialsPerByte = 0 nonceTrialsPerByte = 0
@ -212,7 +217,7 @@ class addressGenerator(StoppableThread):
elif command == 'createDeterministicAddresses' \ elif command == 'createDeterministicAddresses' \
or command == 'getDeterministicAddress' \ or command == 'getDeterministicAddress' \
or command == 'createChan' or command == 'joinChan': or command == 'createChan' or command == 'joinChan':
if len(deterministicPassphrase) == 0: if not deterministicPassphrase:
self.logger.warning( self.logger.warning(
'You are creating deterministic' 'You are creating deterministic'
' address(es) using a blank passphrase.' ' address(es) using a blank passphrase.'
@ -361,7 +366,7 @@ class addressGenerator(StoppableThread):
address) address)
shared.myECCryptorObjects[ripe] = \ shared.myECCryptorObjects[ripe] = \
highlevelcrypto.makeCryptor( highlevelcrypto.makeCryptor(
hexlify(potentialPrivEncryptionKey)) hexlify(potentialPrivEncryptionKey))
shared.myAddressesByHash[ripe] = address shared.myAddressesByHash[ripe] = address
tag = hashlib.sha512(hashlib.sha512( tag = hashlib.sha512(hashlib.sha512(
encodeVarint(addressVersionNumber) + encodeVarint(addressVersionNumber) +

View File

@ -1,33 +1,38 @@
"""
The objectProcessor thread, of which there is only one,
processes the network objects
"""
# pylint: disable=too-many-locals,too-many-return-statements
# pylint: disable=too-many-branches,too-many-statements
import hashlib import hashlib
import logging import logging
import random import random
import shared
import threading import threading
import time import time
from binascii import hexlify from binascii import hexlify
from subprocess import call # nosec from subprocess import call # nosec
import highlevelcrypto
import knownnodes
from addresses import (
calculateInventoryHash, decodeAddress, decodeVarint, encodeAddress,
encodeVarint, varintDecodeError
)
from bmconfigparser import BMConfigParser
import helper_bitcoin import helper_bitcoin
import helper_inbox import helper_inbox
import helper_msgcoding import helper_msgcoding
import helper_sent import helper_sent
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery import highlevelcrypto
from helper_ackPayload import genAckPayload import l10n
from network import bmproto
from network.node import Peer
import protocol import protocol
import queues import queues
import shared
import state import state
import tr import tr
from addresses import (
calculateInventoryHash, decodeAddress, decodeVarint,
encodeAddress, encodeVarint, varintDecodeError
)
from bmconfigparser import BMConfigParser
from fallback import RIPEMD160Hash from fallback import RIPEMD160Hash
import l10n from helper_sql import sql_ready, SqlBulkExecute, sqlExecute, sqlQuery
from network import bmproto, knownnodes
from network.node import Peer
# pylint: disable=too-many-locals, too-many-return-statements, too-many-branches, too-many-statements
logger = logging.getLogger('default') logger = logging.getLogger('default')
@ -45,6 +50,7 @@ class objectProcessor(threading.Thread):
# objectProcessorQueue. Assuming that Bitmessage wasn't closed # objectProcessorQueue. Assuming that Bitmessage wasn't closed
# forcefully, it should have saved the data in the queue into the # forcefully, it should have saved the data in the queue into the
# objectprocessorqueue table. Let's pull it out. # objectprocessorqueue table. Let's pull it out.
sql_ready.wait()
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''SELECT objecttype, data FROM objectprocessorqueue''') '''SELECT objecttype, data FROM objectprocessorqueue''')
for row in queryreturn: for row in queryreturn:
@ -122,7 +128,10 @@ class objectProcessor(threading.Thread):
state.shutdown = 2 state.shutdown = 2
break break
def checkackdata(self, data): @staticmethod
def checkackdata(data):
"""Checking Acknowledgement of message received or not?"""
# pylint: disable=protected-access
# Let's check whether this is a message acknowledgement bound for us. # Let's check whether this is a message acknowledgement bound for us.
if len(data) < 32: if len(data) < 32:
return return
@ -130,20 +139,22 @@ class objectProcessor(threading.Thread):
# bypass nonce and time, retain object type/version/stream + body # bypass nonce and time, retain object type/version/stream + body
readPosition = 16 readPosition = 16
if data[readPosition:] in shared.ackdataForWhichImWatching: if data[readPosition:] in state.ackdataForWhichImWatching:
logger.info('This object is an acknowledgement bound for me.') logger.info('This object is an acknowledgement bound for me.')
del shared.ackdataForWhichImWatching[data[readPosition:]] del state.ackdataForWhichImWatching[data[readPosition:]]
sqlExecute( sqlExecute(
'UPDATE sent SET status=?, lastactiontime=?' 'UPDATE sent SET status=?, lastactiontime=?'
' WHERE ackdata=?', ' WHERE ackdata=?',
'ackreceived', int(time.time()), data[readPosition:]) 'ackreceived', int(time.time()), data[readPosition:])
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', 'updateSentItemStatusByAckdata',
(data[readPosition:], (
tr._translate( data[readPosition:],
"MainWindow", tr._translate(
"Acknowledgement of the message received %1" "MainWindow",
).arg(l10n.formatTimestamp())) "Acknowledgement of the message received %1"
).arg(l10n.formatTimestamp())
)
)) ))
else: else:
logger.debug('This object is not an acknowledgement bound for me.') logger.debug('This object is not an acknowledgement bound for me.')
@ -164,6 +175,7 @@ class objectProcessor(threading.Thread):
return return
peer = Peer(host, port) peer = Peer(host, port)
with knownnodes.knownNodesLock: with knownnodes.knownNodesLock:
# FIXME: adjust expirestime
knownnodes.addKnownNode( knownnodes.addKnownNode(
stream, peer, is_self=state.ownAddresses.get(peer)) stream, peer, is_self=state.ownAddresses.get(peer))
@ -272,8 +284,9 @@ class objectProcessor(threading.Thread):
queues.workerQueue.put(('sendOutOrStoreMyV4Pubkey', myAddress)) queues.workerQueue.put(('sendOutOrStoreMyV4Pubkey', myAddress))
def processpubkey(self, data): def processpubkey(self, data):
"""Process a pubkey object"""
pubkeyProcessingStartTime = time.time() pubkeyProcessingStartTime = time.time()
shared.numberOfPubkeysProcessed += 1 state.numberOfPubkeysProcessed += 1
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateNumberOfPubkeysProcessed', 'no data')) 'updateNumberOfPubkeysProcessed', 'no data'))
readPosition = 20 # bypass the nonce, time, and object type readPosition = 20 # bypass the nonce, time, and object type
@ -444,8 +457,9 @@ class objectProcessor(threading.Thread):
timeRequiredToProcessPubkey) timeRequiredToProcessPubkey)
def processmsg(self, data): def processmsg(self, data):
"""Process a message object"""
messageProcessingStartTime = time.time() messageProcessingStartTime = time.time()
shared.numberOfMessagesProcessed += 1 state.numberOfMessagesProcessed += 1
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateNumberOfMessagesProcessed', 'no data')) 'updateNumberOfMessagesProcessed', 'no data'))
readPosition = 20 # bypass the nonce, time, and object type readPosition = 20 # bypass the nonce, time, and object type
@ -562,7 +576,6 @@ class objectProcessor(threading.Thread):
decryptedData[readPosition:readPosition + 10]) decryptedData[readPosition:readPosition + 10])
readPosition += messageLengthLength readPosition += messageLengthLength
message = decryptedData[readPosition:readPosition + messageLength] message = decryptedData[readPosition:readPosition + messageLength]
# print 'First 150 characters of message:', repr(message[:150])
readPosition += messageLength readPosition += messageLength
ackLength, ackLengthLength = decodeVarint( ackLength, ackLengthLength = decodeVarint(
decryptedData[readPosition:readPosition + 10]) decryptedData[readPosition:readPosition + 10])
@ -633,7 +646,8 @@ class objectProcessor(threading.Thread):
if decodeAddress(toAddress)[1] >= 3 \ if decodeAddress(toAddress)[1] >= 3 \
and not BMConfigParser().safeGetBoolean(toAddress, 'chan'): and not BMConfigParser().safeGetBoolean(toAddress, 'chan'):
# If I'm not friendly with this person: # If I'm not friendly with this person:
if not shared.isAddressInMyAddressBookSubscriptionsListOrWhitelist(fromAddress): if not shared.isAddressInMyAddressBookSubscriptionsListOrWhitelist(
fromAddress):
requiredNonceTrialsPerByte = BMConfigParser().getint( requiredNonceTrialsPerByte = BMConfigParser().getint(
toAddress, 'noncetrialsperbyte') toAddress, 'noncetrialsperbyte')
requiredPayloadLengthExtraBytes = BMConfigParser().getint( requiredPayloadLengthExtraBytes = BMConfigParser().getint(
@ -730,32 +744,14 @@ class objectProcessor(threading.Thread):
# We don't actually need the ackdata for acknowledgement # We don't actually need the ackdata for acknowledgement
# since this is a broadcast message but we can use it to # since this is a broadcast message but we can use it to
# update the user interface when the POW is done generating. # update the user interface when the POW is done generating.
streamNumber = decodeAddress(fromAddress)[2]
ackdata = genAckPayload(streamNumber, 0)
toAddress = '[Broadcast subscribers]' toAddress = '[Broadcast subscribers]'
ripe = ''
# We really should have a discussion about how to ackdata = helper_sent.insert(
# set the TTL for mailing list broadcasts. This is obviously fromAddress=fromAddress,
# hard-coded. status='broadcastqueued',
TTL = 2*7*24*60*60 # 2 weeks subject=subject,
t = ('', message=message,
toAddress, encoding=messageEncodingType)
ripe,
fromAddress,
subject,
message,
ackdata,
int(time.time()), # sentTime (this doesn't change)
int(time.time()), # lastActionTime
0,
'broadcastqueued',
0,
'sent',
messageEncodingType,
TTL)
helper_sent.insert(t)
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'displayNewSentMessage', ( 'displayNewSentMessage', (
@ -791,8 +787,9 @@ class objectProcessor(threading.Thread):
) )
def processbroadcast(self, data): def processbroadcast(self, data):
"""Process a broadcast object"""
messageProcessingStartTime = time.time() messageProcessingStartTime = time.time()
shared.numberOfBroadcastsProcessed += 1 state.numberOfBroadcastsProcessed += 1
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateNumberOfBroadcastsProcessed', 'no data')) 'updateNumberOfBroadcastsProcessed', 'no data'))
inventoryHash = calculateInventoryHash(data) inventoryHash = calculateInventoryHash(data)
@ -975,7 +972,7 @@ class objectProcessor(threading.Thread):
fromAddress = encodeAddress( fromAddress = encodeAddress(
sendersAddressVersion, sendersStream, calculatedRipe) sendersAddressVersion, sendersStream, calculatedRipe)
logger.info('fromAddress: %s' % fromAddress) logger.info('fromAddress: %s', fromAddress)
# Let's store the public key in case we want to reply to this person. # Let's store the public key in case we want to reply to this person.
sqlExecute('''INSERT INTO pubkeys VALUES (?,?,?,?,?)''', sqlExecute('''INSERT INTO pubkeys VALUES (?,?,?,?,?)''',
@ -992,7 +989,7 @@ class objectProcessor(threading.Thread):
fromAddress = encodeAddress( fromAddress = encodeAddress(
sendersAddressVersion, sendersStream, calculatedRipe) sendersAddressVersion, sendersStream, calculatedRipe)
logger.debug('fromAddress: ' + fromAddress) logger.debug('fromAddress: %s', fromAddress)
try: try:
decodedMessage = helper_msgcoding.MsgDecode( decodedMessage = helper_msgcoding.MsgDecode(
@ -1060,7 +1057,8 @@ class objectProcessor(threading.Thread):
del state.neededPubkeys[tag] del state.neededPubkeys[tag]
self.sendMessages(address) self.sendMessages(address)
def sendMessages(self, address): @staticmethod
def sendMessages(address):
""" """
This method is called by the `possibleNewPubkey` when it sees This method is called by the `possibleNewPubkey` when it sees
that we now have the necessary pubkey to send one or more messages. that we now have the necessary pubkey to send one or more messages.
@ -1073,7 +1071,9 @@ class objectProcessor(threading.Thread):
" AND folder='sent'", address) " AND folder='sent'", address)
queues.workerQueue.put(('sendmessage', '')) queues.workerQueue.put(('sendmessage', ''))
def ackDataHasAValidHeader(self, ackData): @staticmethod
def ackDataHasAValidHeader(ackData):
"""Checking ackData with valid Header, not sending ackData when false"""
if len(ackData) < protocol.Header.size: if len(ackData) < protocol.Header.size:
logger.info( logger.info(
'The length of ackData is unreasonably short. Not sending' 'The length of ackData is unreasonably short. Not sending'
@ -1108,11 +1108,12 @@ class objectProcessor(threading.Thread):
return False return False
return True return True
def addMailingListNameToSubject(self, subject, mailingListName): @staticmethod
def addMailingListNameToSubject(subject, mailingListName):
"""Adding mailingListName to subject"""
subject = subject.strip() subject = subject.strip()
if subject[:3] == 'Re:' or subject[:3] == 'RE:': if subject[:3] == 'Re:' or subject[:3] == 'RE:':
subject = subject[3:].strip() subject = subject[3:].strip()
if '[' + mailingListName + ']' in subject: if '[' + mailingListName + ']' in subject:
return subject return subject
else: return '[' + mailingListName + '] ' + subject
return '[' + mailingListName + '] ' + subject

View File

@ -21,29 +21,35 @@ It resends messages when there has been no response:
import gc import gc
import os import os
import shared
import time import time
import knownnodes
import queues import queues
import state import state
import tr import tr
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_sql import sqlQuery, sqlExecute from helper_sql import sqlExecute, sqlQuery
from inventory import Inventory from inventory import Inventory
from network import BMConnectionPool, StoppableThread from network import BMConnectionPool, knownnodes, StoppableThread
#: Equals 4 weeks. You could make this longer if you want
#: but making it shorter would not be advisable because
#: there is a very small possibility that it could keep you
#: from obtaining a needed pubkey for a period of time.
lengthOfTimeToHoldOnToAllPubkeys = 2419200
class singleCleaner(StoppableThread): class singleCleaner(StoppableThread):
"""The singleCleaner thread class"""
name = "singleCleaner" name = "singleCleaner"
cycleLength = 300 cycleLength = 300
expireDiscoveredPeers = 300 expireDiscoveredPeers = 300
def run(self): def run(self): # pylint: disable=too-many-branches
gc.disable() gc.disable()
timeWeLastClearedInventoryAndPubkeysTables = 0 timeWeLastClearedInventoryAndPubkeysTables = 0
try: try:
shared.maximumLengthOfTimeToBotherResendingMessages = ( state.maximumLengthOfTimeToBotherResendingMessages = (
float(BMConfigParser().get( float(BMConfigParser().get(
'bitmessagesettings', 'stopresendingafterxdays')) 'bitmessagesettings', 'stopresendingafterxdays'))
* 24 * 60 * 60 * 24 * 60 * 60
@ -55,7 +61,7 @@ class singleCleaner(StoppableThread):
# Either the user hasn't set stopresendingafterxdays and # Either the user hasn't set stopresendingafterxdays and
# stopresendingafterxmonths yet or the options are missing # stopresendingafterxmonths yet or the options are missing
# from the config file. # from the config file.
shared.maximumLengthOfTimeToBotherResendingMessages = float('inf') state.maximumLengthOfTimeToBotherResendingMessages = float('inf')
# initial wait # initial wait
if state.shutdown == 0: if state.shutdown == 0:
@ -73,7 +79,7 @@ class singleCleaner(StoppableThread):
# queue which will never be handled by a UI. We should clear it to # queue which will never be handled by a UI. We should clear it to
# save memory. # save memory.
# FIXME redundant? # FIXME redundant?
if shared.thisapp.daemon or not state.enableGUI: if state.thisapp.daemon or not state.enableGUI:
queues.UISignalQueue.queue.clear() queues.UISignalQueue.queue.clear()
if timeWeLastClearedInventoryAndPubkeysTables < \ if timeWeLastClearedInventoryAndPubkeysTables < \
int(time.time()) - 7380: int(time.time()) - 7380:
@ -83,7 +89,7 @@ class singleCleaner(StoppableThread):
# pubkeys # pubkeys
sqlExecute( sqlExecute(
"DELETE FROM pubkeys WHERE time<? AND usedpersonally='no'", "DELETE FROM pubkeys WHERE time<? AND usedpersonally='no'",
int(time.time()) - shared.lengthOfTimeToHoldOnToAllPubkeys) int(time.time()) - lengthOfTimeToHoldOnToAllPubkeys)
# Let us resend getpubkey objects if we have not yet heard # Let us resend getpubkey objects if we have not yet heard
# a pubkey, and also msg objects if we have not yet heard # a pubkey, and also msg objects if we have not yet heard
@ -93,7 +99,7 @@ class singleCleaner(StoppableThread):
" WHERE ((status='awaitingpubkey' OR status='msgsent')" " WHERE ((status='awaitingpubkey' OR status='msgsent')"
" AND folder='sent' AND sleeptill<? AND senttime>?)", " AND folder='sent' AND sleeptill<? AND senttime>?)",
int(time.time()), int(time.time()) int(time.time()), int(time.time())
- shared.maximumLengthOfTimeToBotherResendingMessages - state.maximumLengthOfTimeToBotherResendingMessages
) )
for row in queryreturn: for row in queryreturn:
if len(row) < 2: if len(row) < 2:
@ -115,6 +121,7 @@ class singleCleaner(StoppableThread):
# while writing it to disk # while writing it to disk
knownnodes.cleanupKnownNodes() knownnodes.cleanupKnownNodes()
except Exception as err: except Exception as err:
# pylint: disable=protected-access
if "Errno 28" in str(err): if "Errno 28" in str(err):
self.logger.fatal( self.logger.fatal(
'(while writing knownnodes to disk)' '(while writing knownnodes to disk)'
@ -127,17 +134,12 @@ class singleCleaner(StoppableThread):
"MainWindow", "MainWindow",
'Alert: Your disk or data storage volume' 'Alert: Your disk or data storage volume'
' is full. Bitmessage will now exit.'), ' is full. Bitmessage will now exit.'),
True) True)
)) ))
# FIXME redundant? # FIXME redundant?
if shared.daemon or not state.enableGUI: if state.thisapp.daemon or not state.enableGUI:
os._exit(1) os._exit(1)
# # clear download queues
# for thread in threading.enumerate():
# if thread.isAlive() and hasattr(thread, 'downloadQueue'):
# thread.downloadQueue.clear()
# inv/object tracking # inv/object tracking
for connection in BMConnectionPool().connections(): for connection in BMConnectionPool().connections():
connection.clean() connection.clean()
@ -150,7 +152,7 @@ class singleCleaner(StoppableThread):
del state.discoveredPeers[k] del state.discoveredPeers[k]
except KeyError: except KeyError:
pass pass
# TODO: cleanup pending upload / download # ..todo:: cleanup pending upload / download
gc.collect() gc.collect()
@ -177,7 +179,7 @@ class singleCleaner(StoppableThread):
'Doing work necessary to again attempt to request a public key...' 'Doing work necessary to again attempt to request a public key...'
)) ))
sqlExecute( sqlExecute(
'''UPDATE sent SET status='msgqueued' WHERE toaddress=?''', '''UPDATE sent SET status='msgqueued' WHERE toaddress=? AND folder='sent' ''',
address) address)
queues.workerQueue.put(('sendmessage', '')) queues.workerQueue.put(('sendmessage', ''))
@ -188,7 +190,7 @@ class singleCleaner(StoppableThread):
' to our msg. Sending again.' ' to our msg. Sending again.'
) )
sqlExecute( sqlExecute(
'''UPDATE sent SET status='msgqueued' WHERE ackdata=?''', '''UPDATE sent SET status='msgqueued' WHERE ackdata=? AND folder='sent' ''',
ackdata) ackdata)
queues.workerQueue.put(('sendmessage', '')) queues.workerQueue.put(('sendmessage', ''))
queues.UISignalQueue.put(( queues.UISignalQueue.put((

View File

@ -1,8 +1,8 @@
""" """
src/class_singleWorker.py Thread for performing PoW
=========================
""" """
# pylint: disable=protected-access,too-many-branches,too-many-statements,no-self-use,too-many-lines,too-many-locals # pylint: disable=protected-access,too-many-branches,too-many-statements
# pylint: disable=no-self-use,too-many-lines,too-many-locals
from __future__ import division from __future__ import division
@ -16,6 +16,7 @@ import defaults
import helper_inbox import helper_inbox
import helper_msgcoding import helper_msgcoding
import helper_random import helper_random
import helper_sql
import highlevelcrypto import highlevelcrypto
import l10n import l10n
import proofofwork import proofofwork
@ -24,11 +25,13 @@ import queues
import shared import shared
import state import state
import tr import tr
from addresses import calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint from addresses import (
calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint
)
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlQuery from helper_sql import sqlExecute, sqlQuery
from inventory import Inventory from inventory import Inventory
from network import StoppableThread from network import knownnodes, StoppableThread
def sizeof_fmt(num, suffix='h/s'): def sizeof_fmt(num, suffix='h/s'):
@ -60,8 +63,8 @@ class singleWorker(StoppableThread):
def run(self): def run(self):
# pylint: disable=attribute-defined-outside-init # pylint: disable=attribute-defined-outside-init
while not state.sqlReady and state.shutdown == 0: while not helper_sql.sql_ready.wait(1.0) and state.shutdown == 0:
self.stop.wait(2) self.stop.wait(1.0)
if state.shutdown > 0: if state.shutdown > 0:
return return
@ -92,25 +95,34 @@ class singleWorker(StoppableThread):
hexlify(privEncryptionKey)) hexlify(privEncryptionKey))
) )
# Initialize the shared.ackdataForWhichImWatching data structure # Initialize the state.ackdataForWhichImWatching data structure
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''SELECT ackdata FROM sent WHERE status = 'msgsent' ''') '''SELECT ackdata FROM sent WHERE status = 'msgsent' AND folder = 'sent' ''')
for row in queryreturn: for row in queryreturn:
ackdata, = row ackdata, = row
self.logger.info('Watching for ackdata %s', hexlify(ackdata)) self.logger.info('Watching for ackdata %s', hexlify(ackdata))
shared.ackdataForWhichImWatching[ackdata] = 0 state.ackdataForWhichImWatching[ackdata] = 0
# Fix legacy (headerless) watched ackdata to include header # Fix legacy (headerless) watched ackdata to include header
for oldack in shared.ackdataForWhichImWatching: for oldack in state.ackdataForWhichImWatching:
if len(oldack) == 32: if len(oldack) == 32:
# attach legacy header, always constant (msg/1/1) # attach legacy header, always constant (msg/1/1)
newack = '\x00\x00\x00\x02\x01\x01' + oldack newack = '\x00\x00\x00\x02\x01\x01' + oldack
shared.ackdataForWhichImWatching[newack] = 0 state.ackdataForWhichImWatching[newack] = 0
sqlExecute( sqlExecute(
'UPDATE sent SET ackdata=? WHERE ackdata=?', '''UPDATE sent SET ackdata=? WHERE ackdata=? AND folder = 'sent' ''',
newack, oldack newack, oldack
) )
del shared.ackdataForWhichImWatching[oldack] del state.ackdataForWhichImWatching[oldack]
# For the case if user deleted knownnodes
# but is still having onionpeer objects in inventory
if not knownnodes.knownNodesActual:
for item in Inventory().by_type_and_tag(protocol.OBJECT_ONIONPEER):
queues.objectProcessorQueue.put((
protocol.OBJECT_ONIONPEER, item.payload
))
# FIXME: should also delete from inventory
# give some time for the GUI to start # give some time for the GUI to start
# before we start on existing POW tasks. # before we start on existing POW tasks.
@ -237,11 +249,13 @@ class singleWorker(StoppableThread):
return payload return payload
def doPOWForMyV2Pubkey(self, adressHash): def doPOWForMyV2Pubkey(self, adressHash):
""" This function also broadcasts out the pubkey message once it is done with the POW""" """ This function also broadcasts out the pubkey
message once it is done with the POW"""
# Look up my stream number based on my address hash # Look up my stream number based on my address hash
myAddress = shared.myAddressesByHash[adressHash] myAddress = shared.myAddressesByHash[adressHash]
# status # status
_, addressVersionNumber, streamNumber, adressHash = decodeAddress(myAddress) _, addressVersionNumber, streamNumber, adressHash = (
decodeAddress(myAddress))
# 28 days from now plus or minus five minutes # 28 days from now plus or minus five minutes
TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300)) TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300))
@ -509,7 +523,7 @@ class singleWorker(StoppableThread):
sqlExecute( sqlExecute(
'''UPDATE sent SET status='broadcastqueued' ''' '''UPDATE sent SET status='broadcastqueued' '''
'''WHERE status = 'doingbroadcastpow' ''') '''WHERE status = 'doingbroadcastpow' AND folder = 'sent' ''')
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''SELECT fromaddress, subject, message, ''' '''SELECT fromaddress, subject, message, '''
''' ackdata, ttl, encodingtype FROM sent ''' ''' ackdata, ttl, encodingtype FROM sent '''
@ -543,10 +557,12 @@ class singleWorker(StoppableThread):
)) ))
continue continue
sqlExecute( if not sqlExecute(
'''UPDATE sent SET status='doingbroadcastpow' ''' '''UPDATE sent SET status='doingbroadcastpow' '''
''' WHERE ackdata=? AND status='broadcastqueued' ''', ''' WHERE ackdata=? AND status='broadcastqueued' '''
ackdata) ''' AND folder='sent' ''',
ackdata):
continue
# At this time these pubkeys are 65 bytes long # At this time these pubkeys are 65 bytes long
# because they include the encoding byte which we won't # because they include the encoding byte which we won't
@ -667,8 +683,8 @@ class singleWorker(StoppableThread):
# Update the status of the message in the 'sent' table to have # Update the status of the message in the 'sent' table to have
# a 'broadcastsent' status # a 'broadcastsent' status
sqlExecute( sqlExecute(
'UPDATE sent SET msgid=?, status=?, lastactiontime=?' '''UPDATE sent SET msgid=?, status=?, lastactiontime=? '''
' WHERE ackdata=?', ''' WHERE ackdata=? AND folder='sent' ''',
inventoryHash, 'broadcastsent', int(time.time()), ackdata inventoryHash, 'broadcastsent', int(time.time()), ackdata
) )
@ -678,7 +694,8 @@ class singleWorker(StoppableThread):
# Reset just in case # Reset just in case
sqlExecute( sqlExecute(
'''UPDATE sent SET status='msgqueued' ''' '''UPDATE sent SET status='msgqueued' '''
''' WHERE status IN ('doingpubkeypow', 'doingmsgpow')''') ''' WHERE status IN ('doingpubkeypow', 'doingmsgpow') '''
''' AND folder='sent' ''')
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''SELECT toaddress, fromaddress, subject, message, ''' '''SELECT toaddress, fromaddress, subject, message, '''
''' ackdata, status, ttl, retrynumber, encodingtype FROM ''' ''' ackdata, status, ttl, retrynumber, encodingtype FROM '''
@ -714,11 +731,12 @@ class singleWorker(StoppableThread):
# we can calculate the needed pubkey using the private keys # we can calculate the needed pubkey using the private keys
# in our keys.dat file. # in our keys.dat file.
elif BMConfigParser().has_section(toaddress): elif BMConfigParser().has_section(toaddress):
sqlExecute( if not sqlExecute(
'''UPDATE sent SET status='doingmsgpow' ''' '''UPDATE sent SET status='doingmsgpow' '''
''' WHERE toaddress=? AND status='msgqueued' ''', ''' WHERE toaddress=? AND status='msgqueued' AND folder='sent' ''',
toaddress toaddress
) ):
continue
status = 'doingmsgpow' status = 'doingmsgpow'
elif status == 'msgqueued': elif status == 'msgqueued':
# Let's see if we already have the pubkey in our pubkeys table # Let's see if we already have the pubkey in our pubkeys table
@ -729,11 +747,12 @@ class singleWorker(StoppableThread):
# If we have the needed pubkey in the pubkey table already, # If we have the needed pubkey in the pubkey table already,
if queryreturn != []: if queryreturn != []:
# set the status of this msg to doingmsgpow # set the status of this msg to doingmsgpow
sqlExecute( if not sqlExecute(
'''UPDATE sent SET status='doingmsgpow' ''' '''UPDATE sent SET status='doingmsgpow' '''
''' WHERE toaddress=? AND status='msgqueued' ''', ''' WHERE toaddress=? AND status='msgqueued' AND folder='sent' ''',
toaddress toaddress
) ):
continue
status = 'doingmsgpow' status = 'doingmsgpow'
# mark the pubkey as 'usedpersonally' so that # mark the pubkey as 'usedpersonally' so that
# we don't delete it later. If the pubkey version # we don't delete it later. If the pubkey version
@ -816,7 +835,8 @@ class singleWorker(StoppableThread):
''' toaddress=? AND ''' ''' toaddress=? AND '''
''' (status='msgqueued' or ''' ''' (status='msgqueued' or '''
''' status='awaitingpubkey' or ''' ''' status='awaitingpubkey' or '''
''' status='doingpubkeypow')''', ''' status='doingpubkeypow') AND '''
''' folder='sent' ''',
toaddress) toaddress)
del state.neededPubkeys[tag] del state.neededPubkeys[tag]
break break
@ -833,7 +853,7 @@ class singleWorker(StoppableThread):
sqlExecute( sqlExecute(
'''UPDATE sent SET ''' '''UPDATE sent SET '''
''' status='doingpubkeypow' WHERE ''' ''' status='doingpubkeypow' WHERE '''
''' toaddress=? AND status='msgqueued' ''', ''' toaddress=? AND status='msgqueued' AND folder='sent' ''',
toaddress toaddress
) )
queues.UISignalQueue.put(( queues.UISignalQueue.put((
@ -860,7 +880,7 @@ class singleWorker(StoppableThread):
# if we aren't sending this to ourselves or a chan # if we aren't sending this to ourselves or a chan
if not BMConfigParser().has_section(toaddress): if not BMConfigParser().has_section(toaddress):
shared.ackdataForWhichImWatching[ackdata] = 0 state.ackdataForWhichImWatching[ackdata] = 0
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata,
@ -1026,7 +1046,7 @@ class singleWorker(StoppableThread):
# we are willing to do. # we are willing to do.
sqlExecute( sqlExecute(
'''UPDATE sent SET status='toodifficult' ''' '''UPDATE sent SET status='toodifficult' '''
''' WHERE ackdata=? ''', ''' WHERE ackdata=? AND folder='sent' ''',
ackdata) ackdata)
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
@ -1174,7 +1194,7 @@ class singleWorker(StoppableThread):
) )
except: except:
sqlExecute( sqlExecute(
'''UPDATE sent SET status='badkey' WHERE ackdata=?''', '''UPDATE sent SET status='badkey' WHERE ackdata=? AND folder='sent' ''',
ackdata ackdata
) )
queues.UISignalQueue.put(( queues.UISignalQueue.put((
@ -1281,7 +1301,7 @@ class singleWorker(StoppableThread):
sleepTill = int(time.time() + TTL * 1.1) sleepTill = int(time.time() + TTL * 1.1)
sqlExecute( sqlExecute(
'''UPDATE sent SET msgid=?, status=?, retrynumber=?, ''' '''UPDATE sent SET msgid=?, status=?, retrynumber=?, '''
''' sleeptill=?, lastactiontime=? WHERE ackdata=?''', ''' sleeptill=?, lastactiontime=? WHERE ackdata=? AND folder='sent' ''',
inventoryHash, newStatus, retryNumber + 1, inventoryHash, newStatus, retryNumber + 1,
sleepTill, int(time.time()), ackdata sleepTill, int(time.time()), ackdata
) )
@ -1327,7 +1347,7 @@ class singleWorker(StoppableThread):
queryReturn = sqlQuery( queryReturn = sqlQuery(
'''SELECT retrynumber FROM sent WHERE toaddress=? ''' '''SELECT retrynumber FROM sent WHERE toaddress=? '''
''' AND (status='doingpubkeypow' OR status='awaitingpubkey') ''' ''' AND (status='doingpubkeypow' OR status='awaitingpubkey') '''
''' LIMIT 1''', ''' AND folder='sent' LIMIT 1''',
toAddress toAddress
) )
if not queryReturn: if not queryReturn:
@ -1386,7 +1406,6 @@ class singleWorker(StoppableThread):
self.logger.info( self.logger.info(
'making request for v4 pubkey with tag: %s', hexlify(tag)) 'making request for v4 pubkey with tag: %s', hexlify(tag))
# print 'trial value', trialValue
statusbar = 'Doing the computations necessary to request' +\ statusbar = 'Doing the computations necessary to request' +\
' the recipient\'s public key.' ' the recipient\'s public key.'
queues.UISignalQueue.put(('updateStatusBar', statusbar)) queues.UISignalQueue.put(('updateStatusBar', statusbar))
@ -1413,7 +1432,7 @@ class singleWorker(StoppableThread):
'''UPDATE sent SET lastactiontime=?, ''' '''UPDATE sent SET lastactiontime=?, '''
''' status='awaitingpubkey', retrynumber=?, sleeptill=? ''' ''' status='awaitingpubkey', retrynumber=?, sleeptill=? '''
''' WHERE toaddress=? AND (status='doingpubkeypow' OR ''' ''' WHERE toaddress=? AND (status='doingpubkeypow' OR '''
''' status='awaitingpubkey') ''', ''' status='awaitingpubkey') AND folder='sent' ''',
int(time.time()), retryNumber + 1, sleeptill, toAddress) int(time.time()), retryNumber + 1, sleeptill, toAddress)
queues.UISignalQueue.put(( queues.UISignalQueue.put((

View File

@ -1,6 +1,5 @@
""" """
src/class_smtpDeliver.py SMTP client thread for delivering emails
========================
""" """
# pylint: disable=unused-variable # pylint: disable=unused-variable
@ -23,8 +22,9 @@ class smtpDeliver(StoppableThread):
_instance = None _instance = None
def stopThread(self): def stopThread(self):
# pylint: disable=no-member
try: try:
queues.UISignallerQueue.put(("stopThread", "data")) # pylint: disable=no-member queues.UISignallerQueue.put(("stopThread", "data"))
except: except:
pass pass
super(smtpDeliver, self).stopThread() super(smtpDeliver, self).stopThread()
@ -38,6 +38,7 @@ class smtpDeliver(StoppableThread):
def run(self): def run(self):
# pylint: disable=too-many-branches,too-many-statements,too-many-locals # pylint: disable=too-many-branches,too-many-statements,too-many-locals
# pylint: disable=deprecated-lambda
while state.shutdown == 0: while state.shutdown == 0:
command, data = queues.UISignalQueue.get() command, data = queues.UISignalQueue.get()
if command == 'writeNewAddressToTable': if command == 'writeNewAddressToTable':
@ -60,9 +61,9 @@ class smtpDeliver(StoppableThread):
msg = MIMEText(body, 'plain', 'utf-8') msg = MIMEText(body, 'plain', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8') msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = fromAddress + '@' + SMTPDOMAIN msg['From'] = fromAddress + '@' + SMTPDOMAIN
toLabel = map( # pylint: disable=deprecated-lambda toLabel = map(
lambda y: BMConfigParser().safeGet(y, "label"), lambda y: BMConfigParser().safeGet(y, "label"),
filter( # pylint: disable=deprecated-lambda filter(
lambda x: x == toAddress, BMConfigParser().addresses()) lambda x: x == toAddress, BMConfigParser().addresses())
) )
if toLabel: if toLabel:

View File

@ -1,3 +1,6 @@
"""
SMTP server thread
"""
import asyncore import asyncore
import base64 import base64
import email import email
@ -22,10 +25,13 @@ SMTPDOMAIN = "bmaddr.lan"
LISTENPORT = 8425 LISTENPORT = 8425
logger = logging.getLogger('default') logger = logging.getLogger('default')
# pylint: disable=attribute-defined-outside-init
class smtpServerChannel(smtpd.SMTPChannel): class smtpServerChannel(smtpd.SMTPChannel):
"""Asyncore channel for SMTP protocol (server)"""
def smtp_EHLO(self, arg): def smtp_EHLO(self, arg):
"""Process an EHLO"""
if not arg: if not arg:
self.push('501 Syntax: HELO hostname') self.push('501 Syntax: HELO hostname')
return return
@ -33,14 +39,16 @@ class smtpServerChannel(smtpd.SMTPChannel):
self.push('250 AUTH PLAIN') self.push('250 AUTH PLAIN')
def smtp_AUTH(self, arg): def smtp_AUTH(self, arg):
"""Process AUTH"""
if not arg or arg[0:5] not in ["PLAIN"]: if not arg or arg[0:5] not in ["PLAIN"]:
self.push('501 Syntax: AUTH PLAIN') self.push('501 Syntax: AUTH PLAIN')
return return
authstring = arg[6:] authstring = arg[6:]
try: try:
decoded = base64.b64decode(authstring) decoded = base64.b64decode(authstring)
correctauth = "\x00" + BMConfigParser().safeGet("bitmessagesettings", "smtpdusername", "") + \ correctauth = "\x00" + BMConfigParser().safeGet(
"\x00" + BMConfigParser().safeGet("bitmessagesettings", "smtpdpassword", "") "bitmessagesettings", "smtpdusername", "") + "\x00" + BMConfigParser().safeGet(
"bitmessagesettings", "smtpdpassword", "")
logger.debug('authstring: %s / %s', correctauth, decoded) logger.debug('authstring: %s / %s', correctauth, decoded)
if correctauth == decoded: if correctauth == decoded:
self.auth = True self.auth = True
@ -51,6 +59,7 @@ class smtpServerChannel(smtpd.SMTPChannel):
self.push('501 Authentication fail') self.push('501 Authentication fail')
def smtp_DATA(self, arg): def smtp_DATA(self, arg):
"""Process DATA"""
if not hasattr(self, "auth") or not self.auth: if not hasattr(self, "auth") or not self.auth:
self.push('530 Authentication required') self.push('530 Authentication required')
return return
@ -58,15 +67,18 @@ class smtpServerChannel(smtpd.SMTPChannel):
class smtpServerPyBitmessage(smtpd.SMTPServer): class smtpServerPyBitmessage(smtpd.SMTPServer):
"""Asyncore SMTP server class"""
def handle_accept(self): def handle_accept(self):
"""Accept a connection"""
pair = self.accept() pair = self.accept()
if pair is not None: if pair is not None:
conn, addr = pair conn, addr = pair
# print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr)
self.channel = smtpServerChannel(self, conn, addr) self.channel = smtpServerChannel(self, conn, addr)
def send(self, fromAddress, toAddress, subject, message): def send(self, fromAddress, toAddress, subject, message):
status, addressVersionNumber, streamNumber, ripe = decodeAddress(toAddress) """Send a bitmessage"""
# pylint: disable=arguments-differ
streamNumber, ripe = decodeAddress(toAddress)[2:]
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel') stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
ackdata = genAckPayload(streamNumber, stealthLevel) ackdata = genAckPayload(streamNumber, stealthLevel)
sqlExecute( sqlExecute(
@ -78,19 +90,21 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
subject, subject,
message, message,
ackdata, ackdata,
int(time.time()), # sentTime (this will never change) int(time.time()), # sentTime (this will never change)
int(time.time()), # lastActionTime int(time.time()), # lastActionTime
0, # sleepTill time. This will get set when the POW gets done. 0, # sleepTill time. This will get set when the POW gets done.
'msgqueued', 'msgqueued',
0, # retryNumber 0, # retryNumber
'sent', # folder 'sent', # folder
2, # encodingtype 2, # encodingtype
min(BMConfigParser().getint('bitmessagesettings', 'ttl'), 86400 * 2) # not necessary to have a TTL higher than 2 days # not necessary to have a TTL higher than 2 days
min(BMConfigParser().getint('bitmessagesettings', 'ttl'), 86400 * 2)
) )
queues.workerQueue.put(('sendmessage', toAddress)) queues.workerQueue.put(('sendmessage', toAddress))
def decode_header(self, hdr): def decode_header(self, hdr):
"""Email header decoding"""
ret = [] ret = []
for h in decode_header(self.msg_headers[hdr]): for h in decode_header(self.msg_headers[hdr]):
if h[1]: if h[1]:
@ -101,6 +115,8 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
return ret return ret
def process_message(self, peer, mailfrom, rcpttos, data): def process_message(self, peer, mailfrom, rcpttos, data):
"""Process an email"""
# pylint: disable=too-many-locals, too-many-branches
p = re.compile(".*<([^>]+)>") p = re.compile(".*<([^>]+)>")
if not hasattr(self.channel, "auth") or not self.channel.auth: if not hasattr(self.channel, "auth") or not self.channel.auth:
logger.error('Missing or invalid auth') logger.error('Missing or invalid auth')
@ -158,7 +174,8 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
class smtpServer(StoppableThread): class smtpServer(StoppableThread):
def __init__(self, parent=None): """SMTP server thread"""
def __init__(self, _=None):
super(smtpServer, self).__init__(name="smtpServerThread") super(smtpServer, self).__init__(name="smtpServerThread")
self.server = smtpServerPyBitmessage(('127.0.0.1', LISTENPORT), None) self.server = smtpServerPyBitmessage(('127.0.0.1', LISTENPORT), None)
@ -171,7 +188,8 @@ class smtpServer(StoppableThread):
asyncore.loop(1) asyncore.loop(1)
def signals(signal, frame): def signals(_, __):
"""Signal handler"""
logger.warning('Got signal, terminating') logger.warning('Got signal, terminating')
for thread in threading.enumerate(): for thread in threading.enumerate():
if thread.isAlive() and isinstance(thread, StoppableThread): if thread.isAlive() and isinstance(thread, StoppableThread):
@ -179,6 +197,7 @@ def signals(signal, frame):
def runServer(): def runServer():
"""Run SMTP server as a standalone python process"""
logger.warning('Running SMTPd thread') logger.warning('Running SMTPd thread')
smtpThread = smtpServer() smtpThread = smtpServer()
smtpThread.start() smtpThread.start()

View File

@ -2,24 +2,22 @@
sqlThread is defined here sqlThread is defined here
""" """
import threading
from bmconfigparser import BMConfigParser
import sqlite3
import time
import shutil # used for moving the messages.dat file
import sys
import os import os
from debug import logger import shutil # used for moving the messages.dat file
import sqlite3
import sys
import threading
import time
import helper_sql import helper_sql
import helper_startup import helper_startup
import paths import paths
import queues import queues
import state import state
import tr import tr
from bmconfigparser import BMConfigParser
# This thread exists because SQLITE3 is so un-threadsafe that we must from debug import logger
# submit queries to it and it puts results back in a different queue. They # pylint: disable=attribute-defined-outside-init,protected-access
# won't let us just use locks.
class sqlThread(threading.Thread): class sqlThread(threading.Thread):
@ -28,8 +26,9 @@ class sqlThread(threading.Thread):
def __init__(self): def __init__(self):
threading.Thread.__init__(self, name="SQL") threading.Thread.__init__(self, name="SQL")
def run(self): def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements
"""Process SQL queries from `.helper_sql.sqlSubmitQueue`""" """Process SQL queries from `.helper_sql.sqlSubmitQueue`"""
helper_sql.sql_available = True
self.conn = sqlite3.connect(state.appdata + 'messages.dat') self.conn = sqlite3.connect(state.appdata + 'messages.dat')
self.conn.text_factory = str self.conn.text_factory = str
self.cur = self.conn.cursor() self.cur = self.conn.cursor()
@ -38,30 +37,38 @@ class sqlThread(threading.Thread):
try: try:
self.cur.execute( self.cur.execute(
'''CREATE TABLE inbox (msgid blob, toaddress text, fromaddress text, subject text, received text, message text, folder text, encodingtype int, read bool, sighash blob, UNIQUE(msgid) ON CONFLICT REPLACE)''' ) '''CREATE TABLE inbox (msgid blob, toaddress text, fromaddress text, subject text,'''
''' received text, message text, folder text, encodingtype int, read bool, sighash blob,'''
''' UNIQUE(msgid) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text, ackdata blob, senttime integer, lastactiontime integer, sleeptill integer, status text, retrynumber integer, folder text, encodingtype int, ttl int)''' ) '''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text,'''
''' message text, ackdata blob, senttime integer, lastactiontime integer,'''
''' sleeptill integer, status text, retrynumber integer, folder text, encodingtype int, ttl int)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''' ) '''CREATE TABLE subscriptions (label text, address text, enabled bool)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE addressbook (label text, address text)''' ) '''CREATE TABLE addressbook (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE blacklist (label text, address text, enabled bool)''' ) '''CREATE TABLE blacklist (label text, address text, enabled bool)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE whitelist (label text, address text, enabled bool)''' ) '''CREATE TABLE whitelist (label text, address text, enabled bool)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''' ) '''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int,'''
''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob, expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''' ) '''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob,'''
''' expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO subscriptions VALUES('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''') '''INSERT INTO subscriptions VALUES'''
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''' ) '''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''')
self.cur.execute( '''INSERT INTO settings VALUES('version','10')''') self.cur.execute('''INSERT INTO settings VALUES('version','11')''')
self.cur.execute( '''INSERT INTO settings VALUES('lastvacuumtime',?)''', ( self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
int(time.time()),)) int(time.time()),))
self.cur.execute( self.cur.execute(
'''CREATE TABLE objectprocessorqueue (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''' ) '''CREATE TABLE objectprocessorqueue'''
''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
self.conn.commit() self.conn.commit()
logger.info('Created messages database file') logger.info('Created messages database file')
except Exception as err: except Exception as err:
@ -126,33 +133,38 @@ class sqlThread(threading.Thread):
logger.debug( logger.debug(
"In messages.dat database, creating new 'settings' table.") "In messages.dat database, creating new 'settings' table.")
self.cur.execute( self.cur.execute(
'''CREATE TABLE settings (key text, value blob, UNIQUE(key) ON CONFLICT REPLACE)''' ) '''CREATE TABLE settings (key text, value blob, UNIQUE(key) ON CONFLICT REPLACE)''')
self.cur.execute( '''INSERT INTO settings VALUES('version','1')''') self.cur.execute('''INSERT INTO settings VALUES('version','1')''')
self.cur.execute( '''INSERT INTO settings VALUES('lastvacuumtime',?)''', ( self.cur.execute('''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
int(time.time()),)) int(time.time()),))
logger.debug('In messages.dat database, removing an obsolete field from the pubkeys table.') logger.debug('In messages.dat database, removing an obsolete field from the pubkeys table.')
self.cur.execute( self.cur.execute(
'''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''') '''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int,'''
''' usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''')
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys_backup SELECT hash, transmitdata, time, usedpersonally FROM pubkeys;''') '''INSERT INTO pubkeys_backup SELECT hash, transmitdata, time, usedpersonally FROM pubkeys;''')
self.cur.execute( '''DROP TABLE pubkeys''') self.cur.execute('''DROP TABLE pubkeys''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE pubkeys (hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE)''' ) '''CREATE TABLE pubkeys'''
''' (hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys SELECT hash, transmitdata, time, usedpersonally FROM pubkeys_backup;''') '''INSERT INTO pubkeys SELECT hash, transmitdata, time, usedpersonally FROM pubkeys_backup;''')
self.cur.execute( '''DROP TABLE pubkeys_backup;''') self.cur.execute('''DROP TABLE pubkeys_backup;''')
logger.debug('Deleting all pubkeys from inventory. They will be redownloaded and then saved with the correct times.') logger.debug(
'Deleting all pubkeys from inventory.'
' They will be redownloaded and then saved with the correct times.')
self.cur.execute( self.cur.execute(
'''delete from inventory where objecttype = 'pubkey';''') '''delete from inventory where objecttype = 'pubkey';''')
logger.debug('replacing Bitmessage announcements mailing list with a new one.') logger.debug('replacing Bitmessage announcements mailing list with a new one.')
self.cur.execute( self.cur.execute(
'''delete from subscriptions where address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx' ''') '''delete from subscriptions where address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx' ''')
self.cur.execute( self.cur.execute(
'''INSERT INTO subscriptions VALUES('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''') '''INSERT INTO subscriptions VALUES'''
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
logger.debug('Commiting.') logger.debug('Commiting.')
self.conn.commit() self.conn.commit()
logger.debug('Vacuuming message.dat. You might notice that the file size gets much smaller.') logger.debug('Vacuuming message.dat. You might notice that the file size gets much smaller.')
self.cur.execute( ''' VACUUM ''') self.cur.execute(''' VACUUM ''')
# After code refactoring, the possible status values for sent messages # After code refactoring, the possible status values for sent messages
# have changed. # have changed.
@ -176,15 +188,21 @@ class sqlThread(threading.Thread):
'In messages.dat database, removing an obsolete field from' 'In messages.dat database, removing an obsolete field from'
' the inventory table.') ' the inventory table.')
self.cur.execute( self.cur.execute(
'''CREATE TEMPORARY TABLE inventory_backup(hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE);''') '''CREATE TEMPORARY TABLE inventory_backup'''
'''(hash blob, objecttype text, streamnumber int, payload blob,'''
''' receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE);''')
self.cur.execute( self.cur.execute(
'''INSERT INTO inventory_backup SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory;''') '''INSERT INTO inventory_backup SELECT hash, objecttype, streamnumber, payload, receivedtime'''
self.cur.execute( '''DROP TABLE inventory''') ''' FROM inventory;''')
self.cur.execute('''DROP TABLE inventory''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE inventory (hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE)''' ) '''CREATE TABLE inventory'''
''' (hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer,'''
''' UNIQUE(hash) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO inventory SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory_backup;''') '''INSERT INTO inventory SELECT hash, objecttype, streamnumber, payload, receivedtime'''
self.cur.execute( '''DROP TABLE inventory_backup;''') ''' FROM inventory_backup;''')
self.cur.execute('''DROP TABLE inventory_backup;''')
item = '''update settings set value=? WHERE key='version';''' item = '''update settings set value=? WHERE key='version';'''
parameters = (3,) parameters = (3,)
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
@ -214,7 +232,8 @@ class sqlThread(threading.Thread):
if currentVersion == 4: if currentVersion == 4:
self.cur.execute('''DROP TABLE pubkeys''') self.cur.execute('''DROP TABLE pubkeys''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE pubkeys (hash blob, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(hash, addressversion) ON CONFLICT REPLACE)''') '''CREATE TABLE pubkeys (hash blob, addressversion int, transmitdata blob, time int,'''
'''usedpersonally text, UNIQUE(hash, addressversion) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''delete from inventory where objecttype = 'pubkey';''') '''delete from inventory where objecttype = 'pubkey';''')
item = '''update settings set value=? WHERE key='version';''' item = '''update settings set value=? WHERE key='version';'''
@ -230,7 +249,8 @@ class sqlThread(threading.Thread):
if currentVersion == 5: if currentVersion == 5:
self.cur.execute('''DROP TABLE knownnodes''') self.cur.execute('''DROP TABLE knownnodes''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE objectprocessorqueue (objecttype text, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''') '''CREATE TABLE objectprocessorqueue'''
''' (objecttype text, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
item = '''update settings set value=? WHERE key='version';''' item = '''update settings set value=? WHERE key='version';'''
parameters = (6,) parameters = (6,)
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
@ -246,10 +266,15 @@ class sqlThread(threading.Thread):
logger.debug( logger.debug(
'In messages.dat database, dropping and recreating' 'In messages.dat database, dropping and recreating'
' the inventory table.') ' the inventory table.')
self.cur.execute( '''DROP TABLE inventory''') self.cur.execute('''DROP TABLE inventory''')
self.cur.execute( '''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob, expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''' ) self.cur.execute(
self.cur.execute( '''DROP TABLE objectprocessorqueue''') '''CREATE TABLE inventory'''
self.cur.execute( '''CREATE TABLE objectprocessorqueue (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''' ) ''' (hash blob, objecttype int, streamnumber int, payload blob, expirestime integer,'''
''' tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''')
self.cur.execute('''DROP TABLE objectprocessorqueue''')
self.cur.execute(
'''CREATE TABLE objectprocessorqueue'''
''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
item = '''update settings set value=? WHERE key='version';''' item = '''update settings set value=? WHERE key='version';'''
parameters = (7,) parameters = (7,)
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
@ -311,15 +336,24 @@ class sqlThread(threading.Thread):
' fields into the retrynumber field and adding the' ' fields into the retrynumber field and adding the'
' sleeptill and ttl fields...') ' sleeptill and ttl fields...')
self.cur.execute( self.cur.execute(
'''CREATE TEMPORARY TABLE sent_backup (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text, ackdata blob, lastactiontime integer, status text, retrynumber integer, folder text, encodingtype int)''' ) '''CREATE TEMPORARY TABLE sent_backup'''
''' (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text,'''
''' ackdata blob, lastactiontime integer, status text, retrynumber integer,'''
''' folder text, encodingtype int)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO sent_backup SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, 0, folder, encodingtype FROM sent;''') '''INSERT INTO sent_backup SELECT msgid, toaddress, toripe, fromaddress,'''
self.cur.execute( '''DROP TABLE sent''') ''' subject, message, ackdata, lastactiontime,'''
''' status, 0, folder, encodingtype FROM sent;''')
self.cur.execute('''DROP TABLE sent''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text, ackdata blob, senttime integer, lastactiontime integer, sleeptill int, status text, retrynumber integer, folder text, encodingtype int, ttl int)''' ) '''CREATE TABLE sent'''
''' (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text,'''
''' ackdata blob, senttime integer, lastactiontime integer, sleeptill int, status text,'''
''' retrynumber integer, folder text, encodingtype int, ttl int)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO sent SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, lastactiontime, 0, status, 0, folder, encodingtype, 216000 FROM sent_backup;''') '''INSERT INTO sent SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata,'''
self.cur.execute( '''DROP TABLE sent_backup''') ''' lastactiontime, lastactiontime, 0, status, 0, folder, encodingtype, 216000 FROM sent_backup;''')
self.cur.execute('''DROP TABLE sent_backup''')
logger.info('In messages.dat database, finished making TTL-related changes.') logger.info('In messages.dat database, finished making TTL-related changes.')
logger.debug('In messages.dat database, adding address field to the pubkeys table.') logger.debug('In messages.dat database, adding address field to the pubkeys table.')
# We're going to have to calculate the address for each row in the pubkeys # We're going to have to calculate the address for each row in the pubkeys
@ -336,18 +370,45 @@ class sqlThread(threading.Thread):
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
# Now we can remove the hash field from the pubkeys table. # Now we can remove the hash field from the pubkeys table.
self.cur.execute( self.cur.execute(
'''CREATE TEMPORARY TABLE pubkeys_backup (address text, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''' ) '''CREATE TEMPORARY TABLE pubkeys_backup'''
''' (address text, addressversion int, transmitdata blob, time int,'''
''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys_backup SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys;''') '''INSERT INTO pubkeys_backup'''
self.cur.execute( '''DROP TABLE pubkeys''') ''' SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys;''')
self.cur.execute('''DROP TABLE pubkeys''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''' ) '''CREATE TABLE pubkeys'''
''' (address text, addressversion int, transmitdata blob, time int, usedpersonally text,'''
''' UNIQUE(address) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys_backup;''') '''INSERT INTO pubkeys SELECT'''
self.cur.execute( '''DROP TABLE pubkeys_backup''') ''' address, addressversion, transmitdata, time, usedpersonally FROM pubkeys_backup;''')
logger.debug('In messages.dat database, done adding address field to the pubkeys table and removing the hash field.') self.cur.execute('''DROP TABLE pubkeys_backup''')
logger.debug(
'In messages.dat database, done adding address field to the pubkeys table'
' and removing the hash field.')
self.cur.execute('''update settings set value=10 WHERE key='version';''') self.cur.execute('''update settings set value=10 WHERE key='version';''')
# Update the address colunm to unique in addressbook table
item = '''SELECT value FROM settings WHERE key='version';'''
parameters = ''
self.cur.execute(item, parameters)
currentVersion = int(self.cur.fetchall()[0][0])
if currentVersion == 10:
logger.debug(
'In messages.dat database, updating address column to UNIQUE'
' in the addressbook table.')
self.cur.execute(
'''ALTER TABLE addressbook RENAME TO old_addressbook''')
self.cur.execute(
'''CREATE TABLE addressbook'''
''' (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''')
self.cur.execute(
'''INSERT INTO addressbook SELECT label, address FROM old_addressbook;''')
self.cur.execute('''DROP TABLE old_addressbook''')
self.cur.execute('''update settings set value=11 WHERE key='version';''')
# Are you hoping to add a new option to the keys.dat file of existing # Are you hoping to add a new option to the keys.dat file of existing
# Bitmessage users or modify the SQLite database? Add it right # Bitmessage users or modify the SQLite database? Add it right
# above this line! # above this line!
@ -355,7 +416,7 @@ class sqlThread(threading.Thread):
try: try:
testpayload = '\x00\x00' testpayload = '\x00\x00'
t = ('1234', 1, testpayload, '12345678', 'no') t = ('1234', 1, testpayload, '12345678', 'no')
self.cur.execute( '''INSERT INTO pubkeys VALUES(?,?,?,?,?)''', t) self.cur.execute('''INSERT INTO pubkeys VALUES(?,?,?,?,?)''', t)
self.conn.commit() self.conn.commit()
self.cur.execute( self.cur.execute(
'''SELECT transmitdata FROM pubkeys WHERE address='1234' ''') '''SELECT transmitdata FROM pubkeys WHERE address='1234' ''')
@ -365,13 +426,29 @@ class sqlThread(threading.Thread):
self.cur.execute('''DELETE FROM pubkeys WHERE address='1234' ''') self.cur.execute('''DELETE FROM pubkeys WHERE address='1234' ''')
self.conn.commit() self.conn.commit()
if transmitdata == '': if transmitdata == '':
logger.fatal('Problem: The version of SQLite you have cannot store Null values. Please download and install the latest revision of your version of Python (for example, the latest Python 2.7 revision) and try again.\n') logger.fatal(
logger.fatal('PyBitmessage will now exit very abruptly. You may now see threading errors related to this abrupt exit but the problem you need to solve is related to SQLite.\n\n') 'Problem: The version of SQLite you have cannot store Null values.'
' Please download and install the latest revision of your version of Python'
' (for example, the latest Python 2.7 revision) and try again.\n')
logger.fatal(
'PyBitmessage will now exit very abruptly.'
' You may now see threading errors related to this abrupt exit'
' but the problem you need to solve is related to SQLite.\n\n')
os._exit(0) os._exit(0)
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal('(While null value test) Alert: Your disk or data storage volume is full. sqlThread will now exit.') logger.fatal(
queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True))) '(While null value test) Alert: Your disk or data storage volume is full.'
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
else: else:
logger.error(err) logger.error(err)
@ -387,17 +464,27 @@ class sqlThread(threading.Thread):
if int(value) < int(time.time()) - 86400: if int(value) < int(time.time()) - 86400:
logger.info('It has been a long time since the messages.dat file has been vacuumed. Vacuuming now...') logger.info('It has been a long time since the messages.dat file has been vacuumed. Vacuuming now...')
try: try:
self.cur.execute( ''' VACUUM ''') self.cur.execute(''' VACUUM ''')
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal('(While VACUUM) Alert: Your disk or data storage volume is full. sqlThread will now exit.') logger.fatal(
queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True))) '(While VACUUM) Alert: Your disk or data storage volume is full.'
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
item = '''update settings set value=? WHERE key='lastvacuumtime';''' item = '''update settings set value=? WHERE key='lastvacuumtime';'''
parameters = (int(time.time()),) parameters = (int(time.time()),)
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
state.sqlReady = True helper_sql.sql_ready.set()
while True: while True:
item = helper_sql.sqlSubmitQueue.get() item = helper_sql.sqlSubmitQueue.get()
@ -406,8 +493,18 @@ class sqlThread(threading.Thread):
self.conn.commit() self.conn.commit()
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal('(While committing) Alert: Your disk or data storage volume is full. sqlThread will now exit.') logger.fatal(
queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True))) '(While committing) Alert: Your disk or data storage volume is full.'
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
elif item == 'exit': elif item == 'exit':
self.conn.close() self.conn.close()
@ -421,8 +518,18 @@ class sqlThread(threading.Thread):
self.conn.commit() self.conn.commit()
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal('(while movemessagstoprog) Alert: Your disk or data storage volume is full. sqlThread will now exit.') logger.fatal(
queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True))) '(while movemessagstoprog) Alert: Your disk or data storage volume is full.'
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
self.conn.close() self.conn.close()
shutil.move( shutil.move(
@ -437,8 +544,18 @@ class sqlThread(threading.Thread):
self.conn.commit() self.conn.commit()
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal('(while movemessagstoappdata) Alert: Your disk or data storage volume is full. sqlThread will now exit.') logger.fatal(
queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True))) '(while movemessagstoappdata) Alert: Your disk or data storage volume is full.'
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
self.conn.close() self.conn.close()
shutil.move( shutil.move(
@ -451,27 +568,54 @@ class sqlThread(threading.Thread):
self.cur.execute('''delete from sent where folder='trash' ''') self.cur.execute('''delete from sent where folder='trash' ''')
self.conn.commit() self.conn.commit()
try: try:
self.cur.execute( ''' VACUUM ''') self.cur.execute(''' VACUUM ''')
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal('(while deleteandvacuume) Alert: Your disk or data storage volume is full. sqlThread will now exit.') logger.fatal(
queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True))) '(while deleteandvacuume) Alert: Your disk or data storage volume is full.'
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
else: else:
parameters = helper_sql.sqlSubmitQueue.get() parameters = helper_sql.sqlSubmitQueue.get()
rowcount = 0 rowcount = 0
# print 'item', item
# print 'parameters', parameters
try: try:
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
rowcount = self.cur.rowcount rowcount = self.cur.rowcount
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal('(while cur.execute) Alert: Your disk or data storage volume is full. sqlThread will now exit.') logger.fatal(
queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True))) '(while cur.execute) Alert: Your disk or data storage volume is full.'
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
else: else:
logger.fatal('Major error occurred when trying to execute a SQL statement within the sqlThread. Please tell Atheros about this error message or post it in the forum! Error occurred while trying to execute statement: "%s" Here are the parameters; you might want to censor this data with asterisks (***) as it can contain private information: %s. Here is the actual error message thrown by the sqlThread: %s', str(item), str(repr(parameters)), str(err)) logger.fatal(
'Major error occurred when trying to execute a SQL statement within the sqlThread.'
' Please tell Atheros about this error message or post it in the forum!'
' Error occurred while trying to execute statement: "%s" Here are the parameters;'
' you might want to censor this data with asterisks (***)'
' as it can contain private information: %s.'
' Here is the actual error message thrown by the sqlThread: %s',
str(item),
str(repr(parameters)),
str(err))
logger.fatal('This program shall now abruptly exit!') logger.fatal('This program shall now abruptly exit!')
os._exit(0) os._exit(0)

View File

@ -138,6 +138,7 @@ def configureLogging():
def resetLogging(): def resetLogging():
"""Reconfigure logging in runtime when state.appdata dir changed""" """Reconfigure logging in runtime when state.appdata dir changed"""
# pylint: disable=global-statement, used-before-assignment
global logger global logger
for i in logger.handlers: for i in logger.handlers:
logger.removeHandler(i) logger.removeHandler(i)

View File

@ -113,6 +113,7 @@ PACKAGES = {
def detectOS(): def detectOS():
"""Finding out what Operating System is running"""
if detectOS.result is not None: if detectOS.result is not None:
return detectOS.result return detectOS.result
if sys.platform.startswith('openbsd'): if sys.platform.startswith('openbsd'):
@ -132,6 +133,7 @@ detectOS.result = None
def detectOSRelease(): def detectOSRelease():
"""Detecting the release of OS"""
with open("/etc/os-release", 'r') as osRelease: with open("/etc/os-release", 'r') as osRelease:
version = None version = None
for line in osRelease: for line in osRelease:
@ -148,6 +150,7 @@ def detectOSRelease():
def try_import(module, log_extra=False): def try_import(module, log_extra=False):
"""Try to import the non imported packages"""
try: try:
return import_module(module) return import_module(module)
except ImportError: except ImportError:
@ -208,10 +211,8 @@ def check_sqlite():
).fetchone()[0] ).fetchone()[0]
logger.info('SQLite Library Source ID: %s', sqlite_source_id) logger.info('SQLite Library Source ID: %s', sqlite_source_id)
if sqlite_version_number >= 3006023: if sqlite_version_number >= 3006023:
compile_options = ', '.join(map( compile_options = ', '.join(
lambda row: row[0], [row[0] for row in conn.execute('PRAGMA compile_options;')])
conn.execute('PRAGMA compile_options;')
))
logger.info( logger.info(
'SQLite Library Compile Options: %s', compile_options) 'SQLite Library Compile Options: %s', compile_options)
# There is no specific version requirement as yet, so we just # There is no specific version requirement as yet, so we just
@ -236,7 +237,8 @@ def check_openssl():
Here we are checking for openssl with its all dependent libraries Here we are checking for openssl with its all dependent libraries
and version checking. and version checking.
""" """
# pylint: disable=too-many-branches, too-many-return-statements
# pylint: disable=protected-access, redefined-outer-name
ctypes = try_import('ctypes') ctypes = try_import('ctypes')
if not ctypes: if not ctypes:
logger.error('Unable to check OpenSSL.') logger.error('Unable to check OpenSSL.')
@ -300,7 +302,7 @@ def check_openssl():
' ECDH, and ECDSA enabled.') ' ECDH, and ECDSA enabled.')
return False return False
matches = cflags_regex.findall(openssl_cflags) matches = cflags_regex.findall(openssl_cflags)
if len(matches) > 0: if matches:
logger.error( logger.error(
'This OpenSSL library is missing the following required' 'This OpenSSL library is missing the following required'
' features: %s. PyBitmessage requires OpenSSL 0.9.8b' ' features: %s. PyBitmessage requires OpenSSL 0.9.8b'
@ -311,13 +313,13 @@ def check_openssl():
return False return False
# TODO: The minimum versions of pythondialog and dialog need to be determined # ..todo:: The minimum versions of pythondialog and dialog need to be determined
def check_curses(): def check_curses():
"""Do curses dependency check. """Do curses dependency check.
Here we are checking for curses if available or not with check Here we are checking for curses if available or not with check as interface
as interface requires the pythondialog\ package and the dialog requires the `pythondialog <https://pypi.org/project/pythondialog>`_ package
utility. and the dialog utility.
""" """
if sys.hexversion < 0x20600F0: if sys.hexversion < 0x20600F0:
logger.error( logger.error(
@ -419,8 +421,8 @@ def check_dependencies(verbose=False, optional=False):
if sys.hexversion >= 0x3000000: if sys.hexversion >= 0x3000000:
logger.error( logger.error(
'PyBitmessage does not support Python 3+. Python 2.7.4' 'PyBitmessage does not support Python 3+. Python 2.7.4'
' or greater is required.') ' or greater is required. Python 2.7.18 is recommended.')
has_all_dependencies = False sys.exit()
check_functions = [check_ripemd160, check_sqlite, check_openssl] check_functions = [check_ripemd160, check_sqlite, check_openssl]
if optional: if optional:

View File

@ -1,22 +1,28 @@
"""This module is for generating ack payload.""" """
This module is for generating ack payload
"""
import highlevelcrypto
import helper_random
from binascii import hexlify from binascii import hexlify
from struct import pack from struct import pack
from addresses import encodeVarint
# This function generates payload objects for message acknowledgements import helper_random
# Several stealth levels are available depending on the privacy needs; import highlevelcrypto
# a higher level means better stealth, but also higher cost (size+POW) from addresses import encodeVarint
# - level 0: a random 32-byte sequence with a message header appended
# - level 1: a getpubkey request for a (random) dummy key hash
# - level 2: a standard message, encrypted to a random pubkey
def genAckPayload(streamNumber=1, stealthLevel=0): def genAckPayload(streamNumber=1, stealthLevel=0):
"""Generate and return payload obj.""" """
if (stealthLevel == 2): # Generate privacy-enhanced payload Generate and return payload obj.
This function generates payload objects for message acknowledgements
Several stealth levels are available depending on the privacy needs;
a higher level means better stealth, but also higher cost (size+POW)
- level 0: a random 32-byte sequence with a message header appended
- level 1: a getpubkey request for a (random) dummy key hash
- level 2: a standard message, encrypted to a random pubkey
"""
if stealthLevel == 2: # Generate privacy-enhanced payload
# Generate a dummy privkey and derive the pubkey # Generate a dummy privkey and derive the pubkey
dummyPubKeyHex = highlevelcrypto.privToPub( dummyPubKeyHex = highlevelcrypto.privToPub(
hexlify(helper_random.randomBytes(32))) hexlify(helper_random.randomBytes(32)))
@ -29,7 +35,7 @@ def genAckPayload(streamNumber=1, stealthLevel=0):
acktype = 2 # message acktype = 2 # message
version = 1 version = 1
elif (stealthLevel == 1): # Basic privacy payload (random getpubkey) elif stealthLevel == 1: # Basic privacy payload (random getpubkey)
ackdata = helper_random.randomBytes(32) ackdata = helper_random.randomBytes(32)
acktype = 0 # getpubkey acktype = 0 # getpubkey
version = 4 version = 4

14
src/helper_addressbook.py Normal file
View File

@ -0,0 +1,14 @@
"""
Insert value into addressbook
"""
from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute
def insert(address, label):
"""perform insert into addressbook"""
if address not in BMConfigParser().addresses():
return sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', label, address) == 1
return False

View File

@ -1,10 +1,19 @@
"""
Calculates bitcoin and testnet address from pubkey
"""
import hashlib import hashlib
from debug import logger
from pyelliptic import arithmetic from pyelliptic import arithmetic
# This function expects that pubkey begin with \x04
def calculateBitcoinAddressFromPubkey(pubkey): def calculateBitcoinAddressFromPubkey(pubkey):
"""Calculate bitcoin address from given pubkey (65 bytes long hex string)"""
if len(pubkey) != 65: if len(pubkey) != 65:
print 'Could not calculate Bitcoin address from pubkey because function was passed a pubkey that was', len(pubkey), 'bytes long rather than 65.' logger.error('Could not calculate Bitcoin address from pubkey because'
' function was passed a pubkey that was'
' %i bytes long rather than 65.', len(pubkey))
return "error" return "error"
ripe = hashlib.new('ripemd160') ripe = hashlib.new('ripemd160')
sha = hashlib.new('sha256') sha = hashlib.new('sha256')
@ -24,8 +33,11 @@ def calculateBitcoinAddressFromPubkey(pubkey):
def calculateTestnetAddressFromPubkey(pubkey): def calculateTestnetAddressFromPubkey(pubkey):
"""This function expects that pubkey begin with the testnet prefix"""
if len(pubkey) != 65: if len(pubkey) != 65:
print 'Could not calculate Bitcoin address from pubkey because function was passed a pubkey that was', len(pubkey), 'bytes long rather than 65.' logger.error('Could not calculate Bitcoin address from pubkey because'
' function was passed a pubkey that was'
' %i bytes long rather than 65.', len(pubkey))
return "error" return "error"
ripe = hashlib.new('ripemd160') ripe = hashlib.new('ripemd160')
sha = hashlib.new('sha256') sha = hashlib.new('sha256')

View File

@ -1,10 +1,11 @@
"""Helper Inbox performs inbox messagese related operations.""" """Helper Inbox performs inbox messages related operations"""
from helper_sql import sqlExecute, sqlQuery
import queues import queues
from helper_sql import sqlExecute, sqlQuery
def insert(t): def insert(t):
"""Perform an insert into the "inbox" table"""
sqlExecute('''INSERT INTO inbox VALUES (?,?,?,?,?,?,?,?,?,?)''', *t) sqlExecute('''INSERT INTO inbox VALUES (?,?,?,?,?,?,?,?,?,?)''', *t)
# shouldn't emit changedInboxUnread and displayNewInboxMessage # shouldn't emit changedInboxUnread and displayNewInboxMessage
# at the same time # at the same time
@ -12,11 +13,13 @@ def insert(t):
def trash(msgid): def trash(msgid):
"""Mark a message in the `inbox` as `trash`"""
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', msgid) sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', msgid)
queues.UISignalQueue.put(('removeInboxRowByMsgid', msgid)) queues.UISignalQueue.put(('removeInboxRowByMsgid', msgid))
def isMessageAlreadyInInbox(sigHash): def isMessageAlreadyInInbox(sigHash):
"""Check for previous instances of this message"""
queryReturn = sqlQuery( queryReturn = sqlQuery(
'''SELECT COUNT(*) FROM inbox WHERE sighash=?''', sigHash) '''SELECT COUNT(*) FROM inbox WHERE sighash=?''', sigHash)
return queryReturn[0][0] != 0 return queryReturn[0][0] != 0

View File

@ -5,6 +5,11 @@ Message encoding end decoding functions
import string import string
import zlib import zlib
import messagetypes
from bmconfigparser import BMConfigParser
from debug import logger
from tr import _translate
try: try:
import msgpack import msgpack
except ImportError: except ImportError:
@ -13,11 +18,6 @@ except ImportError:
except ImportError: except ImportError:
import fallback.umsgpack.umsgpack as msgpack import fallback.umsgpack.umsgpack as msgpack
import messagetypes
from bmconfigparser import BMConfigParser
from debug import logger
from tr import _translate
BITMESSAGE_ENCODING_IGNORE = 0 BITMESSAGE_ENCODING_IGNORE = 0
BITMESSAGE_ENCODING_TRIVIAL = 1 BITMESSAGE_ENCODING_TRIVIAL = 1
BITMESSAGE_ENCODING_SIMPLE = 2 BITMESSAGE_ENCODING_SIMPLE = 2
@ -25,19 +25,24 @@ BITMESSAGE_ENCODING_EXTENDED = 3
class MsgEncodeException(Exception): class MsgEncodeException(Exception):
"""Exception during message encoding"""
pass pass
class MsgDecodeException(Exception): class MsgDecodeException(Exception):
"""Exception during message decoding"""
pass pass
class DecompressionSizeException(MsgDecodeException): class DecompressionSizeException(MsgDecodeException):
# pylint: disable=super-init-not-called
"""Decompression resulted in too much data (attack protection)"""
def __init__(self, size): def __init__(self, size):
self.size = size self.size = size
class MsgEncode(object): class MsgEncode(object):
"""Message encoder class"""
def __init__(self, message, encoding=BITMESSAGE_ENCODING_SIMPLE): def __init__(self, message, encoding=BITMESSAGE_ENCODING_SIMPLE):
self.data = None self.data = None
self.encoding = encoding self.encoding = encoding
@ -52,6 +57,7 @@ class MsgEncode(object):
raise MsgEncodeException("Unknown encoding %i" % (encoding)) raise MsgEncodeException("Unknown encoding %i" % (encoding))
def encodeExtended(self, message): def encodeExtended(self, message):
"""Handle extended encoding"""
try: try:
msgObj = messagetypes.message.Message() msgObj = messagetypes.message.Message()
self.data = zlib.compress(msgpack.dumps(msgObj.encode(message)), 9) self.data = zlib.compress(msgpack.dumps(msgObj.encode(message)), 9)
@ -64,15 +70,18 @@ class MsgEncode(object):
self.length = len(self.data) self.length = len(self.data)
def encodeSimple(self, message): def encodeSimple(self, message):
"""Handle simple encoding"""
self.data = 'Subject:%(subject)s\nBody:%(body)s' % message self.data = 'Subject:%(subject)s\nBody:%(body)s' % message
self.length = len(self.data) self.length = len(self.data)
def encodeTrivial(self, message): def encodeTrivial(self, message):
"""Handle trivial encoding"""
self.data = message['body'] self.data = message['body']
self.length = len(self.data) self.length = len(self.data)
class MsgDecode(object): class MsgDecode(object):
"""Message decoder class"""
def __init__(self, encoding, data): def __init__(self, encoding, data):
self.encoding = encoding self.encoding = encoding
if self.encoding == BITMESSAGE_ENCODING_EXTENDED: if self.encoding == BITMESSAGE_ENCODING_EXTENDED:
@ -88,6 +97,7 @@ class MsgDecode(object):
self.subject = _translate("MsgDecode", "Unknown encoding") self.subject = _translate("MsgDecode", "Unknown encoding")
def decodeExtended(self, data): def decodeExtended(self, data):
"""Handle extended encoding"""
dc = zlib.decompressobj() dc = zlib.decompressobj()
tmp = "" tmp = ""
while len(tmp) <= BMConfigParser().safeGetInt("zlib", "maxsize"): while len(tmp) <= BMConfigParser().safeGetInt("zlib", "maxsize"):
@ -131,6 +141,7 @@ class MsgDecode(object):
self.body = msgObj.body self.body = msgObj.body
def decodeSimple(self, data): def decodeSimple(self, data):
"""Handle simple encoding"""
bodyPositionIndex = string.find(data, '\nBody:') bodyPositionIndex = string.find(data, '\nBody:')
if bodyPositionIndex > 1: if bodyPositionIndex > 1:
subject = data[8:bodyPositionIndex] subject = data[8:bodyPositionIndex]

View File

@ -2,7 +2,9 @@
import os import os
import random import random
from pyelliptic.openssl import OpenSSL from pyelliptic.openssl import OpenSSL
NoneType = type(None) NoneType = type(None)
@ -56,8 +58,7 @@ def randomrandrange(x, y=None):
""" """
if isinstance(y, NoneType): if isinstance(y, NoneType):
return random.randrange(x) # nosec return random.randrange(x) # nosec
else: return random.randrange(x, y) # nosec
return random.randrange(x, y) # nosec
def randomchoice(population): def randomchoice(population):

View File

@ -1,85 +1,113 @@
#!/usr/bin/python2.7 """
Additional SQL helper for searching messages.
Used by :mod:`.bitmessageqt`.
"""
from helper_sql import * from helper_sql import sqlQuery
from tr import _translate
try:
from PyQt4 import QtGui
haveQt = True
except ImportError:
haveQt = False
def search_translate (context, text): def search_sql(
if haveQt: xAddress='toaddress', account=None, folder='inbox', where=None,
return QtGui.QApplication.translate(context, text) what=None, unreadOnly=False
else: ):
return text.lower() """
Search for messages from given account and folder having search term
in one of it's fields.
def search_sql(xAddress = "toaddress", account = None, folder = "inbox", where = None, what = None, unreadOnly = False): :param str xAddress: address field checked
if what is not None and what != "": ('fromaddress', 'toaddress' or 'both')
what = "%" + what + "%" :param account: the account which is checked
if where == search_translate("MainWindow", "To"): :type account: :class:`.bitmessageqt.account.BMAccount`
where = "toaddress" instance
elif where == search_translate("MainWindow", "From"): :param str folder: the folder which is checked
where = "fromaddress" :param str where: message field which is checked ('toaddress',
elif where == search_translate("MainWindow", "Subject"): 'fromaddress', 'subject' or 'message'), by default check any field
where = "subject" :param str what: the search term
elif where == search_translate("MainWindow", "Message"): :param bool unreadOnly: if True, search only for unread messages
where = "message" :return: all messages where <where> field contains <what>
:rtype: list[list]
"""
# pylint: disable=too-many-arguments, too-many-branches
if what:
what = '%' + what + '%'
if where == _translate("MainWindow", "To"):
where = 'toaddress'
elif where == _translate("MainWindow", "From"):
where = 'fromaddress'
elif where == _translate("MainWindow", "Subject"):
where = 'subject'
elif where == _translate("MainWindow", "Message"):
where = 'message'
else: else:
where = "toaddress || fromaddress || subject || message" where = 'toaddress || fromaddress || subject || message'
else:
what = None
if folder == "sent": sqlStatementBase = 'SELECT toaddress, fromaddress, subject, ' + (
sqlStatementBase = ''' 'status, ackdata, lastactiontime FROM sent ' if folder == 'sent'
SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime else 'folder, msgid, received, read FROM inbox '
FROM sent ''' )
else:
sqlStatementBase = '''SELECT folder, msgid, toaddress, fromaddress, subject, received, read
FROM inbox '''
sqlStatementParts = [] sqlStatementParts = []
sqlArguments = [] sqlArguments = []
if account is not None: if account is not None:
if xAddress == 'both': if xAddress == 'both':
sqlStatementParts.append("(fromaddress = ? OR toaddress = ?)") sqlStatementParts.append('(fromaddress = ? OR toaddress = ?)')
sqlArguments.append(account) sqlArguments.append(account)
sqlArguments.append(account) sqlArguments.append(account)
else: else:
sqlStatementParts.append(xAddress + " = ? ") sqlStatementParts.append(xAddress + ' = ? ')
sqlArguments.append(account) sqlArguments.append(account)
if folder is not None: if folder is not None:
if folder == "new": if folder == 'new':
folder = "inbox" folder = 'inbox'
unreadOnly = True unreadOnly = True
sqlStatementParts.append("folder = ? ") sqlStatementParts.append('folder = ? ')
sqlArguments.append(folder) sqlArguments.append(folder)
else: else:
sqlStatementParts.append("folder != ?") sqlStatementParts.append('folder != ?')
sqlArguments.append("trash") sqlArguments.append('trash')
if what is not None: if what:
sqlStatementParts.append("%s LIKE ?" % (where)) sqlStatementParts.append('%s LIKE ?' % (where))
sqlArguments.append(what) sqlArguments.append(what)
if unreadOnly: if unreadOnly:
sqlStatementParts.append("read = 0") sqlStatementParts.append('read = 0')
if len(sqlStatementParts) > 0: if sqlStatementParts:
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts) sqlStatementBase += 'WHERE ' + ' AND '.join(sqlStatementParts)
if folder == "sent": if folder == 'sent':
sqlStatementBase += " ORDER BY lastactiontime" sqlStatementBase += ' ORDER BY lastactiontime'
return sqlQuery(sqlStatementBase, sqlArguments) return sqlQuery(sqlStatementBase, sqlArguments)
def check_match(toAddress, fromAddress, subject, message, where = None, what = None):
if what is not None and what != "": def check_match(
if where in (search_translate("MainWindow", "To"), search_translate("MainWindow", "All")): toAddress, fromAddress, subject, message, where=None, what=None):
if what.lower() not in toAddress.lower(): """
return False Check if a single message matches a filter (used when new messages
elif where in (search_translate("MainWindow", "From"), search_translate("MainWindow", "All")): are added to messagelists)
if what.lower() not in fromAddress.lower(): """
return False # pylint: disable=too-many-arguments
elif where in (search_translate("MainWindow", "Subject"), search_translate("MainWindow", "All")): if not what:
if what.lower() not in subject.lower(): return True
return False
elif where in (search_translate("MainWindow", "Message"), search_translate("MainWindow", "All")): if where in (
if what.lower() not in message.lower(): _translate("MainWindow", "To"), _translate("MainWindow", "All")
return False ):
if what.lower() not in toAddress.lower():
return False
elif where in (
_translate("MainWindow", "From"), _translate("MainWindow", "All")
):
if what.lower() not in fromAddress.lower():
return False
elif where in (
_translate("MainWindow", "Subject"),
_translate("MainWindow", "All")
):
if what.lower() not in subject.lower():
return False
elif where in (
_translate("MainWindow", "Message"),
_translate("MainWindow", "All")
):
if what.lower() not in message.lower():
return False
return True return True

View File

@ -1,4 +1,48 @@
from helper_sql import * """
Insert values into sent table
"""
def insert(t): import time
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t) import uuid
from addresses import decodeAddress
from bmconfigparser import BMConfigParser
from helper_ackPayload import genAckPayload
from helper_sql import sqlExecute
# pylint: disable=too-many-arguments
def insert(msgid=None, toAddress='[Broadcast subscribers]', fromAddress=None, subject=None,
message=None, status='msgqueued', ripe=None, ackdata=None, sentTime=None,
lastActionTime=None, sleeptill=0, retryNumber=0, encoding=2, ttl=None, folder='sent'):
"""Perform an insert into the `sent` table"""
# pylint: disable=unused-variable
# pylint: disable-msg=too-many-locals
valid_addr = True
if not ripe or not ackdata:
addr = fromAddress if toAddress == '[Broadcast subscribers]' else toAddress
new_status, addressVersionNumber, streamNumber, new_ripe = decodeAddress(addr)
valid_addr = True if new_status == 'success' else False
if not ripe:
ripe = new_ripe
if not ackdata:
stealthLevel = BMConfigParser().safeGetInt(
'bitmessagesettings', 'ackstealthlevel')
new_ackdata = genAckPayload(streamNumber, stealthLevel)
ackdata = new_ackdata
if valid_addr:
msgid = msgid if msgid else uuid.uuid4().bytes
sentTime = sentTime if sentTime else int(time.time()) # sentTime (this doesn't change)
lastActionTime = lastActionTime if lastActionTime else int(time.time())
ttl = ttl if ttl else BMConfigParser().getint('bitmessagesettings', 'ttl')
t = (msgid, toAddress, ripe, fromAddress, subject, message, ackdata,
sentTime, lastActionTime, sleeptill, status, retryNumber, folder,
encoding, ttl)
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
return ackdata
else:
return None

View File

@ -16,26 +16,34 @@ SQLite objects can only be used from one thread.
or isn't thread-safe. or isn't thread-safe.
""" """
import threading
import Queue import Queue
import threading
sqlSubmitQueue = Queue.Queue() sqlSubmitQueue = Queue.Queue()
"""the queue for SQL""" """the queue for SQL"""
sqlReturnQueue = Queue.Queue() sqlReturnQueue = Queue.Queue()
"""the queue for results""" """the queue for results"""
sqlLock = threading.Lock() sql_lock = threading.Lock()
""" lock to prevent queueing a new request until the previous response
is available """
sql_available = False
"""set to True by `.threads.sqlThread` immediately upon start"""
sql_ready = threading.Event()
"""set by `.threads.sqlThread` when ready for processing (after
initialization is done)"""
def sqlQuery(sqlStatement, *args): def sqlQuery(sql_statement, *args):
""" """
Query sqlite and return results Query sqlite and return results
:param str sqlStatement: SQL statement string :param str sql_statement: SQL statement string
:param list args: SQL query parameters :param list args: SQL query parameters
:rtype: list :rtype: list
""" """
sqlLock.acquire() assert sql_available
sqlSubmitQueue.put(sqlStatement) sql_lock.acquire()
sqlSubmitQueue.put(sql_statement)
if args == (): if args == ():
sqlSubmitQueue.put('') sqlSubmitQueue.put('')
@ -44,44 +52,48 @@ def sqlQuery(sqlStatement, *args):
else: else:
sqlSubmitQueue.put(args) sqlSubmitQueue.put(args)
queryreturn, _ = sqlReturnQueue.get() queryreturn, _ = sqlReturnQueue.get()
sqlLock.release() sql_lock.release()
return queryreturn return queryreturn
def sqlExecuteChunked(sqlStatement, idCount, *args): def sqlExecuteChunked(sql_statement, idCount, *args):
"""Execute chunked SQL statement to avoid argument limit"""
# SQLITE_MAX_VARIABLE_NUMBER, # SQLITE_MAX_VARIABLE_NUMBER,
# unfortunately getting/setting isn't exposed to python # unfortunately getting/setting isn't exposed to python
assert sql_available
sqlExecuteChunked.chunkSize = 999 sqlExecuteChunked.chunkSize = 999
if idCount == 0 or idCount > len(args): if idCount == 0 or idCount > len(args):
return 0 return 0
totalRowCount = 0 total_row_count = 0
with sqlLock: with sql_lock:
for i in range( for i in range(
len(args) - idCount, len(args), len(args) - idCount, len(args),
sqlExecuteChunked.chunkSize - (len(args) - idCount) sqlExecuteChunked.chunkSize - (len(args) - idCount)
): ):
chunk_slice = args[ chunk_slice = args[
i:i + sqlExecuteChunked.chunkSize - (len(args) - idCount) i:i + sqlExecuteChunked.chunkSize - (len(args) - idCount)
] ]
sqlSubmitQueue.put( sqlSubmitQueue.put(
sqlStatement.format(','.join('?' * len(chunk_slice))) sql_statement.format(','.join('?' * len(chunk_slice)))
) )
# first static args, and then iterative chunk # first static args, and then iterative chunk
sqlSubmitQueue.put( sqlSubmitQueue.put(
args[0:len(args) - idCount] + chunk_slice args[0:len(args) - idCount] + chunk_slice
) )
retVal = sqlReturnQueue.get() ret_val = sqlReturnQueue.get()
totalRowCount += retVal[1] total_row_count += ret_val[1]
sqlSubmitQueue.put('commit') sqlSubmitQueue.put('commit')
return totalRowCount return total_row_count
def sqlExecute(sqlStatement, *args): def sqlExecute(sql_statement, *args):
sqlLock.acquire() """Execute SQL statement (optionally with arguments)"""
sqlSubmitQueue.put(sqlStatement) assert sql_available
sql_lock.acquire()
sqlSubmitQueue.put(sql_statement)
if args == (): if args == ():
sqlSubmitQueue.put('') sqlSubmitQueue.put('')
@ -89,30 +101,34 @@ def sqlExecute(sqlStatement, *args):
sqlSubmitQueue.put(args) sqlSubmitQueue.put(args)
_, rowcount = sqlReturnQueue.get() _, rowcount = sqlReturnQueue.get()
sqlSubmitQueue.put('commit') sqlSubmitQueue.put('commit')
sqlLock.release() sql_lock.release()
return rowcount return rowcount
def sqlStoredProcedure(procName): def sqlStoredProcedure(procName):
sqlLock.acquire() """Schedule procName to be run"""
assert sql_available
sql_lock.acquire()
sqlSubmitQueue.put(procName) sqlSubmitQueue.put(procName)
sqlLock.release() sql_lock.release()
class SqlBulkExecute: class SqlBulkExecute(object):
"""This is used when you have to execute the same statement in a cycle.""" """This is used when you have to execute the same statement in a cycle."""
def __enter__(self): def __enter__(self):
sqlLock.acquire() sql_lock.acquire()
return self return self
def __exit__(self, exc_type, value, traceback): def __exit__(self, exc_type, value, traceback):
sqlSubmitQueue.put('commit') sqlSubmitQueue.put('commit')
sqlLock.release() sql_lock.release()
@staticmethod @staticmethod
def execute(sqlStatement, *args): def execute(sql_statement, *args):
"""Used for statements that do not return results.""" """Used for statements that do not return results."""
sqlSubmitQueue.put(sqlStatement) assert sql_available
sqlSubmitQueue.put(sql_statement)
if args == (): if args == ():
sqlSubmitQueue.put('') sqlSubmitQueue.put('')

View File

@ -2,11 +2,12 @@
Startup operations. Startup operations.
""" """
# pylint: disable=too-many-branches,too-many-statements # pylint: disable=too-many-branches,too-many-statements
from __future__ import print_function
import logging
import os import os
import platform import platform
import sys import sys
import time
from distutils.version import StrictVersion from distutils.version import StrictVersion
import defaults import defaults
@ -15,6 +16,13 @@ import paths
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
try:
from plugins.plugin import get_plugin
except ImportError:
get_plugin = None
logger = logging.getLogger('default')
# The user may de-select Portable Mode in the settings if they want # The user may de-select Portable Mode in the settings if they want
# the config files to stay in the application data folder. # the config files to stay in the application data folder.
@ -30,14 +38,14 @@ def loadConfig():
needToCreateKeysFile = config.safeGet( needToCreateKeysFile = config.safeGet(
'bitmessagesettings', 'settingsversion') is None 'bitmessagesettings', 'settingsversion') is None
if not needToCreateKeysFile: if not needToCreateKeysFile:
print( logger.info(
'Loading config files from directory specified' 'Loading config files from directory specified'
' on startup: %s' % state.appdata) ' on startup: %s', state.appdata)
else: else:
config.read(paths.lookupExeFolder() + 'keys.dat') config.read(paths.lookupExeFolder() + 'keys.dat')
try: try:
config.get('bitmessagesettings', 'settingsversion') config.get('bitmessagesettings', 'settingsversion')
print('Loading config files from same directory as program.') logger.info('Loading config files from same directory as program.')
needToCreateKeysFile = False needToCreateKeysFile = False
state.appdata = paths.lookupExeFolder() state.appdata = paths.lookupExeFolder()
except: except:
@ -48,7 +56,8 @@ def loadConfig():
needToCreateKeysFile = config.safeGet( needToCreateKeysFile = config.safeGet(
'bitmessagesettings', 'settingsversion') is None 'bitmessagesettings', 'settingsversion') is None
if not needToCreateKeysFile: if not needToCreateKeysFile:
print('Loading existing config files from', state.appdata) logger.info(
'Loading existing config files from %s', state.appdata)
if needToCreateKeysFile: if needToCreateKeysFile:
@ -103,9 +112,10 @@ def loadConfig():
# Just use the same directory as the program and forget about # Just use the same directory as the program and forget about
# the appdata folder # the appdata folder
state.appdata = '' state.appdata = ''
print('Creating new config files in same directory as program.') logger.info(
'Creating new config files in same directory as program.')
else: else:
print('Creating new config files in', state.appdata) logger.info('Creating new config files in %s', state.appdata)
if not os.path.exists(state.appdata): if not os.path.exists(state.appdata):
os.makedirs(state.appdata) os.makedirs(state.appdata)
if not sys.platform.startswith('win'): if not sys.platform.startswith('win'):
@ -255,7 +265,7 @@ def updateConfig():
'bitmessagesettings', 'hidetrayconnectionnotifications', 'false') 'bitmessagesettings', 'hidetrayconnectionnotifications', 'false')
if config.safeGetInt('bitmessagesettings', 'maxoutboundconnections') < 1: if config.safeGetInt('bitmessagesettings', 'maxoutboundconnections') < 1:
config.set('bitmessagesettings', 'maxoutboundconnections', '8') config.set('bitmessagesettings', 'maxoutboundconnections', '8')
print('WARNING: your maximum outbound connections must be a number.') logger.warning('Your maximum outbound connections must be a number.')
# TTL is now user-specifiable. Let's add an option to save # TTL is now user-specifiable. Let's add an option to save
# whatever the user selects. # whatever the user selects.
@ -266,15 +276,47 @@ def updateConfig():
config.save() config.save()
def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections(): def adjustHalfOpenConnectionsLimit():
"""Check for (mainly XP and Vista) limitations""" """Check and satisfy half-open connections limit (mainly XP and Vista)"""
if BMConfigParser().safeGet(
'bitmessagesettings', 'socksproxytype', 'none') != 'none':
state.maximumNumberOfHalfOpenConnections = 4
return
is_limited = False
try: try:
if sys.platform[0:3] == "win": if sys.platform[0:3] == "win":
# Some XP and Vista systems can only have 10 outgoing
# connections at a time.
VER_THIS = StrictVersion(platform.version()) VER_THIS = StrictVersion(platform.version())
return ( is_limited = (
StrictVersion("5.1.2600") <= VER_THIS and StrictVersion("5.1.2600") <= VER_THIS and
StrictVersion("6.0.6000") >= VER_THIS StrictVersion("6.0.6000") >= VER_THIS
) )
return False except ValueError:
except Exception:
pass pass
state.maximumNumberOfHalfOpenConnections = 9 if is_limited else 64
def start_proxyconfig():
"""Check socksproxytype and start any proxy configuration plugin"""
if not get_plugin:
return
config = BMConfigParser()
proxy_type = config.safeGet('bitmessagesettings', 'socksproxytype')
if proxy_type and proxy_type not in ('none', 'SOCKS4a', 'SOCKS5'):
try:
proxyconfig_start = time.time()
if not get_plugin('proxyconfig', name=proxy_type)(config):
raise TypeError()
except TypeError:
# cannot import shutdown here ):
logger.error(
'Failed to run proxy config plugin %s',
proxy_type, exc_info=True)
os._exit(0) # pylint: disable=protected-access
else:
logger.info(
'Started proxy config plugin %s in %s sec',
proxy_type, time.time() - proxyconfig_start)

Some files were not shown because too many files have changed in this diff Show More