forked from mirror/django-mailbox
Cleaning up management commands for PEP-8 and consistency.
This commit is contained in:
parent
992375fc6b
commit
db6190a295
2 changed files with 27 additions and 9 deletions
|
|
@ -1,17 +1,30 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
from django_mailbox.models import Mailbox
|
from django_mailbox.models import Mailbox
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
mailboxes = Mailbox.active_mailboxes.all()
|
mailboxes = Mailbox.active_mailboxes.all()
|
||||||
if args:
|
if args:
|
||||||
mailboxes = mailboxes.filter(name = ' '.join(args))
|
mailboxes = mailboxes.filter(
|
||||||
|
name=' '.join(args)
|
||||||
|
)
|
||||||
for mailbox in mailboxes:
|
for mailbox in mailboxes:
|
||||||
self.stdout.write('Gathering messages for %s\n' % mailbox.name)
|
logger.info(
|
||||||
|
'Gathering messages for %s',
|
||||||
|
mailbox.name
|
||||||
|
)
|
||||||
messages = mailbox.get_new_mail()
|
messages = mailbox.get_new_mail()
|
||||||
for message in messages:
|
for message in messages:
|
||||||
self.stdout.write('Received %s (from %s)\n' % (
|
logger.info(
|
||||||
message.subject,
|
'Received %s (from %s)',
|
||||||
message.from_address
|
message.subject,
|
||||||
))
|
message.from_address
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,11 @@ from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
from django_mailbox.models import Mailbox
|
from django_mailbox.models import Mailbox
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
args = "<[Mailbox Name (optional)]>"
|
args = "<[Mailbox Name (optional)]>"
|
||||||
command = "Receive incoming mail via stdin"
|
command = "Receive incoming mail via stdin"
|
||||||
|
|
@ -22,14 +24,17 @@ class Command(BaseCommand):
|
||||||
else:
|
else:
|
||||||
mailbox = self.get_mailbox_for_message(message)
|
mailbox = self.get_mailbox_for_message(message)
|
||||||
mailbox.process_incoming_message(message)
|
mailbox.process_incoming_message(message)
|
||||||
logger.info("Message received from %s" % message['from'])
|
logger.info(
|
||||||
|
"Message received from %s",
|
||||||
|
message['from']
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
logger.warning("Message not processable.")
|
logger.warning("Message not processable.")
|
||||||
|
|
||||||
def get_mailbox_by_name(self, name):
|
def get_mailbox_by_name(self, name):
|
||||||
mailbox, created = Mailbox.objects.get_or_create(
|
mailbox, created = Mailbox.objects.get_or_create(
|
||||||
name=name,
|
name=name,
|
||||||
)
|
)
|
||||||
return mailbox
|
return mailbox
|
||||||
|
|
||||||
def get_mailbox_for_message(self, message):
|
def get_mailbox_for_message(self, message):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue