diff --git a/helpdesk/management/commands/get_email.py b/helpdesk/management/commands/get_email.py index c3b9e33f..141683d3 100644 --- a/helpdesk/management/commands/get_email.py +++ b/helpdesk/management/commands/get_email.py @@ -25,6 +25,7 @@ from django.core.files.base import ContentFile from django.core.management.base import BaseCommand from django.db.models import Q from django.utils.translation import ugettext as _ +from django.conf import settings from helpdesk.lib import send_templated_mail, safe_template_context from helpdesk.models import Queue, Ticket, FollowUp, Attachment, IgnoreEmail @@ -75,18 +76,22 @@ def process_email(quiet=False): def process_queue(q, quiet=False): if not quiet: print "Processing: %s" % q - if q.email_box_type == 'pop3': + + email_box_type = settings.QUEUE_EMAIL_BOX_TYPE if settings.QUEUE_EMAIL_BOX_TYPE else q.email_box_type + + if email_box_type == 'pop3': if q.email_box_ssl: if not q.email_box_port: q.email_box_port = 995 - server = poplib.POP3_SSL(q.email_box_host, int(q.email_box_port)) + server = poplib.POP3_SSL(q.email_box_host or settings.QUEUE_EMAIL_BOX_HOST, int(q.email_box_port)) else: if not q.email_box_port: q.email_box_port = 110 - server = poplib.POP3(q.email_box_host, int(q.email_box_port)) + server = poplib.POP3(q.email_box_host or settings.QUEUE_EMAIL_BOX_HOST, int(q.email_box_port)) server.getwelcome() - server.user(q.email_box_user) - server.pass_(q.email_box_pass) + server.user(q.email_box_user or settings.QUEUE_EMAIL_BOX_USER) + server.pass_(q.email_box_pass or settings.QUEUE_EMAIL_BOX_PASSWORD) + messagesInfo = server.list()[1] @@ -102,15 +107,15 @@ def process_queue(q, quiet=False): server.quit() - elif q.email_box_type == 'imap': + elif email_box_type == 'imap': if q.email_box_ssl: if not q.email_box_port: q.email_box_port = 993 - server = imaplib.IMAP4_SSL(q.email_box_host, int(q.email_box_port)) + server = imaplib.IMAP4_SSL(q.email_box_host or settings.QUEUE_EMAIL_BOX_HOST, int(q.email_box_port)) else: if not q.email_box_port: q.email_box_port = 143 - server = imaplib.IMAP4(q.email_box_host, int(q.email_box_port)) + server = imaplib.IMAP4(q.email_box_host or settings.QUEUE_EMAIL_BOX_HOST, int(q.email_box_port)) - server.login(q.email_box_user, q.email_box_pass) + server.login(q.email_box_user or settings.QUEUE_EMAIL_BOX_USER, q.email_box_pass or settings.QUEUE_EMAIL_BOX_PASSWORD) server.select(q.email_box_imap_folder) status, data = server.search(None, 'NOT', 'DELETED') diff --git a/helpdesk/settings.py b/helpdesk/settings.py index 8d7112ce..9fb46bb5 100644 --- a/helpdesk/settings.py +++ b/helpdesk/settings.py @@ -124,3 +124,9 @@ HELPDESK_FOOTER_SHOW_API_LINK = getattr(settings, 'HELPDESK_FOOTER_SHOW_API_LINK # show / hide 'change language' link at bottom of page HELPDESK_FOOTER_SHOW_CHANGE_LANGUAGE_LINK = getattr(settings, 'HELPDESK_FOOTER_SHOW_CHANGE_LANGUAGE_LINK', False) +''' email options ''' +# default Queue email submission settings +QUEUE_EMAIL_BOX_TYPE = getattr(settings, 'QUEUE_EMAIL_BOX_TYPE', None) +QUEUE_EMAIL_BOX_HOST = getattr(settings, 'QUEUE_EMAIL_BOX_HOST', None) +QUEUE_EMAIL_BOX_USER = getattr(settings, 'QUEUE_EMAIL_BOX_USER', None) +QUEUE_EMAIL_BOX_PASSWORD = getattr(settings, 'QUEUE_EMAIL_BOX_PASSWORD', None)