mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-07 19:08:32 -05:00
Upgrades black to v23, upgrades ruff
This commit is contained in:
@@ -32,7 +32,6 @@ class MailAccountAdminForm(forms.ModelForm):
|
||||
|
||||
|
||||
class MailAccountAdmin(admin.ModelAdmin):
|
||||
|
||||
list_display = ("name", "imap_server", "username")
|
||||
|
||||
fieldsets = [
|
||||
@@ -47,7 +46,6 @@ class MailAccountAdmin(admin.ModelAdmin):
|
||||
|
||||
|
||||
class MailRuleAdmin(admin.ModelAdmin):
|
||||
|
||||
radio_fields = {
|
||||
"attachment_type": admin.VERTICAL,
|
||||
"action": admin.VERTICAL,
|
||||
@@ -122,7 +120,6 @@ class MailRuleAdmin(admin.ModelAdmin):
|
||||
|
||||
class ProcessedMailAdmin(admin.ModelAdmin):
|
||||
class Meta:
|
||||
|
||||
model = ProcessedMail
|
||||
fields = "__all__"
|
||||
|
||||
|
@@ -146,10 +146,8 @@ class TagMailAction(BaseMailAction):
|
||||
"""
|
||||
|
||||
def __init__(self, parameter):
|
||||
|
||||
# The custom tag should look like "apple:<color>"
|
||||
if "apple:" in parameter.lower():
|
||||
|
||||
_, self.color = parameter.split(":")
|
||||
self.color = self.color.strip()
|
||||
|
||||
@@ -163,7 +161,6 @@ class TagMailAction(BaseMailAction):
|
||||
self.color = None
|
||||
|
||||
def get_criteria(self):
|
||||
|
||||
# AppleMail: We only need to check if mails are \Flagged
|
||||
if self.color:
|
||||
return {"flagged": False}
|
||||
@@ -178,7 +175,6 @@ class TagMailAction(BaseMailAction):
|
||||
|
||||
# AppleMail
|
||||
elif self.color:
|
||||
|
||||
# Remove all existing $MailFlagBits
|
||||
M.flag(
|
||||
message_uid,
|
||||
@@ -205,7 +201,6 @@ def mailbox_login(mailbox: MailBox, account: MailAccount):
|
||||
logger = logging.getLogger("paperless_mail")
|
||||
|
||||
try:
|
||||
|
||||
if account.is_token:
|
||||
mailbox.xoauth2(account.username, account.password)
|
||||
else:
|
||||
@@ -253,7 +248,6 @@ def apply_mail_action(
|
||||
message_date = make_aware(message_date)
|
||||
|
||||
try:
|
||||
|
||||
action = get_rule_action(rule)
|
||||
|
||||
with get_mailbox(
|
||||
@@ -477,7 +471,6 @@ class MailAccountHandler(LoggingMixin):
|
||||
account.imap_port,
|
||||
account.imap_security,
|
||||
) as M:
|
||||
|
||||
supports_gmail_labels = "X-GM-EXT-1" in M.client.capabilities
|
||||
supports_auth_plain = "AUTH=PLAIN" in M.client.capabilities
|
||||
|
||||
@@ -520,13 +513,11 @@ class MailAccountHandler(LoggingMixin):
|
||||
M: MailBox,
|
||||
rule: MailRule,
|
||||
):
|
||||
|
||||
self.log("debug", f"Rule {rule}: Selecting folder {rule.folder}")
|
||||
|
||||
try:
|
||||
M.folder.set(rule.folder)
|
||||
except MailboxFolderSelectError as err:
|
||||
|
||||
self.log(
|
||||
"error",
|
||||
f"Unable to access folder {rule.folder}, attempting folder listing",
|
||||
@@ -653,7 +644,6 @@ class MailAccountHandler(LoggingMixin):
|
||||
consume_tasks = list()
|
||||
|
||||
for att in message.attachments:
|
||||
|
||||
if (
|
||||
att.content_disposition != "attachment"
|
||||
and rule.attachment_type
|
||||
@@ -682,7 +672,6 @@ class MailAccountHandler(LoggingMixin):
|
||||
mime_type = magic.from_buffer(att.payload, mime=True)
|
||||
|
||||
if is_mime_type_supported(mime_type):
|
||||
|
||||
os.makedirs(settings.SCRATCH_DIR, exist_ok=True)
|
||||
_, temp_filename = tempfile.mkstemp(
|
||||
prefix="paperless-mail-",
|
||||
|
@@ -4,7 +4,6 @@ from paperless_mail import tasks
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
help = """
|
||||
""".replace(
|
||||
" ",
|
||||
@@ -12,5 +11,4 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
||||
tasks.process_mail_accounts()
|
||||
|
@@ -6,7 +6,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
|
@@ -5,7 +5,6 @@ from django.db.migrations import RunPython
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0001_initial"),
|
||||
]
|
||||
|
@@ -5,7 +5,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0002_auto_20201117_1334"),
|
||||
]
|
||||
|
@@ -5,7 +5,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0003_auto_20201118_1940"),
|
||||
]
|
||||
|
@@ -5,7 +5,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0004_mailrule_order"),
|
||||
]
|
||||
|
@@ -6,7 +6,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("documents", "1011_auto_20210101_2340"),
|
||||
("paperless_mail", "0005_help_texts"),
|
||||
|
@@ -5,7 +5,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0006_auto_20210101_2340"),
|
||||
]
|
||||
|
@@ -5,7 +5,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0007_auto_20210106_0138"),
|
||||
]
|
||||
|
@@ -5,7 +5,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0008_auto_20210516_0940"),
|
||||
]
|
||||
|
@@ -5,7 +5,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0008_auto_20210516_0940"),
|
||||
]
|
||||
|
@@ -30,7 +30,6 @@ def migrate_tags_to_tag(apps, schema_editor):
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0009_mailrule_assign_tags"),
|
||||
]
|
||||
|
@@ -4,7 +4,6 @@ from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0010_auto_20220311_1602"),
|
||||
]
|
||||
|
@@ -5,7 +5,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0011_remove_mailrule_assign_tag"),
|
||||
]
|
||||
|
@@ -4,7 +4,6 @@ from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0009_alter_mailrule_action_alter_mailrule_folder"),
|
||||
("paperless_mail", "0012_alter_mailrule_assign_tags"),
|
||||
|
@@ -5,7 +5,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0013_merge_20220412_1051"),
|
||||
]
|
||||
|
@@ -5,7 +5,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0014_alter_mailrule_action"),
|
||||
]
|
||||
|
@@ -5,7 +5,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0015_alter_mailrule_action"),
|
||||
]
|
||||
|
@@ -7,7 +7,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
("paperless_mail", "0016_mailrule_consumption_scope"),
|
||||
|
@@ -8,7 +8,6 @@ from django.db import models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
("paperless_mail", "0017_mailaccount_owner_mailrule_owner"),
|
||||
|
@@ -230,7 +230,6 @@ class MailRule(document_models.ModelWithOwner):
|
||||
|
||||
|
||||
class ProcessedMail(document_models.ModelWithOwner):
|
||||
|
||||
rule = models.ForeignKey(
|
||||
MailRule,
|
||||
null=False,
|
||||
|
@@ -250,14 +250,12 @@ class MailDocumentParser(DocumentParser):
|
||||
return html
|
||||
|
||||
def generate_pdf_from_mail(self, mail):
|
||||
|
||||
url = self.gotenberg_server + "/forms/chromium/convert/html"
|
||||
self.log("info", "Converting mail to PDF")
|
||||
|
||||
css_file = os.path.join(os.path.dirname(__file__), "templates/output.css")
|
||||
|
||||
with open(css_file, "rb") as css_handle:
|
||||
|
||||
files = {
|
||||
"html": ("index.html", self.mail_to_html(mail)),
|
||||
"css": ("output.css", css_handle),
|
||||
|
@@ -18,7 +18,6 @@ from paperless_mail.models import MailRule
|
||||
)
|
||||
class TestMailLiveServer(TestCase):
|
||||
def setUp(self) -> None:
|
||||
|
||||
self.mail_account_handler = MailAccountHandler()
|
||||
self.account = MailAccount.objects.create(
|
||||
name="test",
|
||||
@@ -35,7 +34,6 @@ class TestMailLiveServer(TestCase):
|
||||
return super().tearDown()
|
||||
|
||||
def test_process_non_gmail_server_flag(self):
|
||||
|
||||
try:
|
||||
rule1 = MailRule.objects.create(
|
||||
name="testrule",
|
||||
@@ -53,9 +51,7 @@ class TestMailLiveServer(TestCase):
|
||||
pass
|
||||
|
||||
def test_process_non_gmail_server_tag(self):
|
||||
|
||||
try:
|
||||
|
||||
rule2 = MailRule.objects.create(
|
||||
name="testrule",
|
||||
account=self.account,
|
||||
|
@@ -78,7 +78,6 @@ class BogusClient:
|
||||
|
||||
|
||||
class BogusMailBox(ContextManager):
|
||||
|
||||
# Common values so tests don't need to remember an accepted login
|
||||
USERNAME: str = "admin"
|
||||
ASCII_PASSWORD: str = "secret"
|
||||
@@ -230,7 +229,6 @@ class TestMail(
|
||||
flagged: bool = False,
|
||||
processed: bool = False,
|
||||
) -> MailMessage:
|
||||
|
||||
if to is None:
|
||||
to = ["tosomeone@somewhere.com"]
|
||||
|
||||
@@ -546,7 +544,7 @@ class TestMail(
|
||||
("*.png", ["f2.png"]),
|
||||
]
|
||||
|
||||
for (pattern, matches) in tests:
|
||||
for pattern, matches in tests:
|
||||
with self.subTest(msg=pattern):
|
||||
self._queue_consumption_tasks_mock.reset_mock()
|
||||
account = MailAccount(name=str(uuid.uuid4()))
|
||||
@@ -567,7 +565,6 @@ class TestMail(
|
||||
)
|
||||
|
||||
def test_handle_mail_account_mark_read(self):
|
||||
|
||||
account = MailAccount.objects.create(
|
||||
name="test",
|
||||
imap_server="",
|
||||
@@ -591,7 +588,6 @@ class TestMail(
|
||||
self.assertEqual(len(self.bogus_mailbox.messages), 3)
|
||||
|
||||
def test_handle_mail_account_delete(self):
|
||||
|
||||
account = MailAccount.objects.create(
|
||||
name="test",
|
||||
imap_server="",
|
||||
@@ -614,7 +610,6 @@ class TestMail(
|
||||
self.assertEqual(len(self.bogus_mailbox.messages), 1)
|
||||
|
||||
def test_handle_mail_account_delete_no_filters(self):
|
||||
|
||||
account = MailAccount.objects.create(
|
||||
name="test",
|
||||
imap_server="",
|
||||
@@ -738,7 +733,6 @@ class TestMail(
|
||||
self.assertEqual(len(self.bogus_mailbox.messages), 3)
|
||||
|
||||
def test_tag_mail_action_applemail_wrong_input(self):
|
||||
|
||||
self.assertRaises(
|
||||
MailError,
|
||||
TagMailAction,
|
||||
@@ -822,7 +816,6 @@ class TestMail(
|
||||
self.assertEqual(len(self.bogus_mailbox.messages_spam), 1)
|
||||
|
||||
def test_error_skip_rule(self):
|
||||
|
||||
account = MailAccount.objects.create(
|
||||
name="test2",
|
||||
imap_server="",
|
||||
@@ -953,7 +946,6 @@ class TestMail(
|
||||
self.assertEqual(self.bogus_mailbox.messages[0].from_, "amazon@amazon.de")
|
||||
|
||||
def test_error_create_correspondent(self):
|
||||
|
||||
account = MailAccount.objects.create(
|
||||
name="test2",
|
||||
imap_server="",
|
||||
@@ -999,7 +991,6 @@ class TestMail(
|
||||
)
|
||||
|
||||
def test_filters(self):
|
||||
|
||||
account = MailAccount.objects.create(
|
||||
name="test3",
|
||||
imap_server="",
|
||||
@@ -1007,7 +998,7 @@ class TestMail(
|
||||
password="secret",
|
||||
)
|
||||
|
||||
for (f_body, f_from, f_to, f_subject, expected_mail_count) in [
|
||||
for f_body, f_from, f_to, f_subject, expected_mail_count in [
|
||||
(None, None, None, "Claim", 1),
|
||||
("electronic", None, None, None, 1),
|
||||
(None, "amazon", None, None, 2),
|
||||
|
@@ -37,7 +37,6 @@ class MailRuleViewSet(ModelViewSet, PassUserMixin):
|
||||
|
||||
|
||||
class MailAccountTestView(GenericAPIView):
|
||||
|
||||
permission_classes = (IsAuthenticated,)
|
||||
serializer_class = MailAccountSerializer
|
||||
|
||||
|
Reference in New Issue
Block a user