Add IMAP document souce support, merge with existing POP3 email support, make POP3MailLog generic

This commit is contained in:
Roberto Rosario
2012-03-14 01:25:49 -04:00
parent a234c76326
commit 19b3553705
13 changed files with 795 additions and 71 deletions

View File

@@ -9,8 +9,9 @@ from django.db.models import Q
from job_processor.api import process_job
from lock_manager import Lock, LockError
from .models import POP3Email
from .models import POP3Email, IMAPEmail
from .conf.settings import POP3_TIMEOUT
from .literals import IMAP_LOCK_TIMEOUT
logger = logging.getLogger(__name__)
@@ -39,3 +40,29 @@ def task_fetch_pop3_emails():
task_fetch_single_pop3_email(pop3_email)
except Exception, exc:
logger.error('Unhandled exception: %s' % exc)
def task_fetch_single_imap_email(imap_email):
try:
lock_id = u'task_fetch_iamp_email-%d' % imap_email.pk
logger.debug('trying to acquire lock: %s' % lock_id)
lock = Lock.acquire_lock(lock_id, IMAP_LOCK_TIMEOUT)
logger.debug('acquired lock: %s' % lock_id)
try:
imap_email.fetch_mail()
except Exception, exc:
raise
finally:
lock.release()
except LockError:
logger.error('unable to obtain lock')
pass
def task_fetch_imap_emails():
logger.debug('executing')
for imap_email in IMAPEmail.objects.filter(enabled=True):
try:
task_fetch_single_imap_email(imap_email)
except Exception, exc:
logger.error('Unhandled exception: %s' % exc)