@ -1,5 +1,6 @@
from mailu import models
from mailu import models , utils
from mailu . ui import ui , forms , access
from mailu . ui import ui , forms , access
from flask import current_app as app
import flask
import flask
import flask_login
import flask_login
@ -10,6 +11,8 @@ import wtforms
@ui.route ( ' /fetch/list/<path:user_email> ' , methods = [ ' GET ' ] )
@ui.route ( ' /fetch/list/<path:user_email> ' , methods = [ ' GET ' ] )
@access.owner ( models . User , ' user_email ' )
@access.owner ( models . User , ' user_email ' )
def fetch_list ( user_email ) :
def fetch_list ( user_email ) :
if not app . config [ ' FETCHMAIL_ENABLED ' ] :
flask . abort ( 404 )
user_email = user_email or flask_login . current_user . email
user_email = user_email or flask_login . current_user . email
user = models . User . query . get ( user_email ) or flask . abort ( 404 )
user = models . User . query . get ( user_email ) or flask . abort ( 404 )
return flask . render_template ( ' fetch/list.html ' , user = user )
return flask . render_template ( ' fetch/list.html ' , user = user )
@ -19,13 +22,18 @@ def fetch_list(user_email):
@ui.route ( ' /fetch/create/<path:user_email> ' , methods = [ ' GET ' , ' POST ' ] )
@ui.route ( ' /fetch/create/<path:user_email> ' , methods = [ ' GET ' , ' POST ' ] )
@access.owner ( models . User , ' user_email ' )
@access.owner ( models . User , ' user_email ' )
def fetch_create ( user_email ) :
def fetch_create ( user_email ) :
if not app . config [ ' FETCHMAIL_ENABLED ' ] :
flask . abort ( 404 )
user_email = user_email or flask_login . current_user . email
user_email = user_email or flask_login . current_user . email
user = models . User . query . get ( user_email ) or flask . abort ( 404 )
user = models . User . query . get ( user_email ) or flask . abort ( 404 )
form = forms . FetchForm ( )
form = forms . FetchForm ( )
form . password . validators = [ wtforms . validators . DataRequired ( ) ]
form . password . validators = [ wtforms . validators . DataRequired ( ) ]
utils . formatCSVField ( form . folders )
if form . validate_on_submit ( ) :
if form . validate_on_submit ( ) :
fetch = models . Fetch ( user = user )
fetch = models . Fetch ( user = user )
form . populate_obj ( fetch )
form . populate_obj ( fetch )
if form . folders . data :
fetch . folders = form . folders . data . replace ( ' ' , ' ' ) . split ( ' , ' )
models . db . session . add ( fetch )
models . db . session . add ( fetch )
models . db . session . commit ( )
models . db . session . commit ( )
flask . flash ( ' Fetch configuration created ' )
flask . flash ( ' Fetch configuration created ' )
@ -37,12 +45,17 @@ def fetch_create(user_email):
@ui.route ( ' /fetch/edit/<fetch_id> ' , methods = [ ' GET ' , ' POST ' ] )
@ui.route ( ' /fetch/edit/<fetch_id> ' , methods = [ ' GET ' , ' POST ' ] )
@access.owner ( models . Fetch , ' fetch_id ' )
@access.owner ( models . Fetch , ' fetch_id ' )
def fetch_edit ( fetch_id ) :
def fetch_edit ( fetch_id ) :
if not app . config [ ' FETCHMAIL_ENABLED ' ] :
flask . abort ( 404 )
fetch = models . Fetch . query . get ( fetch_id ) or flask . abort ( 404 )
fetch = models . Fetch . query . get ( fetch_id ) or flask . abort ( 404 )
form = forms . FetchForm ( obj = fetch )
form = forms . FetchForm ( obj = fetch )
utils . formatCSVField ( form . folders )
if form . validate_on_submit ( ) :
if form . validate_on_submit ( ) :
if not form . password . data :
if not form . password . data :
form . password . data = fetch . password
form . password . data = fetch . password
form . populate_obj ( fetch )
form . populate_obj ( fetch )
if form . folders . data :
fetch . folders = form . folders . data . replace ( ' ' , ' ' ) . split ( ' , ' )
models . db . session . commit ( )
models . db . session . commit ( )
flask . flash ( ' Fetch configuration updated ' )
flask . flash ( ' Fetch configuration updated ' )
return flask . redirect (
return flask . redirect (
@ -55,6 +68,8 @@ def fetch_edit(fetch_id):
@access.confirmation_required ( " delete a fetched account " )
@access.confirmation_required ( " delete a fetched account " )
@access.owner ( models . Fetch , ' fetch_id ' )
@access.owner ( models . Fetch , ' fetch_id ' )
def fetch_delete ( fetch_id ) :
def fetch_delete ( fetch_id ) :
if not app . config [ ' FETCHMAIL_ENABLED ' ] :
flask . abort ( 404 )
fetch = models . Fetch . query . get ( fetch_id ) or flask . abort ( 404 )
fetch = models . Fetch . query . get ( fetch_id ) or flask . abort ( 404 )
user = fetch . user
user = fetch . user
models . db . session . delete ( fetch )
models . db . session . delete ( fetch )