From 0a4fc76b61125f3a9a26c5c5679449373be7ec5a Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Thu, 15 Oct 2020 16:45:28 +0200 Subject: [PATCH] optimize import --- app/auth/views/fido.py | 1 + app/config.py | 2 +- app/dashboard/views/batch_import.py | 4 +--- app/dashboard/views/custom_alias.py | 2 -- app/dashboard/views/custom_domain.py | 2 +- app/dashboard/views/enter_sudo.py | 2 +- app/dashboard/views/fido_manage.py | 2 +- app/dashboard/views/fido_setup.py | 3 +-- app/dashboard/views/mailbox_detail.py | 2 +- app/dashboard/views/mfa_setup.py | 2 +- app/dashboard/views/setting.py | 1 - app/email_utils.py | 5 +---- app/models.py | 5 +---- app/pgp_utils.py | 1 - app/spamassassin_utils.py | 5 ++++- 15 files changed, 15 insertions(+), 24 deletions(-) diff --git a/app/auth/views/fido.py b/app/auth/views/fido.py index d2b374d1..b480dd0d 100644 --- a/app/auth/views/fido.py +++ b/app/auth/views/fido.py @@ -1,5 +1,6 @@ import json import secrets + import webauthn from flask import ( request, diff --git a/app/config.py b/app/config.py index f25b4f8f..ca5e4687 100644 --- a/app/config.py +++ b/app/config.py @@ -1,9 +1,9 @@ import os import random +import socket import string import subprocess from urllib.parse import urlparse -import socket from dotenv import load_dotenv diff --git a/app/dashboard/views/batch_import.py b/app/dashboard/views/batch_import.py index 00e4a363..1e190dfe 100644 --- a/app/dashboard/views/batch_import.py +++ b/app/dashboard/views/batch_import.py @@ -1,15 +1,13 @@ import arrow from flask import render_template, flash, request, redirect, url_for from flask_login import login_required, current_user -from flask_wtf import FlaskForm -from wtforms import StringField, validators from app import s3 from app.config import JOB_BATCH_IMPORT from app.dashboard.base import dashboard_bp from app.extensions import db from app.log import LOG -from app.models import CustomDomain, File, BatchImport, Job +from app.models import File, BatchImport, Job from app.utils import random_string diff --git a/app/dashboard/views/custom_alias.py b/app/dashboard/views/custom_alias.py index 670676d1..58c4dd7d 100644 --- a/app/dashboard/views/custom_alias.py +++ b/app/dashboard/views/custom_alias.py @@ -4,9 +4,7 @@ from itsdangerous import TimestampSigner, SignatureExpired from app.config import ( DISABLE_ALIAS_SUFFIX, - ALIAS_DOMAINS, CUSTOM_ALIAS_SECRET, - PREMIUM_ALIAS_DOMAINS, ) from app.dashboard.base import dashboard_bp from app.extensions import db diff --git a/app/dashboard/views/custom_domain.py b/app/dashboard/views/custom_domain.py index 32d0c044..129961ce 100644 --- a/app/dashboard/views/custom_domain.py +++ b/app/dashboard/views/custom_domain.py @@ -3,7 +3,7 @@ from flask_login import login_required, current_user from flask_wtf import FlaskForm from wtforms import StringField, validators -from app.config import EMAIL_SERVERS_WITH_PRIORITY, ALIAS_DOMAINS +from app.config import EMAIL_SERVERS_WITH_PRIORITY from app.dashboard.base import dashboard_bp from app.email_utils import get_email_domain_part from app.extensions import db diff --git a/app/dashboard/views/enter_sudo.py b/app/dashboard/views/enter_sudo.py index c2c4819e..e5f5a33c 100644 --- a/app/dashboard/views/enter_sudo.py +++ b/app/dashboard/views/enter_sudo.py @@ -1,10 +1,10 @@ +from functools import wraps from time import time from flask import render_template, flash, redirect, url_for, session, request from flask_login import login_required, current_user from flask_wtf import FlaskForm from wtforms import PasswordField, validators -from functools import wraps from app.dashboard.base import dashboard_bp from app.log import LOG diff --git a/app/dashboard/views/fido_manage.py b/app/dashboard/views/fido_manage.py index db684868..6a089666 100644 --- a/app/dashboard/views/fido_manage.py +++ b/app/dashboard/views/fido_manage.py @@ -4,10 +4,10 @@ from flask_wtf import FlaskForm from wtforms import HiddenField, validators from app.dashboard.base import dashboard_bp +from app.dashboard.views.enter_sudo import sudo_required from app.extensions import db from app.log import LOG from app.models import RecoveryCode, Fido -from app.dashboard.views.enter_sudo import sudo_required class FidoManageForm(FlaskForm): diff --git a/app/dashboard/views/fido_setup.py b/app/dashboard/views/fido_setup.py index ddc7717c..6ca731ce 100644 --- a/app/dashboard/views/fido_setup.py +++ b/app/dashboard/views/fido_setup.py @@ -1,7 +1,6 @@ import json import secrets import uuid -from time import time import webauthn from flask import render_template, flash, redirect, url_for, session @@ -11,10 +10,10 @@ from wtforms import StringField, HiddenField, validators from app.config import RP_ID, URL from app.dashboard.base import dashboard_bp +from app.dashboard.views.enter_sudo import sudo_required from app.extensions import db from app.log import LOG from app.models import Fido, RecoveryCode -from app.dashboard.views.enter_sudo import sudo_required class FidoTokenForm(FlaskForm): diff --git a/app/dashboard/views/mailbox_detail.py b/app/dashboard/views/mailbox_detail.py index 1f422397..2df0e4fb 100644 --- a/app/dashboard/views/mailbox_detail.py +++ b/app/dashboard/views/mailbox_detail.py @@ -14,7 +14,7 @@ from app.email_utils import email_can_be_used_as_mailbox from app.email_utils import mailbox_already_used, render, send_email from app.extensions import db from app.log import LOG -from app.models import Alias, DeletedAlias, AuthorizedAddress +from app.models import Alias, AuthorizedAddress from app.models import Mailbox from app.pgp_utils import PGPException, load_public_key diff --git a/app/dashboard/views/mfa_setup.py b/app/dashboard/views/mfa_setup.py index afb639e4..0ec18e1c 100644 --- a/app/dashboard/views/mfa_setup.py +++ b/app/dashboard/views/mfa_setup.py @@ -5,9 +5,9 @@ from flask_wtf import FlaskForm from wtforms import StringField, validators from app.dashboard.base import dashboard_bp +from app.dashboard.views.enter_sudo import sudo_required from app.extensions import db from app.log import LOG -from app.dashboard.views.enter_sudo import sudo_required class OtpTokenForm(FlaskForm): diff --git a/app/dashboard/views/setting.py b/app/dashboard/views/setting.py index 62868afa..269127fe 100644 --- a/app/dashboard/views/setting.py +++ b/app/dashboard/views/setting.py @@ -34,7 +34,6 @@ from app.models import ( EmailChange, User, Alias, - DeletedAlias, CustomDomain, Client, AliasGeneratorEnum, diff --git a/app/email_utils.py b/app/email_utils.py index 5b1b97a5..ed5e6956 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -1,14 +1,12 @@ import email import os +import re from email.header import decode_header from email.message import Message -from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.utils import make_msgid, formatdate, parseaddr from smtplib import SMTP -from typing import Optional -import re import arrow import dkim @@ -32,7 +30,6 @@ from app.config import ( SENDER, URL, LANDING_PAGE_URL, - PREMIUM_ALIAS_DOMAINS, ) from app.dns_utils import get_mx_domains from app.extensions import db diff --git a/app/models.py b/app/models.py index 322d7984..5e303591 100644 --- a/app/models.py +++ b/app/models.py @@ -9,7 +9,7 @@ import bcrypt from arrow import Arrow from flask import url_for from flask_login import UserMixin -from sqlalchemy import text, desc, CheckConstraint, and_, func, case +from sqlalchemy import text, desc, CheckConstraint from sqlalchemy_utils import ArrowType from app import s3 @@ -24,9 +24,6 @@ from app.config import ( LANDING_PAGE_URL, FIRST_ALIAS_DOMAIN, DISABLE_ONBOARDING, - PAGE_LIMIT, - ALIAS_DOMAINS, - PREMIUM_ALIAS_DOMAINS, ) from app.errors import AliasInTrashError from app.extensions import db diff --git a/app/pgp_utils.py b/app/pgp_utils.py index c1ac6f7b..a0ccb054 100644 --- a/app/pgp_utils.py +++ b/app/pgp_utils.py @@ -7,7 +7,6 @@ from memory_profiler import memory_usage from app.config import GNUPGHOME from app.log import LOG from app.models import Mailbox, Contact -from app.utils import random_string gpg = gnupg.GPG(gnupghome=GNUPGHOME) gpg.encoding = "utf-8" diff --git a/app/spamassassin_utils.py b/app/spamassassin_utils.py index 0a05f745..e725a6ae 100644 --- a/app/spamassassin_utils.py +++ b/app/spamassassin_utils.py @@ -1,7 +1,10 @@ """Inspired from https://github.com/petermat/spamassassin_client """ -import socket, select, re, logging +import logging +import re +import select +import socket from io import BytesIO from app.log import LOG