2020-02-18 11:32:17 +00:00
|
|
|
"""Onionr - Private P2P Communication.
|
2018-07-16 07:40:58 +00:00
|
|
|
|
2020-02-18 11:32:17 +00:00
|
|
|
Private messages in an email like fashion
|
|
|
|
"""
|
|
|
|
import locale
|
|
|
|
import sys
|
|
|
|
import os
|
2020-04-03 09:27:37 +00:00
|
|
|
|
|
|
|
import ujson as json
|
2020-02-18 11:32:17 +00:00
|
|
|
|
|
|
|
from onionrusers import contactmanager
|
|
|
|
from utils import reconstructhash
|
|
|
|
from onionrutils import bytesconverter
|
2020-02-24 10:45:29 +00:00
|
|
|
import config
|
2020-02-18 11:32:17 +00:00
|
|
|
import notifier
|
|
|
|
"""
|
2018-07-16 07:40:58 +00:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-02-18 11:32:17 +00:00
|
|
|
"""
|
2018-11-03 03:24:14 +00:00
|
|
|
|
2018-08-17 21:50:16 +00:00
|
|
|
locale.setlocale(locale.LC_ALL, '')
|
2018-07-16 07:40:58 +00:00
|
|
|
|
2019-03-02 06:22:59 +00:00
|
|
|
plugin_name = 'pms'
|
2020-10-14 22:28:56 +00:00
|
|
|
PLUGIN_VERSION = '0.1.2'
|
2019-03-02 06:22:59 +00:00
|
|
|
|
2018-11-03 03:24:14 +00:00
|
|
|
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
2019-03-02 19:17:18 +00:00
|
|
|
import sentboxdb, mailapi, loadinbox # import after path insert
|
2020-01-29 03:39:01 +00:00
|
|
|
from onblacklist import on_blacklist_add
|
|
|
|
|
2019-03-02 19:17:18 +00:00
|
|
|
flask_blueprint = mailapi.flask_blueprint
|
2020-09-01 22:41:59 +00:00
|
|
|
security_whitelist = ['mail.mailstatic', 'mail.mailindex']
|
2018-07-16 07:40:58 +00:00
|
|
|
|
2020-02-18 11:32:17 +00:00
|
|
|
|
2019-08-29 09:25:21 +00:00
|
|
|
def add_deleted(keyStore, b_hash):
|
2019-03-02 06:22:59 +00:00
|
|
|
existing = keyStore.get('deleted_mail')
|
2019-08-29 09:25:21 +00:00
|
|
|
bHash = reconstructhash.reconstruct_hash(b_hash)
|
2019-03-02 06:22:59 +00:00
|
|
|
if existing is None:
|
|
|
|
existing = []
|
|
|
|
else:
|
|
|
|
if bHash in existing:
|
|
|
|
return
|
2019-08-29 09:25:21 +00:00
|
|
|
keyStore.put('deleted_mail', existing.append(b_hash))
|
2019-03-02 06:22:59 +00:00
|
|
|
|
2020-02-18 11:32:17 +00:00
|
|
|
|
2019-02-10 18:43:45 +00:00
|
|
|
def on_insertblock(api, data={}):
|
2019-02-11 22:36:43 +00:00
|
|
|
meta = json.loads(data['meta'])
|
2019-06-16 22:34:43 +00:00
|
|
|
if meta['type'] == 'pm':
|
2019-07-24 18:23:31 +00:00
|
|
|
sentboxTools = sentboxdb.SentBox()
|
2019-06-16 22:34:43 +00:00
|
|
|
sentboxTools.addToSent(data['hash'], data['peer'], data['content'], meta['subject'])
|
2019-02-10 18:43:45 +00:00
|
|
|
|
2020-02-18 11:32:17 +00:00
|
|
|
|
2019-08-08 03:45:18 +00:00
|
|
|
def on_processblocks(api, data=None):
|
|
|
|
if data['type'] != 'pm':
|
|
|
|
return
|
2020-04-06 04:21:21 +00:00
|
|
|
notification_func = notifier.notify
|
2019-08-08 03:45:18 +00:00
|
|
|
data['block'].decrypt()
|
2019-08-08 06:25:48 +00:00
|
|
|
metadata = data['block'].bmetadata
|
2018-07-16 07:40:58 +00:00
|
|
|
|
2019-08-08 03:45:18 +00:00
|
|
|
signer = bytesconverter.bytes_to_str(data['block'].signer)
|
|
|
|
user = contactmanager.ContactManager(signer, saveUser=False)
|
|
|
|
name = user.get_info("name")
|
2019-08-08 06:25:48 +00:00
|
|
|
if name != 'anonymous' and name != None:
|
2019-08-08 03:45:18 +00:00
|
|
|
signer = name.title()
|
|
|
|
else:
|
|
|
|
signer = signer[:5]
|
2019-07-21 00:29:08 +00:00
|
|
|
|
2020-04-06 04:21:21 +00:00
|
|
|
|
2019-08-08 03:45:18 +00:00
|
|
|
if data['block'].decrypted:
|
2020-02-26 02:30:04 +00:00
|
|
|
config.reload()
|
2020-04-06 04:21:21 +00:00
|
|
|
|
|
|
|
if config.get('mail.notificationSound', True):
|
|
|
|
notification_func = notifier.notification_with_sound
|
2020-02-24 10:45:29 +00:00
|
|
|
if config.get('mail.notificationSetting', True):
|
2020-04-05 08:52:40 +00:00
|
|
|
if not config.get('mail.strangersNotification', True):
|
|
|
|
if not user.isFriend():
|
|
|
|
return
|
2020-04-06 04:21:21 +00:00
|
|
|
notification_func(title="Onionr Mail - New Message", message="From: %s\n\nSubject: %s" % (signer, metadata['subject']))
|