1
0
Fork 1
mirror of https://github.com/coddingtonbear/django-mailbox.git synced 2026-07-09 22:38:19 +02:00

Utilize read-only method in get_new_mail

This commit is contained in:
Mike Varga 2022-10-14 13:50:40 -04:00
parent 88b35117ae
commit 9c0cac66e2

View file

@ -17,6 +17,7 @@ import mimetypes
import os.path
import sys
import uuid
from datetime import timedelta
from tempfile import NamedTemporaryFile
import django
@ -35,6 +36,8 @@ from django_mailbox.transports import Pop3Transport, ImapTransport, \
logger = logging.getLogger(__name__)
INITIAL_IMPORT_LOOKBACK_DAYS = 365
class MailboxQuerySet(models.QuerySet):
def get_new_mail(self):
@ -420,7 +423,12 @@ class Mailbox(models.Model):
connection = self.get_connection()
if not connection:
return
for message in connection.get_message(condition):
since = self.last_polling
if since is None:
since = now() - timedelta(days=INITIAL_IMPORT_LOOKBACK_DAYS)
for message in connection.get_new_message_ro(since=since):
msg = self.process_incoming_message(message)
if not msg is None:
yield msg