Improve initialization of preprocessor
This commit is contained in:
@@ -440,10 +440,18 @@ class MailAccountHandler(LoggingMixin):
|
||||
def _init_preprocessors(self):
|
||||
self._message_preprocessors: list[MailMessagePreprocessor] = []
|
||||
for preprocessor_type in self._message_preprocessor_types:
|
||||
if preprocessor_type.able_to_run():
|
||||
self._init_preprocessor(preprocessor_type)
|
||||
|
||||
def _init_preprocessor(self, preprocessor_type):
|
||||
if preprocessor_type.able_to_run():
|
||||
try:
|
||||
self._message_preprocessors.append(preprocessor_type())
|
||||
else:
|
||||
self.log.debug(f"Skipping mail preprocessor {preprocessor_type.NAME}")
|
||||
except Exception as e:
|
||||
self.log.warning(
|
||||
f"Error while initializing preprocessor {preprocessor_type.NAME}: {e}",
|
||||
)
|
||||
else:
|
||||
self.log.debug(f"Skipping mail preprocessor {preprocessor_type.NAME}")
|
||||
|
||||
def _correspondent_from_name(self, name: str) -> Optional[Correspondent]:
|
||||
try:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import abc
|
||||
import os
|
||||
from email import message_from_bytes
|
||||
from email import policy
|
||||
from email.message import Message
|
||||
@@ -45,7 +46,11 @@ class MailMessageDecryptor(MailMessagePreprocessor, LoggingMixin):
|
||||
|
||||
@staticmethod
|
||||
def able_to_run() -> bool:
|
||||
return settings.EMAIL_ENABLE_GPG_DECRYPTOR
|
||||
if not settings.EMAIL_ENABLE_GPG_DECRYPTOR:
|
||||
return False
|
||||
if settings.EMAIL_GNUPG_HOME is None:
|
||||
return True
|
||||
return os.path.isdir(settings.EMAIL_GNUPG_HOME)
|
||||
|
||||
def run(self, message: MailMessage) -> MailMessage:
|
||||
if not hasattr(message, "obj"):
|
||||
|
||||
Reference in New Issue
Block a user