2014-08-22 20:02:58 -07:00
|
|
|
import logging
|
|
|
|
|
|
2012-06-27 20:45:01 -07:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
|
|
|
|
from django_mailbox.models import Mailbox
|
|
|
|
|
|
2014-08-22 20:02:58 -07:00
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
|
2012-06-27 20:45:01 -07:00
|
|
|
class Command(BaseCommand):
|
|
|
|
|
def handle(self, *args, **options):
|
2012-10-09 05:52:04 +00:00
|
|
|
mailboxes = Mailbox.active_mailboxes.all()
|
2012-06-27 20:45:01 -07:00
|
|
|
if args:
|
2014-08-22 20:02:58 -07:00
|
|
|
mailboxes = mailboxes.filter(
|
|
|
|
|
name=' '.join(args)
|
|
|
|
|
)
|
2012-06-27 20:45:01 -07:00
|
|
|
for mailbox in mailboxes:
|
2014-08-22 20:02:58 -07:00
|
|
|
logger.info(
|
|
|
|
|
'Gathering messages for %s',
|
|
|
|
|
mailbox.name
|
|
|
|
|
)
|
2012-06-28 09:41:31 -07:00
|
|
|
messages = mailbox.get_new_mail()
|
|
|
|
|
for message in messages:
|
2014-08-22 20:02:58 -07:00
|
|
|
logger.info(
|
|
|
|
|
'Received %s (from %s)',
|
|
|
|
|
message.subject,
|
|
|
|
|
message.from_address
|
|
|
|
|
)
|