1
0
Fork 1
mirror of https://github.com/coddingtonbear/django-mailbox.git synced 2026-07-10 06:48:19 +02:00

flake8 fixes

This commit is contained in:
Pascal F 2023-11-25 06:37:16 +01:00
parent 1c7ddca6ca
commit d55b6d0c8a
No known key found for this signature in database
GPG key ID: 3C576B538F890866
7 changed files with 17 additions and 24 deletions

View file

@ -15,7 +15,6 @@ import email
import logging import logging
import mimetypes import mimetypes
import os.path import os.path
import sys
import uuid import uuid
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
@ -42,7 +41,7 @@ class MailboxQuerySet(models.QuerySet):
for mailbox in self.all(): for mailbox in self.all():
logger.debug('Receiving mail for %s' % mailbox) logger.debug('Receiving mail for %s' % mailbox)
count += sum(1 for i in mailbox.get_new_mail()) count += sum(1 for i in mailbox.get_new_mail())
logger.debug('Received %d %s.', count, 'mails' if count != 1 else 'mail') logger.debug('Received %d %s.', count, 'mail(s)')
class MailboxManager(models.Manager): class MailboxManager(models.Manager):
@ -123,6 +122,13 @@ class Mailbox(models.Model):
objects = MailboxManager() objects = MailboxManager()
active_mailboxes = ActiveMailboxManager() active_mailboxes = ActiveMailboxManager()
class Meta:
verbose_name = _('Mailbox')
verbose_name_plural = _('Mailboxes')
def __str__(self):
return self.name
@property @property
def _protocol_info(self): def _protocol_info(self):
return urlparse(self.uri) return urlparse(self.uri)
@ -448,13 +454,12 @@ class Mailbox(models.Model):
def get_new_mail(self, condition=None): def get_new_mail(self, condition=None):
"""Connect to this transport and fetch new messages.""" """Connect to this transport and fetch new messages."""
new_mail = []
connection = self.get_connection() connection = self.get_connection()
if not connection: if not connection:
return return
for message in connection.get_message(condition): for message in connection.get_message(condition):
msg = self.process_incoming_message(message) msg = self.process_incoming_message(message)
if not msg is None: if msg is not None:
yield msg yield msg
self.last_polling = now() self.last_polling = now()
if django.VERSION >= (1, 5): # Django 1.5 introduces update_fields if django.VERSION >= (1, 5): # Django 1.5 introduces update_fields
@ -483,14 +488,6 @@ class Mailbox(models.Model):
) )
def __str__(self):
return self.name
class Meta:
verbose_name = _('Mailbox')
verbose_name_plural = _('Mailboxes')
class IncomingMessageManager(models.Manager): class IncomingMessageManager(models.Manager):
def get_queryset(self): def get_queryset(self):
return super().get_queryset().filter( return super().get_queryset().filter(
@ -757,7 +754,7 @@ class Message(models.Model):
"""Returns an `email.message.EmailMessage` instance representing the """Returns an `email.message.EmailMessage` instance representing the
contents of this message and all attachments. contents of this message and all attachments.
See [email.message.EmailMessage]_ for more information as to what methods See [email.message.EmailMessage]_ for more information like what methods
and properties are available on `email.message.EmailMessage` instances. and properties are available on `email.message.EmailMessage` instances.
.. note:: .. note::

View file

@ -1,6 +1,5 @@
import gzip import gzip
import os.path import os.path
import sys
import copy import copy
from unittest import mock from unittest import mock
@ -423,7 +422,7 @@ class TestProcessEmail(EmailMessageTestCase):
msg = self.mailbox.process_incoming_message(message) msg = self.mailbox.process_incoming_message(message)
actual_email_object = msg.get_email_object() # actual_email_object = msg.get_email_object()
self.assertTrue(msg.eml.name.endswith('.eml.gz')) self.assertTrue(msg.eml.name.endswith('.eml.gz'))

View file

@ -2,7 +2,7 @@ from unittest import mock
from django.core.management import call_command, CommandError from django.core.management import call_command, CommandError
from django.test import TestCase from django.test import TestCase
import django
class CommandsTestCase(TestCase): class CommandsTestCase(TestCase):
def test_processincomingmessage_no_args(self): def test_processincomingmessage_no_args(self):
@ -21,7 +21,6 @@ class CommandsTestCase(TestCase):
# Make sure that we called with the right arguments # Make sure that we called with the right arguments
self.assertEqual(kwargs['mailbox_name'], mailbox_name) self.assertEqual(kwargs['mailbox_name'], mailbox_name)
def test_processincomingmessage_with_arg(self): def test_processincomingmessage_with_arg(self):
"""Check that processincomingmessage works with mailbox_name given""" """Check that processincomingmessage works with mailbox_name given"""

View file

@ -9,4 +9,3 @@ class EmailTransport:
message = email.message_from_bytes(contents) message = email.message_from_bytes(contents)
return message return message

View file

@ -1,4 +1,4 @@
import sys
from .base import EmailTransport from .base import EmailTransport

View file

@ -63,4 +63,3 @@ class Office365Transport(EmailTransport):
o365message.delete() o365message.delete()
return return