From 62163eaf0e219cc044b1f227e81f79b9ca8c5c98 Mon Sep 17 00:00:00 2001 From: Alex Seeholzer Date: Tue, 1 Nov 2016 14:40:35 +0100 Subject: [PATCH] patch: implicit closing of open files; --- helpdesk/management/commands/get_email.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/helpdesk/management/commands/get_email.py b/helpdesk/management/commands/get_email.py index 75ff9d01..55a92a4f 100644 --- a/helpdesk/management/commands/get_email.py +++ b/helpdesk/management/commands/get_email.py @@ -234,17 +234,17 @@ def process_queue(q, logger): logger.info("Found %s messages in local mailbox directory" % str(len(mail))) for m in mail: logger.info("Processing message %s" % str(m)) - f = open(m, 'r') - ticket = ticket_from_message(message=f.read(), queue=q, logger=logger) - if ticket: - logger.info("Successfully processed message %s, ticket/comment created." % str(m)) - try: - # unlink(m) #delete message file if ticket was successful - logger.info("Successfully deleted message %s." % str(m)) - except: - logger.error("Unable to delete message %s." % str(m)) - else: - logger.warn("Message %s was not successfully processed, and will be left in local directory" % str(m)) + with open(m, 'r') as f: + ticket = ticket_from_message(message=f.read(), queue=q, logger=logger) + if ticket: + logger.info("Successfully processed message %s, ticket/comment created." % str(m)) + try: + # unlink(m) #delete message file if ticket was successful + logger.info("Successfully deleted message %s." % str(m)) + except: + logger.error("Unable to delete message %s." % str(m)) + else: + logger.warn("Message %s was not successfully processed, and will be left in local directory" % str(m)) def decodeUnknown(charset, string):