diff --git a/management/commands/get_email.py b/management/commands/get_email.py index 671f44ce..940a476b 100644 --- a/management/commands/get_email.py +++ b/management/commands/get_email.py @@ -57,7 +57,14 @@ def process_email(): def process_queue(q): print "Processing: %s" % q if q.email_box_type == 'pop3': - server = poplib.POP3(q.email_box_host) + + if q.email_box_ssl: + if not q.email_box_port: q.email_box_port = 995 + server = poplib.POP3_SSL(q.email_box_host, q.email_box_port) + else: + if not q.email_box_port: q.email_box_port = 110 + server = poplib.POP3(q.email_box_host, q.email_box_port) + server.getwelcome() server.user(q.email_box_user) server.pass_(q.email_box_pass) @@ -75,9 +82,13 @@ def process_queue(q): server.quit() elif q.email_box_type == 'imap': - if not q.email_box_port: q.email_box_port = 143 + if q.email_box_ssl: + if not q.email_box_port: q.email_box_port = 993 + server = imaplib.IMAP4_SSL(q.email_box_host, q.email_box_port) + else: + if not q.email_box_port: q.email_box_port = 143 + server = imaplib.IMAP4(q.email_box_host, q.email_box_port) - server = imaplib.IMAP4(q.email_box_host, q.email_box_port) server.login(q.email_box_user, q.email_box_pass) server.select(q.email_box_imap_folder) status, data = server.search(None, 'ALL') @@ -150,8 +161,7 @@ def ticket_from_message(message, queue): high_priority_types = ('high', 'important', '1', 'urgent') - if smtp_priority in high_priority_types - or smtp_importance in high_priority_types: + if smtp_priority in high_priority_types or smtp_importance in high_priority_types: priority = 2 if ticket == None: @@ -192,8 +202,7 @@ def ticket_from_message(message, queue): fail_silently=True, ) - if queue.updated_ticket_cc - and queue.updated_ticket_cc != queue.new_ticket_cc: + if queue.updated_ticket_cc and queue.updated_ticket_cc != queue.new_ticket_cc: send_templated_mail( 'newticket_cc', context, diff --git a/models.py b/models.py index 9fa3f93b..7c4a321a 100644 --- a/models.py +++ b/models.py @@ -114,6 +114,14 @@ class Queue(models.Model): 'servers. Leave it blank to use the defaults.'), ) + email_box_ssl = models.BooleanField( + _('Use SSL for E-Mail?'), + blank=True, + null=True, + help_text=_('Whether to use SSL for IMAP or POP3 - the default ports ' + 'when using SSL are 993 for IMAP and 995 for POP3.'), + ) + email_box_user = models.CharField( _('E-Mail Username'), max_length=200, @@ -179,9 +187,13 @@ class Queue(models.Model): self.email_box_imap_folder = 'INBOX' if not self.email_box_port: - if self.email_box_type == 'imap': + if self.email_box_type == 'imap' and self.email_box_ssl: + self.email_box_port = 993 + elif self.email_box_type == 'imap' and not self.email_box_ssl: self.email_box_port = 143 - else: + elif self.email_box_type == 'pop3' and self.email_box_ssl: + self.email_box_port = 995 + elif self.email_box_type == 'pop3' and not self.email_box_ssl: self.email_box_port = 110 super(Queue, self).save() diff --git a/views/api.py b/views/api.py index 45b54743..d74f183f 100644 --- a/views/api.py +++ b/views/api.py @@ -55,7 +55,8 @@ def api(request, method): # TODO: Move away from having the username & password in every request. request.user = authenticate( username=request.POST.get('user', False), - password=request.POST.get('password')) + password=request.POST.get('password'), + ) if request.user is None: return api_return(STATUS_ERROR_PERMISSIONS) diff --git a/views/staff.py b/views/staff.py index 154e1c70..71bc094e 100644 --- a/views/staff.py +++ b/views/staff.py @@ -32,13 +32,17 @@ def dashboard(request): with options for them to 'Take' ownership of said tickets. """ - tickets = Ticket.objects - .filter(assigned_to=request.user) - .exclude(status=Ticket.CLOSED_STATUS) + tickets = Ticket.objects.filter( + assigned_to=request.user, + ).exclude( + status=Ticket.CLOSED_STATUS, + ) - unassigned_tickets = Ticket.objects - .filter(assigned_to__isnull=True) - .exclude(status=Ticket.CLOSED_STATUS) + unassigned_tickets = Ticket.objects.filter( + assigned_to__isnull=True, + ).exclude( + status=Ticket.CLOSED_STATUS, + ) # The following query builds a grid of queues & ticket statuses, # to be displayed to the user. EG: