diff --git a/.env.example b/.env.example index db411580..153d94e6 100644 --- a/.env.example +++ b/.env.example @@ -20,6 +20,8 @@ ADMIN_EMAIL=admin@sl.local MAX_NB_EMAIL_FREE_PLAN=3 # custom domain needs to point to these MX servers EMAIL_SERVERS_WITH_PRIORITY=[(10, "email.hostname.")] +# these emails are ignored when computing stats +IGNORED_EMAILS = ["my_email@domain.com"] # <<< Database >>> # delete and recreate sqlite database diff --git a/app/config.py b/app/config.py index 4d60f853..52ffdd03 100644 --- a/app/config.py +++ b/app/config.py @@ -52,6 +52,12 @@ EMAIL_SERVERS_WITH_PRIORITY = eval( ) # [(10, "email.hostname.")] EMAIL_SERVERS = [es for _, es in EMAIL_SERVERS_WITH_PRIORITY] +# these emails are ignored when computing stats +if os.environ.get("IGNORED_EMAILS"): + IGNORED_EMAILS = eval(os.environ.get("IGNORED_EMAILS")) +else: + IGNORED_EMAILS = [] + # Database DB_URI = os.environ["DB_URI"] diff --git a/cron.py b/cron.py index b597842e..501e0ad2 100644 --- a/cron.py +++ b/cron.py @@ -1,6 +1,7 @@ import arrow from app import email_utils +from app.config import IGNORED_EMAILS from app.extensions import db from app.log import LOG from app.models import ( @@ -15,16 +16,11 @@ from app.models import ( from server import create_app - - -_ignored_emails = ["nguyenkims", "mbpcmeo", "son@simplelogin.io", "demo.simplelogin"] - - def stats(): """send admin stats everyday""" # nb user q = User.query - for ie in _ignored_emails: + for ie in IGNORED_EMAILS: q = q.filter(~User.email.contains(ie)) nb_user = q.count() @@ -33,7 +29,7 @@ def stats(): # nb gen emails q = db.session.query(GenEmail, User).filter(GenEmail.user_id == User.id) - for ie in _ignored_emails: + for ie in IGNORED_EMAILS: q = q.filter(~User.email.contains(ie)) nb_gen_email = q.count() @@ -45,7 +41,7 @@ def stats(): ForwardEmail.gen_email_id == GenEmail.id, GenEmail.user_id == User.id, ) - for ie in _ignored_emails: + for ie in IGNORED_EMAILS: q = q.filter(~User.email.contains(ie)) nb_forward = nb_block = nb_reply = 0