mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-10-12 02:26:09 -05:00
Chore: Enable ruff FBT (#8645)
This commit is contained in:

committed by
GitHub

parent
b274665e21
commit
e560fa3be0
@@ -121,7 +121,7 @@ class MarkReadMailAction(BaseMailAction):
|
||||
return {"seen": False}
|
||||
|
||||
def post_consume(self, M: MailBox, message_uid: str, parameter: str):
|
||||
M.flag(message_uid, [MailMessageFlags.SEEN], True)
|
||||
M.flag(message_uid, [MailMessageFlags.SEEN], value=True)
|
||||
|
||||
|
||||
class MoveMailAction(BaseMailAction):
|
||||
@@ -142,7 +142,7 @@ class FlagMailAction(BaseMailAction):
|
||||
return {"flagged": False}
|
||||
|
||||
def post_consume(self, M: MailBox, message_uid: str, parameter: str):
|
||||
M.flag(message_uid, [MailMessageFlags.FLAGGED], True)
|
||||
M.flag(message_uid, [MailMessageFlags.FLAGGED], value=True)
|
||||
|
||||
|
||||
class TagMailAction(BaseMailAction):
|
||||
@@ -150,7 +150,7 @@ class TagMailAction(BaseMailAction):
|
||||
A mail action that tags mails after processing.
|
||||
"""
|
||||
|
||||
def __init__(self, parameter: str, supports_gmail_labels: bool):
|
||||
def __init__(self, parameter: str, *, supports_gmail_labels: bool):
|
||||
# The custom tag should look like "apple:<color>"
|
||||
if "apple:" in parameter.lower():
|
||||
_, self.color = parameter.split(":")
|
||||
@@ -188,19 +188,19 @@ class TagMailAction(BaseMailAction):
|
||||
M.flag(
|
||||
message_uid,
|
||||
set(itertools.chain(*APPLE_MAIL_TAG_COLORS.values())),
|
||||
False,
|
||||
value=False,
|
||||
)
|
||||
|
||||
# Set new $MailFlagBits
|
||||
M.flag(message_uid, APPLE_MAIL_TAG_COLORS.get(self.color), True)
|
||||
M.flag(message_uid, APPLE_MAIL_TAG_COLORS.get(self.color), value=True)
|
||||
|
||||
# Set the general \Flagged
|
||||
# This defaults to the "red" flag in AppleMail and
|
||||
# "stars" in Thunderbird or GMail
|
||||
M.flag(message_uid, [MailMessageFlags.FLAGGED], True)
|
||||
M.flag(message_uid, [MailMessageFlags.FLAGGED], value=True)
|
||||
|
||||
elif self.keyword:
|
||||
M.flag(message_uid, [self.keyword], True)
|
||||
M.flag(message_uid, [self.keyword], value=True)
|
||||
|
||||
else:
|
||||
raise MailError("No keyword specified.")
|
||||
@@ -268,7 +268,7 @@ def apply_mail_action(
|
||||
mailbox_login(M, account)
|
||||
M.folder.set(rule.folder)
|
||||
|
||||
action = get_rule_action(rule, supports_gmail_labels)
|
||||
action = get_rule_action(rule, supports_gmail_labels=supports_gmail_labels)
|
||||
try:
|
||||
action.post_consume(M, message_uid, rule.action_parameter)
|
||||
except errors.ImapToolsError:
|
||||
@@ -356,7 +356,7 @@ def queue_consumption_tasks(
|
||||
).delay()
|
||||
|
||||
|
||||
def get_rule_action(rule: MailRule, supports_gmail_labels: bool) -> BaseMailAction:
|
||||
def get_rule_action(rule: MailRule, *, supports_gmail_labels: bool) -> BaseMailAction:
|
||||
"""
|
||||
Returns a BaseMailAction instance for the given rule.
|
||||
"""
|
||||
@@ -370,12 +370,15 @@ def get_rule_action(rule: MailRule, supports_gmail_labels: bool) -> BaseMailActi
|
||||
elif rule.action == MailRule.MailAction.MARK_READ:
|
||||
return MarkReadMailAction()
|
||||
elif rule.action == MailRule.MailAction.TAG:
|
||||
return TagMailAction(rule.action_parameter, supports_gmail_labels)
|
||||
return TagMailAction(
|
||||
rule.action_parameter,
|
||||
supports_gmail_labels=supports_gmail_labels,
|
||||
)
|
||||
else:
|
||||
raise NotImplementedError("Unknown action.") # pragma: no cover
|
||||
|
||||
|
||||
def make_criterias(rule: MailRule, supports_gmail_labels: bool):
|
||||
def make_criterias(rule: MailRule, *, supports_gmail_labels: bool):
|
||||
"""
|
||||
Returns criteria to be applied to MailBox.fetch for the given rule.
|
||||
"""
|
||||
@@ -393,7 +396,10 @@ def make_criterias(rule: MailRule, supports_gmail_labels: bool):
|
||||
if rule.filter_body:
|
||||
criterias["body"] = rule.filter_body
|
||||
|
||||
rule_query = get_rule_action(rule, supports_gmail_labels).get_criteria()
|
||||
rule_query = get_rule_action(
|
||||
rule,
|
||||
supports_gmail_labels=supports_gmail_labels,
|
||||
).get_criteria()
|
||||
if isinstance(rule_query, dict):
|
||||
if len(rule_query) or len(criterias):
|
||||
return AND(**rule_query, **criterias)
|
||||
@@ -563,7 +569,7 @@ class MailAccountHandler(LoggingMixin):
|
||||
total_processed_files += self._handle_mail_rule(
|
||||
M,
|
||||
rule,
|
||||
supports_gmail_labels,
|
||||
supports_gmail_labels=supports_gmail_labels,
|
||||
)
|
||||
except Exception as e:
|
||||
self.log.exception(
|
||||
@@ -588,6 +594,7 @@ class MailAccountHandler(LoggingMixin):
|
||||
self,
|
||||
M: MailBox,
|
||||
rule: MailRule,
|
||||
*,
|
||||
supports_gmail_labels: bool,
|
||||
):
|
||||
folders = [rule.folder]
|
||||
@@ -616,7 +623,7 @@ class MailAccountHandler(LoggingMixin):
|
||||
f"does not exist in account {rule.account}",
|
||||
) from err
|
||||
|
||||
criterias = make_criterias(rule, supports_gmail_labels)
|
||||
criterias = make_criterias(rule, supports_gmail_labels=supports_gmail_labels)
|
||||
|
||||
self.log.debug(
|
||||
f"Rule {rule}: Searching folder with criteria {criterias}",
|
||||
|
Reference in New Issue
Block a user