From 3421b809f432ee49586df91b627ef70aa3e07cbf Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Tue, 15 Jun 2021 09:33:30 +0300 Subject: Use tasks.check_mail in commands.checkmail --- servo/management/commands/checkmail.py | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/servo/management/commands/checkmail.py b/servo/management/commands/checkmail.py index 07d5727..6a20f2f 100644 --- a/servo/management/commands/checkmail.py +++ b/servo/management/commands/checkmail.py @@ -1,34 +1,12 @@ # -*- coding: utf-8 -*- -import logging -from email.parser import Parser - from django.core.management.base import BaseCommand -from servo.models import Configuration, Note, User +from servo.tasks import check_mail class Command(BaseCommand): help = "Checks IMAP box for new mail" def handle(self, *args, **options): - uid = Configuration.conf('imap_act') - - if uid == '': - raise ValueError('Incoming message user not configured') - - user = User.objects.get(pk=uid) - server = Configuration.get_imap_server() - typ, data = server.search(None, "UnSeen") - - for num in data[0].split(): - #logging.debug("** Processing message %s" % num) - typ, data = server.fetch(num, "(RFC822)") - # parsestr() seems to return an email.message? - msg = Parser().parsestr(data[0][1]) - Note.from_email(msg, user) - #server.copy(num, 'servo') - server.store(num, '+FLAGS', '\\Seen') - - server.close() - server.logout() + check_mail() -- cgit v1.2.3