-
Notifications
You must be signed in to change notification settings - Fork 166
/
getmail.py
30 lines (24 loc) · 820 Bytes
/
getmail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import logging
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
)