mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-17 10:13:56 -05:00
adapt to starttls interface change in imap_tools
pin imap-tools version to avoid breaking changes improve mail log
This commit is contained in:
parent
c161829803
commit
3c8196527f
2
Pipfile
2
Pipfile
@ -19,7 +19,7 @@ djangorestframework = "~=3.13"
|
|||||||
filelock = "*"
|
filelock = "*"
|
||||||
fuzzywuzzy = {extras = ["speedup"], version = "*"}
|
fuzzywuzzy = {extras = ["speedup"], version = "*"}
|
||||||
gunicorn = "*"
|
gunicorn = "*"
|
||||||
imap-tools = "*"
|
imap-tools = "~=0.53.0"
|
||||||
langdetect = "*"
|
langdetect = "*"
|
||||||
pathvalidate = "*"
|
pathvalidate = "*"
|
||||||
pillow = "~=9.0"
|
pillow = "~=9.0"
|
||||||
|
@ -18,6 +18,7 @@ from imap_tools import MailboxFolderSelectError
|
|||||||
from imap_tools import MailBoxUnencrypted
|
from imap_tools import MailBoxUnencrypted
|
||||||
from imap_tools import MailMessage
|
from imap_tools import MailMessage
|
||||||
from imap_tools import MailMessageFlags
|
from imap_tools import MailMessageFlags
|
||||||
|
from imap_tools.mailbox import MailBoxTls
|
||||||
from paperless_mail.models import MailAccount
|
from paperless_mail.models import MailAccount
|
||||||
from paperless_mail.models import MailRule
|
from paperless_mail.models import MailRule
|
||||||
|
|
||||||
@ -89,14 +90,18 @@ def make_criterias(rule):
|
|||||||
|
|
||||||
|
|
||||||
def get_mailbox(server, port, security):
|
def get_mailbox(server, port, security):
|
||||||
if security == MailAccount.IMAP_SECURITY_NONE:
|
try:
|
||||||
mailbox = MailBoxUnencrypted(server, port)
|
if security == MailAccount.IMAP_SECURITY_NONE:
|
||||||
elif security == MailAccount.IMAP_SECURITY_STARTTLS:
|
mailbox = MailBoxUnencrypted(server, port)
|
||||||
mailbox = MailBox(server, port, starttls=True)
|
elif security == MailAccount.IMAP_SECURITY_STARTTLS:
|
||||||
elif security == MailAccount.IMAP_SECURITY_SSL:
|
mailbox = MailBoxTls(server, port)
|
||||||
mailbox = MailBox(server, port)
|
elif security == MailAccount.IMAP_SECURITY_SSL:
|
||||||
else:
|
mailbox = MailBox(server, port)
|
||||||
raise NotImplementedError("Unknown IMAP security") # pragma: nocover
|
else:
|
||||||
|
raise NotImplementedError("Unknown IMAP security") # pragma: nocover
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error while retrieving mailbox from {server}: {e}")
|
||||||
|
raise
|
||||||
return mailbox
|
return mailbox
|
||||||
|
|
||||||
|
|
||||||
@ -154,32 +159,45 @@ class MailAccountHandler(LoggingMixin):
|
|||||||
self.log("debug", f"Processing mail account {account}")
|
self.log("debug", f"Processing mail account {account}")
|
||||||
|
|
||||||
total_processed_files = 0
|
total_processed_files = 0
|
||||||
|
try:
|
||||||
with get_mailbox(
|
with get_mailbox(
|
||||||
account.imap_server,
|
account.imap_server,
|
||||||
account.imap_port,
|
account.imap_port,
|
||||||
account.imap_security,
|
account.imap_security,
|
||||||
) as M:
|
) as M:
|
||||||
|
|
||||||
try:
|
|
||||||
M.login(account.username, account.password)
|
|
||||||
except Exception:
|
|
||||||
raise MailError(f"Error while authenticating account {account}")
|
|
||||||
|
|
||||||
self.log(
|
|
||||||
"debug",
|
|
||||||
f"Account {account}: Processing " f"{account.rules.count()} rule(s)",
|
|
||||||
)
|
|
||||||
|
|
||||||
for rule in account.rules.order_by("order"):
|
|
||||||
try:
|
try:
|
||||||
total_processed_files += self.handle_mail_rule(M, rule)
|
M.login(account.username, account.password)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log(
|
self.log(
|
||||||
"error",
|
"error",
|
||||||
f"Rule {rule}: Error while processing rule: {e}",
|
f"Error while authenticating account {account}: {e}",
|
||||||
exc_info=True,
|
exc_info=False,
|
||||||
)
|
)
|
||||||
|
return total_processed_files
|
||||||
|
|
||||||
|
self.log(
|
||||||
|
"debug",
|
||||||
|
f"Account {account}: Processing "
|
||||||
|
f"{account.rules.count()} rule(s)",
|
||||||
|
)
|
||||||
|
|
||||||
|
for rule in account.rules.order_by("order"):
|
||||||
|
try:
|
||||||
|
total_processed_files += self.handle_mail_rule(M, rule)
|
||||||
|
except Exception as e:
|
||||||
|
self.log(
|
||||||
|
"error",
|
||||||
|
f"Rule {rule}: Error while processing rule: {e}",
|
||||||
|
exc_info=True,
|
||||||
|
)
|
||||||
|
except MailError:
|
||||||
|
raise
|
||||||
|
except Exception as e:
|
||||||
|
self.log(
|
||||||
|
"error",
|
||||||
|
f"Error while retrieving mailbox {account}: {e}",
|
||||||
|
exc_info=False,
|
||||||
|
)
|
||||||
|
|
||||||
return total_processed_files
|
return total_processed_files
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user