2020-04-03 09:27:37 +00:00
|
|
|
"""Onionr - Private P2P Communication.
|
2019-03-02 19:17:18 +00:00
|
|
|
|
2020-04-03 09:27:37 +00:00
|
|
|
HTTP endpoints for mail plugin
|
|
|
|
"""
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
import ujson as json
|
|
|
|
from flask import Response, request, redirect, Blueprint, abort
|
2020-09-01 22:41:59 +00:00
|
|
|
from flask import send_from_directory
|
2020-04-03 09:27:37 +00:00
|
|
|
import deadsimplekv as simplekv
|
|
|
|
|
|
|
|
from onionrusers import contactmanager
|
|
|
|
from onionrutils import stringvalidators
|
|
|
|
from utils import reconstructhash, identifyhome
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
import loadinbox
|
|
|
|
import sentboxdb
|
|
|
|
"""
|
2019-03-02 19:17:18 +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-04-03 09:27:37 +00:00
|
|
|
"""
|
2019-03-02 19:17:18 +00:00
|
|
|
flask_blueprint = Blueprint('mail', __name__)
|
2019-07-29 18:05:27 +00:00
|
|
|
kv = simplekv.DeadSimpleKV(identifyhome.identify_home() + '/mailcache.dat')
|
2020-09-01 22:41:59 +00:00
|
|
|
root = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
@flask_blueprint.route('/mail/<path:path>', endpoint='mailstatic')
|
|
|
|
def load_mail(path):
|
|
|
|
return send_from_directory(root + '/web/', path)
|
|
|
|
|
|
|
|
|
|
|
|
@flask_blueprint.route('/mail/', endpoint='mailindex')
|
|
|
|
def load_mail_index():
|
|
|
|
return send_from_directory(root + '/web/', 'index.html')
|
|
|
|
|
2019-03-02 19:17:18 +00:00
|
|
|
|
2019-03-11 05:10:37 +00:00
|
|
|
@flask_blueprint.route('/mail/ping')
|
|
|
|
def mail_ping():
|
|
|
|
return 'pong!'
|
|
|
|
|
2019-03-02 19:17:18 +00:00
|
|
|
@flask_blueprint.route('/mail/deletemsg/<block>', methods=['POST'])
|
|
|
|
def mail_delete(block):
|
2019-06-25 23:07:35 +00:00
|
|
|
if not stringvalidators.validate_hash(block):
|
2019-03-03 06:26:55 +00:00
|
|
|
abort(504)
|
2019-07-29 18:05:27 +00:00
|
|
|
block = reconstructhash.deconstruct_hash(block)
|
2019-03-02 19:17:18 +00:00
|
|
|
existing = kv.get('deleted_mail')
|
|
|
|
if existing is None:
|
|
|
|
existing = []
|
|
|
|
if block not in existing:
|
|
|
|
existing.append(block)
|
|
|
|
kv.put('deleted_mail', existing)
|
2019-04-09 17:30:54 +00:00
|
|
|
kv.flush()
|
2019-03-02 19:17:18 +00:00
|
|
|
return 'success'
|
|
|
|
|
|
|
|
@flask_blueprint.route('/mail/getinbox')
|
|
|
|
def list_inbox():
|
2019-07-21 00:29:08 +00:00
|
|
|
return ','.join(loadinbox.load_inbox())
|
2019-03-03 06:26:55 +00:00
|
|
|
|
2019-04-09 17:30:54 +00:00
|
|
|
@flask_blueprint.route('/mail/getsentbox')
|
|
|
|
def list_sentbox():
|
|
|
|
kv.refresh()
|
2019-07-21 00:29:08 +00:00
|
|
|
sentbox_list = sentboxdb.SentBox().listSent()
|
2019-04-09 17:30:54 +00:00
|
|
|
list_copy = list(sentbox_list)
|
|
|
|
deleted = kv.get('deleted_mail')
|
|
|
|
if deleted is None:
|
|
|
|
deleted = []
|
2019-08-09 20:07:32 +00:00
|
|
|
for sent in list_copy:
|
|
|
|
if sent['hash'] in deleted:
|
|
|
|
sentbox_list.remove(sent)
|
2019-06-17 04:24:12 +00:00
|
|
|
continue
|
2019-08-09 20:07:32 +00:00
|
|
|
sent['name'] = contactmanager.ContactManager(sent['peer'], saveUser=False).get_info('name')
|
2019-04-09 17:30:54 +00:00
|
|
|
return json.dumps(sentbox_list)
|