2019-03-02 19:17:18 +00:00
|
|
|
'''
|
|
|
|
Onionr - P2P Anonymous Storage Network
|
|
|
|
|
|
|
|
HTTP endpoints for mail plugin.
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
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/>.
|
|
|
|
'''
|
2019-03-03 06:26:55 +00:00
|
|
|
import sys, os, json
|
|
|
|
from flask import Response, request, redirect, Blueprint, abort
|
2019-03-02 19:17:18 +00:00
|
|
|
import core
|
2019-03-05 03:16:33 +00:00
|
|
|
from onionrusers import contactmanager
|
2019-03-02 19:17:18 +00:00
|
|
|
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
2019-03-03 06:26:55 +00:00
|
|
|
import loadinbox, sentboxdb
|
2019-03-02 19:17:18 +00:00
|
|
|
|
|
|
|
flask_blueprint = Blueprint('mail', __name__)
|
|
|
|
c = core.Core()
|
|
|
|
kv = c.keyStore
|
|
|
|
|
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-03-03 06:26:55 +00:00
|
|
|
if not c._utils.validateHash(block):
|
|
|
|
abort(504)
|
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)
|
|
|
|
return 'success'
|
|
|
|
|
|
|
|
@flask_blueprint.route('/mail/getinbox')
|
|
|
|
def list_inbox():
|
2019-03-03 06:26:55 +00:00
|
|
|
return ','.join(loadinbox.load_inbox(c))
|
|
|
|
|
|
|
|
@flask_blueprint.route('/mail/getsentbox')
|
|
|
|
def list_sentbox():
|
|
|
|
sentbox_list = sentboxdb.SentBox(c).listSent()
|
|
|
|
sentbox_list_copy = list(sentbox_list)
|
|
|
|
deleted = kv.get('deleted_mail')
|
|
|
|
if deleted is None:
|
|
|
|
deleted = []
|
2019-03-05 17:11:49 +00:00
|
|
|
for x in range(len(sentbox_list_copy) - 1):
|
2019-03-03 06:26:55 +00:00
|
|
|
if sentbox_list_copy[x]['hash'] in deleted:
|
2019-03-04 19:03:35 +00:00
|
|
|
x -= 1
|
2019-03-03 06:26:55 +00:00
|
|
|
sentbox_list.pop(x)
|
2019-03-05 03:16:33 +00:00
|
|
|
else:
|
2019-03-05 17:11:49 +00:00
|
|
|
sentbox_list[x]['name'] = contactmanager.ContactManager(c, sentbox_list_copy[x]['peer'], saveUser=False).get_info('name')
|
2019-03-03 06:26:55 +00:00
|
|
|
|
|
|
|
return json.dumps(sentbox_list)
|