mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-22 16:03:19 +01:00
Wrap IMAP login attempt in a try except, log error if session timeout and exit script gracefully to prevent crashes, to address #568
This commit is contained in:
parent
a2c10edb35
commit
9340e149d5
@ -13,6 +13,8 @@ scripts/get_email.py - Designed to be run from cron, this script checks the
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import base64
|
||||||
|
import binascii
|
||||||
import email
|
import email
|
||||||
import imaplib
|
import imaplib
|
||||||
import mimetypes
|
import mimetypes
|
||||||
@ -21,8 +23,8 @@ from os.path import isfile, join
|
|||||||
import poplib
|
import poplib
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
import base64
|
import ssl
|
||||||
import binascii
|
import sys
|
||||||
from time import ctime
|
from time import ctime
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
@ -201,11 +203,20 @@ def process_queue(q, logger):
|
|||||||
|
|
||||||
logger.info("Attempting IMAP server login")
|
logger.info("Attempting IMAP server login")
|
||||||
|
|
||||||
server.login(q.email_box_user or
|
try:
|
||||||
settings.QUEUE_EMAIL_BOX_USER,
|
server.login(q.email_box_user or
|
||||||
q.email_box_pass or
|
settings.QUEUE_EMAIL_BOX_USER,
|
||||||
settings.QUEUE_EMAIL_BOX_PASSWORD)
|
q.email_box_pass or
|
||||||
server.select(q.email_box_imap_folder)
|
settings.QUEUE_EMAIL_BOX_PASSWORD)
|
||||||
|
server.select(q.email_box_imap_folder)
|
||||||
|
except imaplib.IMAP.abort:
|
||||||
|
logger.error("IMAP login failed. Check that the server is accessible and that the username and password are correct.")
|
||||||
|
server.logout()
|
||||||
|
sys.exit()
|
||||||
|
except ssl.SSLError:
|
||||||
|
logger.error("IMAP login failed due to SSL error. This is often due to a timeout. Please check your connection and try again.")
|
||||||
|
server.logout()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
status, data = server.search(None, 'NOT', 'DELETED')
|
status, data = server.search(None, 'NOT', 'DELETED')
|
||||||
|
Loading…
Reference in New Issue
Block a user