moving mail over to blueprint system
This commit is contained in:
parent
c89bf5b430
commit
c45c016123
8 changed files with 81 additions and 23 deletions
13
onionr/static-data/default-plugins/pms/loadinbox.py
Normal file
13
onionr/static-data/default-plugins/pms/loadinbox.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import onionrblockapi
|
||||
def load_inbox(myCore):
|
||||
inbox_list = []
|
||||
deleted = myCore.keyStore.get('deleted_mail')
|
||||
if deleted is None:
|
||||
deleted = []
|
||||
|
||||
for blockHash in myCore.getBlocksByType('pm'):
|
||||
block = onionrblockapi.Block(blockHash, core=myCore)
|
||||
block.decrypt()
|
||||
if block.decrypted and blockHash not in deleted:
|
||||
inbox_list.append(blockHash)
|
||||
return inbox_list
|
||||
43
onionr/static-data/default-plugins/pms/mailapi.py
Normal file
43
onionr/static-data/default-plugins/pms/mailapi.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
'''
|
||||
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/>.
|
||||
'''
|
||||
import sys, os
|
||||
from flask import Response, request, redirect, Blueprint
|
||||
import core
|
||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
import loadinbox
|
||||
|
||||
flask_blueprint = Blueprint('mail', __name__)
|
||||
c = core.Core()
|
||||
kv = c.keyStore
|
||||
|
||||
@flask_blueprint.route('/mail/deletemsg/<block>', methods=['POST'])
|
||||
def mail_delete(block):
|
||||
assert c._utils.validateHash(block)
|
||||
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():
|
||||
return ','.join(loadinbox.load_inbox(c))
|
||||
|
|
@ -23,21 +23,16 @@ import logger, config, threading, time, readline, datetime
|
|||
from onionrblockapi import Block
|
||||
import onionrexceptions
|
||||
from onionrusers import onionrusers
|
||||
from flask import Response, request, redirect, Blueprint
|
||||
import locale, sys, os, json
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
|
||||
plugin_name = 'pms'
|
||||
PLUGIN_VERSION = '0.0.1'
|
||||
flask_blueprint = Blueprint('mail', __name__)
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
import sentboxdb # import after path insert
|
||||
|
||||
@flask_blueprint.route('/mailhello')
|
||||
def mailhello():
|
||||
return "hello world from mail"
|
||||
import sentboxdb, mailapi, loadinbox # import after path insert
|
||||
flask_blueprint = mailapi.flask_blueprint
|
||||
|
||||
def draw_border(text):
|
||||
#https://stackoverflow.com/a/20757491
|
||||
|
|
@ -83,7 +78,7 @@ class OnionrMail:
|
|||
displayList = []
|
||||
subject = ''
|
||||
|
||||
# this could use a lot of memory if someone has recieved a lot of messages
|
||||
# this could use a lot of memory if someone has received a lot of messages
|
||||
for blockHash in self.myCore.getBlocksByType('pm'):
|
||||
pmBlocks[blockHash] = Block(blockHash, core=self.myCore)
|
||||
pmBlocks[blockHash].decrypt()
|
||||
|
|
@ -327,10 +322,6 @@ def on_pluginrequest(api, data=None):
|
|||
cmd = path.split('/')[1]
|
||||
if cmd == 'sentbox':
|
||||
resp = OnionrMail(api).get_sent_list(display=False)
|
||||
elif cmd == 'deletemsg':
|
||||
print('path', data['path'])
|
||||
#add_deleted(keyStore, data['path'].split('/')[2])
|
||||
resp = 'success'
|
||||
if resp != '':
|
||||
api.get_onionr().clientAPIInst.pluginResponses[data['pluginResponse']] = resp
|
||||
|
||||
|
|
@ -345,5 +336,4 @@ def on_init(api, data = None):
|
|||
mail = OnionrMail(pluginapi)
|
||||
api.commands.register(['mail'], mail.menu)
|
||||
api.commands.register_help('mail', 'Interact with OnionrMail')
|
||||
print("YEET2")
|
||||
return
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ function showSentboxWindow(to, content){
|
|||
overlay('sentboxDisplay')
|
||||
}
|
||||
|
||||
fetch('/getblocksbytype/pm', {
|
||||
fetch('/mail/getinbox', {
|
||||
headers: {
|
||||
"token": webpass
|
||||
}})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue