1
0
Fork 0

updating location of logic for getmail command (#264)

* moving logic for processing all the new emails from all mailboxes to a method under Mailbox so it can be called from other modules

* moving logger lines into handle method as requested
This commit is contained in:
Jace Manshadi 2023-01-24 06:08:47 -08:00 committed by GitHub
parent cefbcdebd2
commit 462fdd3e49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 21 deletions

View file

@ -5,26 +5,7 @@ from django.core.management.base import BaseCommand
from django_mailbox.models import Mailbox
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
class Command(BaseCommand):
def handle(self, *args, **options):
mailboxes = Mailbox.active_mailboxes.all()
if args:
mailboxes = mailboxes.filter(
name=' '.join(args)
)
for mailbox in mailboxes:
logger.info(
'Gathering messages for %s',
mailbox.name
)
messages = mailbox.get_new_mail()
for message in messages:
logger.info(
'Received %s (from %s)',
message.subject,
message.from_address
)
logging.basicConfig(level=logging.INFO)
Mailbox.get_new_mail_all_mailboxes(args)